Subversion Repositories SmartDukaan

Rev

Rev 20126 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
App::uses('AppController', 'Controller');
/**
 * Mobileappsettings Controller
 *
 * @property Mobileappsetting $Mobileappsetting
 * @property PaginatorComponent $Paginator
 */
class MobileappsettingsController extends AppController {

/**
 * Components
 *
 * @var array
 */
        public $components = array('Paginator');
        
        public function beforeFilter() {
                parent::beforeFilter();
                $this->Auth->allow();
        }

        public function index() {       
                $this->layout = 'ajax';
                $t = $this->request->query('t');
                $imeinumber = $this->request->query('imeinumber');
                if(!empty($t) && $t >0){
                        $options = array('conditions'=>array("unix_timestamp(modified) > "=>$t));
                }else{
                        $options = null;
                }
                $settings = $this->Mobileappsetting->find('all',$options);
                $options = array('fields'=>array("unix_timestamp(modified) t"),'order'=>array('modified'=>'desc'));
                $lasttimestamp = $this->Mobileappsetting->find('first',$options);       
                $failureCount = 0;
                /*if(isset($imeinumber) && !empty($imeinumber)) {
                        $this->loadModel('GcmUser');
                        $options = array('conditions'=>array('imeinumber'=>$imeinumber),'fields'=>array('failurecount'),'order'=>array('id'=>'desc'));
                        $data = $this->GcmUser->find('first',$options);
                        if(!empty($data)){
                                $failureCount = $data['GcmUser']['failurecount'];
                        }
                }*/
                $result = array('settings' => $settings,'t'=>$lasttimestamp[0]['t'],'failureCount'=>$failureCount);
                $this->set(array(
                    'result' => $result,
                    '_serialize' => array('result')
                ));
                $this->render('/Elements/json');
        }
/**
 * admin_index method
 *
 * @return void
 */
        public function admin_index() {
                $this->Mobileappsetting->recursive = 0;
                $this->set('mobileappsettings', $this->Paginator->paginate());
        }

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

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

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