Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

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