Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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'];
61
			$data['template_id'] = 1;
62
			// debug(json_encode($data,JSON_NUMERIC_CHECK));
63
			$url = $this->apihost."addDealObject";
64
			$response = $this->make_request($url,json_encode($data,JSON_NUMERIC_CHECK));
65
			// debug($response);
66
			if (key($response)) {
67
				$this->Session->setFlash(current($response));
68
				return $this->redirect(array('action' => 'index'));
69
			} else {
70
				$this->Session->setFlash(current($response));
71
			}
72
 
73
		}
74
	}
75
 
76
/**
77
 * admin_edit method
78
 *
79
 * @throws NotFoundException
80
 * @param string $id
81
 * @return void
82
 */
83
	public function admin_edit($id = null) {
84
 
85
		if ($this->request->is(array('post', 'put'))) {
86
			$data = $this->request->data['Objects'];
87
			$data['template_id'] = 1;
88
			$data['_id'] = $id;
89
			// debug(json_encode($data,JSON_NUMERIC_CHECK));
90
			$url = $this->apihost."addDealObject/?update=1";
91
			$response = $this->make_request($url,json_encode($data,JSON_NUMERIC_CHECK));
92
			if (key($response)) {
93
				$this->Session->setFlash(current($response));
94
				return $this->redirect(array('action' => 'index'));
95
			} else {
96
				$this->Session->setFlash(current($response));
97
			}
98
		}
99
		else
100
		{
101
			$url = $this->apihost."getDealObjects/?edit=1&id=".$id;
102
			$response = $this->make_request($url,null);
103
			$Objects = $response[0];
104
			$this->set(compact('Objects'));
105
		}
106
		// if ($this->request->is(array('post', 'put'))) {
107
		// 	if ($this->Exceptionalnlc->save($this->request->data)) {
108
		// 		$this->Session->setFlash(__('The exceptionalnlc has been saved.'));
109
		// 		return $this->redirect(array('action' => 'index'));
110
		// 	} else {
111
		// 		$this->Session->setFlash(__('The exceptionalnlc could not be saved. Please, try again.'));
112
		// 	}
113
		// } else {
114
		// 	$options = array('conditions' => array('Exceptionalnlc.' . $this->Exceptionalnlc->primaryKey => $id));
115
		// 	$this->request->data = $this->Exceptionalnlc->find('first', $options);
116
		// }
117
	}
118
 
119
/**
120
 * admin_delete method
121
 *
122
 * @throws NotFoundException
123
 * @param string $id
124
 * @return void
125
 */
126
 
127
	public function admin_delete($id = null) {	
128
 
129
		$url = $this->apihost."deleteDealObject/".$id;
130
		// echo $url;
131
		$response = $this->make_request($url,null);
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
		// if ($this->remove_object($id,'Objects')) {
139
		// 	$this->Session->setFlash(__('The object has been deleted.'));
140
		// } else {
141
		// 	$this->Session->setFlash(__('The object could not be deleted. Please, try again.'));
142
		// }
143
		// return $this->redirect(array('action' => 'index'));
144
	}	
145
 
146
}