Subversion Repositories SmartDukaan

Rev

Rev 14662 | Rev 20126 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13591 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Mobileappsettings Controller
5
 *
6
 * @property Mobileappsetting $Mobileappsetting
7
 * @property PaginatorComponent $Paginator
8
 */
9
class MobileappsettingsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
13593 anikendra 18
	public function index() {	
19
		$this->layout = 'ajax';
14662 anikendra 20
		$t = $this->request->query('t');
15530 anikendra 21
		$imeinumber = $this->request->query('imeinumber');
14662 anikendra 22
		if(!empty($t) && $t >0){
23
			$options = array('conditions'=>array("unix_timestamp(modified) > "=>$t));
24
		}else{
25
			$options = null;
26
		}
27
		$settings = $this->Mobileappsetting->find('all',$options);
28
		$options = array('fields'=>array("unix_timestamp(modified) t"),'order'=>array('modified'=>'desc'));
15530 anikendra 29
		$lasttimestamp = $this->Mobileappsetting->find('first',$options);	
30
		$failureCount = 0;
31
		if(isset($imeinumber) && !empty($imeinumber)) {
32
			$this->loadModel('GcmUser');
33
			$options = array('conditions'=>array('imeinumber'=>$imeinumber),'fields'=>array('failurecount'),'order'=>array('id'=>'desc'));
34
			$data = $this->GcmUser->find('first',$options);
35
			if(!empty($data)){
36
				$failureCount = $data['GcmUser']['failurecount'];
37
			}
38
		}
39
		$result = array('settings' => $settings,'t'=>$lasttimestamp[0]['t'],'failureCount'=>$failureCount);
13593 anikendra 40
		$this->set(array(
41
		    'result' => $result,
42
		    '_serialize' => array('result')
43
		));
44
		$this->render('/Elements/json');
45
	}
13591 anikendra 46
/**
47
 * admin_index method
48
 *
49
 * @return void
50
 */
51
	public function admin_index() {
52
		$this->Mobileappsetting->recursive = 0;
53
		$this->set('mobileappsettings', $this->Paginator->paginate());
54
	}
55
 
56
/**
57
 * admin_view method
58
 *
59
 * @throws NotFoundException
60
 * @param string $id
61
 * @return void
62
 */
63
	public function admin_view($id = null) {
64
		if (!$this->Mobileappsetting->exists($id)) {
65
			throw new NotFoundException(__('Invalid mobileappsetting'));
66
		}
67
		$options = array('conditions' => array('Mobileappsetting.' . $this->Mobileappsetting->primaryKey => $id));
68
		$this->set('mobileappsetting', $this->Mobileappsetting->find('first', $options));
69
	}
70
 
71
/**
72
 * admin_add method
73
 *
74
 * @return void
75
 */
76
	public function admin_add() {
77
		if ($this->request->is('post')) {
78
			$this->Mobileappsetting->create();
79
			if ($this->Mobileappsetting->save($this->request->data)) {
80
				$this->Session->setFlash(__('The mobileappsetting has been saved.'));
81
				return $this->redirect(array('action' => 'index'));
82
			} else {
83
				$this->Session->setFlash(__('The mobileappsetting could not be saved. Please, try again.'));
84
			}
85
		}
86
	}
87
 
88
/**
89
 * admin_edit method
90
 *
91
 * @throws NotFoundException
92
 * @param string $id
93
 * @return void
94
 */
95
	public function admin_edit($id = null) {
96
		if (!$this->Mobileappsetting->exists($id)) {
97
			throw new NotFoundException(__('Invalid mobileappsetting'));
98
		}
99
		if ($this->request->is(array('post', 'put'))) {
100
			if ($this->Mobileappsetting->save($this->request->data)) {
101
				$this->Session->setFlash(__('The mobileappsetting has been saved.'));
102
				return $this->redirect(array('action' => 'index'));
103
			} else {
104
				$this->Session->setFlash(__('The mobileappsetting could not be saved. Please, try again.'));
105
			}
106
		} else {
107
			$options = array('conditions' => array('Mobileappsetting.' . $this->Mobileappsetting->primaryKey => $id));
108
			$this->request->data = $this->Mobileappsetting->find('first', $options);
109
		}
110
	}
111
 
112
/**
113
 * admin_delete method
114
 *
115
 * @throws NotFoundException
116
 * @param string $id
117
 * @return void
118
 */
119
	public function admin_delete($id = null) {
120
		$this->Mobileappsetting->id = $id;
121
		if (!$this->Mobileappsetting->exists()) {
122
			throw new NotFoundException(__('Invalid mobileappsetting'));
123
		}
124
		$this->request->onlyAllow('post', 'delete');
125
		if ($this->Mobileappsetting->delete()) {
126
			$this->Session->setFlash(__('The mobileappsetting has been deleted.'));
127
		} else {
128
			$this->Session->setFlash(__('The mobileappsetting could not be deleted. Please, try again.'));
129
		}
130
		return $this->redirect(array('action' => 'index'));
131
	}}