Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
13646 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Exceptionalnlcs Controller
5
 *
6
 * @property Exceptionalnlc $Exceptionalnlc
7
 * @property PaginatorComponent $Paginator
8
 */
9
class ExceptionalnlcsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
18
	public function beforeFilter() {
19
		parent::beforeFilter();
13946 anikendra 20
//		Configure::load('live');
13646 anikendra 21
		$this->apihost = Configure::read('pythonapihost');
22
	}
23
/**
24
 * admin_index method
25
 *
26
 * @return void
27
 */
28
	public function admin_index() {
14098 anikendra 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."exceptionalNlc/getExceptionalNlc/?limit=$limit&offset=$offset";
13646 anikendra 36
		$response = $this->make_request($url,null);
37
		$this->set('exceptionalnlcs', $response);
14098 anikendra 38
		$this->set('page',$page);
13646 anikendra 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=ExceptionalNlc&$type=$search";
52
		$response = $this->make_request($url,null);
53
		$this->set('exceptionalnlcs', $response);
54
		$this->set('page',1);
55
		$this->render('admin_index');
13646 anikendra 56
	}
57
 
58
/**
59
 * admin_add method
60
 *
61
 * @return void
62
 */
63
	public function admin_add() {
64
		if ($this->request->is('post')) {
65
			$url = $this->apihost."exceptionalNlc/addExceptionalNlc";
14561 anikendra 66
			$data = $this->request->data['Exceptionalnlc'];
67
			$url = $this->generateMultiUrl($url,$data);
68
			$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
13646 anikendra 69
			$response = $this->make_request($url,$jsonVar);
70
			if (key($response)) {
71
				$this->Session->setFlash(current($response));
72
				return $this->redirect(array('action' => 'index'));
73
			} else {
74
				$this->Session->setFlash(current($response));
75
			}	
76
		}
77
	}
78
 
79
/**
80
 * admin_edit method
81
 *
82
 * @throws NotFoundException
83
 * @param string $id
84
 * @return void
85
 */
86
	public function admin_edit($id = null) {
87
		if (!$this->Exceptionalnlc->exists($id)) {
88
			throw new NotFoundException(__('Invalid exceptionalnlc'));
89
		}
90
		if ($this->request->is(array('post', 'put'))) {
91
			if ($this->Exceptionalnlc->save($this->request->data)) {
92
				$this->Session->setFlash(__('The exceptionalnlc has been saved.'));
93
				return $this->redirect(array('action' => 'index'));
94
			} else {
95
				$this->Session->setFlash(__('The exceptionalnlc could not be saved. Please, try again.'));
96
			}
97
		} else {
98
			$options = array('conditions' => array('Exceptionalnlc.' . $this->Exceptionalnlc->primaryKey => $id));
99
			$this->request->data = $this->Exceptionalnlc->find('first', $options);
100
		}
101
	}
102
 
103
/**
104
 * admin_delete method
105
 *
106
 * @throws NotFoundException
107
 * @param string $id
108
 * @return void
109
 */
14517 anikendra 110
 
111
	public function admin_delete($id = null) {		
15848 anikendra 112
		$response = $this->remove($id,'ExceptionalNlc');
113
		if ($response) {
114
			$this->Session->setFlash(current($response));
13646 anikendra 115
		} else {
15848 anikendra 116
			$this->Session->setFlash(current($response));
13646 anikendra 117
		}
118
		return $this->redirect(array('action' => 'index'));
14517 anikendra 119
	}
120
}