Ejemplo n.º 1
0
 /**
  * @param $entityTable
  */
 public static function preProcess($entityTable)
 {
     self::$_entityId = (int) CRM_Utils_Request::retrieve('id', 'Positive');
     self::$_entityTable = $entityTable;
     if (self::$_entityId && $entityTable) {
         $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor(self::$_entityId, $entityTable);
         if ($checkParentExistsForThisId) {
             self::$_hasParent = TRUE;
             self::$_parentEntityId = $checkParentExistsForThisId;
             self::$_scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId($checkParentExistsForThisId, $entityTable);
         } else {
             self::$_parentEntityId = self::$_entityId;
             self::$_scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId(self::$_entityId, $entityTable);
         }
         if (property_exists(self::$_scheduleReminderDetails, 'id')) {
             self::$_scheduleReminderID = self::$_scheduleReminderDetails->id;
         }
     }
     CRM_Core_OptionValue::getValues(array('name' => $entityTable . '_repeat_exclude_dates_' . self::$_parentEntityId), $optionValue);
     $excludeOptionValues = array();
     if (!empty($optionValue)) {
         foreach ($optionValue as $key => $val) {
             $excludeOptionValues[$val['value']] = substr(CRM_Utils_Date::mysqlToIso($val['value']), 0, 10);
         }
         self::$_excludeDateInfo = $excludeOptionValues;
     }
     // Assign variables
     $entityType = CRM_Core_DAO_AllCoreTables::getBriefName(CRM_Core_DAO_AllCoreTables::getClassForTable($entityTable));
     $tpl = CRM_Core_Smarty::singleton();
     $tpl->assign('recurringEntityType', ts($entityType));
     $tpl->assign('currentEntityId', self::$_entityId);
     $tpl->assign('entityTable', self::$_entityTable);
     $tpl->assign('scheduleReminderId', self::$_scheduleReminderID);
     $tpl->assign('hasParent', self::$_hasParent);
 }
Ejemplo n.º 2
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);
 }