Subversion Repositories SmartDukaan

Rev

Rev 14509 | Go to most recent revision | 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')) {
64
			$url = $this->apihost."negativeDeals/addNegativeDeals";
65
			$jsonVar = json_encode($this->request->data['NegativeDeal'], JSON_NUMERIC_CHECK );
66
			$response = $this->make_request($url,$jsonVar);
67
			if (key($response)) {
68
				$this->Session->setFlash(current($response));
69
				return $this->redirect(array('action' => 'index'));
70
			} else {
71
				$this->Session->setFlash(current($response));
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
		if (!$this->Exceptionalnlc->exists($id)) {
85
			throw new NotFoundException(__('Invalid exceptionalnlc'));
86
		}
87
		if ($this->request->is(array('post', 'put'))) {
88
			if ($this->Exceptionalnlc->save($this->request->data)) {
89
				$this->Session->setFlash(__('The exceptionalnlc has been saved.'));
90
				return $this->redirect(array('action' => 'index'));
91
			} else {
92
				$this->Session->setFlash(__('The exceptionalnlc could not be saved. Please, try again.'));
93
			}
94
		} else {
95
			$options = array('conditions' => array('Exceptionalnlc.' . $this->Exceptionalnlc->primaryKey => $id));
96
			$this->request->data = $this->Exceptionalnlc->find('first', $options);
97
		}
98
	}
99
 
100
/**
101
 * admin_delete method
102
 *
103
 * @throws NotFoundException
104
 * @param string $id
105
 * @return void
106
 */
107
 
108
	public function admin_delete($id = null) {		
109
		if ($this->remove($id,'NegativeDeals')) {
110
			$this->Session->setFlash(__('The negative deal has been deleted.'));
111
		} else {
112
			$this->Session->setFlash(__('The negative could not be deleted. Please, try again.'));
113
		}
114
		return $this->redirect(array('action' => 'index'));
115
	}	
116
}