Subversion Repositories SmartDukaan

Rev

Rev 17630 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
App::uses('AppController', 'Controller');
/**
 * Exceptionalnlcs Controller
 *
 * @property Exceptionalnlc $Exceptionalnlc
 * @property PaginatorComponent $Paginator
 */
class DealobjectsController 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."featuredDeals/getAllFeaturedDealObject/?limit=$limit&offset=$offset";
                $response = $this->make_request($url,null);
                $this->set('dealobjects', $response);
                $this->set('page',$page);
        }

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


/**
 * admin_add method
 *
 * @return void
 */
        public function admin_add() {
                if ($this->request->is('post')) {                       
                        // date_default_timezone_set('UTC'); 
                        $otherrank = array();
                        $othercat = array();
                        $othercat['mobilerank'] = $this->request->data['Dealobjects']['Mobiles'];
                        $othercat['tabletrank'] = $this->request->data['Dealobjects']['Tablets'];
                        $othercat['accessrank'] = $this->request->data['Dealobjects']['Accessories'];
                        $rankandcat['3'] = $othercat['mobilerank'];
                        $rankandcat['5'] = $othercat['tabletrank'];
                        $rankandcat['6'] = $othercat['accessrank'];
                        $this->request->data['Dealobjects']['startDate'] = 1000*mktime($this->request->data['Dealobjects']['startDate']['hour'],$this->request->data['Dealobjects']['startDate']['min'],0,$this->request->data['Dealobjects']['startDate']['month'],$this->request->data['Dealobjects']['startDate']['day'],$this->request->data['Dealobjects']['startDate']['year']);
                        $this->request->data['Dealobjects']['endDate'] = 1000*mktime($this->request->data['Dealobjects']['endDate']['hour'],$this->request->data['Dealobjects']['endDate']['min'],0,$this->request->data['Dealobjects']['endDate']['month'],$this->request->data['Dealobjects']['endDate']['day'],$this->request->data['Dealobjects']['endDate']['year']);
                        $form_val = array();
                        $form_val['_id'] = $this->request->data['Dealobjects']['id'];
                        
                        $form_val['startDate'] = $this->request->data['Dealobjects']['startDate'];
                        $form_val['endDate'] = $this->request->data['Dealobjects']['endDate'];
                        $form_val['otherInfo'] = $rankandcat;
                        $form_val['offer_id'] = $this->request->data['Dealobjects']['OfferId'];
                        $url = $this->apihost."featuredDeals/addFeaturedDealObject";
                        $response = $this->make_request($url,json_encode($form_val,JSON_NUMERIC_CHECK));
                        if (key($response)) {
                                $this->Session->setFlash(current($response));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(current($response));
                        }       
                }
        }


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

        public function admin_delete($id = null) {              
                $url = $this->apihost."deleteFeaturedDealObject/".$id;
                $response = $this->make_request($url,null);
                if (key($response)) {
                        $this->Session->setFlash(current($response));
                        return $this->redirect(array('action' => 'index'));
                } else {
                        $this->Session->setFlash(current($response));
                }
        }       
}