icefusion

Untitled

Oct 30th, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.87 KB | None | 0 0
  1. <?php
  2.  
  3. class Admin_SkuOptionsController extends Zend_Controller_Action {
  4.  
  5.     private $messages;
  6.     private $obrigatorios;
  7.     private $nomeFront;
  8.     private $form;
  9.     private $editData;
  10.     private $session;
  11.  
  12.     public function init() {
  13.         if (!Zend_Auth::getInstance()->hasIdentity()) {
  14.             return $this->redirect('/admin/auth');
  15.         }
  16.         $this->messages = new Icefusion_View_Helper_General_Message();
  17.         $this->session = new Icefusion_View_Helper_General_Session();
  18.         $this->obrigatorios = array('sku_id' => 'Sku', 'name' => 'Nome');
  19.         $this->nomeFront = array('sku_id' => 'Sku', 'name' => 'Nome', 'color' => 'Cor',);
  20.         $this->form = new Icefusion_View_Helper_Admin_Forms_SkuOptions();
  21.         $url = new Icefusion_View_Helper_General_FullUrl();
  22.         $this->view->cadastrar = $url->FullUrl('admin/skuoptions/add');
  23.         $this->editData = new Zend_Session_Namespace('adm');
  24.     }
  25.  
  26.     public function indexAction() {
  27.         $this->redirect('admin/skuoptions/list');
  28.     }
  29.  
  30.     public function addAction() {
  31.         $this->view->form = $this->form->getFormCadastro($this->editData->data);
  32.         unset($this->editData->data);
  33.         $this->view->message = $this->messages->adminMessageSession->message;
  34.         unset($this->messages->adminMessageSession->message);
  35.         unset($this->session->adminSession->session);
  36.     }
  37.  
  38.     public function listAction() {
  39.         if ($this->_request->isPost()) {
  40.             $data = $this->_request->getPost();
  41.             $actionUrl = explode('/', $data['gridAction_id']);
  42.             $action = end($actionUrl);
  43.             switch ($action) {
  44.                 case 'edit':
  45.                     $this->edit($data, $data['gridAction_id']);
  46.                     break;
  47.                 case 'delete':
  48.                     $this->delete($data, $data['gridAction_id']);
  49.                     break;
  50.             }
  51.         } else {
  52.             $report = new Icefusion_View_Helper_Admin_Reports_SkuOptions();
  53.             $this->view->report = $report->getReportTable();
  54.         }
  55.     }
  56.  
  57.     public function saveAction() {        
  58.         $form = new Icefusion_View_Helper_Admin_Forms_SkuOptions();        
  59.         if ($this->_request->isPost()) {            
  60.             $data = $this->_request->getPost();            
  61.             $invalido = $form->isValidated($data, $this->obrigatorios);            
  62.             if (!isset($invalido) || count($invalido) == 0) {
  63.                 unset($data['submit']);                
  64.                 $sku = new Application_Model_DbTable_SkuOptions();                
  65.                 if ($data['id'] == '') {
  66.                     unset($data['id']);  
  67.                     $data['img'] = null;
  68.                     try{
  69.                     $lastId = $sku->insert($data);                                        
  70.                     unset($this->messages->adminMessageSession->message);
  71.                     $this->view->message = "";
  72.                     $this->messages->successSave();
  73.                     $this->session->adminSession->lastId = $lastId;
  74.                     $this->redirect("admin/skuoptions/add");
  75.                     }catch(Exception $e){
  76.                         var_dump($e);exit;
  77.                     }
  78.                 } else {
  79.                     $where = 'id = ' . $data['id'];
  80.                     $lastId = $sku->update($data, $where);
  81.                     unset($this->messages->adminMessageSession->message);
  82.                     $this->view->message = "";
  83.                     $this->messages->successEdit();
  84.                     $this->session->adminSession->lastId = $lastId;
  85.                     $this->redirect("admin/skuoptions/add");
  86.                 }
  87.             } else {
  88.                 unset($this->messages->adminMessageSession->message);
  89.                 $this->view->message = "";
  90.                 $this->messages->errorSave($invalido, $this->nomeFront);
  91.                 $this->redirect("admin/skuoptions/add");
  92.             }
  93.         }
  94.     }
  95.  
  96.     private function edit($postMassIds, $retorno) {
  97.         $ids = explode(',', $postMassIds['postMassIdsid']);
  98.         if (count($ids) == 1) {
  99.             $model = new Application_Model_SkuOptions();
  100.             $data = $model->getDataById($ids[0]);
  101.             $this->editData->data = $data;
  102.             $this->_redirect('admin/skuoptions/add');
  103.         } else {
  104.             $this->_redirect($retorno);
  105.         }
  106.     }
  107.  
  108.     private function delete($data, $retorno) {
  109.         $ids = explode(',', $data['postMassIdsid']);
  110.         $categoria = new Application_Model_DbTable_SkuOptions();
  111.         foreach ($ids as $id) {
  112.             try {
  113.                 $where = 'id = ' . $id;
  114.                 $categoria->delete($where);
  115.             } catch (Exception $e) {
  116.                 print_r($e);
  117.                 die;
  118.             }
  119.         }
  120.         $this->_redirect($retorno);
  121.     }
  122.  
  123. }
Advertisement
Add Comment
Please, Sign In to add comment