Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
13532 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * UserUrls Controller
5
 *
6
 * @property UserUrl $UserUrl
7
 * @property PaginatorComponent $Paginator
8
 */
9
class UserUrlsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
13591 anikendra 18
	public function beforeFilter() {
19
		parent::beforeFilter();
20
		$this->Auth->allow('add');
21
	}
13532 anikendra 22
/**
23
 * index method
24
 *
25
 * @return void
26
 */
27
	public function index() {
13591 anikendra 28
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 29
		$this->UserUrl->recursive = 0;
30
		$this->set('userUrls', $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) {
13591 anikendra 41
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 42
		if (!$this->UserUrl->exists($id)) {
43
			throw new NotFoundException(__('Invalid user url'));
44
		}
45
		$options = array('conditions' => array('UserUrl.' . $this->UserUrl->primaryKey => $id));
46
		$this->set('userUrl', $this->UserUrl->find('first', $options));
47
	}
48
 
49
/**
50
 * add method
51
 *
52
 * @return void
53
 */
54
	public function add() {
55
		if ($this->request->is('post')) {
13595 anikendra 56
			if(isset($this->request->data['pushdata']) && !empty($this->request->data['pushdata'])) {
57
				$pushdata = json_decode($this->request->data['pushdata'],1);	
14661 anikendra 58
				$pushdata['pushdata'][0]['ip'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
17096 anikendra 59
				$this->log(print_r($pushdata['pushdata'][0],1),'nodejs');
17091 anikendra 60
				/*
13595 anikendra 61
				$this->UserUrl->create();
62
				if ($this->UserUrl->saveAll($pushdata['pushdata'])) {
63
					$result = array('success' => true,'message'=>__('The url has been saved.'));
64
				} else {
65
					$result = array('success' => false,'message'=>__('The url could not be saved. Please, try again.'));
66
				}
17101 anikendra 67
				*/
14934 anikendra 68
				if(isset($pushdata['pushdata'][0]['httpstatus']) && !empty($pushdata['pushdata'][0]['httpstatus'])) {
69
					$this->loadModel('SaholicLog');
70
					$this->SaholicLog->create();
71
					$this->SaholicLog->saveAll($pushdata['pushdata']);
17101 anikendra 72
				}				
17091 anikendra 73
				//Nodejs api call
17101 anikendra 74
				$url = Configure::read('nodeurl') . '/addBrowsingHistory/?pushed_by=php';
75
				$this->make_request($url,json_encode($pushdata));
17091 anikendra 76
				$result = array('success' => true,'message'=>__('The url has been saved.'));
13595 anikendra 77
				$this->response->type('json');
78
				$this->layout = 'ajax';
79
				$this->set(array(
80
				    'result' => $result,
81
				    // 'callback' => $callback,
82
				    '_serialize' => array('result')
83
				));
84
				$this->render('/Elements/json');
85
			}			
13591 anikendra 86
		}		
13532 anikendra 87
	}
88
 
89
/**
90
 * edit method
91
 *
92
 * @throws NotFoundException
93
 * @param string $id
94
 * @return void
95
 */
96
	public function edit($id = null) {
13591 anikendra 97
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 98
		if (!$this->UserUrl->exists($id)) {
99
			throw new NotFoundException(__('Invalid user url'));
100
		}
101
		if ($this->request->is(array('post', 'put'))) {
102
			if ($this->UserUrl->save($this->request->data)) {
103
				$this->Session->setFlash(__('The user url has been saved.'));
104
				return $this->redirect(array('action' => 'index'));
105
			} else {
106
				$this->Session->setFlash(__('The user url could not be saved. Please, try again.'));
107
			}
108
		} else {
109
			$options = array('conditions' => array('UserUrl.' . $this->UserUrl->primaryKey => $id));
110
			$this->request->data = $this->UserUrl->find('first', $options);
111
		}
112
		$users = $this->UserUrl->User->find('list');
113
		$this->set(compact('users'));
114
	}
115
 
116
/**
117
 * delete method
118
 *
119
 * @throws NotFoundException
120
 * @param string $id
121
 * @return void
122
 */
123
	public function delete($id = null) {
13591 anikendra 124
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 125
		$this->UserUrl->id = $id;
126
		if (!$this->UserUrl->exists()) {
127
			throw new NotFoundException(__('Invalid user url'));
128
		}
129
		$this->request->onlyAllow('post', 'delete');
130
		if ($this->UserUrl->delete()) {
131
			$this->Session->setFlash(__('The user url has been deleted.'));
132
		} else {
133
			$this->Session->setFlash(__('The user url could not be deleted. Please, try again.'));
134
		}
135
		return $this->redirect(array('action' => 'index'));
136
	}
137
 
138
/**
139
 * admin_index method
140
 *
141
 * @return void
142
 */
17113 anikendra 143
	public function admin_index() {		
14434 anikendra 144
		$q = $this->request->query('q');
145
		if(isset($q) && !empty($q)){
17113 anikendra 146
			// $this->Paginator->settings = array('conditions' => array('UserUrl.url LIKE'=>'%'.$q.'%'),'order' => array('id'=>'desc'));
147
 			$url = Configure::read('nodeurl') . "/searchBrowsingHistory/?search_term=$q&posted_by=php";
14654 anikendra 148
 			$this->set(compact('q'));
149
		} else {
17113 anikendra 150
			// $this->Paginator->settings = array('order' => array('id'=>'desc'));
151
			$url = Configure::read('nodeurl') . '/getBrowsingHistory/?posted_by=php';
14654 anikendra 152
 		}
17113 anikendra 153
		// $this->set('userUrls', $this->Paginator->paginate());
17101 anikendra 154
		$page = $this->request->query('page');
155
		if(!isset($page)){
156
			$page = 1;
17113 anikendra 157
		}
17101 anikendra 158
		$url = $this->UserUrl->getNodeUrl($url,$page);
159
		$userUrls = $this->make_request($url,null);
160
		$this->set(compact('userUrls', 'page'));
13532 anikendra 161
	}
162
 
163
/**
164
 * admin_view method
165
 *
166
 * @throws NotFoundException
167
 * @param string $id
168
 * @return void
169
 */
170
	public function admin_view($id = null) {
171
		if (!$this->UserUrl->exists($id)) {
172
			throw new NotFoundException(__('Invalid user url'));
173
		}
174
		$options = array('conditions' => array('UserUrl.' . $this->UserUrl->primaryKey => $id));
175
		$this->set('userUrl', $this->UserUrl->find('first', $options));
176
	}
177
 
14401 anikendra 178
	public function admin_by($userId = null) {
17101 anikendra 179
		/*$options = array('conditions' => array('UserUrl.user_id' => $userId),'order'=>array('id'=>'desc'),'limit' => 100);
14401 anikendra 180
		$this->Paginator->settings = $options;
181
		$userUrls = $this->Paginator->paginate();		
17101 anikendra 182
		$this->set(compact('userUrls'));*/
183
		$page = $this->request->query('page');
184
		if(!isset($page)){
185
			$page = 1;
186
		}	
187
		$url = Configure::read('nodeurl') . '/getBrowsingHistoryByUserId/?posted_by=php&user_id='.$userId;
188
		$url = $this->UserUrl->getNodeUrl($url,$page);
189
		$userUrls = $this->make_request($url,null);
190
		$userInfoApiUrl = Configure::read('nodeurl') . '/getUserById/?user_id='.$userId;
191
		$user = $this->make_request($userInfoApiUrl,null);
192
		$this->set(compact('userUrls', 'page','user','userId'));
14401 anikendra 193
	}
13532 anikendra 194
/**
195
 * admin_add method
196
 *
197
 * @return void
198
 */
199
	public function admin_add() {
200
		if ($this->request->is('post')) {
201
			$this->UserUrl->create();
202
			if ($this->UserUrl->save($this->request->data)) {
203
				$this->Session->setFlash(__('The user url has been saved.'));
204
				return $this->redirect(array('action' => 'index'));
205
			} else {
206
				$this->Session->setFlash(__('The user url could not be saved. Please, try again.'));
207
			}
208
		}
209
		$users = $this->UserUrl->User->find('list');
210
		$this->set(compact('users'));
211
	}
212
 
213
/**
214
 * admin_edit method
215
 *
216
 * @throws NotFoundException
217
 * @param string $id
218
 * @return void
219
 */
220
	public function admin_edit($id = null) {
221
		if (!$this->UserUrl->exists($id)) {
222
			throw new NotFoundException(__('Invalid user url'));
223
		}
224
		if ($this->request->is(array('post', 'put'))) {
225
			if ($this->UserUrl->save($this->request->data)) {
226
				$this->Session->setFlash(__('The user url has been saved.'));
227
				return $this->redirect(array('action' => 'index'));
228
			} else {
229
				$this->Session->setFlash(__('The user url could not be saved. Please, try again.'));
230
			}
231
		} else {
232
			$options = array('conditions' => array('UserUrl.' . $this->UserUrl->primaryKey => $id));
233
			$this->request->data = $this->UserUrl->find('first', $options);
234
		}
235
		$users = $this->UserUrl->User->find('list');
236
		$this->set(compact('users'));
237
	}
238
 
239
/**
240
 * admin_delete method
241
 *
242
 * @throws NotFoundException
243
 * @param string $id
244
 * @return void
245
 */
246
	public function admin_delete($id = null) {
247
		$this->UserUrl->id = $id;
248
		if (!$this->UserUrl->exists()) {
249
			throw new NotFoundException(__('Invalid user url'));
250
		}
251
		$this->request->onlyAllow('post', 'delete');
252
		if ($this->UserUrl->delete()) {
253
			$this->Session->setFlash(__('The user url has been deleted.'));
254
		} else {
255
			$this->Session->setFlash(__('The user url could not be deleted. Please, try again.'));
256
		}
257
		return $this->redirect(array('action' => 'index'));
258
	}}