Subversion Repositories SmartDukaan

Rev

Rev 15004 | Rev 15581 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 15004 Rev 15261
Line 18... Line 18...
18
	public function beforeFilter() {		
18
	public function beforeFilter() {		
19
		parent::beforeFilter();
19
		parent::beforeFilter();
20
		$this->Auth->allow('notificationactive');
20
		$this->Auth->allow('notificationactive');
21
		$this->apihost = Configure::read('pythonapihost');
21
		$this->apihost = Configure::read('pythonapihost');
22
	}
22
	}
23
/**
-
 
24
 * index method
-
 
25
 *
-
 
26
 * @return void
-
 
27
 */
-
 
28
	public function index() {
-
 
29
		$this->NotificationCampaign->recursive = 0;
-
 
30
		$this->set('notificationCampaigns', $this->Paginator->paginate());
-
 
31
	}
-
 
32
 
-
 
33
/**
-
 
34
 * view method
-
 
35
 *
-
 
36
 * @throws NotFoundException
-
 
37
 * @param string $id
-
 
38
 * @return void
-
 
39
 */
-
 
40
	public function view($id = null) {
-
 
41
		if (!$this->NotificationCampaign->exists($id)) {
-
 
42
			throw new NotFoundException(__('Invalid notification campaign'));
-
 
43
		}
-
 
44
		$options = array('conditions' => array('NotificationCampaign.' . $this->NotificationCampaign->primaryKey => $id));
-
 
45
		$this->set('notificationCampaign', $this->NotificationCampaign->find('first', $options));
-
 
46
	}
-
 
47
 
-
 
48
/**
-
 
49
 * add method
-
 
50
 *
-
 
51
 * @return void
-
 
52
 */
-
 
53
	public function add() {
-
 
54
		if ($this->request->is('post')) {
-
 
55
			$this->NotificationCampaign->create();
-
 
56
			if ($this->NotificationCampaign->save($this->request->data)) {
-
 
57
				$this->Session->setFlash(__('The notification campaign has been saved.'));
-
 
58
				return $this->redirect(array('action' => 'index'));
-
 
59
			} else {
-
 
60
				$this->Session->setFlash(__('The notification campaign could not be saved. Please, try again.'));
-
 
61
			}
-
 
62
		}
-
 
63
	}
-
 
64
 
-
 
65
/**
-
 
66
 * edit method
-
 
67
 *
-
 
68
 * @throws NotFoundException
-
 
69
 * @param string $id
-
 
70
 * @return void
-
 
71
 */
-
 
72
	public function edit($id = null) {
-
 
73
		if (!$this->NotificationCampaign->exists($id)) {
-
 
74
			throw new NotFoundException(__('Invalid notification campaign'));
-
 
75
		}
-
 
76
		if ($this->request->is(array('post', 'put'))) {
-
 
77
			if ($this->NotificationCampaign->save($this->request->data)) {
-
 
78
				$this->Session->setFlash(__('The notification campaign has been saved.'));
-
 
79
				return $this->redirect(array('action' => 'index'));
-
 
80
			} else {
-
 
81
				$this->Session->setFlash(__('The notification campaign could not be saved. Please, try again.'));
-
 
82
			}
-
 
83
		} else {
-
 
84
			$options = array('conditions' => array('NotificationCampaign.' . $this->NotificationCampaign->primaryKey => $id));
-
 
85
			$this->request->data = $this->NotificationCampaign->find('first', $options);
-
 
86
		}
-
 
87
	}
-
 
88
 
-
 
89
/**
-
 
90
 * delete method
-
 
91
 *
-
 
92
 * @throws NotFoundException
-
 
93
 * @param string $id
-
 
94
 * @return void
-
 
95
 */
-
 
96
	public function delete($id = null) {
-
 
97
		$this->NotificationCampaign->id = $id;
-
 
98
		if (!$this->NotificationCampaign->exists()) {
-
 
99
			throw new NotFoundException(__('Invalid notification campaign'));
-
 
100
		}
-
 
101
		$this->request->onlyAllow('post', 'delete');
-
 
102
		if ($this->NotificationCampaign->delete()) {
-
 
103
			$this->Session->setFlash(__('The notification campaign has been deleted.'));
-
 
104
		} else {
-
 
105
			$this->Session->setFlash(__('The notification campaign could not be deleted. Please, try again.'));
-
 
106
		}
-
 
107
		return $this->redirect(array('action' => 'index'));
-
 
108
	}
