Rev 13532 | Rev 13688 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?phpApp::uses('AppController', 'Controller');/*** Preferences Controller** @property Preference $Preference* @property PaginatorComponent $Paginator*/class PreferencesController extends AppController {/*** Components** @var array*/public $components = array('Paginator');public function brand($action='hide') {$this->response->type('json');$this->layout = 'ajax';$userId = $this->request->query('user_id');$productId = $this->request->query('product_id');$hide = $this->request->query('hide');if(isset($hide) && !empty($hide) && $hide == 1){$this->loadModel('StoreProduct');$options = array('conditions'=>array('id'=>$productId),'fields'=>array('category_id','brand'),'recursive'=>-1);$product = $this->StoreProduct->find('first',$options);$this->loadModel('UserCategoryHiddenBrand');$data = array('user_id' => $userId, 'category_id' => $product['StoreProduct']['category_id'],'brand'=>$product['StoreProduct']['brand']);$this->UserCategoryHiddenBrand->create();if($this->UserCategoryHiddenBrand->save($data)){$result = array('success'=>true,'message'=>'brand hidden');}else{$result = array('success'=>false,'message'=>'database issue');}}else{$result = array('success'=>false,'message'=>'brand not hidden');}// $callback = $this->request->query('callback');$this->set(array('result' => $result,// 'callback' => $callback,'_serialize' => array('result')));$this->render('/Elements/json');}/*** index method** @return void*/public function index() {$this->Preference->recursive = 0;$this->set('preferences', $this->Paginator->paginate());}/*** view method** @throws NotFoundException* @param string $id* @return void*/public function view($id = null) {if (!$this->Preference->exists($id)) {throw new NotFoundException(__('Invalid preference'));}$options = array('conditions' => array('Preference.' . $this->Preference->primaryKey => $id));$this->set('preference', $this->Preference->find('first', $options));}/*** add method** @return void*/public function add() {if ($this->request->is('post')) {$this->Preference->create();if ($this->Preference->save($this->request->data)) {$this->Session->setFlash(__('The preference has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The preference could not be saved. Please, try again.'));}}$users = $this->Preference->User->find('list');$this->set(compact('users'));}/*** edit method** @throws NotFoundException* @param string $id* @return void*/public function edit($id = null) {if (!$this->Preference->exists($id)) {throw new NotFoundException(__('Invalid preference'));}if ($this->request->is(array('post', 'put'))) {if ($this->Preference->save($this->request->data)) {$this->Session->setFlash(__('The preference has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The preference could not be saved. Please, try again.'));}} else {$options = array('conditions' => array('Preference.' . $this->Preference->primaryKey => $id));$this->request->data = $this->Preference->find('first', $options);}$users = $this->Preference->User->find('list');$this->set(compact('users'));}/*** delete method** @throws NotFoundException* @param string $id* @return void*/public function delete($id = null) {$this->Preference->id = $id;if (!$this->Preference->exists()) {throw new NotFoundException(__('Invalid preference'));}$this->request->onlyAllow('post', 'delete');if ($this->Preference->delete()) {$this->Session->setFlash(__('The preference has been deleted.'));} else {$this->Session->setFlash(__('The preference could not be deleted. Please, try again.'));}return $this->redirect(array('action' => 'index'));}/*** admin_index method** @return void*/public function admin_index() {$this->Preference->recursive = 0;$this->set('preferences', $this->Paginator->paginate());}/*** admin_view method** @throws NotFoundException* @param string $id* @return void*/public function admin_view($id = null) {if (!$this->Preference->exists($id)) {throw new NotFoundException(__('Invalid preference'));}$options = array('conditions' => array('Preference.' . $this->Preference->primaryKey => $id));$this->set('preference', $this->Preference->find('first', $options));}/*** admin_add method** @return void*/public function admin_add() {if ($this->request->is('post')) {$this->Preference->create();if ($this->Preference->save($this->request->data)) {$this->Session->setFlash(__('The preference has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The preference could not be saved. Please, try again.'));}}$users = $this->Preference->User->find('list');$this->set(compact('users'));}/*** admin_edit method** @throws NotFoundException* @param string $id* @return void*/public function admin_edit($id = null) {if (!$this->Preference->exists($id)) {throw new NotFoundException(__('Invalid preference'));}if ($this->request->is(array('post', 'put'))) {if ($this->Preference->save($this->request->data)) {$this->Session->setFlash(__('The preference has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The preference could not be saved. Please, try again.'));}} else {$options = array('conditions' => array('Preference.' . $this->Preference->primaryKey => $id));$this->request->data = $this->Preference->find('first', $options);}$users = $this->Preference->User->find('list');$this->set(compact('users'));}/*** admin_delete method** @throws NotFoundException* @param string $id* @return void*/public function admin_delete($id = null) {$this->Preference->id = $id;if (!$this->Preference->exists()) {throw new NotFoundException(__('Invalid preference'));}$this->request->onlyAllow('post', 'delete');if ($this->Preference->delete()) {$this->Session->setFlash(__('The preference has been deleted.'));} else {$this->Session->setFlash(__('The preference could not be deleted. Please, try again.'));}return $this->redirect(array('action' => 'index'));}}