コード例 #1
0
 public function editAction()
 {
     //load params
     $this->_globalSettings = HCMS_Utils::loadThemeConfig('config.php', 'contact');
     $fieldTypes = HCMS_Utils::loadThemeConfig('types.php', 'contact');
     if ($this->_request->getParam('form_id')) {
         $this->_formId = $this->_request->getParam('form_id');
     }
     if (!isset($this->_globalSettings['forms'][$this->_formId])) {
         throw new Exception("Form not found");
     }
     $this->_formParams = $this->_globalSettings['forms'][$this->_formId];
     $this->_fields = Contact_Form_Generic::getFieldsArr($fieldTypes, $this->_formParams['fields']);
     $data = $this->getRequest()->getPost('data');
     $id = $this->_getParam('id');
     //check if cancel button is pressed
     if ($this->_formHelper->isCancel()) {
         //cancel form
         return $this->_formHelper->returnCancel($this->view->url(array('action' => 'index')), $this->translate('Action canceled'));
     }
     //create form object
     $form = new Contact_Form_AdminSubscribe($data);
     //postback - save?
     if ($this->_formHelper->isSave()) {
         //check if valid
         if ($form->isValid()) {
             $values = $form->getValues();
             $subscription = new Contact_Model_Subscription($values);
             if (isset($data['id'])) {
                 $oldSubscription = new Contact_Model_Subscription();
                 if (Contact_Model_SubscriptionMapper::getInstance()->find($data['id'], $oldSubscription) && $oldSubscription->get_status() != $subscription->get_status()) {
                     $dt = date("Y-m-d H:i:s");
                     switch ($subscription->get_status()) {
                         case 'subscribed':
                             $subscription->set_subscribed_dt($dt);
                             break;
                         case 'unsubscribed':
                             $subscription->set_unsubscribed_dt($dt);
                             break;
                         default:
                             break;
                     }
                 }
             }
             Contact_Model_SubscriptionMapper::getInstance()->save($subscription);
             //sending done, return success
             return $this->_formHelper->returnSuccess($this->view->url(array('action' => 'index')), $this->translate('Saved'));
         } else {
             $this->_formHelper->returnError($form->getMessages());
         }
     } elseif (!$this->_formHelper->getRequest()->isPost()) {
         //edit action
         if (isset($id) && $id > 0) {
             $subscription = new Contact_Model_Subscription();
             if (!Contact_Model_SubscriptionMapper::getInstance()->find($id, $subscription)) {
                 throw new Exception("Record not found");
             }
             //fetch data
             $data = $subscription->toArray();
             //populate form with data
             $form->setData($data);
         }
     }
     $this->view->data = $data;
     $this->view->fields = $this->_fields;
     $this->view->formParams = $this->_formParams;
     $this->view->formId = $this->_formId;
 }
コード例 #2
0
 /**
  * Delete Page
  *
  * @param int $ids
  */
 public function delete(Contact_Model_Subscription $subscription)
 {
     //delete page
     $result = $this->_dbTable->getAdapter()->delete('contact_subscription', array('id = ?' => $subscription->get_id()));
     return $result > 0;
 }