Subversion Repositories SmartDukaan

Rev

Rev 14434 | Rev 14661 | 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);	
58
				$this->log(print_r($pushdata,1));
59
				$this->UserUrl->create();
60
				if ($this->UserUrl->saveAll($pushdata['pushdata'])) {
61
					$result = array('success' => true,'message'=>__('The url has been saved.'));
62
				} else {
63
					$result = array('success' => false,'message'=>__('The url could not be saved. Please, try again.'));
64
				}
65
				$this->response->type('json');
66
				$this->layout = 'ajax';
67
				$this->set(array(
68
				    'result' => $result,
69
				    // 'callback' => $callback,
70
				    '_serialize' => array('result')
71
				));
72
				$this->render('/Elements/json');
73
			}			
13591 anikendra 74
		}		
13532 anikendra 75
	}
76
 
77
/**
78
 * edit method
79
 *
80
 * @throws NotFoundException
81
 * @param string $id
82
 * @return void
83
 */
84
	public function edit($id = null) {
13591 anikendra 85
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 86
		if (!$this->UserUrl->exists($id)) {
87
			throw new NotFoundException(__('Invalid user url'));
88
		}
89
		if ($this->request->is(array('post', 'put'))) {
90
			if ($this->UserUrl->save($this->request->data)) {
91
				$this->Session->setFlash(__('The user url has been saved.'));
92
				return $this->redirect(array('action' => 'index'));
93
			} else {
94
				$this->Session->setFlash(__('The user url could not be saved. Please, try again.'));
95
			}
96
		} else {
97
			$options = array('conditions' => array('UserUrl.' . $this->UserUrl->primaryKey => $id));
98
			$this->request->data = $this->UserUrl->find('first', $options);
99
		}
100
		$users = $this->UserUrl->User->find('list');
101
		$this->set(compact('users'));
102
	}
103
 
104
/**
105
 * delete method
106
 *
107
 * @throws NotFoundException
108
 * @param string $id
109
 * @return void
110
 */
111
	public function delete($id = null) {
13591 anikendra 112
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 113
		$this->UserUrl->id = $id;
114
		if (!$this->UserUrl->exists()) {
115
			throw new NotFoundException(__('Invalid user url'));
116
		}
117
		$this->request->onlyAllow('post', 'delete');
118
		if ($this->UserUrl->delete()) {
119
			$this->Session->setFlash(__('The user url has been deleted.'));
120
		} else {
121
			$this->Session->setFlash(__('The user url could not be deleted. Please, try again.'));
122
		}
123
		return $this->redirect(array('action' => 'index'));
124
	}
125
 
126
/**
127
 * admin_index method
128
 *
129
 * @return void
130
 */
131
	public function admin_index() {
132
		$this->UserUrl->recursive = 0;
14434 anikendra 133
		$q = $this->request->query('q');
134
		if(isset($q) && !empty($q)){
14654 anikendra 135
			$this->Paginator->settings = array('conditions' => array('UserUrl.url LIKE'=>'%'.$q.'%'),'order' => array('id'=>'desc'));
136
 			$this->set(compact('q'));
137
		} else {
138
			$this->Paginator->settings = array('order' => array('id'=>'desc'));
139
 		}
13532 anikendra 140
		$this->set('userUrls', $this->Paginator->paginate());
141
	}
142
 
143
/**
144
 * admin_view method
145
 *
146
 * @throws NotFoundException
147
 * @param string $id
148
 * @return void
149
 */
150
	public function admin_view($id = null) {
151
		if (!$this->UserUrl->exists($id)) {
152
			throw new NotFoundException(__('Invalid user url'));
153
		}
154
		$options = array('conditions' => array('UserUrl.' . $this->UserUrl->primaryKey => $id));
155
		$this->set('userUrl', $this->UserUrl->find('first', $options));
156
	}
157
 
14401 anikendra 158
	public function admin_by($userId = null) {
159
		$options = array('conditions' => array('UserUrl.user_id' => $userId),'order'=>array('id'=>'desc'),'limit' => 100);
160
		$this->Paginator->settings = $options;
161
		$userUrls = $this->Paginator->paginate();		
162
		$this->set(compact('userUrls'));
163
	}
13532 anikendra 164
/**
165
 * admin_add method
166
 *
167
 * @return void
168
 */
169
	public function admin_add() {
170
		if ($this->request->is('post')) {
171
			$this->UserUrl->create();
172
			if ($this->UserUrl->save($this->request->data)) {
173
				$this->Session->setFlash(__('The user url has been saved.'));
174
				return $this->redirect(array('action' => 'index'));
175
			} else {
176
				$this->Session->setFlash(__('The user url could not be saved. Please, try again.'));
177
			}
178
		}
179
		$users = $this->UserUrl->User->find('list');
180
		$this->set(compact('users'));
181
	}
182
 
183
/**
184
 * admin_edit method
185
 *
186
 * @throws NotFoundException
187
 * @param string $id
188
 * @return void
189
 */
190
	public function admin_edit($id = null) {
191
		if (!$this->UserUrl->exists($id)) {
192
			throw new NotFoundException(__('Invalid user url'));
193
		}
194
		if ($this->request->is(array('post', 'put'))) {
195
			if ($this->UserUrl->save($this->request->data)) {
196
				$this->Session->setFlash(__('The user url has been saved.'));
197
				return $this->redirect(array('action' => 'index'));
198
			} else {
199
				$this->Session->setFlash(__('The user url could not be saved. Please, try again.'));
200
			}
201
		} else {
202
			$options = array('conditions' => array('UserUrl.' . $this->UserUrl->primaryKey => $id));
203
			$this->request->data = $this->UserUrl->find('first', $options);
204
		}
205
		$users = $this->UserUrl->User->find('list');
206
		$this->set(compact('users'));
207
	}
208
 
209
/**
210
 * admin_delete method
211
 *
212
 * @throws NotFoundException
213
 * @param string $id
214
 * @return void
215
 */
216
	public function admin_delete($id = null) {
217
		$this->UserUrl->id = $id;
218
		if (!$this->UserUrl->exists()) {
219
			throw new NotFoundException(__('Invalid user url'));
220
		}
221
		$this->request->onlyAllow('post', 'delete');
222
		if ($this->UserUrl->delete()) {
223
			$this->Session->setFlash(__('The user url has been deleted.'));
224
		} else {
225
			$this->Session->setFlash(__('The user url could not be deleted. Please, try again.'));
226
		}
227
		return $this->redirect(array('action' => 'index'));
228
	}}