Beispiel #1
0
 public function execute()
 {
     $type = $this->getInput()->get('save_type');
     switch ($type) {
         case "lead":
         case "contact":
             $model = new PeopleModel();
             break;
         case "company":
             $model = new CompanyModel();
             break;
         case "deal":
             $model = new DealModel();
             break;
     }
     $model->store();
     header('Location: ' . base64_decode($this->getInput()->get('return')));
 }
Beispiel #2
0
 /**
  * Method to store a record
  *
  * @return boolean True on success
  */
 public function store($data = null)
 {
     $app = \Cobalt\Container::fetch('app');
     //Load Tables
     $row = new NoteTable();
     $oldRow = new NoteTable();
     if ($data == null) {
         $data = $app->input->getArray(array('note' => 'string', 'deal_id' => 'int', 'person_id' => 'int', 'name' => 'string', 'category_id' => 'int', 'company_id' => 'int', 'note_id' => 'int', 'event_id' => 'int'));
     }
     if (array_key_exists('note_id', $data)) {
         $data['id'] = $data['note_id'];
     }
     if (array_key_exists('is_email', $data)) {
         $model = new Mail();
         $email = $model->getEmail($data['email_id']);
         $data['note'] = $email;
     }
     /** check for and automatically associate and create primary contacts or people **/
     if (array_key_exists('person_name', $data) && $data['person_name'] != "") {
         $peopleModel = new People();
         $existingPerson = $peopleModel->checkPersonName($data['person_name']);
         if ($existingPerson == "") {
             $pdata = array();
             $name = explode(" ", $data['person_name']);
             $pdata['first_name'] = array_key_exists(0, $name) ? $name[0] : "";
             $pdata['last_name'] = array_key_exists(1, $name) ? $name[1] : "";
             $data['person_id'] = $peopleModel->store($pdata);
         } else {
             $data['person_id'] = $existingPerson;
         }
     }
     /** check for and automatically associate and create deals **/
     if (array_key_exists('deal_name', $data) && $data['deal_name'] != "" && (!array_key_exists('deal_id', $data) || empty($data['deal_id']) || $data['deal_id'] == 0)) {
         $dealModel = new Deal();
         $existingDeal = $dealModel->checkDealName($data['deal_name']);
         if ($existingDeal == "") {
             $pdata = array();
             $pdata['name'] = $data['deal_name'];
             $data['deal_id'] = $dealModel->store($pdata);
         } else {
             $data['deal_id'] = $existingDeal;
         }
     }
     //date generation
     $date = DateHelper::formatDBDate(date('Y-m-d H:i:s'));
     if (!array_key_exists('id', $data)) {
         $data['created'] = $date;
         $status = "created";
     } else {
         $row->load($data['id']);
         $oldRow->load($data['id']);
         $status = "updated";
     }
     $data['modified'] = $date;
     $data['owner_id'] = UsersHelper::getUserId();
     // Bind the form fields to the table
     if (!$row->bind($data)) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     //$app->triggerEvent('onBeforeNoteSave', array(&$row));
     // Make sure the record is valid
     if (!$row->check()) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     // Store the web link table to the database
     if (!$row->store()) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     if (array_key_exists('id', $data) && intval($data['id'])) {
         $id = $data['id'];
     } else {
         $id = $this->db->insertId();
     }
     ActivityHelper::saveActivity($oldRow, $row, 'note', $status);
     //Store email attachments
     if (array_key_exists('is_email', $data)) {
         $model = new CobaltModelMail();
         $model->storeAttachments($data['email_id'], $data['person_id']);
     }
     //$app->triggerEvent('onAfterNoteSave', array(&$row));
     return $id;
 }