Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

<?php
App::uses('AppController', 'Controller');
/**
 * StoreCashbacks Controller
 *
 * @property StoreCashback $StoreCashback
 * @property PaginatorComponent $Paginator
 */
class StoreCashbacksController extends AppController {

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

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

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

/**
 * add method
 *
 * @return void
 */
        public function add() {
                if ($this->request->is('post')) {
                        $this->StoreCashback->create();
                        if ($this->StoreCashback->save($this->request->data)) {
                                $this->Session->setFlash(__('The store cashback has been saved.'));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The store cashback could not be saved. Please, try again.'));
                        }
                }
                $stores = $this->StoreCashback->Store->find('list');
                $categories = $this->StoreCashback->Category->find('list');
                $this->set(compact('stores', 'categories'));
        }

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

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

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

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

/**
 * admin_add method
 *
 * @return void
 */
        public function admin_add() {
                if ($this->request->is('post')) {
                        $this->StoreCashback->create();
                        if ($this->StoreCashback->save($this->request->data)) {
                                $this->Session->setFlash(__('The store cashback has been saved.'));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The store cashback could not be saved. Please, try again.'));
                        }
                }
                $stores = $this->StoreCashback->Store->find('list');
                $categories = $this->StoreCashback->Category->find('list');
                $this->set(compact('stores', 'categories'));
        }

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

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