Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

<?php
App::uses('AppController', 'Controller');
/**
 * NotificationRules Controller
 *
 * @property NotificationRule $NotificationRule
 * @property PaginatorComponent $Paginator
 */
class NotificationRulesController extends AppController {

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

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

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

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

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

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

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

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

/**
 * admin_add method
 *
 * @return void
 */
        public function admin_add() {
                if ($this->request->is('post')) {
                        $this->NotificationRule->create();
                        if ($this->NotificationRule->save($this->request->data)) {
                                $this->Session->setFlash(__('The notification rule has been saved.'));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The notification rule could not be saved. Please, try again.'));
                        }
                }
                $popup_types = array('forced'=>'Forced','clicktoskip'=>'Click To Skip','dismisstoskip'=>'Dismiss To Skip');
                $types = array('link'=>'Link','popup'=>'Popup');//,'inline'=>'Inline')
                $this->set(compact('types','popup_types'));
        }

/**
 * admin_edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function admin_edit($id = null) {
                if (!$this->NotificationRule->exists($id)) {
                        throw new NotFoundException(__('Invalid notification rule'));
                }
                if ($this->request->is(array('post', 'put'))) {
                        if ($this->NotificationRule->save($this->request->data)) {
                                $this->Session->setFlash(__('The notification rule has been saved.'));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The notification rule could not be saved. Please, try again.'));
                        }
                } else {
                        $options = array('conditions' => array('NotificationRule.' . $this->NotificationRule->primaryKey => $id));
                        $this->request->data = $this->NotificationRule->find('first', $options);
                }
                $popup_types = array('forced'=>'Forced','clicktoskip'=>'Click To Skip','dismisstoskip'=>'Dismiss To Skip');
                $types = array('link'=>'Link','popup'=>'Popup');//,'inline'=>'Inline')
                $this->set(compact('types','popup_types'));
        }

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