Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

<?php
App::uses('AppController', 'Controller');
/**
 * Offers Controller
 *
 * @property Offer $Offer
 * @property PaginatorComponent $Paginator
 */
class OffersController extends AppController {

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

        public function beforeFilter() {
                parent::beforeFilter();
                $callback = $this->request->query('callback');
        }
/**
 * index method
 *
 * @return void
 */
        public function index() {
                $this->Offer->recursive = 0;
                $this->response->type('json');
                $this->layout = 'ajax';
                $result = array('offers' => $this->Paginator->paginate());
                $this->set(array(
                    'result' => $result,
                    'callback' => $callback,
                    '_serialize' => array('result')
                ));
                $this->render('/Elements/jsonp');
        }

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

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

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

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

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

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

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

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