Exemple #1
0
 /**
  * Add custom fields to menu item form for render a simple category layout menu item
  */
 private function simpleCategoryLayout()
 {
     $txtCategory = $this->createElement("select", "category")->setOrder($this->order++)->setLabel("CONTACT_CATEGORY_SELECT")->setRequired(true);
     $mdlCategory = new Contact_Model_Category();
     $categoryList = $mdlCategory->getSimpleList();
     foreach ($categoryList as $category) {
         $txtCategory->addMultiOption($category->id, $category->title);
     }
     $this->addElement($txtCategory);
 }
 /**
  * Edit action for contact controller
  * @throws Exception
  */
 public function editAction()
 {
     // action body
     try {
         $translate = Zend_Registry::get('Zend_Translate');
         $frmContact = new Contact_Form_Contact();
         $frmContact->setAction($this->_request->getBaseUrl() . "/contact/contact/edit");
         $id = $this->getRequest()->getParam('id', 0);
         $mdlContact = new Contact_Model_Contact();
         $contact = $mdlContact->find($id)->current();
         if (!$contact) {
             throw new Exception($translate->translate("LBL_ROW_NOT_FOUND"));
         }
         $mdlAccount = new Acl_Model_Account();
         $accountList = $mdlAccount->getSimpleList();
         $cbAccount = $frmContact->getElement('account_id');
         foreach ($accountList as $account) {
             $cbAccount->addMultiOption($account->id, $account->email);
         }
         $mdlCategory = new Contact_Model_Category();
         $categoryList = $mdlCategory->getSimpleList();
         $cbCategory = $frmContact->getElement('category_id');
         foreach ($categoryList as $category) {
             $cbCategory->addMultiOption($category->id, $category->title);
         }
         if ($this->getRequest()->isPost()) {
             if ($frmContact->isValid($_POST)) {
                 $fileName = $contact->image;
                 if ($frmContact->image->isUploaded()) {
                     $ext = end(explode('.', $frmContact->image->getFileName()));
                     $frmContact->image->addFilter('Rename', implode('_', array('cc', date('YmdHis'))) . '.' . $ext);
                     $frmContact->image->receive();
                     $fileName = $frmContact->image->getFileName(null, false);
                     chmod(DIR_MOD_CONTACT_IMG_UPLOADS . '/' . $fileName, 0755);
                     $thumb = Zend_Layout::getMvcInstance()->getView()->thumbnail(DIR_MOD_CONTACT_IMG_UPLOADS . '/' . $fileName, 70, 70, DIR_MOD_CONTACT_THUMB_UPLOADS . '/', DIR_MOD_CONTACT_THUMB_UPLOADS);
                     chmod($thumb, 0755);
                     # eliminando original
                     unlink(DIR_MOD_CONTACT_IMG_UPLOADS . '/' . $contact->image);
                     $imgParts = explode('.', $contact->image);
                     $nameImg = current($imgParts);
                     $ext = end($imgParts);
                     # eliminando thumb original
                     unlink(DIR_MOD_CONTACT_THUMB_UPLOADS . '/' . $nameImg . '_thumb.' . $ext);
                 }
                 $contact->setFromArray($frmContact->getValues());
                 $contact->image = $fileName;
                 $contact->save();
                 $this->_helper->flashMessenger->addMessage(array('type' => 'info', 'header' => '', 'message' => $translate->translate("LBL_ITEM_UPDATED_SUCCESSFULLY")));
                 $this->_helper->redirector("listregistered", "contact", "contact");
             }
         } else {
             $frmContact->populate($contact->toArray());
             $fields = array();
             foreach ($frmContact->getElements() as $element) {
                 $fields[] = $element->getName();
             }
             $frmContact->addDisplayGroup($fields, 'form', array('legend' => "CONTACT_EDIT"));
         }
         $this->view->frmContact = $frmContact;
     } catch (Exception $e) {
         $this->_helper->flashMessenger->addMessage(array('type' => 'error', 'header' => '', 'message' => $e->getMessage()));
         $this->_helper->redirector("listregistered", "contact", "contact");
     }
     return;
 }
 /**
  * View action for category controller
  * @throws Exception
  */
 public function viewAction()
 {
     // action body
     try {
         $translate = Zend_Registry::get('Zend_Translate');
         $params = $this->getRequest()->getParams();
         $mdlCategory = new Contact_Model_Category();
         $mdlContact = new Contact_Model_Contact();
         $category = $mdlCategory->find((int) $params['category'])->current();
         if (!$category) {
             throw new Exception($translate->translate("CONTACT_ROW_NOT_FOUND"));
         }
         $contactList = $mdlContact->getByCategory($category);
         $this->view->contacts = $contactList;
     } catch (Exception $e) {
         $this->_helper->flashMessenger->addMessage(array('type' => 'error', 'header' => '', 'message' => $e->getMessage()));
         $this->_helper->redirector("index", "contact", "contact");
     }
     return;
 }