Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 131 lines (118 sloc) 3.14 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
<?php
/**
* Types Controller
*
* PHP version 5
*
* @category Controller
* @package Croogo
* @version 1.0
* @author Fahad Ibnay Heylaal <contact@fahad19.com>
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @link http://www.croogo.org
*/
class TypesController extends AppController {

/**
* Controller name
*
* @var string
* @access public
*/
public $name = 'Types';

/**
* Models used by the Controller
*
* @var array
* @access public
*/
public $uses = array('Type');

/**
* beforeFilter
*
* @return void
* @access public
*/
public function beforeFilter() {
parent::beforeFilter();
if ($this->action == 'admin_edit') {
$this->Security->disabledFields = array('alias');
}
}

/**
* Admin index
*
* @return void
* @access public
*/
public function admin_index() {
$this->set('title_for_layout', __('Type'));

$this->Type->recursive = 0;
$this->paginate['Type']['order'] = 'Type.title ASC';
$this->set('types', $this->paginate());
$this->set('displayFields', $this->Type->displayFields());
}

/**
* Admin add
*
* @return void
* @access public
*/
public function admin_add() {
$this->set('title_for_layout', __('Add Type'));

if (!empty($this->request->data)) {
$this->Type->create();
if ($this->Type->save($this->request->data)) {
$this->Session->setFlash(__('The Type has been saved'), 'default', array('class' => 'success'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The Type could not be saved. Please, try again.'), 'default', array('class' => 'error'));
}
}

$vocabularies = $this->Type->Vocabulary->find('list');
$this->set(compact('vocabularies'));
}

/**
* Admin edit
*
* @param integer $id
* @return void
* @access public
*/
public function admin_edit($id = null) {
$this->set('title_for_layout', __('Edit Type'));

if (!$id && empty($this->request->data)) {
$this->Session->setFlash(__('Invalid Type'), 'default', array('class' => 'error'));
$this->redirect(array('action' => 'index'));
}
if (!empty($this->request->data)) {
if ($this->Type->save($this->request->data)) {
$this->Session->setFlash(__('The Type has been saved'), 'default', array('class' => 'success'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The Type could not be saved. Please, try again.'), 'default', array('class' => 'error'));
}
}
if (empty($this->request->data)) {
$this->request->data = $this->Type->read(null, $id);
}

$vocabularies = $this->Type->Vocabulary->find('list');
$this->set(compact('vocabularies'));
}

/**
* Admin delete
*
* @param integer $id
* @return void
* @access public
*/
public function admin_delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for Type'), 'default', array('class' => 'error'));
$this->redirect(array('action' => 'index'));
}
if ($this->Type->delete($id)) {
$this->Session->setFlash(__('Type deleted'), 'default', array('class' => 'success'));
$this->redirect(array('action' => 'index'));
}
}
}
Something went wrong with that request. Please try again.