/** * 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); }
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(); }
/** * @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); }
/** * Set variables up before form is built. * * @return void */ public function preProcess() { $config = CRM_Core_Config::singleton(); if (in_array('CiviEvent', $config->enableComponents)) { $this->assign('CiviEvent', TRUE); } CRM_Core_Form_RecurringEntity::preProcess('civicrm_event'); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST'); $this->assign('action', $this->_action); $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, NULL, 'GET'); if ($this->_id) { $this->_isRepeatingEvent = CRM_Core_BAO_RecurringEntity::getParentFor($this->_id, 'civicrm_event'); $this->assign('eventId', $this->_id); if (!empty($this->_addBlockName) && empty($this->_addProfileBottom) && empty($this->_addProfileBottomAdd)) { $this->add('hidden', 'id', $this->_id); } $this->_single = TRUE; $params = array('id' => $this->_id); CRM_Event_BAO_Event::retrieve($params, $eventInfo); // its an update mode, do a permission check if (!CRM_Event_BAO_Event::checkPermission($this->_id, CRM_Core_Permission::EDIT)) { CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); } $participantListingID = CRM_Utils_Array::value('participant_listing_id', $eventInfo); //CRM_Core_DAO::getFieldValue( 'CRM_Event_DAO_Event', $this->_id, 'participant_listing_id' ); if ($participantListingID) { $participantListingURL = CRM_Utils_System::url('civicrm/event/participant', "reset=1&id={$this->_id}", TRUE, NULL, TRUE, TRUE); $this->assign('participantListingURL', $participantListingURL); } $this->assign('isOnlineRegistration', CRM_Utils_Array::value('is_online_registration', $eventInfo)); $this->assign('id', $this->_id); } // figure out whether we’re handling an event or an event template if ($this->_id) { $this->_isTemplate = CRM_Utils_Array::value('is_template', $eventInfo); } elseif ($this->_action & CRM_Core_Action::ADD) { $this->_isTemplate = CRM_Utils_Request::retrieve('is_template', 'Boolean', $this); } $this->assign('isTemplate', $this->_isTemplate); if ($this->_id) { if ($this->_isTemplate) { $title = CRM_Utils_Array::value('template_title', $eventInfo); CRM_Utils_System::setTitle(ts('Edit Event Template') . " - {$title}"); } else { $configureText = ts('Configure Event'); $title = CRM_Utils_Array::value('title', $eventInfo); //If it is a repeating event change title if ($this->_isRepeatingEvent) { $configureText = 'Configure Repeating Event'; } CRM_Utils_System::setTitle($configureText . " - {$title}"); } $this->assign('title', $title); } elseif ($this->_action & CRM_Core_Action::ADD) { if ($this->_isTemplate) { $title = ts('New Event Template'); CRM_Utils_System::setTitle($title); } else { $title = ts('New Event'); CRM_Utils_System::setTitle($title); } $this->assign('title', $title); } if (CRM_Core_Permission::check('view event participants') && CRM_Core_Permission::check('view all contacts')) { $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1', 'label'); $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0', 'label'); $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes)); $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending)); $this->assign('findParticipants', $findParticipants); } $this->_templateId = (int) CRM_Utils_Request::retrieve('template_id', 'Integer', $this); //Is a repeating event if ($this->_isRepeatingEvent) { $isRepeatingEntity = TRUE; $this->assign('isRepeatingEntity', $isRepeatingEntity); } // CRM-16776 - show edit/copy/create buttons for Profiles if user has required permission. $ufGroups = CRM_Core_PseudoConstant::get('CRM_Core_DAO_UFField', 'uf_group_id'); $ufCreate = CRM_ACL_API::group(CRM_Core_Permission::CREATE, NULL, 'civicrm_uf_group', $ufGroups); $ufEdit = CRM_ACL_API::group(CRM_Core_Permission::EDIT, NULL, 'civicrm_uf_group', $ufGroups); $checkPermission = array(array('administer CiviCRM', 'manage event profiles')); if (CRM_Core_Permission::check($checkPermission) || !empty($ufCreate) || !empty($ufEdit)) { $this->assign('perm', TRUE); } // also set up tabs CRM_Event_Form_ManageEvent_TabHeader::build($this); // Set Done button URL and breadcrumb. Templates go back to Manage Templates, // otherwise go to Manage Event for new event or ManageEventEdit if event if exists. $breadCrumb = array(); if (!$this->_isTemplate) { if ($this->_id) { $this->_doneUrl = CRM_Utils_System::url(CRM_Utils_System::currentPath(), "action=update&reset=1&id={$this->_id}"); } else { $this->_doneUrl = CRM_Utils_System::url('civicrm/event/manage', 'reset=1'); $breadCrumb = array(array('title' => ts('Manage Events'), 'url' => $this->_doneUrl)); } } else { $this->_doneUrl = CRM_Utils_System::url('civicrm/admin/eventTemplate', 'reset=1'); $breadCrumb = array(array('title' => ts('Manage Event Templates'), 'url' => $this->_doneUrl)); } CRM_Utils_System::appendBreadCrumb($breadCrumb); }