Subversion Repositories SmartDukaan

Rev

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