Subversion Repositories SmartDukaan

Rev

Rev 14517 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
14509 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Exceptionalnlcs Controller
5
 *
6
 * @property Exceptionalnlc $Exceptionalnlc
7
 * @property PaginatorComponent $Paginator
8
 */
9
class NegativeDealsController 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."negativeDeals/getNegativeDeals/?limit=$limit&offset=$offset";
36
		$response = $this->make_request($url,null);
37
		$this->set('negativedeals', $response);
38
		$this->set('page',$page);
39
	}
40
 
41
/**
42
 * admin_view method
43
 *
44
 * @throws NotFoundException
45
 * @param string $id
46
 * @return void
47
 */
14517 anikendra 48
	public function admin_search() {
49
		$type = $this->request->query('type');
50
		$search = $this->request->query('search');				
51
		$url = $this->apihost."Catalog/searchProducts/?class=".Inflector::pluralize($this->name)."&$type=$search";
52
		$response = $this->make_request($url,null);
53
		$this->set('negativedeals', $response);
54
		$this->set('page',1);
55
		$this->render('admin_index');
14509 anikendra 56
	}
57
/**
58
 * admin_add method
59
 *
60
 * @return void
61
 */
62
	public function admin_new() {
63
		if ($this->request->is('post')) {
14561 anikendra 64
			$data = $this->request->data['NegativeDeal'];
14509 anikendra 65
			$url = $this->apihost."negativeDeals/addNegativeDeals";
14561 anikendra 66
			$url = $this->generateMultiUrl($url,$data);
67
			$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
14509 anikendra 68
			$response = $this->make_request($url,$jsonVar);
69
			if (key($response)) {
70
				$this->Session->setFlash(current($response));
71
				return $this->redirect(array('action' => 'index'));
72
			} else {
73
				$this->Session->setFlash(current($response));
74
			}	
75
		}
76
	}
77
 
78
/**
79
 * admin_edit method
80
 *
81
 * @throws NotFoundException
82
 * @param string $id
83
 * @return void
84
 */
85
	public function admin_edit($id = null) {
86
		if (!$this->Exceptionalnlc->exists($id)) {
87
			throw new NotFoundException(__('Invalid exceptionalnlc'));
88
		}
89
		if ($this->request->is(array('post', 'put'))) {
90
			if ($this->Exceptionalnlc->save($this->request->data)) {
91
				$this->Session->setFlash(__('The exceptionalnlc has been saved.'));
92
				return $this->redirect(array('action' => 'index'));
93
			} else {
94
				$this->Session->setFlash(__('The exceptionalnlc could not be saved. Please, try again.'));
95
			}
96
		} else {
97
			$options = array('conditions' => array('Exceptionalnlc.' . $this->Exceptionalnlc->primaryKey => $id));
98
			$this->request->data = $this->Exceptionalnlc->find('first', $options);
99
		}
100
	}
101
 
102
/**
103
 * admin_delete method
104
 *
105
 * @throws NotFoundException
106
 * @param string $id
107
 * @return void
108
 */
109
 
110
	public function admin_delete($id = null) {		
111
		if ($this->remove($id,'NegativeDeals')) {
112
			$this->Session->setFlash(__('The negative deal has been deleted.'));
113
		} else {
114
			$this->Session->setFlash(__('The negative could not be deleted. Please, try again.'));
115
		}
116
		return $this->redirect(array('action' => 'index'));
117
	}	
118
}