Exemple #1
0
 function index()
 {
     $mcontacts = new Model_Contacts();
     $groups = $mcontacts->getGroups();
     $fields = $mcontacts->getContactFields();
     $msg = null;
     if (isset($this->args[0])) {
         if ($this->args[0] == "add") {
             $this->view->setTitle("Новый контакт");
             if (isset($this->post["submit"])) {
                 $mcontacts->addContact($this->post);
                 $msg = "Контакт сохранён!";
             }
             if (isset($this->get["email"])) {
                 $email = $this->get["email"];
             } else {
                 $email = null;
             }
             $this->view->contacts_addcontact(array("msg" => $msg, "email" => $email, "groups" => $groups, "post" => $this->post, "fields" => $fields));
         } elseif ($this->args[0] == "edit") {
             $this->view->setTitle("Правка контакта");
             if (isset($this->post["submit"])) {
                 $mcontacts->editContact($this->post);
                 $msg = "Контакт сохранён!";
                 $post = $mcontacts->getContact($this->post["email"]);
                 $email = $this->post["email"];
             } else {
                 $post = $mcontacts->getContact($this->get["email"]);
                 $email = $this->get["email"];
             }
             $this->view->contacts_editcontact(array("msg" => $msg, "email" => $email, "groups" => $groups, "post" => $post, "fields" => $fields));
         }
     } else {
         $this->view->setTitle("Контакты");
         if (isset($this->get["groups"])) {
             $contacts = $mcontacts->getContacts($this->get["groups"]);
             $this->view->contacts_groupcontacts(array("contacts" => $contacts));
         } else {
             $contacts = $mcontacts->getContacts();
             $this->view->contacts_contacts(array("groups" => $groups, "contacts" => $contacts));
         }
     }
 }
 /**
  * save
  * @author Thomas Schedler <*****@*****.**>
  * @version 1.1
  */
 public function save()
 {
     $this->core->logger->debug('massiveart->generic->data->GenericDataTypeContact->save()');
     try {
         $this->getModelContacts()->setLanguageId($this->setup->getLanguageId());
         $intUserId = Zend_Auth::getInstance()->getIdentity()->id;
         /**
          * add|edit|newVersion core and instance data
          */
         switch ($this->setup->getActionType()) {
             case $this->core->sysConfig->generic->actions->add:
                 $arrCoreData = array('idGenericForms' => $this->setup->getGenFormId(), 'idUnits' => $this->setup->getParentId(), 'idUsers' => $intUserId, 'creator' => $intUserId, 'created' => date('Y-m-d H:i:s'));
                 if (count($this->setup->CoreFields()) > 0) {
                     foreach ($this->setup->CoreFields() as $strField => $obField) {
                         $arrCoreData[$strField] = $obField->getValue();
                     }
                 }
                 /**
                  * add contact 
                  */
                 $this->setup->setElementId($this->objModelContacts->addContact($arrCoreData));
                 $this->insertFileData('contact', array('Id' => $this->setup->getElementId()));
                 break;
             case $this->core->sysConfig->generic->actions->edit:
                 $arrCoreData = array('idUsers' => $intUserId);
                 if (count($this->setup->CoreFields()) > 0) {
                     foreach ($this->setup->CoreFields() as $strField => $obField) {
                         $arrCoreData[$strField] = $obField->getValue();
                     }
                 }
                 /**
                  * add contact 
                  */
                 $this->objModelContacts->editContact($this->setup->getElementId(), $arrCoreData);
                 $this->updateFileData('contact', array('Id' => $this->setup->getElementId()));
                 break;
         }
         return $this->setup->getElementId();
     } catch (Exception $exc) {
         $this->core->logger->err($exc);
     }
 }