Subversion Repositories SmartDukaan

Rev

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

<?php
App::uses('AppController', 'Controller');
/**
 * Retailers Controller
 *
 * @property Retailer $Retailer
 * @property PaginatorComponent $Paginator
 */
class RetailersController extends AppController {

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

/**
 * index method
 *
 * @return void
 */
        public function index() {
                $this->layout = 'ajax';
                $this->Retailer->recursive = 0;
                $options = array('conditions'=>array('status' =>'new'));        
                $result = $this->Retailer->find('first',$options);
                $this->set(array(
                    'result' => $result,
                    '_serialize' => array('result')
                ));
                $this->render('/Elements/json');
        }
public function notificationactive(){
                $retailerId = $this->request->query('retailerid');
                $options = array('conditions' => array('id'=> $retailerId,'status'=>'new','expiresAt >'=>date('Y-m-d H:i:s',time())));
                $count = $this->NotificationCampaign->find('count',$options);
                
                if(!$count){
                        $result = array('success'=>false);
                }else{
                        $result = array('success'=>true);
                }
                
                $this->response->type('json');
                $this->layout = 'ajax';
                $this->set(array(
                    'result' => $result,
                    '_serialize' => array('result')
                ));
                $this->render('/Elements/json');
        }

        /*public function index() {     
                $this->layout = 'ajax';
                $t = $this->request->query('t');
                $retailer = $this->Mobileappsetting->find('one',$options);
                $options = array('fields'=>array("unix_timestamp(modified) t"),'order'=>array('modified'=>'desc'));
                $lasttimestamp = $this->Mobileappsetting->find('first',$options);               
                $result = array('settings' => $settings,'t'=>$lasttimestamp[0]['t']);
                $this->set(array(
                    'result' => $result,
                    '_serialize' => array('result')
                ));
                $this->render('/Elements/json');
        }*/
/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function view($id = null) {
                if (!$this->Retailer->exists($id)) {
                        throw new NotFoundException(__('Invalid retailer'));
                }
                $options = array('conditions' => array('Retailer.' . $this->Retailer->primaryKey => $id));
                $this->set('retailer', $this->Retailer->find('first', $options));
        }

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

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

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

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

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

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

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

        
}