/** * @param int $id * * @return bool */ public static function deleteParticipantStatusType($id) { // return early if there are participants with this status $participant = new CRM_Event_DAO_Participant(); $participant->status_id = $id; if ($participant->find()) { return FALSE; } CRM_Utils_Weight::delWeight('CRM_Event_DAO_ParticipantStatusType', $id); $dao = new CRM_Event_DAO_ParticipantStatusType(); $dao->id = $id; $dao->find(TRUE); $dao->delete(); return TRUE; }
static function deleteParticipantStatusType($id) { // return early if there are participants with this status require_once 'CRM/Event/DAO/Participant.php'; $participant = new CRM_Event_DAO_Participant(); $participant->status_id = $id; if ($participant->find()) { return false; } require_once 'CRM/Utils/Weight.php'; CRM_Utils_Weight::delWeight('CRM_Event_DAO_ParticipantStatusType', $id); $dao = new CRM_Event_DAO_ParticipantStatusType(); $dao->id = $id; $dao->find(true); $dao->delete(); return true; }
/** * Process the form * * @return void * @access public */ public function postProcess() { $ids = array('uf_group' => $this->_gid); if ($this->_action & CRM_Core_Action::DELETE) { $fieldValues = array('uf_group_id' => $this->_gid); $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_UFField', $this->_id, $fieldValues); $deleted = CRM_Core_BAO_UFField::del($this->_id); //update group_type every time. CRM-3608 if ($this->_gid && $deleted) { //get the profile type. $groupType = 'null'; $fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($this->_gid); if (!empty($fieldsType)) { $groupType = implode(',', $fieldsType); } //set group type CRM_Core_DAO::setFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'group_type', $groupType); } CRM_Core_Session::setStatus(ts('Selected Profile Field has been deleted.')); return; } // store the submitted values in an array $params = $this->controller->exportValues('Field'); if ($params['visibility'] == 'User and User Admin Only') { $params['is_searchable'] = 0; $params['in_selector'] = 0; } if ($this->_action & CRM_Core_Action::UPDATE) { $ids['uf_field'] = $this->_id; } //check for duplicate fields if (CRM_Core_BAO_UFField::duplicateField($params, $ids)) { CRM_Core_Session::setStatus(ts('The selected field was not added. It already exists in this profile.')); return; } else { $ufField = CRM_Core_BAO_UFField::add($params, $ids); $name = $this->_selectFields[$ufField->field_name]; //reset other field is searchable and in selector settings, CRM-4363 if ($this->_hasSearchableORInSelector && in_array($ufField->field_type, array('Participant', 'Contribution', 'Membership'))) { CRM_Core_BAO_UFField::resetInSelectorANDSearchable($this->_gid); } $config =& CRM_Core_Config::singleton(); $showBestResult = false; if (in_array($ufField->field_name, array('country', 'state_province')) && count($config->countryLimit) > 1) { // get state or country field weight if exists $field = 'state_province'; if ($ufField->field_name == 'state_province') { $field = 'country'; } $ufFieldDAO =& new CRM_Core_DAO_UFField(); $ufFieldDAO->field_name = $field; $ufFieldDAO->location_type_id = $ufField->location_type_id; $ufFieldDAO->uf_group_id = $ufField->uf_group_id; if ($ufFieldDAO->find(true)) { if ($field == 'country' && $ufFieldDAO->weight > $ufField->weight) { $showBestResult = true; } elseif ($field == 'state_province' && $ufFieldDAO->weight < $ufField->weight) { $showBestResult = true; } } } //update group_type every time. CRM-3608 if ($this->_gid && is_a($ufField, 'CRM_Core_DAO_UFField')) { //get the profile type. $groupType = 'null'; $fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($this->_gid); if (!empty($fieldsType)) { $groupType = implode(',', $fieldsType); } //set group type CRM_Core_DAO::setFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'group_type', $groupType); } CRM_Core_Session::setStatus(ts('Your CiviCRM Profile Field \'%1\' has been saved.', array(1 => $name))); } $buttonName = $this->controller->getButtonName(); $session =& CRM_Core_Session::singleton(); if ($buttonName == $this->getButtonName('next', 'new')) { CRM_Core_Session::setStatus(ts(' You can add another profile field.')); $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/uf/group/field', "reset=1&action=add&gid={$this->_gid}&sbr={$showBestResult}")); } else { $session->set('showBestResult', $showBestResult); } }
/** * Function to process the form * * @access public * * @return None */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { $fieldValues = array('option_group_id' => $this->_gid); $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues); if (CRM_Core_BAO_OptionValue::del($this->_id)) { if ($this->_gName == 'phone_type') { CRM_Core_BAO_Phone::setOptionToNull(CRM_Utils_Array::value('value', $this->_defaultValues)); } CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', array(1 => $this->_GName))); } else { CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_GName))); CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues); } } else { $params = $ids = array(); $params = $this->exportValues(); // allow multiple defaults within group. $allowMultiDefaults = array('email_greeting', 'postal_greeting', 'addressee', 'from_email_address'); if (in_array($this->_gName, $allowMultiDefaults)) { if ($this->_gName == 'from_email_address') { $params['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID()); } elseif ($filter = CRM_Utils_Array::value('contactOptions', $params)) { $params['filter'] = $filter; $params['reset_default_for'] = array('filter' => "0, " . $params['filter']); } //make sure we should has to have space, CRM-6977 if ($this->_gName == 'from_email_address') { $params['label'] = str_replace('"<', '" <', $params['label']); } } // set db value of filter in params if filter is non editable if ($this->_id && !array_key_exists('filter', $params) && !$this->_gName == 'participant_role') { $params['filter'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'filter', 'id'); } $groupParams = array('name' => $this->_gName); $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id); CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => $this->_GName, 2 => $optionValue->label))); } }
/** * Process the form. * * @return void */ public function postProcess() { if ($this->_action == CRM_Core_Action::DELETE) { $fieldValues = array('price_field_id' => $this->_fid); $wt = CRM_Utils_Weight::delWeight('CRM_Price_DAO_PriceFieldValue', $this->_oid, $fieldValues); $label = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $this->_oid, 'label', 'id'); if (CRM_Price_BAO_PriceFieldValue::del($this->_oid)) { CRM_Core_Session::setStatus(ts('%1 option has been deleted.', array(1 => $label)), ts('Record Deleted'), 'success'); } return NULL; } else { $params = $ids = array(); $params = $this->controller->exportValues('Option'); $fieldLabel = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $this->_fid, 'label'); $params['amount'] = CRM_Utils_Rule::cleanMoney(trim($params['amount'])); $params['price_field_id'] = $this->_fid; $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE); $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); $ids = array(); if ($this->_oid) { $ids['id'] = $this->_oid; } $optionValue = CRM_Price_BAO_PriceFieldValue::create($params, $ids); CRM_Core_Session::setStatus(ts("The option '%1' has been saved.", array(1 => $params['label'])), ts('Value Saved'), 'success'); } }
/** * Delete a PDF Page Format. * * @param int $id * ID of the PDF Page Format to be deleted. * */ public static function del($id) { if ($id) { $dao = new CRM_Core_DAO_OptionValue(); $dao->id = $id; if ($dao->find(TRUE)) { if ($dao->option_group_id == self::_getGid()) { $filter = array('option_group_id' => self::_getGid()); CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $id, $filter); $dao->delete(); return; } } } CRM_Core_Error::fatal(ts('Invalid value passed to delete function.')); }
/** * Delete membership Types. * * @param int $membershipStatusId * * @throws CRM_Core_Exception */ public static function del($membershipStatusId) { //check dependencies //checking if membership status is present in some other table $check = FALSE; $dependency = array('Membership', 'MembershipLog'); foreach ($dependency as $name) { $baoString = 'CRM_Member_BAO_' . $name; $dao = new $baoString(); $dao->status_id = $membershipStatusId; if ($dao->find(TRUE)) { throw new CRM_Core_Exception(ts('This membership status cannot be deleted as memberships exist with this status')); } } CRM_Utils_Weight::delWeight('CRM_Member_DAO_MembershipStatus', $membershipStatusId); //delete from membership Type table $membershipStatus = new CRM_Member_DAO_MembershipStatus(); $membershipStatus->id = $membershipStatusId; $membershipStatus->delete(); $membershipStatus->free(); }
/** * Process the form * * @param null * * @return void * @access public */ public function postProcess() { // store the submitted values in an array $params = $this->controller->exportValues('Option'); // set values for custom field properties and save require_once 'CRM/Core/DAO/OptionValue.php'; require_once 'CRM/Utils/String.php'; $customOption =& new CRM_Core_DAO_OptionValue(); $customOption->label = $params['label']; $customOption->name = CRM_Utils_String::titleToVar($params['label']); $customOption->weight = $params['weight']; $customOption->value = $params['value']; $customOption->is_active = CRM_Utils_Array::value('is_active', $params, false); if ($this->_action == CRM_Core_Action::DELETE) { $fieldValues = array('option_group_id' => $this->_optionGroupID); $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues); CRM_Core_BAO_CustomOption::del($this->_id); CRM_Core_Session::setStatus(ts('Your multiple choice option has been deleted', array(1 => $customOption->label))); return; } if ($this->_action & CRM_Core_Action::UPDATE) { $customOption->id = $this->_id; CRM_Core_BAO_CustomOption::updateCustomValues($params); } if ($this->_id) { $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'weight', 'id'); } $fieldValues = array('option_group_id' => $this->_optionGroupID); $customOption->weight = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, $params['weight'], $fieldValues); $customOption->option_group_id = $this->_optionGroupID; $customField =& new CRM_Core_DAO_CustomField(); $customField->id = $this->_fid; if ($customField->find(true) && ($customField->html_type == 'CheckBox' || $customField->html_type == 'AdvMulti-Select' || $customField->html_type == 'Multi-Select')) { $defVal = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, substr($customField->default_value, 1, -1)); if (CRM_Utils_Array::value('default_value', $params)) { if (!in_array($customOption->value, $defVal)) { if (empty($defVal[0])) { $defVal = array($customOption->value); } else { $defVal[] = $customOption->value; } $customField->default_value = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $defVal) . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR; $customField->save(); } } else { if (in_array($customOption->value, $defVal)) { $tempVal = array(); foreach ($defVal as $v) { if ($v != $customOption->value) { $tempVal[] = $v; } } $customField->default_value = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $tempVal) . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR; $customField->save(); } } } else { switch ($customField->data_type) { case 'Money': require_once 'CRM/Utils/Rule.php'; $customOption->value = CRM_Utils_Rule::cleanMoney($customOption->value); break; case 'Int': $customOption->value = intval($customOption->value); break; case 'Float': $customOption->value = floatval($customOption->value); break; } if (CRM_Utils_Array::value('default_value', $params)) { $customField->default_value = $customOption->value; $customField->save(); } else { if ($customField->find(true) && $customField->default_value == $customOption->value) { // this is the case where this option is the current default value and we have been reset $customField->default_value = 'null'; $customField->save(); } } } $customOption->save(); CRM_Core_Session::setStatus(ts('Your multiple choice option \'%1\' has been saved', array(1 => $customOption->label))); $buttonName = $this->controller->getButtonName(); $session =& CRM_Core_Session::singleton(); if ($buttonName == $this->getButtonName('next', 'new')) { CRM_Core_Session::setStatus(ts(' You can add another option.')); $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field/option', 'reset=1&action=add&fid=' . $this->_fid . '&gid=' . $this->_gid)); } }
/** * Process the form * * @param null * * @return void * @access public */ public function postProcess() { require_once 'CRM/Core/OptionValue.php'; if ($this->_action == CRM_Core_Action::DELETE) { $fieldValues = array('option_group_id' => $this->_ogId); $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_oid, $fieldValues); $label = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_OptionValue", $this->_oid, 'label', 'id'); if (CRM_Core_BAO_OptionValue::del($this->_oid)) { CRM_Core_Session::setStatus(ts('%1 option has been deleted.', array(1 => $label))); } return; } else { $params = $ids = array(); $params = $this->controller->exportValues('Option'); $fieldLabel = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $this->_fid, 'label'); $params['description'] = $fieldLabel . ' - ' . $params['label']; $params['value'] = CRM_Utils_Rule::cleanMoney(trim($params['value'])); $groupParams = array('id' => $this->_ogId); // make name value consistant. $params['name'] = $params['value']; $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_oid); CRM_Core_Session::setStatus(ts('The option \'%1\' has been saved.', array(1 => $params['label']))); } }
/** * Delete the price set field. * * @param int $id Field Id * * @return boolean * * @access public * @static * */ public static function deleteField($id) { $field = new CRM_Price_DAO_Field(); $field->id = $id; if ($field->find(true)) { // delete the options for this field require_once 'CRM/Price/BAO/FieldValue.php'; CRM_Price_BAO_FieldValue::deleteValues($id); // reorder the weight before delete $fieldValues = array('price_set_id' => $field->price_set_id); require_once 'CRM/Utils/Weight.php'; CRM_Utils_Weight::delWeight('CRM_Price_DAO_Field', $field->id, $fieldValues); // now delete the field return $field->delete(); } return null; }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { require_once 'CRM/Member/BAO/MembershipStatus.php'; if ($this->_action & CRM_Core_Action::DELETE) { $wt = CRM_Utils_Weight::delWeight('CRM_Member_DAO_MembershipStatus', $this->_id); CRM_Member_BAO_MembershipStatus::del($this->_id); CRM_Core_Session::setStatus(ts('Selected membership status 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['membershipStatus'] = $this->_id; } if ($this->_id) { $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $this->_id, 'weight', 'id'); } $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Member_DAO_MembershipStatus', $oldWeight, $params['weight']); // only for add mode, set label to name. if ($this->_action & CRM_Core_Action::ADD) { $params['name'] = $params['label']; } $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params, $ids); CRM_Core_Session::setStatus(ts('The membership status \'%1\' has been saved.', array(1 => $membershipStatus->label))); } }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { $fieldValues = array('option_group_id' => $this->_gid); $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues); if (CRM_Core_BAO_OptionValue::del($this->_id)) { if ($this->_gName == 'phone_type') { require_once 'CRM/Core/BAO/Phone.php'; CRM_Core_BAO_Phone::setOptionToNull(CRM_Utils_Array::value('value', $this->_defaultValues)); } CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', array(1 => $this->_GName))); } else { CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_GName))); CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues); } } else { $params = $ids = array(); $params = $this->exportValues(); // allow multiple defaults within group. $allowMultiDefaults = array('email_greeting', 'postal_greeting', 'addressee', 'from_email_address'); if (CRM_Utils_Array::value('is_default', $params) && in_array($this->_gName, $allowMultiDefaults)) { if ($this->_gName == 'from_email_address') { $params['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID()); } else { if ($filter = CRM_Utils_Array::value('contactOptions', $params)) { $params['filter'] = $filter; $params['reset_default_for'] = array('filter' => "0, " . $params['filter']); } } } $groupParams = array('name' => $this->_gName); require_once 'CRM/Core/OptionValue.php'; $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id); CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => $this->_GName, 2 => $optionValue->label))); } }
/** * Delete the price set field. * * @param int $id Field Id * * @return boolean * * @access public * @static * */ public static function deleteField($id) { $field =& new CRM_Price_DAO_Field(); $field->id = $id; if ($field->find(true)) { // delete the options for this field require_once 'CRM/Core/OptionGroup.php'; CRM_Core_OptionGroup::deleteAssoc("civicrm_price_field.amount.{$id}"); // reorder the weight before delete $fieldValues = array('price_set_id' => $field->price_set_id); require_once 'CRM/Utils/Weight.php'; CRM_Utils_Weight::delWeight('CRM_Price_DAO_Field', $field->id, $fieldValues); // now delete the field return $field->delete(); } return null; }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { $fieldValues = array('option_group_id' => $this->_gid); $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues); if (CRM_Core_BAO_OptionValue::del($this->_id)) { if ($this->_gName == 'phone_type') { require_once 'CRM/Core/BAO/Phone.php'; CRM_Core_BAO_Phone::setOptionToNull(CRM_Utils_Array::value('value', $this->_defaultValues)); } CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', array(1 => $this->_GName))); } else { CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_GName))); CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues); } } else { $params = $ids = array(); $params = $this->exportValues(); //set defaultGreeting option in params as per contact type if (CRM_Utils_Array::value('contactOptions', $params)) { $params['filter'] = CRM_Utils_Array::value('contactOptions', $params); $params['defaultGreeting'] = 1; } $groupParams = array('name' => $this->_gName); require_once 'CRM/Core/OptionValue.php'; $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id); CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => $this->_GName, 2 => $optionValue->label))); } }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { require_once 'CRM/Member/BAO/MembershipType.php'; if ($this->_action & CRM_Core_Action::DELETE) { $wt = CRM_Utils_Weight::delWeight('CRM_Member_DAO_MembershipType', $this->_id); CRM_Member_BAO_MembershipType::del($this->_id); CRM_Core_Session::setStatus(ts('Selected membership type has been deleted.')); } else { $params = $ids = array(); $params = $this->exportValues(); $this->set('searchDone', 0); if (CRM_Utils_Array::value('_qf_MembershipType_refresh', $_POST)) { $this->search($params); $this->set('searchDone', 1); return; } $params['minimum_fee'] = CRM_Utils_Rule::cleanMoney($params['minimum_fee']); if (CRM_Utils_Array::value('relationship_type_id', $params)) { $relationId = explode('_', $params['relationship_type_id']); $params['relationship_type_id'] = $relationId[0]; $params['relationship_direction'] = $relationId[1] . '_' . $relationId[2]; } if ($this->_action & CRM_Core_Action::UPDATE) { $ids['membershipType'] = $this->_id; } if ($params['duration_unit'] == 'lifetime' and empty($params['duration_interval'])) { $params['duration_interval'] = 1; } $config =& CRM_Core_Config::singleton(); $periods = array('fixed_period_start_day', 'fixed_period_rollover_day'); foreach ($periods as $per) { if ($params[$per][$config->dateformatMonthVar] && $params[$per]['d']) { $mon = $params[$per][$config->dateformatMonthVar]; $dat = $params[$per]['d']; $mon = $mon < 9 ? '0' . $mon : $mon; $dat = $dat < 9 ? '0' . $dat : $dat; $params[$per] = $mon . $dat; } else { $params[$per] = 'null'; } } $oldWeight = null; $ids['memberOfContact'] = CRM_Utils_Array::value('contact_check', $params); if ($this->_id) { $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_id, 'weight', 'id'); } $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Member_DAO_MembershipType', $oldWeight, $params['weight']); $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids); CRM_Core_Session::setStatus(ts('The membership type \'%1\' has been saved.', array(1 => $membershipType->name))); } }
/** * Process the form submission. */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { $fieldValues = array('option_group_id' => $this->_gid); $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues); if (CRM_Core_BAO_OptionValue::del($this->_id)) { if ($this->_gName == 'phone_type') { CRM_Core_BAO_Phone::setOptionToNull(CRM_Utils_Array::value('value', $this->_defaultValues)); } CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', array(1 => $this->_gLabel)), ts('Record Deleted'), 'success'); } else { CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_gLabel)), ts('Sorry'), 'error'); CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues); } } else { $params = $ids = array(); $params = $this->exportValues(); // allow multiple defaults within group. $allowMultiDefaults = array('email_greeting', 'postal_greeting', 'addressee', 'from_email_address'); if (in_array($this->_gName, $allowMultiDefaults)) { if ($this->_gName == 'from_email_address') { $params['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID()); } elseif ($filter = CRM_Utils_Array::value('contactOptions', $params)) { $params['filter'] = $filter; $params['reset_default_for'] = array('filter' => "0, " . $params['filter']); } //make sure we should has to have space, CRM-6977 if ($this->_gName == 'from_email_address') { $params['label'] = str_replace('"<', '" <', $params['label']); } } // set value of filter if not present in params if ($this->_id && !array_key_exists('filter', $params)) { if ($this->_gName == 'participant_role') { $params['filter'] = 0; } else { $params['filter'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'filter', 'id'); } } $groupParams = array('name' => $this->_gName); $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id); // CRM-11516 if (!empty($params['financial_account_id'])) { $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); $params = array('entity_table' => 'civicrm_option_value', 'entity_id' => $optionValue->id, 'account_relationship' => $relationTypeId, 'financial_account_id' => $params['financial_account_id']); CRM_Financial_BAO_FinancialTypeAccount::add($params); } CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => $this->_gLabel, 2 => $optionValue->label)), ts('Saved'), 'success'); } }
/** * Run the page. * * This method is called after the page is created. It checks for the * type of action and executes that action. * * @param null * * @return void * @access public */ function run() { require_once 'CRM/Core/BAO/CustomGroup.php'; // get the group id $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this); $action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'browse'); // default to 'browse' if ($action & CRM_Core_Action::DELETE) { $session =& CRM_Core_Session::singleton(); $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field', 'reset=1&action=browse&gid=' . $this->_gid)); $controller =& new CRM_Core_Controller_Simple('CRM_Custom_Form_DeleteField', "Delete Custom Field", ''); $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, false, 0); $controller->set('id', $id); $controller->setEmbedded(true); $controller->process(); $controller->run(); $fieldValues = array('custom_group_id' => $this->_gid); $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_CustomField', $id, $fieldValues); } if ($this->_gid) { $groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_gid); $this->assign('gid', $this->_gid); $this->assign('groupTitle', $groupTitle); CRM_Utils_System::setTitle(ts('%1 - Custom Fields', array(1 => $groupTitle))); } // assign vars to templates $this->assign('action', $action); $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, false, 0); // what action to take ? if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) { $this->edit($action); // no browse for edit/update/view } else { if ($action & CRM_Core_Action::PREVIEW) { $this->preview($id); } else { require_once 'CRM/Core/BAO/CustomField.php'; require_once 'CRM/Core/BAO/UFField.php'; $this->browse(); } } // Call the parents run method parent::run(); }
/** * Function to process the form * * @access public * * @return None */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { CRM_Utils_Weight::delWeight('CRM_Member_DAO_MembershipType', $this->_id); CRM_Member_BAO_MembershipType::del($this->_id); CRM_Core_Session::setStatus(ts('Selected membership type has been deleted.')); } else { $buttonName = $this->controller->getButtonName(); $submitted = $this->controller->exportValues($this->_name); $this->set('searchDone', 0); if ($buttonName == '_qf_MembershipType_refresh') { $this->search($submitted); $this->set('searchDone', 1); return; } $fields = array('name', 'weight', 'is_active', 'member_org', 'visibility', 'period_type', 'minimum_fee', 'description', 'auto_renew', 'autorenewal_msg_id', 'duration_unit', 'renewal_msg_id', 'duration_interval', 'renewal_reminder_day', 'contribution_type_id', 'fixed_period_start_day', 'fixed_period_rollover_day'); $params = $ids = array(); foreach ($fields as $fld) { $params[$fld] = CRM_Utils_Array::value($fld, $submitted, 'NULL'); } //clean money. if ($params['minimum_fee']) { $params['minimum_fee'] = CRM_Utils_Rule::cleanMoney($params['minimum_fee']); } $hasRelTypeVal = FALSE; if (!CRM_Utils_System::isNull($submitted['relationship_type_id'])) { // To insert relation ids and directions with value separator $relTypeDirs = $submitted['relationship_type_id']; $relIds = $relDirection = array(); foreach ($relTypeDirs as $key => $value) { $relationId = explode('_', $value); if (count($relationId) == 3 && is_numeric($relationId[0])) { $relIds[] = $relationId[0]; $relDirection[] = $relationId[1] . '_' . $relationId[2]; } } if (!empty($relIds)) { $hasRelTypeVal = TRUE; $params['relationship_type_id'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $relIds); $params['relationship_direction'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $relDirection); } } if (!$hasRelTypeVal) { $params['relationship_type_id'] = $params['relationship_direction'] = 'NULL'; } if ($params['duration_unit'] == 'lifetime' && empty($params['duration_interval'])) { $params['duration_interval'] = 1; } $config = CRM_Core_Config::singleton(); $periods = array('fixed_period_start_day', 'fixed_period_rollover_day'); foreach ($periods as $per) { if (CRM_Utils_Array::value('M', $params[$per]) && CRM_Utils_Array::value('d', $params[$per])) { $mon = $params[$per]['M']; $dat = $params[$per]['d']; $mon = $mon < 9 ? '0' . $mon : $mon; $dat = $dat < 9 ? '0' . $dat : $dat; $params[$per] = $mon . $dat; } else { $params[$per] = 'NULL'; } } $oldWeight = NULL; $ids['memberOfContact'] = CRM_Utils_Array::value('contact_check', $submitted); if ($this->_id) { $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_id, 'weight', 'id'); } $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Member_DAO_MembershipType', $oldWeight, $params['weight']); if ($this->_action & CRM_Core_Action::UPDATE) { $ids['membershipType'] = $this->_id; } $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids); CRM_Core_Session::setStatus(ts('The membership type \'%1\' has been saved.', array(1 => $membershipType->name))); $session = CRM_Core_Session::singleton(); if ($buttonName == $this->getButtonName('upload', 'new')) { CRM_Core_Session::setStatus(ts(' You can add another membership type.')); $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/member/membershipType', 'action=add&reset=1')); } } }
/** * Run the page. * * This method is called after the page is created. It checks for the * type of action and executes that action. * * @return void */ public function run() { $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0); if ($id) { $values = civicrm_api3('custom_field', 'getsingle', array('id' => $id)); $this->_gid = $values['custom_group_id']; } else { $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this); } if ($isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_reserved', 'id')) { CRM_Core_Error::fatal("You cannot add or edit fields in a reserved custom field-set."); } $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); if ($action & CRM_Core_Action::DELETE) { $session = CRM_Core_Session::singleton(); $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field', 'reset=1&action=browse&gid=' . $this->_gid)); $controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_DeleteField', "Delete Custom Field", ''); $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0); $controller->set('id', $id); $controller->setEmbedded(TRUE); $controller->process(); $controller->run(); $fieldValues = array('custom_group_id' => $this->_gid); $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_CustomField', $id, $fieldValues); } if ($this->_gid) { $groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_gid); $this->assign('gid', $this->_gid); $this->assign('groupTitle', $groupTitle); if ($action & CRM_Core_Action::BROWSE) { CRM_Utils_System::setTitle(ts('%1 - Custom Fields', array(1 => $groupTitle))); } } // assign vars to templates $this->assign('action', $action); // what action to take ? if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) { // no browse for edit/update/view $this->edit($action); } elseif ($action & CRM_Core_Action::PREVIEW) { $this->preview($id); } else { $this->browse(); } // Call the parents run method return parent::run(); }
/** * Process the form when submitted * * @return void * @access public */ public function postProcess() { $group = new CRM_Core_DAO_CustomGroup(); $group->id = $this->_id; $group->find(TRUE); $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_CustomGroup', $this->_id); CRM_Core_BAO_CustomGroup::deleteGroup($group); CRM_Core_Session::setStatus(ts("The Group '%1' has been deleted.", array(1 => $group->title)), '', 'success'); }
/** * Function to process the form * * @access public * * @return void */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { $fieldValues = array('option_group_id' => $this->_gid); $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues); if (CRM_Core_BAO_OptionValue::del($this->_id)) { CRM_Core_Session::setStatus(ts('Selected Survey type has been deleted.'), ts('Record Deleted'), 'success'); } } else { $params = $ids = array(); $params = $this->exportValues(); // set db value of filter in params if filter is non editable if ($this->_id && !array_key_exists('filter', $params)) { $params['filter'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'filter', 'id'); } $groupParams = array('name' => $this->_gName); $params['component_id'] = CRM_Core_Component::getComponentID('CiviCampaign'); $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id); CRM_Core_Session::setStatus(ts('The Survey type \'%1\' has been saved.', array(1 => $optionValue->label)), ts('Saved'), 'success'); } }
/** * Delete membership Types. * * @param int $membershipTypeId * * @throws CRM_Core_Exception * @return bool|mixed */ public static function del($membershipTypeId) { // Check dependencies. $check = FALSE; $status = array(); $dependency = array('Membership' => 'membership_type_id', 'MembershipBlock' => 'membership_type_default'); foreach ($dependency as $name => $field) { $baoString = 'CRM_Member_BAO_' . $name; $dao = new $baoString(); $dao->{$field} = $membershipTypeId; /** @noinspection PhpUndefinedMethodInspection */ if ($dao->find(TRUE)) { $check = TRUE; $status[] = $name; } } if ($check) { $cnt = 1; $message = ts('This membership type cannot be deleted due to following reason(s):'); if (in_array('Membership', $status)) { $findMembersURL = CRM_Utils_System::url('civicrm/member/search', 'reset=1'); $deleteURL = CRM_Utils_System::url('civicrm/contact/search/advanced', 'reset=1'); $message .= '<br/>' . ts('%3. There are some contacts who have this membership type assigned to them. Search for contacts with this membership type from <a href=\'%1\'>Find Members</a>. If you are still getting this message after deleting these memberships, there may be contacts in the Trash (deleted) with this membership type. Try using <a href="%2">Advanced Search</a> and checking "Search in Trash".', array(1 => $findMembersURL, 2 => $deleteURL, 3 => $cnt)); $cnt++; } if (in_array('MembershipBlock', $status)) { $deleteURL = CRM_Utils_System::url('civicrm/admin/contribute', 'reset=1'); $message .= ts('%2. This Membership Type is used in an <a href=\'%1\'>Online Contribution page</a>. Uncheck this membership type in the Memberships tab.', array(1 => $deleteURL, 2 => $cnt)); throw new CRM_Core_Exception($message); } } CRM_Utils_Weight::delWeight('CRM_Member_DAO_MembershipType', $membershipTypeId); //delete from membership Type table $membershipType = new CRM_Member_DAO_MembershipType(); $membershipType->id = $membershipTypeId; //fix for membership type delete api $result = FALSE; if ($membershipType->find(TRUE)) { return $membershipType->delete(); } return $result; }
/** * Process the form. * * @return void */ public function postProcess() { $ids = array('uf_group' => $this->_gid); if ($this->_action & CRM_Core_Action::DELETE) { $fieldValues = array('uf_group_id' => $this->_gid); CRM_Utils_Weight::delWeight('CRM_Core_DAO_UFField', $this->_id, $fieldValues); $deleted = CRM_Core_BAO_UFField::del($this->_id); //update group_type every time. CRM-3608 if ($this->_gid && $deleted) { //get the profile type. $fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($this->_gid, TRUE); CRM_Core_BAO_UFGroup::updateGroupTypes($this->_gid, $fieldsType); } CRM_Core_Session::setStatus(ts('Selected Profile Field has been deleted.'), ts('Profile Field Deleted'), 'success'); return; } // store the submitted values in an array $params = $this->controller->exportValues('Field'); if ($params['visibility'] == 'User and User Admin Only') { $params['is_searchable'] = $params['in_selector'] = 0; } if ($this->_action & CRM_Core_Action::UPDATE) { $ids['uf_field'] = $this->_id; } $name = NULL; if (isset($params['field_name'][1]) && isset($this->_selectFields[$params['field_name'][1]])) { // we dont get a name for a html formatting element $name = $this->_selectFields[$params['field_name'][1]]; } //Hack for Formatting Field Name if ($params['field_name'][0] == 'Formatting') { $params['field_name'][1] = 'formatting_' . rand(1000, 9999); } //check for duplicate fields if ($params["field_name"][0] != "Formatting" && CRM_Core_BAO_UFField::duplicateField($params, $ids)) { CRM_Core_Session::setStatus(ts('The selected field already exists in this profile.'), ts('Field Not Added'), 'error'); return; } else { $params['weight'] = CRM_Core_BAO_UFField::autoWeight($params); $ufField = CRM_Core_BAO_UFField::add($params, $ids); //reset other field is searchable and in selector settings, CRM-4363 if ($this->_hasSearchableORInSelector && in_array($ufField->field_type, array('Participant', 'Contribution', 'Membership', 'Activity', 'Case'))) { CRM_Core_BAO_UFField::resetInSelectorANDSearchable($this->_gid); } $config = CRM_Core_Config::singleton(); $showBestResult = FALSE; if (in_array($ufField->field_name, array('country', 'state_province')) && count($config->countryLimit) > 1) { // get state or country field weight if exists $field = 'state_province'; if ($ufField->field_name == 'state_province') { $field = 'country'; } $ufFieldDAO = new CRM_Core_DAO_UFField(); $ufFieldDAO->field_name = $field; $ufFieldDAO->location_type_id = $ufField->location_type_id; $ufFieldDAO->uf_group_id = $ufField->uf_group_id; if ($ufFieldDAO->find(TRUE)) { if ($field == 'country' && $ufFieldDAO->weight > $ufField->weight) { $showBestResult = TRUE; } elseif ($field == 'state_province' && $ufFieldDAO->weight < $ufField->weight) { $showBestResult = TRUE; } } } //update group_type every time. CRM-3608 if ($this->_gid && is_a($ufField, 'CRM_Core_DAO_UFField')) { // get the profile type. $fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($this->_gid, TRUE); CRM_Core_BAO_UFGroup::updateGroupTypes($this->_gid, $fieldsType); } CRM_Core_Session::setStatus(ts('Your CiviCRM Profile Field \'%1\' has been saved to \'%2\'.', array(1 => $name, 2 => $this->_title)), ts('Profile Field Saved'), 'success'); } $buttonName = $this->controller->getButtonName(); $session = CRM_Core_Session::singleton(); if ($buttonName == $this->getButtonName('next', 'new')) { $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/uf/group/field/add', "reset=1&action=add&gid={$this->_gid}&sbr={$showBestResult}")); } else { $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/uf/group/field', "reset=1&action=browse&gid={$this->_gid}")); $session->set('showBestResult', $showBestResult); } }
/** * Delete the price set field. * * @param int $id Field Id * * @return boolean * * @access public * @static * */ public static function deleteField($id) { $field = new CRM_Price_DAO_PriceField(); $field->id = $id; if ($field->find(TRUE)) { // delete the options for this field CRM_Price_BAO_PriceFieldValue::deleteValues($id); // reorder the weight before delete $fieldValues = array('price_set_id' => $field->price_set_id); CRM_Utils_Weight::delWeight('CRM_Price_DAO_PriceField', $field->id, $fieldValues); // now delete the field return $field->delete(); } return NULL; }
/** * Process the form * * @param null * * @return void * @access public */ public function postProcess() { require_once 'CRM/Price/BAO/FieldValue.php'; if ($this->_action == CRM_Core_Action::DELETE) { $fieldValues = array('price_field_id' => $this->_fid); $wt = CRM_Utils_Weight::delWeight('CRM_Price_DAO_FieldValue', $this->_oid, $fieldValues); $label = CRM_Core_DAO::getFieldValue("CRM_Price_DAO_FieldValue", $this->_oid, 'label', 'id'); if (CRM_Price_BAO_FieldValue::del($this->_oid)) { CRM_Core_Session::setStatus(ts('%1 option has been deleted.', array(1 => $label))); } return; } else { $params = $ids = array(); $params = $this->controller->exportValues('Option'); $fieldLabel = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $this->_fid, 'label'); $params['amount'] = CRM_Utils_Rule::cleanMoney(trim($params['amount'])); $params['price_field_id'] = $this->_fid; $params['is_default'] = CRM_Utils_Array::value('is_default', $params, false); $ids = array(); if ($this->_oid) { $ids['id'] = $this->_oid; } $optionValue = CRM_Price_BAO_FieldValue::create($params, $ids); CRM_Core_Session::setStatus(ts('The option \'%1\' has been saved.', array(1 => $params['label']))); } }