/** * Implementation of hook_civicrm_uninstall */ function hrdemog_civicrm_uninstall() { $customGroup = civicrm_api3('CustomGroup', 'getsingle', array('return' => "id", 'name' => "Extended_Demographics")); civicrm_api3('CustomGroup', 'delete', array('id' => $customGroup['id'])); //delete optionGroup if ($visaGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'is_visa_required_20130702051150', 'id', 'name')) { CRM_Core_BAO_OptionGroup::del($visaGroupID); } return _hrdemog_civix_civicrm_uninstall(); }
/** * Process the form submission. */ public function postProcess() { CRM_Utils_System::flushCache(); $params = $this->exportValues(); if ($this->_action & CRM_Core_Action::DELETE) { CRM_Core_BAO_OptionGroup::del($this->_id); CRM_Core_Session::setStatus(ts('Selected option group has been deleted.'), ts('Record Deleted'), 'success'); } else { $params = $ids = array(); // store the submitted values in an array $params = $this->exportValues(); if ($this->_action & CRM_Core_Action::UPDATE) { $ids['optionGroup'] = $this->_id; } $optionGroup = CRM_Core_BAO_OptionGroup::add($params, $ids); CRM_Core_Session::setStatus(ts('The Option Group \'%1\' has been saved.', array(1 => $optionGroup->name)), ts('Saved'), 'success'); } }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { $params = $this->exportValues(); require_once 'CRM/Core/BAO/OptionGroup.php'; if ($this->_action & CRM_Core_Action::DELETE) { CRM_Core_BAO_OptionGroup::del($this->_id); CRM_Core_Session::setStatus(ts('Selected option group has been deleted.')); } else { $params = $ids = array(); // store the submitted values in an array $params = $this->exportValues(); if ($this->_action & CRM_Core_Action::UPDATE) { $ids['optionGroup'] = $this->_id; } $optionGroup = CRM_Core_BAO_OptionGroup::add($params, $ids); CRM_Core_Session::setStatus(ts('The Option Group \'%1\' has been saved.', array(1 => $optionGroup->name))); } }
/** * Function to delete the event * * @param int $id event id * * @access public * @static * */ static function del($id) { if (!$id) { return null; } require_once 'CRM/Utils/Hook.php'; CRM_Utils_Hook::pre('delete', 'Event', $id, CRM_Core_DAO::$_nullArray); require_once 'CRM/Core/BAO/CustomGroup.php'; $extends = array('event'); $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(null, null, $extends); foreach ($groupTree as $values) { $query = "DELETE FROM " . $values['table_name'] . " WHERE entity_id = " . $id; $params = array(1 => array($values['table_name'], 'string'), 2 => array($id, 'integer')); CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); } $dependencies = array('CRM_Core_DAO_OptionGroup' => array('name' => 'civicrm_event.amount.' . $id), 'CRM_Core_DAO_UFJoin' => array('entity_id' => $id, 'entity_table' => 'civicrm_event')); require_once 'CRM/Core/BAO/OptionGroup.php'; foreach ($dependencies as $daoName => $values) { require_once str_replace('_', DIRECTORY_SEPARATOR, $daoName) . ".php"; eval('$dao = new ' . $daoName . '( );'); if ($daoName == 'CRM_Core_DAO_OptionGroup') { $dao->name = $values['name']; $dao->find(); while ($dao->fetch()) { CRM_Core_BAO_OptionGroup::del($dao->id); } } else { foreach ($values as $fieldName => $fieldValue) { $dao->{$fieldName} = $fieldValue; } $dao->find(); while ($dao->fetch()) { $dao->delete(); } } } require_once 'CRM/Core/OptionGroup.php'; CRM_Core_OptionGroup::deleteAssoc("civicrm_event.amount.{$id}.discount.%", "LIKE"); // price set cleanup, CRM-5527 require_once 'CRM/Price/BAO/Set.php'; CRM_Price_BAO_Set::removeFrom('civicrm_event', $id); require_once 'CRM/Event/DAO/Event.php'; $event = new CRM_Event_DAO_Event(); $event->id = $id; if ($event->find(true)) { $locBlockId = $event->loc_block_id; $result = $event->delete(); if (!is_null($locBlockId)) { self::deleteEventLocBlock($locBlockId, $id); } CRM_Utils_Hook::post('delete', 'Event', $id, $event); return $result; } return null; }
/** * Function to check if option group is related to more than one * custom field * * @params int $optionGroupId option group id * * @return * @static */ static function checkOptionGroup($optionGroupId) { $query = "\nSELECT count(*)\nFROM civicrm_custom_field\nWHERE option_group_id = {$optionGroupId}"; $count = CRM_Core_DAO::singleValueQuery($query); if ($count < 2) { //delete the option group require_once "CRM/Core/BAO/OptionGroup.php"; CRM_Core_BAO_OptionGroup::del($optionGroupId); } }
/** * 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'); } } }
/** * Process the form * * @param null * * @return void * @access public */ public function postProcess() { // store the submitted values in an array $params = $this->controller->exportValues($this->_name); $session = CRM_Core_Session::singleton(); $params['last_modified_id'] = $session->get('userID'); $params['last_modified_date'] = date('YmdHis'); if ($this->_surveyId) { $params['id'] = $this->_surveyId; } else { $params['created_id'] = $session->get('userID'); $params['created_date'] = date('YmdHis'); } $params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0); $params['is_default'] = CRM_Utils_Array::value('is_default', $params, 0); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_surveyId, 'Survey'); $survey = CRM_Campaign_BAO_Survey::create($params); $this->_surveyId = $survey->id; if (!empty($this->_values['result_id'])) { $query = "SELECT COUNT(*) FROM civicrm_survey WHERE result_id = %1"; $countSurvey = (int) CRM_Core_DAO::singleValueQuery($query, array(1 => array($this->_values['result_id'], 'Positive'))); // delete option group if no any survey is using it. if (!$countSurvey) { CRM_Core_BAO_OptionGroup::del($this->_values['result_id']); } } parent::endPostProcess(); }
/** * Process the form * * @param null * * @return void * @access public */ public function postProcess() { // store the submitted values in an array $params = $this->controller->exportValues($this->_name); $session = CRM_Core_Session::singleton(); $params['last_modified_id'] = $session->get('userID'); $params['last_modified_date'] = date('YmdHis'); require_once 'CRM/Core/BAO/OptionValue.php'; require_once 'CRM/Core/BAO/OptionGroup.php'; $updateResultSet = false; if (CRM_Utils_Array::value('option_type', $params) == 2 && CRM_Utils_Array::value('option_group_id', $params)) { if ($params['option_group_id'] == CRM_Utils_Array::value('result_id', $this->_values)) { $updateResultSet = true; } } if ($this->_surveyId) { if ($this->_action & CRM_Core_Action::DELETE) { CRM_Campaign_BAO_Survey::del($this->_surveyId); CRM_Core_Session::setStatus(ts(' Survey has been deleted.')); $session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey')); return; } $params['id'] = $this->_surveyId; } else { $params['created_id'] = $session->get('userID'); $params['created_date'] = date('YmdHis'); } $params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0); $params['is_default'] = CRM_Utils_Array::value('is_default', $params, 0); $recontactInterval = array(); if ($updateResultSet) { $optionValue = new CRM_Core_DAO_OptionValue(); $optionValue->option_group_id = $this->_values['result_id']; $optionValue->delete(); $params['result_id'] = $this->_values['result_id']; } else { $opGroupName = 'civicrm_survey_' . rand(10, 1000) . '_' . date('YmdHis'); $optionGroup = new CRM_Core_DAO_OptionGroup(); $optionGroup->name = $opGroupName; $optionGroup->label = $params['title'] . ' Response Set'; $optionGroup->is_active = 1; $optionGroup->save(); $params['result_id'] = $optionGroup->id; } foreach ($params['option_value'] as $k => $v) { if (strlen(trim($v))) { $optionValue = new CRM_Core_DAO_OptionValue(); $optionValue->option_group_id = $params['result_id']; $optionValue->label = $params['option_label'][$k]; $optionValue->name = CRM_Utils_String::titleToVar($params['option_label'][$k]); $optionValue->value = trim($v); $optionValue->weight = $params['option_weight'][$k]; $optionValue->is_active = 1; if (CRM_Utils_Array::value('default_option', $params) && $params['default_option'] == $k) { $optionValue->is_default = 1; } $optionValue->save(); if (CRM_Utils_Array::value($k, $params['option_interval'])) { $recontactInterval[$optionValue->label] = $params['option_interval'][$k]; } } } $params['recontact_interval'] = serialize($recontactInterval); $surveyId = CRM_Campaign_BAO_Survey::create($params); if (CRM_Utils_Array::value('result_id', $this->_values) && !$updateResultSet) { $query = "SELECT COUNT(*) FROM civicrm_survey WHERE result_id = %1"; $countSurvey = CRM_Core_DAO::singleValueQuery($query, array(1 => array($this->_values['result_id'], 'Integer'))); // delete option group if no any survey is using it. if (!($countSurvey >= 1)) { CRM_Core_BAO_OptionGroup::del($this->_values['result_id']); } } require_once 'CRM/Core/BAO/UFJoin.php'; // also update the ProfileModule tables $ufJoinParams = array('is_active' => 1, 'module' => 'CiviCampaign', 'entity_table' => 'civicrm_survey', 'entity_id' => $surveyId->id); // first delete all past entries if ($this->_surveyId) { CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams); } if (CRM_Utils_Array::value('profile_id', $params)) { $ufJoinParams['weight'] = 1; $ufJoinParams['uf_group_id'] = $params['profile_id']; CRM_Core_BAO_UFJoin::create($ufJoinParams); } if (!is_a($surveyId, 'CRM_Core_Error')) { CRM_Core_Session::setStatus(ts('Survey %1 has been saved.', array(1 => $params['title']))); } if ($this->_context == 'dialog') { $returnArray = array('returnSuccess' => true); echo json_encode($returnArray); CRM_Utils_System::civiExit(); } $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->getButtonName('next', 'new')) { CRM_Core_Session::setStatus(ts(' You can add another Survey.')); $session->replaceUserContext(CRM_Utils_System::url('civicrm/survey/add', 'reset=1&action=add')); } else { $session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey')); } }