-
 
109
 
23
 
110
/**
24
/**
111
 * admin_index method
25
 * admin_index method
112
 *
26
 *
113
 * @return void
27
 * @return void
Line 242... Line 156...
242
		$sqlQuery1 = "SELECT * FROM notification_campaigns where id=$id" ;
156
		$sqlQuery1 = "SELECT * FROM notification_campaigns where id=$id" ;
243
		$resultData=$this->NotificationCampaign->query($sqlQuery1);
157
		$resultData=$this->NotificationCampaign->query($sqlQuery1);
244
		
158
		
245
		$this->set('data', $resul);
159
		$this->set('data', $resul);
246
		$this->set('notificationData', $resultData);
160
		$this->set('notificationData', $resultData);
247
		//$resul = $this->Paginator->paginate();
-
 
248
		//debug($resultData);
-
 
249
	}
161
	}
250
 
162
 
251
	public function admin_user($id = null) {
163
	public function admin_user($id = null) {
252
		$sqlQuery = "SELECT * FROM pushnotifications where user_id=$id order by id desc" ;
164
		$sqlQuery = "SELECT * FROM pushnotifications where user_id=$id order by id desc" ;
253
		$resul=$this->NotificationCampaign->query($sqlQuery);
165
		$resul=$this->NotificationCampaign->query($sqlQuery);
254
		$this->set('userdata', $resul);
166
		$this->set('userdata', $resul);
255
		//$this->set('notificationData', $resultData);
-
 
256
		//$resul = $this->Paginator->paginate();
-
 
257
		//debug($resul);
-
 
258
	}
167
	}
-
 
168
 
259
	public function admin_sort($id = null) {
169
	public function admin_sort($id = null) {
260
		$sort = $this->request->query('type');
170
		$sort = $this->request->query('type');
261
		$direction = $this->request->query('order');
171
		$direction = $this->request->query('order');
262
		//$cid = $this->request->query('cid');
172
		//$cid = $this->request->query('cid');
263
		if($sort=='user_id'){
173
		if($sort=='user_id'){
Line 297... Line 207...
297
		    'result' => $result,
207
		    'result' => $result,
298
		    '_serialize' => array('result')
208
		    '_serialize' => array('result')
299
		));
209
		));
300
		$this->render('/Elements/json');
210
		$this->render('/Elements/json');
301
	}
211
	}
-
 
212
 
-
 
213
	public function admin_send(){
-
 
214
		if ($this->request->is('post')) {			
-
 
215
			$sql = $this->request->data['NotificationCampaign']['sql'];
-
 
216
			if(!empty($sql)){
-
 
217
				$users = $this->NotificationCampaign->query($sql);
-
 
218
				// debug($users);
-
 
219
				$message = $this->request->data['NotificationCampaign'];
-
 
220
				// $data = array('name'=>$message['name'],'title'=>$message['title'],'type'=>$message['type'],'message'=>$message['message'],'url'=>$message['url'],'expiresat'=>$message['expiresat'],'sql'=>$message['sql']);
-
 
221
				$this->NotificationCampaign->create();
-
 
222
				if($this->NotificationCampaign->save($message)){
-
 
223
					$message['cid'] = $this->NotificationCampaign->getLastInsertId();
-
 
224
				} else{
-
 
225
					debug($this->NotificationCampaign->validationErrors);
-
 
226
					$message['cid'] = $message['name'];
-
 
227
				}				
-
 
228
				$this->loadModel('Pushnotification');
-
 
229
				foreach ($users as $key => $value) {									
-
 
230
					$data = array('notification_campaign_id'=>$message['cid'],'user_id'=>$value['User']['id'],'type'=>'pending');
-
 
231
					$this->Pushnotification->create();
-
 
232
					$this->Pushnotification->save($data);
-
 
233
				}
-
 
234
				$this->Session->setFlash(__('Push notification scheduled for '.sizeof($users).' users'));
-
 
235
				return $this->redirect(array('controller' => 'administration', 'action' => 'dashboard', 'admin' => false));
-
 
236
			}
-
 
237
		}
-
 
238
	}
302
}
239
}
303
240