Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
App::uses('AppController', 'Controller');
/**
 * UserFilters Controller
 *
 * @property UserFilter $UserFilter
 * @property PaginatorComponent $Paginator
 */
class UserFiltersController extends AppController {

/**
 * Components
 *
 * @var array
 */
        public $components = array('Paginator');

/**
 * index method
 *
 * @return void
 */
        public function index() {
                $this->UserFilter->recursive = 0;
                $this->set('userFilters', $this->Paginator->paginate());
        }

/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function view($id = null) {
                if (!$this->UserFilter->exists($id)) {
                        throw new NotFoundException(__('Invalid user filter'));
                }
                $options = array('conditions' => array('UserFilter.' . $this->UserFilter->primaryKey => $id));
                $this->set('userFilter', $this->UserFilter->find('first', $options));
        }

/**
 * add method
 *
 * @return void
 */
        public function add() {
                if ($this->request->is('post')) {
                        $this->log(print_r($this->request->data,1),'user_filters');
                        $this->UserFilter->create();
                        if ($this->UserFilter->save($this->request->data)) {
                                $result = array('success'=>true,'message'=>__('The user filter has been saved.'));
                                // $this->Session->setFlash(__('The user filter has been saved.'));
                                // return $this->redirect(array('action' => 'index'));
                        } else {
                                $result = array('success'=>false,'message'=>__('The user filter could not be saved. Please, try again.'));
                                // $this->Session->setFlash(__('The user filter could not be saved. Please, try again.'));
                        }
                }
                // $users = $this->UserFilter->User->find('list');
                // $this->set(compact('users'));
                $this->response->type('json');
                $this->layout = 'ajax';
                $this->set(array(
                    'result' => $result,
                    // 'callback' => $callback,
                    '_serialize' => array('result')
                ));
                $this->render('/Elements/json');
        }

/**
 * edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function edit($id = null) {
                if (!$this->UserFilter->exists($id)) {
                        throw new NotFoundException(__('Invalid user filter'));
                }
                if ($this->request->is(array('post', 'put'))) {
                        if ($this->UserFilter->save($this->request->data)) {
                                $this->Session->setFlash(__('The user filter has been saved.'));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The user filter could not be saved. Please, try again.'));
                        }
                } else {
                        $options = array('conditions' => array('UserFilter.' . $this->UserFilter->primaryKey => $id));
                        $this->request->data = $this->UserFilter->find('first', $options);
                }
                $users = $this->UserFilter->User->find('list');
                $this->set(compact('users'));
        }

/**
 * delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function delete($id = null) {
                $this->UserFilter->id = $id;
                if (!$this->UserFilter->exists()) {
                        throw new NotFoundException(__('Invalid user filter'));
                }
                $this->request->onlyAllow('post', 'delete');
                if ($this->UserFilter->delete()) {
                        $this->Session->setFlash(__('The user filter has been deleted.'));
                } else {
                        $this->Session->setFlash(__('The user filter could not be deleted. Please, try again.'));
                }
                return $this->redirect(array('action' => 'index'));
        }

/**
 * admin_index method
 *
 * @return void
 */
        public function admin_index() {
                $this->UserFilter->recursive = 0;
                $this->set('userFilters', $this->Paginator->paginate());
        }

/**
 * admin_view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function admin_view($id = null) {
                if (!$this->UserFilter->exists($id)) {
                        throw new NotFoundException(__('Invalid user filter'));
                }
                $options = array('conditions' => array('UserFilter.' . $this->UserFilter->primaryKey => $id));
                $this->set('userFilter', $this->UserFilter->find('first', $options));
        }

/**
 * admin_add method
 *
 * @return void
 */
        public function admin_add() {
                if ($this->request->is('post')) {
                        $this->UserFilter->create();
                        if ($this->UserFilter->save($this->request->data)) {
                                $this->Session->setFlash(__('The user filter has been saved.'));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The user filter could not be saved. Please, try again.'));
                        }
                }
                $users = $this->UserFilter->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->UserFilter->exists($id)) {
                        throw new NotFoundException(__('Invalid user filter'));
                }
                if ($this->request->is(array('post', 'put'))) {
                        if ($this->UserFilter->save($this->request->data)) {
                                $this->Session->setFlash(__('The user filter has been saved.'));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The user filter could not be saved. Please, try again.'));
                        }
                } else {
                        $options = array('conditions' => array('UserFilter.' . $this->UserFilter->primaryKey => $id));
                        $this->request->data = $this->UserFilter->find('first', $options);
                }
                $users = $this->UserFilter->User->find('list');
                $this->set(compact('users'));
        }

/**
 * admin_delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function admin_delete($id = null) {
                $this->UserFilter->id = $id;
                if (!$this->UserFilter->exists()) {
                        throw new NotFoundException(__('Invalid user filter'));
                }
                $this->request->onlyAllow('post', 'delete');
                if ($this->UserFilter->delete()) {
                        $this->Session->setFlash(__('The user filter has been deleted.'));
                } else {
                        $this->Session->setFlash(__('The user filter could not be deleted. Please, try again.'));
                }
                return $this->redirect(array('action' => 'index'));
        }}