Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

<?php
App::uses('AppController', 'Controller');
/**
 * Exceptionalnlcs Controller
 *
 * @property Exceptionalnlc $Exceptionalnlc
 * @property PaginatorComponent $Paginator
 */
class NegativeDealsController extends AppController {

/**
 * Components
 *
 * @var array
 */
        public $components = array('Paginator');

        public function beforeFilter() {
                parent::beforeFilter();
//              Configure::load('live');
                $this->apihost = Configure::read('pythonapihost');
        }
/**
 * admin_index method
 *
 * @return void
 */
        public function admin_index() {
                $page = $this->request->query('page');
                if(!isset($page)){
                        $page = 1;
                }
                $limit = Configure::read('admindashboardlimit');
                $offset = ($page - 1)*$limit;
                $url = $this->apihost."negativeDeals/getNegativeDeals/?limit=$limit&offset=$offset";
                $response = $this->make_request($url,null);
                $this->set('negativedeals', $response);
                $this->set('page',$page);
        }

/**
 * admin_view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function admin_search() {
                $type = $this->request->query('type');
                $search = $this->request->query('search');                              
                $url = $this->apihost."Catalog/searchProducts/?class=".Inflector::pluralize($this->name)."&$type=$search";
                $response = $this->make_request($url,null);
                $this->set('negativedeals', $response);
                $this->set('page',1);
                $this->render('admin_index');
        }
/**
 * admin_add method
 *
 * @return void
 */
        public function admin_new() {
                if ($this->request->is('post')) {
                        $data = $this->request->data['NegativeDeal'];
                        $url = $this->apihost."negativeDeals/addNegativeDeals";
                        $url = $this->generateMultiUrl($url,$data);
                        $jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
                        $response = $this->make_request($url,$jsonVar);
                        if (key($response)) {
                                $this->Session->setFlash(current($response));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(current($response));
                        }       
                }
        }

/**
 * admin_edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function admin_edit($id = null) {
                if (!$this->Exceptionalnlc->exists($id)) {
                        throw new NotFoundException(__('Invalid exceptionalnlc'));
                }
                if ($this->request->is(array('post', 'put'))) {
                        if ($this->Exceptionalnlc->save($this->request->data)) {
                                $this->Session->setFlash(__('The exceptionalnlc has been saved.'));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The exceptionalnlc could not be saved. Please, try again.'));
                        }
                } else {
                        $options = array('conditions' => array('Exceptionalnlc.' . $this->Exceptionalnlc->primaryKey => $id));
                        $this->request->data = $this->Exceptionalnlc->find('first', $options);
                }
        }

/**
 * admin_delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */

        public function admin_delete($id = null) {              
                if ($this->remove($id,'NegativeDeals')) {
                        $this->Session->setFlash(__('The negative deal has been deleted.'));
                } else {
                        $this->Session->setFlash(__('The negative could not be deleted. Please, try again.'));
                }
                return $this->redirect(array('action' => 'index'));
        }       
}