Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

<?php
App::uses('AppController', 'Controller');
/**
 * SearchAnalytics Controller
 *
 * @property SearchAnalytic $SearchAnalytic
 * @property PaginatorComponent $Paginator
 */
class SearchAnalyticsController extends AppController {

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

        public function beforeFilter() {                
                parent::beforeFilter();
                $this->Auth->allow('add');
        }
/**
 * index method
 *
 * @return void
 */
        public function index() {
                $this->SearchAnalytic->recursive = 0;
                $this->set('searchAnalytics', $this->Paginator->paginate());
        }

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

/**
 * add method
 *
 * @return void
 */
        public function add() {
                $this->log(print_r($this->request->data,1),'searchanalytics');
                if ($this->request->is('post')) {
                        $this->SearchAnalytic->create();
                        if ($this->SearchAnalytic->save($this->request->data)) {
                                // $this->Session->setFlash(__('The search analytic has been saved.'));
                                // return $this->redirect(array('action' => 'index'));
                                $response =array('success'=>true,'message'=> 'The search analytic has been saved');
                        } else {
                                // $this->Session->setFlash(__('The search analytic could not be saved. Please, try again.'));
                                $response =array('success'=>false,'message'=> 'The search analytic could not be saved. Please, try again');
                        }
                        $this->response->type('json');
                        $this->layout = 'ajax';
                        $this->set(array(
                            'result' => $response,
                            // '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->SearchAnalytic->exists($id)) {
                        throw new NotFoundException(__('Invalid search analytic'));
                }
                if ($this->request->is(array('post', 'put'))) {
                        if ($this->SearchAnalytic->save($this->request->data)) {
                                $this->Session->setFlash(__('The search analytic has been saved.'));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The search analytic could not be saved. Please, try again.'));
                        }
                } else {
                        $options = array('conditions' => array('SearchAnalytic.' . $this->SearchAnalytic->primaryKey => $id));
                        $this->request->data = $this->SearchAnalytic->find('first', $options);
                }
        }

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

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

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

/**
 * admin_add method
 *
 * @return void
 */
        public function admin_add() {
                if ($this->request->is('post')) {
                        $this->SearchAnalytic->create();
                        if ($this->SearchAnalytic->save($this->request->data)) {
                                $this->Session->setFlash(__('The search analytic has been saved.'));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The search analytic could not be saved. Please, try again.'));
                        }
                }
        }

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

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