Subversion Repositories SmartDukaan

Rev

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

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

/**
 * admin_view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function admin_search() {
        }

/**
 * admin_add method
 *
 * @return void
 */
        public function admin_add() {
                if ($this->request->is('post')) {
                        $data = $this->request->data['Objects'];
                        // debug($data);
            if($data['template_id']=='template2')
            {
                $senddata['template_id'] = 2;
                $senddata['name'] = $data['name'];
                $senddata['img_url'] = $data['img_url'];
                $senddata['link'] = $data['link'];
            }

            if($data['template_id']=='template1')
            {
                $senddata['template_id'] = 1;
                $senddata['name'] = $data['name'];
                $senddata['img_url'] = $data['img_url'];
                $senddata['link1'] = $data['link1'];
                $senddata['link2'] = $data['link2'];
                $senddata['link3'] = $data['link3'];
                $senddata['link4'] = $data['link4'];
                $senddata['link5'] = $data['link5'];
            }
                        
                        // debug(json_encode($data,JSON_NUMERIC_CHECK));
                        $url = $this->apihost."addDealObject";
                        $response = $this->make_request($url,json_encode($senddata,JSON_NUMERIC_CHECK));
                        // debug($response);
                        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->request->is(array('post', 'put'))) {
                        $data = $this->request->data['Objects'];

            if($data['template_id']==2)
            {
                $senddata['template_id'] = 2;
                $senddata['name'] = $data['name'];
                $senddata['img_url'] = $data['img_url'];
                $senddata['link'] = $data['link'];
            }

            if($data['template_id']==1)
            {
                $senddata['template_id'] = 1;
                $senddata['name'] = $data['name'];
                $senddata['img_url'] = $data['img_url'];
                $senddata['link1'] = $data['link1'];
                $senddata['link2'] = $data['link2'];
                $senddata['link3'] = $data['link3'];
                $senddata['link4'] = $data['link4'];
                $senddata['link5'] = $data['link5'];
            }
                        
                        $senddata['_id'] = $id;
                        // debug(json_encode($data,JSON_NUMERIC_CHECK));
                        $url = $this->apihost."addDealObject/?update=1";
                        $response = $this->make_request($url,json_encode($senddata,JSON_NUMERIC_CHECK));
                        if (key($response)) {
                                $this->Session->setFlash(current($response));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(current($response));
                        }
                }
                else
                {
                        $url = $this->apihost."getDealObjects/?edit=1&id=".$id;
                        $response = $this->make_request($url,null);
                        $Objects = $response[0];
                        $this->set(compact('Objects'));
                }
                // 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) {      

                $url = $this->apihost."deleteDealObject/".$id;
                // echo $url;
                $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));
                }
                // if ($this->remove_object($id,'Objects')) {
                //      $this->Session->setFlash(__('The object has been deleted.'));
                // } else {
                //      $this->Session->setFlash(__('The object could not be deleted. Please, try again.'));
                // }
                // return $this->redirect(array('action' => 'index'));
        }       

}