Subversion Repositories SmartDukaan

Rev

Rev 14401 | Rev 14654 | 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)){
135
			$this->Paginator->settings = array('conditions' => array('UserUrl.url LIKE'=>'%'.$q.'%'));
136
			$this->set(compact('q'));
137
		}
13532 anikendra 138
		$this->set('userUrls', $this->Paginator->paginate());
139
	}
140
 
141
/**
142
 * admin_view method
143
 *
144
 * @throws NotFoundException
145
 * @param string $id
146
 * @return void
147
 */
148
	public function admin_view($id = null) {
149
		if (!$this->UserUrl->exists($id)) {
150
			throw new NotFoundException(__('Invalid user url'));
151
		}
152
		$options = array('conditions' => array('UserUrl.' . $this->UserUrl->primaryKey => $id));
153
		$this->set('userUrl', $this->UserUrl->find('first', $options));
154
	}
155
 
14401 anikendra 156
	public function admin_by($userId = null) {
157
		$options = array('conditions' => array('UserUrl.user_id' => $userId),'order'=>array('id'=>'desc'),'limit' => 100);
158
		$this->Paginator->settings = $options;
159
		$userUrls = $this->Paginator->paginate();		
160
		$this->set(compact('userUrls'));
161
	}
13532 anikendra 162
/**
163
 * admin_add method
164
 *
165
 * @return void
166
 */
167
	public function admin_add() {
168
		if ($this->request->is('post')) {
169
			$this->UserUrl->create();
170
			if ($this->UserUrl->save($this->request->data)) {
171
				$this->Session->setFlash(__('The user url has been saved.'));
172
				return $this->redirect(array('action' => 'index'));
173
			} else {
174
				$this->Session->setFlash(__('The user url could not be saved. Please, try again.'));
175
			}
176
		}
177
		$users = $this->UserUrl->User->find('list');
178
		$this->set(compact('users'));
179
	}
180
 
181
/**
182
 * admin_edit method
183
 *
184
 * @throws NotFoundException
185
 * @param string $id
186
 * @return void
187
 */
188
	public function admin_edit($id = null) {
189
		if (!$this->UserUrl->exists($id)) {
190
			throw new NotFoundException(__('Invalid user url'));
191
		}
192
		if ($this->request->is(array('post', 'put'))) {
193
			if ($this->UserUrl->save($this->request->data)) {
194
				$this->Session->setFlash(__('The user url has been saved.'));
195
				return $this->redirect(array('action' => 'index'));
196
			} else {
197
				$this->Session->setFlash(__('The user url could not be saved. Please, try again.'));
198
			}
199
		} else {
200
			$options = array('conditions' => array('UserUrl.' . $this->UserUrl->primaryKey => $id));
201
			$this->request->data = $this->UserUrl->find('first', $options);
202
		}
203
		$users = $this->UserUrl->User->find('list');
204
		$this->set(compact('users'));
205
	}
206
 
207
/**
208
 * admin_delete method
209
 *
210
 * @throws NotFoundException
211
 * @param string $id
212
 * @return void
213
 */
214
	public function admin_delete($id = null) {
215
		$this->UserUrl->id = $id;
216
		if (!$this->UserUrl->exists()) {
217
			throw new NotFoundException(__('Invalid user url'));
218
		}
219
		$this->request->onlyAllow('post', 'delete');
220
		if ($this->UserUrl->delete()) {
221
			$this->Session->setFlash(__('The user url has been deleted.'));
222
		} else {
223
			$this->Session->setFlash(__('The user url could not be deleted. Please, try again.'));
224
		}
225
		return $this->redirect(array('action' => 'index'));
226
	}}