/** * Process the form submission. * * @param array $params * @param string $type * @param array $linkedEntities * * @throws \CiviCRM_API3_Exception */ public static function postProcess($params = array(), $type, $linkedEntities = array()) { //Check entity_id not present in params take it from class variable if (empty($params['entity_id'])) { $params['entity_id'] = self::$_entityId; } //Process this function only when you get this variable if ($params['allowRepeatConfigToSubmit'] == 1) { if (!empty($params['entity_table']) && !empty($params['entity_id']) && $type) { $params['used_for'] = $type; if (empty($params['parent_entity_id'])) { $params['parent_entity_id'] = self::$_parentEntityId; } if (!empty($params['schedule_reminder_id'])) { $params['id'] = $params['schedule_reminder_id']; } else { $params['id'] = self::$_scheduleReminderID; } //Save post params to the schedule reminder table $recurobj = new CRM_Core_BAO_RecurringEntity(); $dbParams = $recurobj->mapFormValuesToDB($params); //Delete repeat configuration and rebuild if (!empty($params['id'])) { CRM_Core_BAO_ActionSchedule::del($params['id']); unset($params['id']); } $actionScheduleObj = CRM_Core_BAO_ActionSchedule::add($dbParams); //exclude dates $excludeDateList = array(); if (CRM_Utils_Array::value('exclude_date_list', $params) && CRM_Utils_Array::value('parent_entity_id', $params) && $actionScheduleObj->entity_value) { //Since we get comma separated values lets get them in array $excludeDates = explode(",", $params['exclude_date_list']); //Check if there exists any values for this option group $optionGroupIdExists = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $type . '_repeat_exclude_dates_' . $params['parent_entity_id'], 'id', 'name'); if ($optionGroupIdExists) { CRM_Core_BAO_OptionGroup::del($optionGroupIdExists); } $optionGroupParams = array('name' => $type . '_repeat_exclude_dates_' . $actionScheduleObj->entity_value, 'title' => $type . ' recursion', 'is_reserved' => 0, 'is_active' => 1); $opGroup = CRM_Core_BAO_OptionGroup::add($optionGroupParams); if ($opGroup->id) { $oldWeight = 0; $fieldValues = array('option_group_id' => $opGroup->id); foreach ($excludeDates as $val) { $optionGroupValue = array('option_group_id' => $opGroup->id, 'label' => CRM_Utils_Date::processDate($val), 'value' => CRM_Utils_Date::processDate($val), 'name' => $opGroup->name, 'description' => 'Used for recurring ' . $type, 'weight' => CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, CRM_Utils_Array::value('weight', $params), $fieldValues), 'is_active' => 1); $excludeDateList[] = $optionGroupValue['value']; CRM_Core_BAO_OptionValue::create($optionGroupValue); } } } //Set type for API $apiEntityType = explode("_", $type); if (!empty($apiEntityType[1])) { $apiType = $apiEntityType[1]; } //Delete relations if any from recurring entity tables before inserting new relations for this entity id if ($params['entity_id']) { //If entity has any pre delete function, consider that first if (CRM_Utils_Array::value('pre_delete_func', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]) && CRM_Utils_Array::value('helper_class', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']])) { $preDeleteResult = call_user_func_array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['pre_delete_func'], array($params['entity_id'])); if (!empty($preDeleteResult)) { call_user_func(array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['helper_class'], $preDeleteResult)); } } //Ready to execute delete on entities if it has delete function set if (CRM_Utils_Array::value('delete_func', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]) && CRM_Utils_Array::value('helper_class', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']])) { //Check if pre delete function has some ids to be deleted if (!empty(CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted)) { foreach (CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted as $eid) { $result = civicrm_api3(ucfirst(strtolower($apiType)), CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func'], array('sequential' => 1, 'id' => $eid)); if ($result['error']) { CRM_Core_Error::statusBounce('Error creating recurring list'); } } } else { $getRelatedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['entity_id'], $params['entity_table'], FALSE); foreach ($getRelatedEntities as $key => $value) { $result = civicrm_api3(ucfirst(strtolower($apiType)), CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func'], array('sequential' => 1, 'id' => $value['id'])); if ($result['error']) { CRM_Core_Error::statusBounce('Error creating recurring list'); } } } } // find all entities from the recurring set. At this point we 'll get entities which were not deleted // for e.g due to participants being present. We need to delete them from recurring tables anyway. $pRepeatingEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['entity_id'], $params['entity_table']); foreach ($pRepeatingEntities as $val) { CRM_Core_BAO_RecurringEntity::delEntity($val['id'], $val['table'], TRUE); } } $recursion = new CRM_Core_BAO_RecurringEntity(); $recursion->dateColumns = $params['dateColumns']; $recursion->scheduleId = $actionScheduleObj->id; if (!empty($excludeDateList)) { $recursion->excludeDates = $excludeDateList; $recursion->excludeDateRangeColumns = $params['excludeDateRangeColumns']; } if (!empty($params['intervalDateColumns'])) { $recursion->intervalDateColumns = $params['intervalDateColumns']; } $recursion->entity_id = $params['entity_id']; $recursion->entity_table = $params['entity_table']; if (!empty($linkedEntities)) { $recursion->linkedEntities = $linkedEntities; } $recursion->generate(); $status = ts('Repeat Configuration has been saved'); CRM_Core_Session::setStatus($status, ts('Saved'), 'success'); } } }
/** * Implementation of hook_civicrm_uninstall */ function hrui_civicrm_uninstall() { //Enable Individual sub types _hrui_toggleContactSubType(TRUE); // get a list of all tab options $options = CRM_Core_OptionGroup::values('contact_view_options', TRUE, FALSE); $tabsToSet = array($options['Activities'], $options['Tags']); // get tab options from DB $options = hrui_getViewOptionsSetting(); // set activity & tag tab options foreach ($tabsToSet as $key) { $options[$key] = 1; } $options = array_keys($options); // set modified options in the DB hrui_setViewOptionsSetting($options); _hrui_setActiveFields(TRUE); // show communication preferences block $groupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'contact_edit_options', 'id', 'name'); $params = array('option_group_id' => $groupID, 'name' => 'CommunicationPreferences'); CRM_Core_BAO_OptionValue::retrieve($params, $defaults); $defaults['is_active'] = 1; CRM_Core_BAO_OptionValue::create($defaults); _hrui_wordReplacement(TRUE); return _hrui_civix_civicrm_uninstall(); }