public function createEntry($id, $key) { $e = self::$_extensions; $ids = array(); $groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::OPTION_GROUP_NAME, 'id', 'name'); $params = array('option_group_id' => $groupId, 'weight' => CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', array('option_group_id' => $groupId)), 'label' => $e['per_id'][$id]['label'], 'name' => $e['per_id'][$id]['label'], 'value' => $key, 'grouping' => $e['per_id'][$id]['type'], 'is_active' => 1); $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids); }
public function install() { if (array_key_exists($this->ext->key, $this->customSearches)) { CRM_Core_Error::fatal('This custom search is already registered.'); } $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', array('option_group_id' => $this->groupId)); $params = array('option_group_id' => $this->groupId, 'weight' => $weight, 'description' => $this->ext->label . ' (' . $this->ext->key . ')', 'name' => $this->ext->key, 'value' => max($this->customSearches) + 1, 'label' => $this->ext->key, 'is_active' => 1); $ids = array(); $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids); }
/** * @param CRM_Extension_Info $info * * @return bool * @throws Exception */ public function onPreInstall(CRM_Extension_Info $info) { $customSearchesByName = $this->getCustomSearchesByName(); if (array_key_exists($info->key, $customSearchesByName)) { CRM_Core_Error::fatal('This custom search is already registered.'); } $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', array('option_group_id' => $this->groupId)); $params = array('option_group_id' => $this->groupId, 'weight' => $weight, 'description' => $info->label . ' (' . $info->key . ')', 'name' => $info->key, 'value' => max($customSearchesByName) + 1, 'label' => $info->key, 'is_active' => 1); $ids = array(); $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids); return $optionValue ? TRUE : FALSE; }
/** * @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; }
public function install() { if (array_key_exists($this->ext->key, $this->customReports)) { CRM_Core_Error::fatal('This report is already registered.'); } if ($this->ext->typeInfo['component'] === 'Contact') { $compId = 'null'; } else { $comp = CRM_Core_Component::get($this->ext->typeInfo['component']); $compId = $comp->componentID; } if (empty($compId)) { CRM_Core_Error::fatal("Component for which you're trying to install the extension (" . $this->ext->typeInfo['component'] . ") is currently disabled."); } $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', array('option_group_id' => $this->groupId)); $ids = array(); $params = array('label' => $this->ext->label . ' (' . $this->ext->key . ')', 'value' => $this->ext->typeInfo['reportUrl'], 'name' => $this->ext->key, 'weight' => $weight, 'description' => $this->ext->label . ' (' . $this->ext->key . ')', 'component_id' => $compId, 'option_group_id' => $this->groupId, 'is_active' => 1); $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids); }
/** * Add a OptionValue. OptionValues are used to classify CRM entities (including Contacts, Groups and Actions). * * Allowed @params array keys are: * * {@example OptionValueCreate.php} * * @return array of newly created option_value property values. * {@getfields OptionValue_create} * @access public */ function civicrm_api3_option_value_create($params) { $weight = 0; if (!array_key_exists('label', $params) && array_key_exists('name', $params)) { // no idea why that's a "mandatory" field $params['label'] = $params['name']; } if (!CRM_Utils_Array::value('value', $params) && array_key_exists('option_group_id', $params)) { require_once 'CRM/Utils/Weight.php'; $fieldValues = array('option_group_id' => $params['option_group_id']); // use the next available value /* CONVERT(value, DECIMAL) is used to convert varchar field 'value' to decimal->integer */ $params['value'] = (int) CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues, 'CONVERT(value, DECIMAL)'); $weight = $params['value']; } if (!array_key_exists('weight', $params) && array_key_exists('value', $params)) { // no idea why that's a "mandatory" field $params['weight'] = $params['value']; } elseif (array_key_exists('weight', $params) && $params['weight'] == 'next') { // weight is numeric, so it's safe-ish to treat symbol 'next' as magical value $params['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', array('option_group_id' => $params['option_group_id'])); } if (array_key_exists('component', $params)) { if (empty($params['component'])) { $params['component_id'] = ''; } else { $params['component_id'] = array_search($params['component'], CRM_Core_PseudoConstant::component()); } unset($params['component']); } if (CRM_Utils_Array::value('id', $params)) { $ids = array('optionValue' => $params['id']); } $optionValueBAO = CRM_Core_BAO_OptionValue::add($params, $ids); civicrm_api('option_value', 'getfields', array('version' => 3, 'cache_clear' => 1)); $values = array(); _civicrm_api3_object_to_array($optionValueBAO, $values[$optionValueBAO->id]); return civicrm_api3_create_success($values, $params); }
/** * Creates a new entry in the database. * * @param array $params (reference), array $ids * * @return object CRM_Price_DAO_FieldValue object * @access public * @static */ static function create(&$params, $ids) { if (!is_array($params) || empty($params)) { return; } if ($id = CRM_Utils_Array::value('id', $ids)) { if (isset($params['name'])) { unset($params['name']); } $oldWeight = null; if ($id) { $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_FieldValue', $id, 'weight', 'id'); } $fieldValues = array('price_field_id' => CRM_Utils_Array::value('price_field_id', $params, 0)); $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_FieldValue', $oldWeight, $params['weight'], $fieldValues); } else { if (!CRM_Utils_Array::value('name', $params)) { $params['name'] = CRM_Utils_String::munge(CRM_Utils_Array::value('label', $params), '_', 64); } $params['weight'] = 1; } $params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0); return self::add($params, $ids); }
/** * Browse all price fields. * * @param null * * @return void * @access public */ function browse() { $customOption = array(); CRM_Price_BAO_PriceFieldValue::getValues($this->_fid, $customOption); $config = CRM_Core_Config::singleton(); $financialType = CRM_Contribute_PseudoConstant::financialType(); foreach ($customOption as $id => $values) { $action = array_sum(array_keys($this->actionLinks())); if (CRM_Utils_Array::value('financial_type_id', $values)) { $customOption[$id]['financial_type_id'] = $financialType[$values['financial_type_id']]; } // update enable/disable links depending on price_field properties. if ($this->_isSetReserved) { $action -= CRM_Core_Action::UPDATE + CRM_Core_Action::DELETE + CRM_Core_Action::DISABLE + CRM_Core_Action::ENABLE; } else { if ($values['is_active']) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } } if (CRM_Utils_Array::value('is_default', $customOption[$id])) { $customOption[$id]['is_default'] = '<img src="' . $config->resourceBase . 'i/check.gif" />'; } else { $customOption[$id]['is_default'] = ''; } $customOption[$id]['order'] = $customOption[$id]['weight']; $customOption[$id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('oid' => $id, 'fid' => $this->_fid, 'sid' => $this->_sid)); } // Add order changing widget to selector $returnURL = CRM_Utils_System::url('civicrm/admin/price/field/option', "action=browse&reset=1&fid={$this->_fid}&sid={$this->_sid}"); $filter = "price_field_id = {$this->_fid}"; CRM_Utils_Weight::addOrder($customOption, 'CRM_Price_DAO_PriceFieldValue', 'id', $returnURL, $filter); $this->assign('customOption', $customOption); $this->assign('sid', $this->_sid); }
/** * Get next available value. * We will take the highest numeric value (or 0 if no numeric values exist) * and add one. The calling function is responsible for any * more complex decision making * * @param array $params * * @return int */ public static function getDefaultWeight($params) { return (int) CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', array('option_group_id' => $params['option_group_id'])); }
function upgrade($rev) { // fix CRM-5270: if civicrm_report_instance.description is localised, // recreate it based on the first locale’s description_xx_YY contents // and drop all the description_xx_YY columns if (!CRM_Core_DAO::checkFieldExists('civicrm_report_instance', 'description')) { require_once 'CRM/Core/DAO/Domain.php'; $domain = new CRM_Core_DAO_Domain(); $domain->find(true); $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales); CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_report_instance ADD description VARCHAR(255)"); CRM_Core_DAO::executeQuery("UPDATE civicrm_report_instance SET description = description_{$locales[0]}"); CRM_Core_DAO::executeQuery("DROP TRIGGER civicrm_report_instance_before_insert"); foreach ($locales as $locale) { CRM_Core_DAO::executeQuery("DROP VIEW civicrm_report_instance_{$locale}"); CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_report_instance DROP description_{$locale}"); } } //We execute some part of php after sql and then again sql //So using conditions for skipping some part of sql CRM-4575 $upgrade =& new CRM_Upgrade_Form(); //Run the SQL file (1) $upgrade->processSQL($rev); //replace with ; in report instance $sql = "UPDATE civicrm_report_instance \n SET form_values = REPLACE(form_values,'#',';') "; CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray); //delete unnecessary activities $bulkEmailID = CRM_Core_OptionGroup::getValue('activity_type', 'Bulk Email', 'name'); if ($bulkEmailID) { $mailingActivityIds = array(); $query = " \n SELECT max( ca.id ) as aid, \n ca.source_record_id sid\n FROM civicrm_activity ca\n WHERE ca.activity_type_id = %1 \n GROUP BY ca.source_record_id"; $params = array(1 => array($bulkEmailID, 'Integer')); $dao = CRM_Core_DAO::executeQuery($query, $params); while ($dao->fetch()) { $updateQuery = "\n UPDATE civicrm_activity_target cat, civicrm_activity ca \n SET cat.activity_id = {$dao->aid} \n WHERE ca.source_record_id IS NOT NULL AND\n ca.activity_type_id = %1 AND \n ca.id <> {$dao->aid} AND \n ca.source_record_id = {$dao->sid} AND \n ca.id = cat.activity_id"; $updateParams = array(1 => array($bulkEmailID, 'Integer')); CRM_Core_DAO::executeQuery($updateQuery, $updateParams); $deleteQuery = " \n DELETE ca.* \n FROM civicrm_activity ca \n WHERE ca.source_record_id IS NOT NULL AND \n ca.activity_type_id = %1 AND \n ca.id <> {$dao->aid} AND \n ca.source_record_id = {$dao->sid}"; $deleteParams = array(1 => array($bulkEmailID, 'Integer')); CRM_Core_DAO::executeQuery($deleteQuery, $deleteParams); } } //CRM-4453 //lets insert column in civicrm_aprticipant table $query = "\n ALTER TABLE `civicrm_participant` \n ADD `fee_currency` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL COMMENT '3 character string, value derived from config setting.' AFTER `discount_id`"; CRM_Core_DAO::executeQuery($query); //get currency from contribution table if exists/default //insert currency when fee_amount != NULL or event is paid. $query = "\n SELECT civicrm_participant.id \n FROM civicrm_participant\n LEFT JOIN civicrm_event \n ON ( civicrm_participant.event_id = civicrm_event.id )\n WHERE civicrm_participant.fee_amount IS NOT NULL OR \n civicrm_event.is_monetary = 1"; $participant = CRM_Core_DAO::executeQuery($query); while ($participant->fetch()) { $query = "\n SELECT civicrm_contribution.currency \n FROM civicrm_contribution, \n civicrm_participant_payment\n WHERE civicrm_contribution.id = civicrm_participant_payment.contribution_id AND \n civicrm_participant_payment.participant_id = {$participant->id}"; $currencyID = CRM_Core_DAO::singleValueQuery($query); if (!$currencyID) { $config =& CRM_Core_Config::singleton(); $currencyID = $config->defaultCurrency; } //finally update participant record. CRM_Core_DAO::setFieldValue('CRM_Event_DAO_Participant', $participant->id, 'fee_currency', $currencyID); } //CRM-4575 //check whether {contact.name} is set in mailing labels require_once 'CRM/Core/BAO/Preferences.php'; $mailingFormat = CRM_Core_BAO_Preferences::value('mailing_format'); $addNewAddressee = true; if (strpos($mailingFormat, '{contact.contact_name}') === false) { $addNewAddressee = false; } else { //else compare individual name format with default individual addressee. $individualNameFormat = CRM_Core_BAO_Preferences::value('individual_name_format'); $defaultAddressee = CRM_Core_OptionGroup::values('addressee', false, false, false, " AND v.filter = 1 AND v.is_default = 1", 'label'); if (array_search($individualNameFormat, $defaultAddressee) !== false) { $addNewAddressee = false; } } require_once 'CRM/Utils/System.php'; $docURL = CRM_Utils_System::docURL2('Update Greetings and Address Data for Contacts', false, null, null, 'color: white; text-decoration: underline;'); if ($addNewAddressee) { //otherwise insert new token in addressee and set as a default $addresseeGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'addressee', 'id', 'name'); $optionValueParams = array('label' => $individualNameFormat, 'is_active' => 1, 'contactOptions' => 1, 'filter' => 1, 'is_default' => 1, 'reset_default_for' => array('filter' => "0, 1")); $action = CRM_Core_Action::ADD; $addresseeGroupParams = array('name' => 'addressee'); $fieldValues = array('option_group_id' => $addresseeGroupId); $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues); $optionValueParams['weight'] = $weight; $addresseeToken = CRM_Core_OptionValue::addOptionValue($optionValueParams, $addresseeGroupParams, $action, $optionId = null); $afterUpgradeMessage = ts("During this upgrade, Postal Addressee values have been stored for each contact record using the system default format - %2.You will need to run the included command-line script to update your Individual contact records to use the \"Individual Name Format\" previously specified for your site %1", array(1 => $docURL, 2 => array_pop($defaultAddressee))); } else { $afterUpgradeMessage = ts("Email Greeting, Postal Greeting and Postal Addressee values have been stored for all contact records based on the system default formats. If you want to use a different format for any of these contact fields - you can run the provided command line script to update contacts to a different format %1 ", array(1 => $docURL)); } //replace contact.contact_name with contact.addressee in civicrm_preference.mailing_format $updateQuery = "\n UPDATE civicrm_preferences \n SET `mailing_format` = \n replace(`mailing_format`, '{contact.contact_name}','{contact.addressee}')"; CRM_Core_DAO::executeQuery($updateQuery); //drop column individual_name_format $alterQuery = "\n ALTER TABLE `civicrm_preferences`\n DROP `individual_name_format`"; CRM_Core_DAO::executeQuery($alterQuery); //set status message for default greetings $template =& CRM_Core_Smarty::singleton(); $template->assign('afterUpgradeMessage', $afterUpgradeMessage); }
/** * Browse all custom data groups. * * @param string $action the action to be invoked * * @return void * @access public */ function browse($action = NULL) { // get all custom groups sorted by weight $customGroup = array(); $dao = new CRM_Core_DAO_CustomGroup(); $dao->orderBy('weight, title'); $dao->find(); while ($dao->fetch()) { $customGroup[$dao->id] = array(); CRM_Core_DAO::storeValues($dao, $customGroup[$dao->id]); // form all action links $action = array_sum(array_keys($this->actionLinks())); // update enable/disable links depending on custom_group properties. if ($dao->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } $customGroup[$dao->id]['order'] = $customGroup[$dao->id]['weight']; $customGroup[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $dao->id)); } $customGroupExtends = CRM_Core_SelectValues::customGroupExtends(); foreach ($customGroup as $key => $array) { CRM_Core_DAO_CustomGroup::addDisplayEnums($customGroup[$key]); $customGroup[$key]['extends_display'] = $customGroupExtends[$customGroup[$key]['extends']]; } //fix for Displaying subTypes $subTypes = array(); $subTypes['Activity'] = CRM_Core_PseudoConstant::activityType(FALSE, TRUE, FALSE, 'label', TRUE); $subTypes['Contribution'] = CRM_Contribute_PseudoConstant::contributionType(); $subTypes['Membership'] = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE); $subTypes['Event'] = CRM_Core_OptionGroup::values('event_type'); $subTypes['Grant'] = CRM_Core_OptionGroup::values('grant_type'); $subTypes['Campaign'] = CRM_Campaign_PseudoConstant::campaignType(); $subTypes['Participant'] = array(); $subTypes['ParticipantRole'] = CRM_Core_OptionGroup::values('participant_role'); $subTypes['ParticipantEventName'] = CRM_Event_PseudoConstant::event(); $subTypes['ParticipantEventType'] = CRM_Core_OptionGroup::values('event_type'); $subTypes['Individual'] = CRM_Contact_BAO_ContactType::subTypePairs('Individual', FALSE, NULL); $subTypes['Household'] = CRM_Contact_BAO_ContactType::subTypePairs('Household', FALSE, NULL); $subTypes['Organization'] = CRM_Contact_BAO_ContactType::subTypePairs('Organization', FALSE, NULL); $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Individual'); $relTypeOrg = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Organization'); $relTypeHou = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Household'); $allRelationshipType = array(); $allRelationshipType = array_merge($relTypeInd, $relTypeOrg); $allRelationshipType = array_merge($allRelationshipType, $relTypeHou); //adding subtype specific relationships CRM-5256 $relSubType = CRM_Contact_BAO_ContactType::subTypeInfo(); foreach ($relSubType as $subType => $val) { $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $val['parent'], FALSE, 'label', TRUE, $subType); $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes); } $subTypes['Relationship'] = $allRelationshipType; $cSubTypes = CRM_Core_Component::contactSubTypes(); $contactSubTypes = array(); foreach ($cSubTypes as $key => $value) { $contactSubTypes[$key] = $key; } $subTypes['Contact'] = $contactSubTypes; CRM_Core_BAO_CustomGroup::getExtendedObjectTypes($subTypes); foreach ($customGroup as $key => $values) { $subValue = CRM_Utils_Array::value('extends_entity_column_value', $customGroup[$key]); $subName = CRM_Utils_Array::value('extends_entity_column_id', $customGroup[$key]); $type = CRM_Utils_Array::value('extends', $customGroup[$key]); if ($subValue) { $subValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($subValue, 1, -1)); $colValue = NULL; foreach ($subValue as $sub) { if ($sub) { if ($type == 'Participant') { if ($subName == 1) { $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantRole'][$sub] : $subTypes['ParticipantRole'][$sub]; } elseif ($subName == 2) { $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantEventName'][$sub] : $subTypes['ParticipantEventName'][$sub]; } elseif ($subName == 3) { $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantEventType'][$sub] : $subTypes['ParticipantEventType'][$sub]; } } elseif ($type == 'Relationship') { $colValue = $colValue ? $colValue . ', ' . $subTypes[$type][$sub . '_a_b'] : $subTypes[$type][$sub . '_a_b']; if (isset($subTypes[$type][$sub . '_b_a'])) { $colValue = $colValue ? $colValue . ', ' . $subTypes[$type][$sub . '_b_a'] : $subTypes[$type][$sub . '_b_a']; } } else { $colValue = $colValue ? $colValue . (isset($subTypes[$type][$sub]) ? ', ' . $subTypes[$type][$sub] : '') : (isset($subTypes[$type][$sub]) ? $subTypes[$type][$sub] : ''); } } } $customGroup[$key]["extends_entity_column_value"] = $colValue; } else { if (is_array(CRM_Utils_Array::value($type, $subTypes))) { $customGroup[$key]["extends_entity_column_value"] = ts("Any"); } } } $returnURL = CRM_Utils_System::url('civicrm/admin/custom/group', "reset=1&action=browse"); CRM_Utils_Weight::addOrder($customGroup, 'CRM_Core_DAO_CustomGroup', 'id', $returnURL); $this->assign('rows', $customGroup); }
/** * Browse all options * * * @return void * @access public * @static */ function browse() { $campaingCompId = CRM_Core_Component::getComponentID('CiviCampaign'); $groupParams = array('name' => $this->_gName); $optionValues = CRM_Core_OptionValue::getRows($groupParams, $this->links(), 'component_id,weight'); foreach ($optionValues as $key => $optionValue) { if (CRM_Utils_Array::value('component_id', $optionValue) != $campaingCompId) { unset($optionValues[$key]); } } $returnURL = CRM_Utils_System::url("civicrm/admin/campaign/surveyType", "reset=1"); $filter = "option_group_id = " . $this->_gid; CRM_Utils_Weight::addOrder($optionValues, 'CRM_Core_DAO_OptionValue', 'id', $returnURL, $filter); $this->assign('rows', $optionValues); }
/** * 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.')); }
/** * Browse all options. */ public function browse() { $groupParams = array('name' => self::$_gName); $optionValue = CRM_Core_OptionValue::getRows($groupParams, $this->links(), 'weight'); $gName = self::$_gName; $returnURL = CRM_Utils_System::url("civicrm/admin/report/options/{$gName}", "reset=1"); $filter = "option_group_id = " . self::$_gId; $session = new CRM_Core_Session(); $session->replaceUserContext($returnURL); CRM_Utils_Weight::addOrder($optionValue, 'CRM_Core_DAO_OptionValue', 'id', $returnURL, $filter); $this->assign('rows', $optionValue); }
/** * Process the form. * * @return void */ public function postProcess() { // get the submitted form values. $params = $this->controller->exportValues($this->_name); $urlParams = 'civicrm/admin/contribute/premium'; if ($this->_action & CRM_Core_Action::PREVIEW) { $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id); $single = $session->get('singleForm'); CRM_Utils_System::redirect($url); return; } if ($this->_action & CRM_Core_Action::DELETE) { $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id); $dao = new CRM_Contribute_DAO_PremiumsProduct(); $dao->id = $this->_pid; $dao->delete(); CRM_Core_Session::setStatus(ts('Selected Premium Product has been removed from this Contribution Page.'), ts('Saved'), 'success'); CRM_Utils_System::redirect($url); } else { $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id); if ($this->_pid) { $params['id'] = $this->_pid; } $dao = new CRM_Contribute_DAO_Premium(); $dao->entity_table = 'civicrm_contribution_page'; $dao->entity_id = $this->_id; $dao->find(TRUE); $premiumID = $dao->id; $params['premiums_id'] = $premiumID; $oldWeight = NULL; if ($this->_pid) { $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PremiumsProduct', $this->_pid, 'weight', 'id'); } // updateOtherWeights needs to filter on premiums_id $filter = array('premiums_id' => $params['premiums_id']); $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Contribute_DAO_PremiumsProduct', $oldWeight, $params['weight'], $filter); $dao = new CRM_Contribute_DAO_PremiumsProduct(); $dao->copyValues($params); $dao->save(); CRM_Utils_System::redirect($url); } }
/** * 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'); }
/** * 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)); } }
/** * Browse function. */ public function browse() { // get all custom groups sorted by weight $premiums = array(); $pageID = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0); $dao = new CRM_Contribute_DAO_Premium(); $dao->entity_table = 'civicrm_contribution_page'; $dao->entity_id = $pageID; $dao->find(TRUE); $premiumID = $dao->id; $this->assign('products', FALSE); $this->assign('id', $pageID); if (!$premiumID) { return; } $dao = new CRM_Contribute_DAO_PremiumsProduct(); $dao->premiums_id = $premiumID; $dao->orderBy('weight'); $dao->find(); while ($dao->fetch()) { $productDAO = new CRM_Contribute_DAO_Product(); $productDAO->id = $dao->product_id; $productDAO->is_active = 1; if ($productDAO->find(TRUE)) { $premiums[$productDAO->id] = array(); $premiums[$productDAO->id]['weight'] = $dao->weight; CRM_Core_DAO::storeValues($productDAO, $premiums[$productDAO->id]); $action = array_sum(array_keys($this->links())); $premiums[$dao->product_id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $pageID, 'pid' => $dao->id), ts('more'), FALSE, 'premium.contributionpage.row', 'Premium', $dao->id); //Financial Type if (!empty($dao->financial_type_id)) { $premiums[$productDAO->id]['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $dao->financial_type_id, 'name'); } } } if (count(CRM_Contribute_PseudoConstant::products($pageID)) == 0) { $this->assign('products', FALSE); } else { $this->assign('products', TRUE); } // Add order changing widget to selector $returnURL = CRM_Utils_System::url('civicrm/admin/contribute/premium', "reset=1&action=update&id={$pageID}"); $filter = "premiums_id = {$premiumID}"; CRM_Utils_Weight::addOrder($premiums, 'CRM_Contribute_DAO_PremiumsProduct', 'id', $returnURL, $filter); $this->assign('rows', $premiums); }
/** * Process the form. * * @return void */ public function postProcess() { // get the submitted form values. $params = $this->controller->exportValues($this->_name); $deletePriceSet = 0; if ($params['membership_type']) { // we do this in case the user has hit the forward/back button $dao = new CRM_Member_DAO_MembershipBlock(); $dao->entity_table = 'civicrm_contribution_page'; $dao->entity_id = $this->_id; $dao->find(TRUE); $membershipID = $dao->id; if ($membershipID) { $params['id'] = $membershipID; } $membershipTypes = array(); if (is_array($params['membership_type'])) { foreach ($params['membership_type'] as $k => $v) { if ($v) { $membershipTypes[$k] = CRM_Utils_Array::value("auto_renew_{$k}", $params); } } } if ($this->_id && !empty($params['member_price_set_id'])) { CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'amount_block_is_active', 0); } // check for price set. $priceSetID = CRM_Utils_Array::value('member_price_set_id', $params); if (!empty($params['member_is_active']) && is_array($membershipTypes) && !$priceSetID) { $usedPriceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 2); if (empty($params['mem_price_field_id']) && !$usedPriceSetId) { $pageTitle = strtolower(CRM_Utils_String::munge($this->_values['title'], '_', 245)); $setParams['title'] = $this->_values['title']; if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle, 'id', 'name')) { $setParams['name'] = $pageTitle; } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle . '_' . $this->_id, 'id', 'name')) { $setParams['name'] = $pageTitle . '_' . $this->_id; } else { $timeSec = explode(".", microtime(TRUE)); $setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1]; } $setParams['is_quick_config'] = 1; $setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember'); $setParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values); $priceSet = CRM_Price_BAO_PriceSet::create($setParams); $priceSetID = $priceSet->id; $fieldParams['price_set_id'] = $priceSet->id; } elseif ($usedPriceSetId) { $setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember'); $setParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values); $setParams['id'] = $usedPriceSetId; $priceSet = CRM_Price_BAO_PriceSet::create($setParams); $priceSetID = $priceSet->id; $fieldParams['price_set_id'] = $priceSet->id; } else { $fieldParams['id'] = CRM_Utils_Array::value('mem_price_field_id', $params); $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', CRM_Utils_Array::value('mem_price_field_id', $params), 'price_set_id'); } $editedFieldParams = array('price_set_id' => $priceSetID, 'name' => 'membership_amount'); $editedResults = array(); CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults); if (empty($editedResults['id'])) { $fieldParams['name'] = strtolower(CRM_Utils_String::munge('Membership Amount', '_', 245)); if (empty($params['mem_price_field_id'])) { CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_PriceField', 0, 1, array('price_set_id' => $priceSetID)); } $fieldParams['weight'] = 1; } else { $fieldParams['id'] = CRM_Utils_Array::value('id', $editedResults); } $fieldParams['label'] = !empty($params['membership_type_label']) ? $params['membership_type_label'] : ts('Membership'); $fieldParams['is_active'] = 1; $fieldParams['html_type'] = 'Radio'; $fieldParams['is_required'] = !empty($params['is_required']) ? 1 : 0; $fieldParams['is_display_amounts'] = !empty($params['display_min_fee']) ? 1 : 0; $rowCount = 1; $options = array(); if (!empty($fieldParams['id'])) { CRM_Core_PseudoConstant::populate($options, 'CRM_Price_DAO_PriceFieldValue', TRUE, 'membership_type_id', NULL, " price_field_id = {$fieldParams['id']} "); } foreach ($membershipTypes as $memType => $memAutoRenew) { if ($priceFieldID = CRM_Utils_Array::key($memType, $options)) { $fieldParams['option_id'][$rowCount] = $priceFieldID; unset($options[$priceFieldID]); } $membetype = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($memType); $fieldParams['option_label'][$rowCount] = CRM_Utils_Array::value('name', $membetype); $fieldParams['option_amount'][$rowCount] = CRM_Utils_Array::value('minimum_fee', $membetype, 0); $fieldParams['option_weight'][$rowCount] = CRM_Utils_Array::value('weight', $membetype); $fieldParams['option_description'][$rowCount] = CRM_Utils_Array::value('description', $membetype); $fieldParams['default_option'] = CRM_Utils_Array::value('membership_type_default', $params); $fieldParams['option_financial_type_id'][$rowCount] = CRM_Utils_Array::value('financial_type_id', $membetype); $fieldParams['membership_type_id'][$rowCount] = $memType; // [$rowCount] = $membetype['']; $rowCount++; } foreach ($options as $priceFieldID => $memType) { CRM_Price_BAO_PriceFieldValue::setIsActive($priceFieldID, '0'); } $priceField = CRM_Price_BAO_PriceField::create($fieldParams); } elseif (!$priceSetID) { $deletePriceSet = 1; } $params['is_required'] = CRM_Utils_Array::value('is_required', $params, FALSE); $params['is_active'] = CRM_Utils_Array::value('member_is_active', $params, FALSE); if ($priceSetID) { $params['membership_types'] = 'null'; $params['membership_type_default'] = CRM_Utils_Array::value('membership_type_default', $params, 'null'); $params['membership_types'] = serialize($membershipTypes); $params['display_min_fee'] = CRM_Utils_Array::value('display_min_fee', $params, FALSE); $params['is_separate_payment'] = CRM_Utils_Array::value('is_separate_payment', $params, FALSE); } $params['entity_table'] = 'civicrm_contribution_page'; $params['entity_id'] = $this->_id; $dao = new CRM_Member_DAO_MembershipBlock(); $dao->copyValues($params); $dao->save(); if ($priceSetID && $params['is_active']) { CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $this->_id, $priceSetID); } if ($deletePriceSet || !CRM_Utils_Array::value('member_is_active', $params, FALSE)) { if ($this->_memPriceSetId) { $pFIDs = array(); $conditionParams = array('price_set_id' => $this->_memPriceSetId, 'html_type' => 'radio', 'name' => 'contribution_amount'); CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_PriceField', $conditionParams, $pFIDs); if (empty($pFIDs['id'])) { CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution_page', $this->_id); CRM_Price_BAO_PriceSet::setIsQuickConfig($this->_memPriceSetId, '0'); } else { CRM_Price_BAO_PriceField::setIsActive($params['mem_price_field_id'], '0'); } } } } parent::endPostProcess(); }
/** * Function to process the form * * @access public * * @return void */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { try { CRM_Member_BAO_MembershipStatus::del($this->_id); } catch (CRM_Core_Exception $e) { CRM_Core_Error::statusBounce($e->getMessage(), NULL, ts('Delete Failed')); } CRM_Core_Session::setStatus(ts('Selected membership status 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['membershipStatus'] = $this->_id; } $oldWeight = NULL; 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)), ts('Saved'), 'success'); } }
/** * Browse all custom data groups. * * * @return void * @access public * @static */ function browse() { // get all custom groups sorted by weight $membershipStatus = array(); require_once 'CRM/Member/DAO/MembershipStatus.php'; $dao =& new CRM_Member_DAO_MembershipStatus(); $dao->orderBy('weight'); $dao->find(); while ($dao->fetch()) { $membershipStatus[$dao->id] = array(); CRM_Core_DAO::storeValues($dao, $membershipStatus[$dao->id]); // form all action links $action = array_sum(array_keys($this->links())); // update enable/disable links depending on if it is is_reserved or is_active if (!$dao->is_reserved) { if ($dao->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } $membershipStatus[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id)); } $membershipStatus[$dao->id]['start_event'] = str_replace("_", " ", CRM_Utils_Array::value('start_event', $membershipStatus[$dao->id])); if (isset($membershipStatus[$dao->id]['end_event'])) { $membershipStatus[$dao->id]['end_event'] = str_replace("_", " ", CRM_Utils_Array::value('end_event', $membershipStatus[$dao->id])); } } // Add order changing widget to selector $returnURL = CRM_Utils_System::url('civicrm/admin/member/membershipStatus', "reset=1&action=browse"); require_once 'CRM/Utils/Weight.php'; CRM_Utils_Weight::addOrder($membershipStatus, 'CRM_Member_DAO_MembershipStatus', 'id', $returnURL); $this->assign('rows', $membershipStatus); }
/** * 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; }
/** * 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')); } } }
/** * 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'); } }
/** * 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); if ($this->_action == CRM_Core_Action::UPDATE) { $dataTypeKey = $this->_defaultDataType[0]; $params['data_type'] = self::$_dataTypeKeys[$this->_defaultDataType[0]]; $params['html_type'] = self::$_dataToHTML[$this->_defaultDataType[0]][$this->_defaultDataType[1]]; } else { $dataTypeKey = $params['data_type'][0]; $params['html_type'] = self::$_dataToHTML[$params['data_type'][0]][$params['data_type'][1]]; $params['data_type'] = self::$_dataTypeKeys[$params['data_type'][0]]; } //fix for 'is_search_range' field. if (in_array($dataTypeKey, array(1, 2, 3, 5))) { if (!CRM_Utils_Array::value('is_searchable', $params)) { $params['is_search_range'] = 0; } } else { $params['is_search_range'] = 0; } $filter = 'null'; if ($dataTypeKey == 11 && CRM_Utils_Array::value('filter_selected', $params)) { if ($params['filter_selected'] == 'Advance' && trim(CRM_Utils_Array::value('filter', $params))) { $filter = trim($params['filter']); } elseif ($params['filter_selected'] == 'Group' && CRM_Utils_Array::value('group_id', $params)) { $filter = 'action=lookup&group=' . implode(',', $params['group_id']); } } $params['filter'] = $filter; // fix for CRM-316 $oldWeight = NULL; if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) { $fieldValues = array('custom_group_id' => $this->_gid); if ($this->_id) { $oldWeight = $this->_values['weight']; } $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_CustomField', $oldWeight, $params['weight'], $fieldValues); } $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower'; //store the primary key for State/Province or Country as default value. if (strlen(trim($params['default_value']))) { switch ($params['data_type']) { case 'StateProvince': $fieldStateProvince = $strtolower($params['default_value']); $query = "\nSELECT id\n FROM civicrm_state_province\n WHERE LOWER(name) = '{$fieldStateProvince}'\n OR abbreviation = '{$fieldStateProvince}'"; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); if ($dao->fetch()) { $params['default_value'] = $dao->id; } break; case 'Country': $fieldCountry = $strtolower($params['default_value']); $query = "\nSELECT id\n FROM civicrm_country\n WHERE LOWER(name) = '{$fieldCountry}'\n OR iso_code = '{$fieldCountry}'"; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); if ($dao->fetch()) { $params['default_value'] = $dao->id; } break; } } // The text_length attribute for Memo fields is in a different input as there // are different label, help text and default value than for other type fields if ($params['data_type'] == "Memo") { $params['text_length'] = $params['note_length']; } // need the FKEY - custom group id $params['custom_group_id'] = $this->_gid; if ($this->_action & CRM_Core_Action::UPDATE) { $params['id'] = $this->_id; } $customField = CRM_Core_BAO_CustomField::create($params); // reset the cache CRM_Core_BAO_Cache::deleteGroup('contact fields'); CRM_Core_Session::setStatus(ts('Your custom field \'%1\' has been saved.', array(1 => $customField->label)), ts('Saved'), 'success'); $buttonName = $this->controller->getButtonName(); $session = CRM_Core_Session::singleton(); if ($buttonName == $this->getButtonName('next', 'new')) { CRM_Core_Session::setStatus(ts(' You can add another custom field.'), '', 'info'); $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field/add', 'reset=1&action=add&gid=' . $this->_gid)); } else { $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field', 'reset=1&action=browse&gid=' . $this->_gid)); } }
/** * 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; }
/** * Browse all price set fields. * * @param null * * @return void * @access public */ function browse() { $resourceManager = CRM_Core_Resources::singleton(); if (!empty($_GET['new']) && $resourceManager->ajaxPopupsEnabled) { $resourceManager->addScriptFile('civicrm', 'js/crm.addNew.js', 999); } $priceField = array(); $priceFieldBAO = new CRM_Price_BAO_PriceField(); // fkey is sid $priceFieldBAO->price_set_id = $this->_sid; $priceFieldBAO->orderBy('weight, label'); $priceFieldBAO->find(); while ($priceFieldBAO->fetch()) { $priceField[$priceFieldBAO->id] = array(); CRM_Core_DAO::storeValues($priceFieldBAO, $priceField[$priceFieldBAO->id]); // get price if it's a text field if ($priceFieldBAO->html_type == 'Text') { $optionValues = array(); $params = array('price_field_id' => $priceFieldBAO->id); CRM_Price_BAO_PriceFieldValue::retrieve($params, $optionValues); $priceField[$priceFieldBAO->id]['price'] = CRM_Utils_Array::value('amount', $optionValues); } $action = array_sum(array_keys($this->actionLinks())); if ($this->_isSetReserved) { $action -= CRM_Core_Action::UPDATE + CRM_Core_Action::DELETE + CRM_Core_Action::ENABLE + CRM_Core_Action::DISABLE; } else { if ($priceFieldBAO->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } } if ($priceFieldBAO->active_on == '0000-00-00 00:00:00') { $priceField[$priceFieldBAO->id]['active_on'] = ''; } if ($priceFieldBAO->expire_on == '0000-00-00 00:00:00') { $priceField[$priceFieldBAO->id]['expire_on'] = ''; } // need to translate html types from the db $htmlTypes = CRM_Price_BAO_PriceField::htmlTypes(); $priceField[$priceFieldBAO->id]['html_type_display'] = $htmlTypes[$priceField[$priceFieldBAO->id]['html_type']]; $priceField[$priceFieldBAO->id]['order'] = $priceField[$priceFieldBAO->id]['weight']; $priceField[$priceFieldBAO->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('fid' => $priceFieldBAO->id, 'sid' => $this->_sid), ts('more'), FALSE, 'priceField.row.actions', 'PriceField', $priceFieldBAO->id); } $returnURL = CRM_Utils_System::url('civicrm/admin/price/field', "reset=1&action=browse&sid={$this->_sid}"); $filter = "price_set_id = {$this->_sid}"; CRM_Utils_Weight::addOrder($priceField, 'CRM_Price_DAO_PriceField', 'id', $returnURL, $filter); $this->assign('priceField', $priceField); }
/** * Browse all membership types. * * * @return void * @access public * @static */ function browse() { // get all membership types sorted by weight $membershipType = array(); require_once 'CRM/Member/DAO/MembershipType.php'; $dao =& new CRM_Member_DAO_MembershipType(); $dao->orderBy('weight'); $dao->find(); require_once 'CRM/Utils/Money.php'; while ($dao->fetch()) { $membershipType[$dao->id] = array(); CRM_Core_DAO::storeValues($dao, $membershipType[$dao->id]); // fix the display of the monetary value, CRM-4038 if (CRM_Utils_Array::value('minimum_fee', $membershipType[$dao->id])) { $membershipType[$dao->id]['minimum_fee'] = CRM_Utils_Money::format($membershipType[$dao->id]['minimum_fee'], null, '%a'); } //adding column for relationship type label. CRM-4178. if ($dao->relationship_type_id) { $relationshipName = 'label_' . $dao->relationship_direction; $membershipType[$dao->id]['relationshipTypeName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $dao->relationship_type_id, $relationshipName); } // form all action links $action = array_sum(array_keys($this->links())); // update enable/disable links depending on if it is is_reserved or is_active if (!isset($dao->is_reserved)) { if ($dao->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } $membershipType[$dao->id]['order'] = $membershipType[$dao->id]['weight']; $membershipType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id)); } } $returnURL = CRM_Utils_System::url('civicrm/admin/member/membershipType', "reset=1&action=browse"); require_once 'CRM/Utils/Weight.php'; CRM_Utils_Weight::addOrder($membershipType, 'CRM_Member_DAO_MembershipType', 'id', $returnURL); CRM_Member_BAO_MembershipType::convertDayFormat($membershipType); $this->assign('rows', $membershipType); }
/** * 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(); }