Rev 17471 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?phpApp::uses('AppController', 'Controller');/*** Exceptionalnlcs Controller** @property Exceptionalnlc $Exceptionalnlc* @property PaginatorComponent $Paginator*/class FeaturedDealsController 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/getFeaturedDeals/?limit=$limit&offset=$offset";$response = $this->make_request($url,null);$this->set('featureddeals', $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";$url = $this->apihost."Catalog/searchProducts/?class=".Inflector::pluralize($this->name)."&$type=$search";debug($url);$response = $this->make_request($url,null);$this->set('featureddeals', $response);$this->set('page',1);$this->render('admin_index');}/*** 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['FeaturedDeal']['Mobiles'];$othercat['tabletrank'] = $this->request->data['FeaturedDeal']['Tablets'];$othercat['accessrank'] = $this->request->data['FeaturedDeal']['Accessories'];$rankandcat['3'] = $othercat['mobilerank'];$rankandcat['5'] = $othercat['tabletrank'];$rankandcat['6'] = $othercat['accessrank'];$this->request->data['FeaturedDeal']['startDate'] = 1000*mktime($this->request->data['FeaturedDeal']['startDate']['hour'],$this->request->data['FeaturedDeal']['startDate']['min'],0,$this->request->data['FeaturedDeal']['startDate']['month'],$this->request->data['FeaturedDeal']['startDate']['day'],$this->request->data['FeaturedDeal']['startDate']['year']);$this->request->data['FeaturedDeal']['endDate'] = 1000*mktime($this->request->data['FeaturedDeal']['endDate']['hour'],$this->request->data['FeaturedDeal']['endDate']['min'],0,$this->request->data['FeaturedDeal']['endDate']['month'],$this->request->data['FeaturedDeal']['endDate']['day'],$this->request->data['FeaturedDeal']['endDate']['year']);$form_val = array();$form_val['skuBundleId'] = $this->request->data['FeaturedDeal']['skuBundleId'];//$form_val['rank'] = $this->request->data['FeaturedDeal']['rankDetails'][0];$form_val['thresholdPrice'] = $this->request->data['FeaturedDeal']['thresholdPrice'];$form_val['startDate'] = $this->request->data['FeaturedDeal']['startDate'];$form_val['endDate'] = $this->request->data['FeaturedDeal']['endDate'];$form_val['otherInfo'] = $rankandcat;//debug($form_val);$url = $this->apihost."featuredDeals/addFeaturedDeals";$response = $this->make_request($url,json_encode($form_val,JSON_NUMERIC_CHECK));//debug($response);// unset($this->request->data['FeaturedDeal']['type']);// foreach ($this->request->data['FeaturedDeal']['rankDetails'] as $key => $value) {// if(empty($value)){// unset($this->request->data['FeaturedDeal']['rankDetails'][$key]);// }// }// $this->log(print_r($this->request->data,1),'featuredeals');// // $url = $this->apihost."featuredDeals/addFeaturedDeals";// // $data = $this->request->data['FeaturedDeal'];// // $url = $this->generateMultiUrl($url,$data);// debug($url);// // $jsonVar = json_encode($data, JSON_NUMERIC_CHECK );// // $jsonVar = json_encode($form_val,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) {// $this->request->onlyAllow('post', 'delete');if ($this->remove($id,'FeaturedDeals')) {$this->Session->setFlash(__('The feature deal has been deleted.'));} else {$this->Session->setFlash(__('The feature deal could not be deleted. Please, try again.'));}return $this->redirect(array('action' => 'index'));}}