2009-07-02 18:11:22 -07:00
|
|
|
<?php
|
|
|
|
|
class IndustriesController extends AppController {
|
|
|
|
|
|
|
|
|
|
var $name = 'Industries';
|
|
|
|
|
var $helpers = array('Html', 'Form');
|
|
|
|
|
|
2009-07-06 19:11:10 -07:00
|
|
|
var $paginate = array(
|
|
|
|
|
'Industry' => array('order' => array('ParentIndustry.name' => 'asc', 'Industry.name' => 'asc'),
|
|
|
|
|
'limit' => 200
|
|
|
|
|
));
|
|
|
|
|
|
2009-07-02 18:11:22 -07:00
|
|
|
function index() {
|
|
|
|
|
$this->Industry->recursive = 0;
|
2009-07-09 00:09:59 -07:00
|
|
|
$industries = $this->Industry->find('all', array('order'=>'Industry.name ASC'));
|
2009-07-02 18:11:22 -07:00
|
|
|
$this->set('industries', $this->paginate());
|
2009-07-09 00:09:59 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($industries as $industry) {
|
|
|
|
|
if(!$industry['Industry']['parent_id']) {
|
|
|
|
|
$parents[] = $industry['Industry'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->set('parents', $parents);
|
|
|
|
|
|
2009-07-02 18:11:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function view($id = null) {
|
|
|
|
|
if (!$id) {
|
|
|
|
|
$this->Session->setFlash(__('Invalid Industry.', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
|
|
|
|
$this->set('industry', $this->Industry->read(null, $id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function add() {
|
|
|
|
|
if (!empty($this->data)) {
|
2009-07-09 00:09:59 -07:00
|
|
|
|
2009-07-02 18:11:22 -07:00
|
|
|
if ($this->Industry->save($this->data)) {
|
2009-07-09 00:09:59 -07:00
|
|
|
|
|
|
|
|
$newid = $this->Industry->id;
|
|
|
|
|
$new_industry = $this->Industry->findById($newid);
|
|
|
|
|
|
|
|
|
|
if($new_industry['Industry']['parent_id'] == 0) {
|
|
|
|
|
|
|
|
|
|
$this->Industry->create();
|
|
|
|
|
$this->data['Industry']['parent_id'] = $newid;
|
|
|
|
|
$this->data['Industry']['name'] = $new_industry['Industry']['name']." - General";
|
|
|
|
|
$this->Industry->save($this->data);
|
|
|
|
|
}
|
|
|
|
|
$this->Session->setFlash(__('The Industry has been saved', true));
|
2009-07-02 18:11:22 -07:00
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
} else {
|
|
|
|
|
$this->Session->setFlash(__('The Industry could not be saved. Please, try again.', true));
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-09 00:09:59 -07:00
|
|
|
|
|
|
|
|
$this->Industry->create();
|
|
|
|
|
if(isset($this->params['named']['parentid'])) {
|
|
|
|
|
$parent = $this->Industry->find('first', array('conditions' => array('Industry.id' => $this->params['named']['parentid']),
|
|
|
|
|
'fields' => 'Industry.id, Industry.name', 'recursive' => 0));
|
|
|
|
|
$this->set('parent', $parent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-06 19:11:10 -07:00
|
|
|
|
2009-07-02 18:11:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function edit($id = null) {
|
|
|
|
|
if (!$id && empty($this->data)) {
|
|
|
|
|
$this->Session->setFlash(__('Invalid Industry', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
|
|
|
|
if (!empty($this->data)) {
|
|
|
|
|
if ($this->Industry->save($this->data)) {
|
|
|
|
|
$this->Session->setFlash(__('The Industry has been saved', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
} else {
|
|
|
|
|
$this->Session->setFlash(__('The Industry could not be saved. Please, try again.', true));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->data)) {
|
|
|
|
|
$this->data = $this->Industry->read(null, $id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function delete($id = null) {
|
|
|
|
|
if (!$id) {
|
|
|
|
|
$this->Session->setFlash(__('Invalid id for Industry', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
|
|
|
|
if ($this->Industry->del($id)) {
|
|
|
|
|
$this->Session->setFlash(__('Industry deleted', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
?>
|