Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Admin_PavilhaoController extends Zend_Controller_Action {
- private $messages;
- private $obrigatorios;
- private $nomeFront;
- private $form;
- private $editData;
- public function init() {
- if (!Zend_Auth::getInstance()->hasIdentity()) {
- return $this->redirect('/admin/auth');
- }
- $this->messages = new Icefusion_View_Helper_General_Message();
- $this->obrigatorios = array('name', 'url', 'status');
- $this->nomeFront = array('name' => 'Nome', 'url' => 'Url', 'status' => 'Status');
- $this->form = new Icefusion_View_Helper_Admin_Forms_Pavilhao();
- $url = new Icefusion_View_Helper_General_FullUrl();
- $this->view->cadastrar = $url->FullUrl('admin/pavilhao/add');
- $this->editData = new Zend_Session_Namespace('adm');
- }
- public function indexAction() {
- $this->redirect('admin/pavilhao/list');
- }
- public function addAction() {
- $this->view->form = $this->form->getFormCadastro($this->editData->data);
- unset($this->editData->data);
- $this->view->message = $this->messages->adminMessageSession->message;
- unset($this->messages->adminMessageSession->message);
- }
- public function listAction() {
- if ($this->_request->isPost()) {
- $data = $this->_request->getPost();
- $actionUrl = explode('/', $data['gridAction_id']);
- $action = end($actionUrl);
- switch ($action) {
- case 'edit':
- $this->edit($data, $data['gridAction_id']);
- break;
- case 'delete':
- $this->delete($data, $data['gridAction_id']);
- break;
- }
- } else {
- $report = new Icefusion_View_Helper_Admin_Reports_Pavilhao();
- $this->view->report = $report->getReportTable();
- }
- }
- public function importAction() {
- $this->view->formExp = $this->form->getFormExportar();
- }
- public function exportAction() {
- }
- public function saveAction() {
- $form = new Icefusion_View_Helper_Admin_Forms_Pavilhao();
- if ($this->_request->isPost()) {
- $data = $this->_request->getPost();
- $invalido = $form->isValidated($data, $this->obrigatorios);
- if (!isset($invalido) || count($invalido) == 0) {
- unset($data['submit']);
- $data['update'] = date("Y-m-d");
- $pavilhao = new Application_Model_DbTable_Pavilhoes();
- if ($data['id'] == '') {
- unset($data['id']);
- $pavilhao->insert($data);
- unset($this->messages->adminMessageSession->message);
- $this->view->message = "";
- $this->messages->successSave();
- $this->redirect("admin/pavilhao/add");
- } else {
- $where = 'id = ' . $data['id'];
- $pavilhao->update($data, $where);
- unset($this->messages->adminMessageSession->message);
- $this->view->message = "";
- $this->messages->successEdit();
- $this->redirect("admin/pavilhao/add");
- }
- } else {
- unset($this->messages->adminMessageSession->message);
- $this->view->message = "";
- $this->messages->errorSave($invalido, $this->nomeFront);
- $this->_redirect("admin/pavilhao/add");
- }
- }
- }
- public function getAddressAction() {
- $retorno->number = 25;
- $retorno->region = "teste";
- $this->_helper->json($retorno);
- }
- private function edit($data, $retorno) {
- $ids = explode(',', $data['postMassIdsid']);
- if (count($ids) == 1) {
- $model = new Application_Model_Pavilhoes();
- $data = $model->getDataById($ids[0]);
- $this->editData->data = $data;
- $this->_redirect('admin/pavilhao/add');
- } else {
- $this->_redirect($retorno);
- }
- }
- private function delete($data, $retorno) {
- $ids = explode(',', $data['postMassIdsid']);
- $categoria = new Application_Model_DbTable_Pavilhoes();
- foreach ($ids as $id) {
- try {
- $where = 'id = ' . $id;
- $categoria->delete($where);
- } catch (Exception $e) {
- print_r($e);
- die;
- }
- }
- $this->_redirect($retorno);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment