Beispiel #1
0
 /**
  * Process the form submission.
  *
  *
  * @param array $params
  * @return array|null
  */
 public function postProcess($params = NULL)
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $deleteParams = array('id' => $this->_activityId);
         $moveToTrash = CRM_Case_BAO_Case::isCaseActivity($this->_activityId);
         CRM_Activity_BAO_Activity::deleteActivity($deleteParams, $moveToTrash);
         // delete tags for the entity
         $tagParams = array('entity_table' => 'civicrm_activity', 'entity_id' => $this->_activityId);
         CRM_Core_BAO_EntityTag::del($tagParams);
         CRM_Core_Session::setStatus(ts("Selected Activity has been deleted successfully."), ts('Record Deleted'), 'success');
         return NULL;
     }
     // store the submitted values in an array
     if (!$params) {
         $params = $this->controller->exportValues($this->_name);
     }
     // Set activity type id.
     if (empty($params['activity_type_id'])) {
         $params['activity_type_id'] = $this->_activityTypeId;
     }
     if (!empty($params['hidden_custom']) && !isset($params['custom'])) {
         $customFields = CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, $this->_activityTypeId);
         $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, NULL, NULL, TRUE));
         $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->_activityId, 'Activity');
     }
     // store the date with proper format
     $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']);
     // format params as arrays
     foreach (array('target', 'assignee', 'followup_assignee') as $name) {
         if (!empty($params["{$name}_contact_id"])) {
             $params["{$name}_contact_id"] = explode(',', $params["{$name}_contact_id"]);
         } else {
             $params["{$name}_contact_id"] = array();
         }
     }
     // get ids for associated contacts
     if (!$params['source_contact_id']) {
         $params['source_contact_id'] = $this->_currentUserId;
     }
     if (isset($this->_activityId)) {
         $params['id'] = $this->_activityId;
     }
     // add attachments as needed
     CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity', $this->_activityId);
     $activity = array();
     if (!empty($params['is_multi_activity']) && !CRM_Utils_Array::crmIsEmptyArray($params['target_contact_id'])) {
         $targetContacts = $params['target_contact_id'];
         foreach ($targetContacts as $targetContactId) {
             $params['target_contact_id'] = array($targetContactId);
             // save activity
             $activity[] = $this->processActivity($params);
         }
     } else {
         // save activity
         $activity = $this->processActivity($params);
     }
     $activityIds = empty($this->_activityIds) ? array($this->_activityId) : $this->_activityIds;
     foreach ($activityIds as $activityId) {
         // set params for repeat configuration in create mode
         $params['entity_id'] = $activityId;
         $params['entity_table'] = 'civicrm_activity';
         if (!empty($params['entity_id']) && !empty($params['entity_table'])) {
             $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor($params['entity_id'], $params['entity_table']);
             if ($checkParentExistsForThisId) {
                 $params['parent_entity_id'] = $checkParentExistsForThisId;
                 $scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId($checkParentExistsForThisId, $params['entity_table']);
             } else {
                 $params['parent_entity_id'] = $params['entity_id'];
                 $scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId($params['entity_id'], $params['entity_table']);
             }
             if (property_exists($scheduleReminderDetails, 'id')) {
                 $params['schedule_reminder_id'] = $scheduleReminderDetails->id;
             }
         }
         $params['dateColumns'] = array('activity_date_time');
         // Set default repetition start if it was not provided.
         if (empty($params['repetition_start_date'])) {
             $params['repetition_start_date'] = $params['activity_date_time'];
         }
         // unset activity id
         unset($params['id']);
         $linkedEntities = array(array('table' => 'civicrm_activity_contact', 'findCriteria' => array('activity_id' => $activityId), 'linkedColumns' => array('activity_id'), 'isRecurringEntityRecord' => FALSE));
         CRM_Core_Form_RecurringEntity::postProcess($params, 'civicrm_activity', $linkedEntities);
     }
     return array('activity' => $activity);
 }
Beispiel #2
0
 public function postProcess()
 {
     if ($this->_id) {
         $params = $this->controller->exportValues($this->_name);
         if ($this->_parentEventStartDate && $this->_parentEventEndDate) {
             $interval = CRM_Core_BAO_RecurringEntity::getInterval($this->_parentEventStartDate, $this->_parentEventEndDate);
             $params['intervalDateColumns'] = array('end_date' => $interval);
         }
         $params['dateColumns'] = array('start_date');
         $params['excludeDateRangeColumns'] = array('start_date', 'end_date');
         $params['entity_table'] = 'civicrm_event';
         $params['entity_id'] = $this->_id;
         // CRM-16568 - check if parent exist for the event.
         $parentId = CRM_Core_BAO_RecurringEntity::getParentFor($this->_id, 'civicrm_event');
         $params['parent_entity_id'] = !empty($parentId) ? $parentId : $params['entity_id'];
         //Unset event id
         unset($params['id']);
         $url = 'civicrm/event/manage/repeat';
         $urlParams = "action=update&reset=1&id={$this->_id}";
         $linkedEntities = array(array('table' => 'civicrm_price_set_entity', 'findCriteria' => array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event'), 'linkedColumns' => array('entity_id'), 'isRecurringEntityRecord' => FALSE), array('table' => 'civicrm_uf_join', 'findCriteria' => array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event'), 'linkedColumns' => array('entity_id'), 'isRecurringEntityRecord' => FALSE), array('table' => 'civicrm_tell_friend', 'findCriteria' => array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event'), 'linkedColumns' => array('entity_id'), 'isRecurringEntityRecord' => TRUE), array('table' => 'civicrm_pcp_block', 'findCriteria' => array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event'), 'linkedColumns' => array('entity_id'), 'isRecurringEntityRecord' => TRUE));
         CRM_Core_Form_RecurringEntity::postProcess($params, 'civicrm_event', $linkedEntities);
         CRM_Utils_System::redirect(CRM_Utils_System::url($url, $urlParams));
     } else {
         CRM_Core_Error::fatal("Could not find Event ID");
     }
     parent::endPostProcess();
 }