| 17596 |
naman |
1 |
<?php
|
|
|
2 |
App::uses('AppController', 'Controller');
|
|
|
3 |
/**
|
|
|
4 |
* Exceptionalnlcs Controller
|
|
|
5 |
*
|
|
|
6 |
* @property Exceptionalnlc $Exceptionalnlc
|
|
|
7 |
* @property PaginatorComponent $Paginator
|
|
|
8 |
*/
|
|
|
9 |
class ObjectsController 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 |
// Configure::load('live');
|
|
|
21 |
$this->apihost = Configure::read('pythonapihost');
|
|
|
22 |
}
|
|
|
23 |
/**
|
|
|
24 |
* admin_index method
|
|
|
25 |
*
|
|
|
26 |
* @return void
|
|
|
27 |
*/
|
|
|
28 |
public function admin_index() {
|
|
|
29 |
$page = $this->request->query('page');
|
|
|
30 |
if(!isset($page)){
|
|
|
31 |
$page = 1;
|
|
|
32 |
}
|
|
|
33 |
$limit = Configure::read('admindashboardlimit');
|
|
|
34 |
$offset = ($page - 1)*$limit;
|
|
|
35 |
$url = $this->apihost."getDealObjects/?limit=$limit&offset=$offset";
|
|
|
36 |
// echo $url;
|
|
|
37 |
$response = $this->make_request($url,null);
|
|
|
38 |
// debug($response);
|
|
|
39 |
$this->set('objects', $response);
|
|
|
40 |
$this->set('page',$page);
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* admin_view method
|
|
|
45 |
*
|
|
|
46 |
* @throws NotFoundException
|
|
|
47 |
* @param string $id
|
|
|
48 |
* @return void
|
|
|
49 |
*/
|
|
|
50 |
public function admin_search() {
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* admin_add method
|
|
|
55 |
*
|
|
|
56 |
* @return void
|
|
|
57 |
*/
|
|
|
58 |
public function admin_add() {
|
|
|
59 |
if ($this->request->is('post')) {
|
|
|
60 |
$data = $this->request->data['Objects'];
|
| 17896 |
naman |
61 |
// debug($data);
|
|
|
62 |
if($data['template_id']=='template2')
|
|
|
63 |
{
|
|
|
64 |
$senddata['template_id'] = 2;
|
|
|
65 |
$senddata['name'] = $data['name'];
|
|
|
66 |
$senddata['img_url'] = $data['img_url'];
|
|
|
67 |
$senddata['link'] = $data['link'];
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
if($data['template_id']=='template1')
|
|
|
71 |
{
|
|
|
72 |
$senddata['template_id'] = 1;
|
|
|
73 |
$senddata['name'] = $data['name'];
|
|
|
74 |
$senddata['img_url'] = $data['img_url'];
|
|
|
75 |
$senddata['link1'] = $data['link1'];
|
|
|
76 |
$senddata['link2'] = $data['link2'];
|
|
|
77 |
$senddata['link3'] = $data['link3'];
|
|
|
78 |
$senddata['link4'] = $data['link4'];
|
|
|
79 |
$senddata['link5'] = $data['link5'];
|
|
|
80 |
}
|
|
|
81 |
|
| 17596 |
naman |
82 |
// debug(json_encode($data,JSON_NUMERIC_CHECK));
|
|
|
83 |
$url = $this->apihost."addDealObject";
|
| 17896 |
naman |
84 |
$response = $this->make_request($url,json_encode($senddata,JSON_NUMERIC_CHECK));
|
| 17596 |
naman |
85 |
// debug($response);
|
|
|
86 |
if (key($response)) {
|
|
|
87 |
$this->Session->setFlash(current($response));
|
|
|
88 |
return $this->redirect(array('action' => 'index'));
|
|
|
89 |
} else {
|
|
|
90 |
$this->Session->setFlash(current($response));
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
/**
|
|
|
97 |
* admin_edit method
|
|
|
98 |
*
|
|
|
99 |
* @throws NotFoundException
|
|
|
100 |
* @param string $id
|
|
|
101 |
* @return void
|
|
|
102 |
*/
|
|
|
103 |
public function admin_edit($id = null) {
|
|
|
104 |
|
|
|
105 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
106 |
$data = $this->request->data['Objects'];
|
| 17896 |
naman |
107 |
|
|
|
108 |
if($data['template_id']==2)
|
|
|
109 |
{
|
|
|
110 |
$senddata['template_id'] = 2;
|
|
|
111 |
$senddata['name'] = $data['name'];
|
|
|
112 |
$senddata['img_url'] = $data['img_url'];
|
|
|
113 |
$senddata['link'] = $data['link'];
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
if($data['template_id']==1)
|
|
|
117 |
{
|
|
|
118 |
$senddata['template_id'] = 1;
|
|
|
119 |
$senddata['name'] = $data['name'];
|
|
|
120 |
$senddata['img_url'] = $data['img_url'];
|
|
|
121 |
$senddata['link1'] = $data['link1'];
|
|
|
122 |
$senddata['link2'] = $data['link2'];
|
|
|
123 |
$senddata['link3'] = $data['link3'];
|
|
|
124 |
$senddata['link4'] = $data['link4'];
|
|
|
125 |
$senddata['link5'] = $data['link5'];
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
$senddata['_id'] = $id;
|
| 17596 |
naman |
129 |
// debug(json_encode($data,JSON_NUMERIC_CHECK));
|
|
|
130 |
$url = $this->apihost."addDealObject/?update=1";
|
| 17896 |
naman |
131 |
$response = $this->make_request($url,json_encode($senddata,JSON_NUMERIC_CHECK));
|
| 17596 |
naman |
132 |
if (key($response)) {
|
|
|
133 |
$this->Session->setFlash(current($response));
|
|
|
134 |
return $this->redirect(array('action' => 'index'));
|
|
|
135 |
} else {
|
|
|
136 |
$this->Session->setFlash(current($response));
|
|
|
137 |
}
|
|
|
138 |
}
|
|
|
139 |
else
|
|
|
140 |
{
|
|
|
141 |
$url = $this->apihost."getDealObjects/?edit=1&id=".$id;
|
|
|
142 |
$response = $this->make_request($url,null);
|
|
|
143 |
$Objects = $response[0];
|
|
|
144 |
$this->set(compact('Objects'));
|
|
|
145 |
}
|
|
|
146 |
// if ($this->request->is(array('post', 'put'))) {
|
|
|
147 |
// if ($this->Exceptionalnlc->save($this->request->data)) {
|
|
|
148 |
// $this->Session->setFlash(__('The exceptionalnlc has been saved.'));
|
|
|
149 |
// return $this->redirect(array('action' => 'index'));
|
|
|
150 |
// } else {
|
|
|
151 |
// $this->Session->setFlash(__('The exceptionalnlc could not be saved. Please, try again.'));
|
|
|
152 |
// }
|
|
|
153 |
// } else {
|
|
|
154 |
// $options = array('conditions' => array('Exceptionalnlc.' . $this->Exceptionalnlc->primaryKey => $id));
|
|
|
155 |
// $this->request->data = $this->Exceptionalnlc->find('first', $options);
|
|
|
156 |
// }
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
/**
|
|
|
160 |
* admin_delete method
|
|
|
161 |
*
|
|
|
162 |
* @throws NotFoundException
|
|
|
163 |
* @param string $id
|
|
|
164 |
* @return void
|
|
|
165 |
*/
|
|
|
166 |
|
|
|
167 |
public function admin_delete($id = null) {
|
|
|
168 |
|
|
|
169 |
$url = $this->apihost."deleteDealObject/".$id;
|
|
|
170 |
// echo $url;
|
|
|
171 |
$response = $this->make_request($url,null);
|
|
|
172 |
if (key($response)) {
|
|
|
173 |
$this->Session->setFlash(current($response));
|
|
|
174 |
return $this->redirect(array('action' => 'index'));
|
|
|
175 |
} else {
|
|
|
176 |
$this->Session->setFlash(current($response));
|
|
|
177 |
}
|
|
|
178 |
// if ($this->remove_object($id,'Objects')) {
|
|
|
179 |
// $this->Session->setFlash(__('The object has been deleted.'));
|
|
|
180 |
// } else {
|
|
|
181 |
// $this->Session->setFlash(__('The object could not be deleted. Please, try again.'));
|
|
|
182 |
// }
|
|
|
183 |
// return $this->redirect(array('action' => 'index'));
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
}
|