Subversion Repositories SmartDukaan

Rev

Details | 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
 
18
	public function beforeFilter() {
19
		parent::beforeFilter();
20
		$this->response->type('json');
21
		$this->layout = 'ajax';
22
		$this->Auth->allow();
23
	}
24
/**
25
 * index method
26
 *
27
 * @return void
28
 */
29
	public function index() {
30
		$this->Userurl->recursive = 0;
31
		$this->set('userurls', $this->Paginator->paginate());
32
	}
33
 
34
/**
35
 * view method
36
 *
37
 * @throws NotFoundException
38
 * @param string $id
39
 * @return void
40
 */
41
	public function view($id = null) {
42
		if (!$this->Userurl->exists($id)) {
43
			throw new NotFoundException(__('Invalid userurl'));
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
		$data = array('url'=>$this->request->query('url'),'user_id'=>$this->request->query('user_id'));
56
		$this->Userurl->create();
57
		if ($this->Userurl->save($data)) {
58
			$message = 'The url has been saved.';
59
		} else {
60
			$message = 'The url could not be saved. Please, try again.';
61
		}
62
		$result = array('success'=>true,'message'=>$message);
63
		$this->set(array(
64
		    'result' => $result,
65
		    'callback' => $callback,
66
		    '_serialize' => array('result')
67
		));
68
		$this->render('/Elements/jsonp');
69
	}
70
 
71
/**
72
 * edit method
73
 *
74
 * @throws NotFoundException
75
 * @param string $id
76
 * @return void
77
 */
78
	public function edit($id = null) {
79
		if (!$this->Userurl->exists($id)) {
80
			throw new NotFoundException(__('Invalid userurl'));
81
		}
82
		if ($this->request->is(array('post', 'put'))) {
83
			if ($this->Userurl->save($this->request->data)) {
84
				$this->Session->setFlash(__('The userurl has been saved.'));
85
				return $this->redirect(array('action' => 'index'));
86
			} else {
87
				$this->Session->setFlash(__('The userurl could not be saved. Please, try again.'));
88
			}
89
		} else {
90
			$options = array('conditions' => array('Userurl.' . $this->Userurl->primaryKey => $id));
91
			$this->request->data = $this->Userurl->find('first', $options);
92
		}
93
	}
94
 
95
/**
96
 * delete method
97
 *
98
 * @throws NotFoundException
99
 * @param string $id
100
 * @return void
101
 */
102
	public function delete($id = null) {
103
		$this->Userurl->id = $id;
104
		if (!$this->Userurl->exists()) {
105
			throw new NotFoundException(__('Invalid userurl'));
106
		}
107
		$this->request->onlyAllow('post', 'delete');
108
		if ($this->Userurl->delete()) {
109
			$this->Session->setFlash(__('The userurl has been deleted.'));
110
		} else {
111
			$this->Session->setFlash(__('The userurl could not be deleted. Please, try again.'));
112
		}
113
		return $this->redirect(array('action' => 'index'));
114
	}
115
 
116
/**
117
 * admin_index method
118
 *
119
 * @return void
120
 */
121
	public function admin_index() {
122
		$this->Userurl->recursive = 0;
123
		$this->set('userurls', $this->Paginator->paginate());
124
	}
125
 
126
/**
127
 * admin_view method
128
 *
129
 * @throws NotFoundException
130
 * @param string $id
131
 * @return void
132
 */
133
	public function admin_view($id = null) {
134
		if (!$this->Userurl->exists($id)) {
135
			throw new NotFoundException(__('Invalid userurl'));
136
		}
137
		$options = array('conditions' => array('Userurl.' . $this->Userurl->primaryKey => $id));
138
		$this->set('userurl', $this->Userurl->find('first', $options));
139
	}
140
 
141
/**
142
 * admin_add method
143
 *
144
 * @return void
145
 */
146
	public function admin_add() {
147
		if ($this->request->is('post')) {
148
			$this->Userurl->create();
149
			if ($this->Userurl->save($this->request->data)) {
150
				$this->Session->setFlash(__('The userurl has been saved.'));
151
				return $this->redirect(array('action' => 'index'));
152
			} else {
153
				$this->Session->setFlash(__('The userurl could not be saved. Please, try again.'));
154
			}
155
		}
156
	}
157
 
158
/**
159
 * admin_edit method
160
 *
161
 * @throws NotFoundException
162
 * @param string $id
163
 * @return void
164
 */
165
	public function admin_edit($id = null) {
166
		if (!$this->Userurl->exists($id)) {
167
			throw new NotFoundException(__('Invalid userurl'));
168
		}
169
		if ($this->request->is(array('post', 'put'))) {
170
			if ($this->Userurl->save($this->request->data)) {
171
				$this->Session->setFlash(__('The userurl has been saved.'));
172
				return $this->redirect(array('action' => 'index'));
173
			} else {
174
				$this->Session->setFlash(__('The userurl could not be saved. Please, try again.'));
175
			}
176
		} else {
177
			$options = array('conditions' => array('Userurl.' . $this->Userurl->primaryKey => $id));
178
			$this->request->data = $this->Userurl->find('first', $options);
179
		}
180
	}
181
 
182
/**
183
 * admin_delete method
184
 *
185
 * @throws NotFoundException
186
 * @param string $id
187
 * @return void
188
 */
189
	public function admin_delete($id = null) {
190
		$this->Userurl->id = $id;
191
		if (!$this->Userurl->exists()) {
192
			throw new NotFoundException(__('Invalid userurl'));
193
		}
194
		$this->request->onlyAllow('post', 'delete');
195
		if ($this->Userurl->delete()) {
196
			$this->Session->setFlash(__('The userurl has been deleted.'));
197
		} else {
198
			$this->Session->setFlash(__('The userurl could not be deleted. Please, try again.'));
199
		}
200
		return $this->redirect(array('action' => 'index'));
201
	}}