function run() { CRM_Utils_System::setTitle(ts("Configuration Checklist")); $this->assign('recentlyViewed', FALSE); $destination = CRM_Utils_System::url('civicrm/admin/configtask', 'reset=1', FALSE, NULL, FALSE); $destination = urlencode($destination); $this->assign('destination', $destination); CRM_Core_OptionValue::getValues(array('name' => 'from_email_address'), $optionValue); if (!empty($optionValue)) { list($id) = array_keys($optionValue); $this->assign('fromEmailId', $id); } return parent::run(); }
function run() { CRM_Utils_System::setTitle(ts("Configuration Checklist")); $this->assign('recentlyViewed', FALSE); $destination = CRM_Utils_System::url('civicrm/admin/configtask', 'reset=1', FALSE, NULL, FALSE); $destination = urlencode($destination); $this->assign('destination', $destination); CRM_Core_OptionValue::getValues(array('name' => 'from_email_address'), $optionValue); if (!empty($optionValue)) { list($id) = array_keys($optionValue); $this->assign('fromEmailId', $id); } $payPalProId = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessorType', 'PayPal', 'id', 'name'); if ($payPalProId) { $this->assign('payPalProId', $payPalProId); } return parent::run(); }
static function &longForShortMapping() { static $longForShortMapping = null; if ($longForShortMapping === null) { $rows = array(); CRM_Core_OptionValue::getValues(array('name' => 'languages'), $rows); $longForShortMapping = array(); foreach ($rows as $row) { $longForShortMapping[$row['value']] = $row['name']; } // hand-crafted enforced overrides for language variants $longForShortMapping['zh'] = 'zh_CN'; $longForShortMapping['en'] = 'en_US'; $longForShortMapping['fr'] = 'fr_FR'; $longForShortMapping['pt'] = 'pt_PT'; $longForShortMapping['es'] = 'es_ES'; } return $longForShortMapping; }
/** * @return array */ public static function &longForShortMapping() { static $longForShortMapping = NULL; if ($longForShortMapping === NULL) { $rows = array(); CRM_Core_OptionValue::getValues(array('name' => 'languages'), $rows); $longForShortMapping = array(); foreach ($rows as $row) { $longForShortMapping[$row['value']] = $row['name']; } // hand-crafted enforced overrides for language variants // NB: when adding support for a regional override for a new language below, update // relevant comments in templates/CRM/common/civicrm.settings.php.template as well $longForShortMapping['zh'] = defined("CIVICRM_LANGUAGE_MAPPING_ZH") ? CIVICRM_LANGUAGE_MAPPING_ZH : 'zh_CN'; $longForShortMapping['en'] = defined("CIVICRM_LANGUAGE_MAPPING_EN") ? CIVICRM_LANGUAGE_MAPPING_EN : 'en_US'; $longForShortMapping['fr'] = defined("CIVICRM_LANGUAGE_MAPPING_FR") ? CIVICRM_LANGUAGE_MAPPING_FR : 'fr_FR'; $longForShortMapping['pt'] = defined("CIVICRM_LANGUAGE_MAPPING_PT") ? CIVICRM_LANGUAGE_MAPPING_PT : 'pt_PT'; $longForShortMapping['es'] = defined("CIVICRM_LANGUAGE_MAPPING_ES") ? CIVICRM_LANGUAGE_MAPPING_ES : 'es_ES'; } return $longForShortMapping; }
function run() { // get requested group status if (isset($_REQUEST['status'])) { if ($_REQUEST['status'] != 'open' && $_REQUEST['status'] != 'closed') { $status = 'open'; } else { $status = $_REQUEST['status']; } } else { $status = 'open'; } // add button URLs $this->assign("status", $status); $this->assign("show_closed_url", CRM_Utils_System::url('civicrm/sepa/dashboard', 'status=closed')); $this->assign("show_open_url", CRM_Utils_System::url('civicrm/sepa/dashboard', 'status=active')); $this->assign("batch_ooff", CRM_Utils_System::url('civicrm/sepa/dashboard', 'update=OOFF')); $this->assign("batch_recur", CRM_Utils_System::url('civicrm/sepa/dashboard', 'update=RCUR')); // check permissions $this->assign('can_delete', CRM_Core_Permission::check('administer CiviCRM')); if (isset($_REQUEST['update'])) { $this->callBatcher($_REQUEST['update']); } // generate status value list $status_2_title = array(); $status_list = array('open' => array(CRM_Core_OptionGroup::getValue('batch_status', 'Open', 'name'), CRM_Core_OptionGroup::getValue('batch_status', 'Reopened', 'name')), 'closed' => array(CRM_Core_OptionGroup::getValue('batch_status', 'Closed', 'name'), CRM_Core_OptionGroup::getValue('batch_status', 'Exported', 'name'), CRM_Core_OptionGroup::getValue('batch_status', 'Received', 'name'))); foreach ($status_list as $title => $values) { foreach ($values as $value) { if (empty($value)) { // delete empty values (i.e. batch_status doesn't exist) unset($status_list[$title][array_search($value, $status_list[$title])]); } else { $status_2_title[$value] = $title; } } } // generate group value list $status2label = array(); $status_values = array(); $status_group_selector = array('name' => 'batch_status'); CRM_Core_OptionValue::getValues($status_group_selector, $status_values); foreach ($status_values as $status_value) { $status2label[$status_value['value']] = $status_value['label']; } $this->assign('closed_status_id', CRM_Core_OptionGroup::getValue('batch_status', 'Closed', 'name')); // now read the details $result = civicrm_api("SepaTransactionGroup", "getdetail", array("version" => 3, "sequential" => 1, "status_ids" => implode(',', $status_list[$status]), "order_by" => $status == 'open' ? 'latest_submission_date' : 'file.created_date')); if (isset($result['is_error']) && $result['is_error']) { CRM_Core_Session::setStatus(sprintf(ts("Couldn't read transaction groups. Error was: '%s'"), $result['error_message']), ts('Error'), 'error'); } else { $groups = array(); foreach ($result["values"] as $id => $group) { // 'beautify' $group['latest_submission_date'] = date('Y-m-d', strtotime($group['latest_submission_date'])); $group['collection_date'] = date('Y-m-d', strtotime($group['collection_date'])); $group['status'] = $status_2_title[$group['status_id']]; $group['status_label'] = $status2label[$group['status_id']]; $remaining_days = (strtotime($group['latest_submission_date']) - strtotime("now")) / (60 * 60 * 24); if ($group['status'] == 'closed') { $group['submit'] = 'closed'; } else { if ($remaining_days <= -1) { $group['submit'] = 'missed'; } elseif ($remaining_days <= 1) { $group['submit'] = 'urgently'; } elseif ($remaining_days <= 6) { $group['submit'] = 'soon'; } else { $group['submit'] = 'later'; } } array_push($groups, $group); } $this->assign("groups", $groups); } parent::run(); }
/** * Get the list of types for objects that a custom group extends to. * * @param array $types * Var which should have the list appended. * * @return array * Array of types. */ public static function getExtendedObjectTypes(&$types = array()) { static $flag = FALSE, $objTypes = array(); if (!$flag) { $extendObjs = array(); CRM_Core_OptionValue::getValues(array('name' => 'cg_extend_objects'), $extendObjs); foreach ($extendObjs as $ovId => $ovValues) { if ($ovValues['description']) { // description is expected to be a callback func to subtypes list($callback, $args) = explode(';', trim($ovValues['description'])); if (empty($args)) { $args = array(); } if (!is_array($args)) { CRM_Core_Error::fatal('Arg is not of type array'); } list($className) = explode('::', $callback); require_once str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; $objTypes[$ovValues['value']] = call_user_func_array($callback, $args); } } $flag = TRUE; } $types = array_merge($types, $objTypes); return $objTypes; }
public static function loadOptionGroupDetails() { $id = CRM_Utils_Request::retrieve('option_group_id', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST'); $status = 'fail'; $opValues = array(); if ($id) { $groupParams['id'] = $id; CRM_Core_OptionValue::getValues($groupParams, $opValues); } $surveyId = CRM_Utils_Request::retrieve('survey_id', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST'); if ($surveyId) { $survey = new CRM_Campaign_DAO_Survey(); $survey->id = $surveyId; $survey->result_id = $id; if ($survey->find(TRUE)) { if ($survey->recontact_interval) { $recontactInterval = unserialize($survey->recontact_interval); foreach ($opValues as $opValId => $opVal) { if (is_numeric($recontactInterval[$opVal['label']])) { $opValues[$opValId]['interval'] = $recontactInterval[$opVal['label']]; } } } } } if (!empty($opValues)) { $status = 'success'; } $result = array('status' => $status, 'result' => $opValues); CRM_Utils_JSON::output($result); }
/** * @param $entityTable */ public static function preProcess($entityTable) { self::$_entityId = (int) CRM_Utils_Request::retrieve('id', 'Positive'); self::$_entityTable = $entityTable; if (self::$_entityId && $entityTable) { $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor(self::$_entityId, $entityTable); if ($checkParentExistsForThisId) { self::$_hasParent = TRUE; self::$_parentEntityId = $checkParentExistsForThisId; self::$_scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId($checkParentExistsForThisId, $entityTable); } else { self::$_parentEntityId = self::$_entityId; self::$_scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId(self::$_entityId, $entityTable); } if (property_exists(self::$_scheduleReminderDetails, 'id')) { self::$_scheduleReminderID = self::$_scheduleReminderDetails->id; } } CRM_Core_OptionValue::getValues(array('name' => $entityTable . '_repeat_exclude_dates_' . self::$_parentEntityId), $optionValue); $excludeOptionValues = array(); if (!empty($optionValue)) { foreach ($optionValue as $key => $val) { $excludeOptionValues[$val['value']] = substr(CRM_Utils_Date::mysqlToIso($val['value']), 0, 10); } self::$_excludeDateInfo = $excludeOptionValues; } // Assign variables $entityType = CRM_Core_DAO_AllCoreTables::getBriefName(CRM_Core_DAO_AllCoreTables::getClassForTable($entityTable)); $tpl = CRM_Core_Smarty::singleton(); $tpl->assign('recurringEntityType', ts($entityType)); $tpl->assign('currentEntityId', self::$_entityId); $tpl->assign('entityTable', self::$_entityTable); $tpl->assign('scheduleReminderId', self::$_scheduleReminderID); $tpl->assign('hasParent', self::$_hasParent); }
function setDefaultValues() { require_once 'CRM/Core/BAO/Domain.php'; $defaults = array(); $params = array(); $locParams = array(); if (isset($this->_id)) { $params['id'] = $this->_id; CRM_Core_BAO_Domain::retrieve($params, $domainDefaults); //get the default domain from email address. fix CRM-3552 require_once 'CRM/Utils/Mail.php'; require_once 'CRM/Core/OptionValue.php'; $optionValues = array(); $grpParams['name'] = 'from_email_address'; CRM_Core_OptionValue::getValues($grpParams, $optionValues); foreach ($optionValues as $Id => $value) { if ($value['is_default'] && $value['is_active']) { $this->_fromEmailId = $Id; $domainDefaults['email_name'] = CRM_Utils_Array::value(1, explode('"', $value['label'])); $domainDefaults['email_address'] = CRM_Utils_Mail::pluckEmailFromHeader($value['label']); break; } } unset($params['id']); $locParams = $params + array('entity_id' => $this->_id, 'entity_table' => 'civicrm_domain'); require_once 'CRM/Core/BAO/Location.php'; $defaults = CRM_Core_BAO_Location::getValues($locParams); $config = CRM_Core_Config::singleton(); if (!isset($defaults['address'][1]['country_id'])) { $defaults['address'][1]['country_id'] = $config->defaultContactCountry; } if (!empty($defaults['address'])) { foreach ($defaults['address'] as $key => $value) { CRM_Contact_Form_Edit_Address::fixStateSelect($this, "address[{$key}][country_id]", "address[{$key}][state_province_id]", CRM_Utils_Array::value('country_id', $value, $config->defaultContactCountry)); } } } $defaults = array_merge($defaults, $domainDefaults); return $defaults; }
/** * This function preserve the civicrm_domain.email_name and civicrm_domain.email_address * as a default option value into "from_email_address" option group * and drop these columns from civicrm_domain table. * @access public * * @return void */ function upgradeDomainFromEmail() { $query = "\nSELECT id\n FROM civicrm_option_group\n WHERE name = 'from_Email_address'"; $fmaGroup = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); $fmaGroupId = NULL; if ($fmaGroup->fetch()) { $fmaGroupId = $fmaGroup->id; } else { //insert 'from_mailing_address' option group. $query = "\nINSERT INTO civicrm_option_group ( name, description, is_reserved, is_active )\nVALUES ('from_email_address', 'From Email Address', 0, 1)"; CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); //get the group id. $query = "\nSELECT id\n FROM civicrm_option_group\n WHERE name = 'from_email_address'"; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); if ($dao->fetch()) { $fmaGroupId = $dao->id; } } if ($fmaGroupId) { //get domain from email address and name as default value. $domain = CRM_Core_BAO_Domain::getDomain(); $domain->selectAdd(); $domain->selectAdd('email_name', 'email_address'); $domain->find(TRUE); $formEmailAddress = '"' . $domain->email_name . '"<' . $domain->email_address . '>'; //first check given domain email address exist in option //value, if yes make it as domain email address by making //it as default from email address.. //get the existing from email address. $optionValues = array(); $grpParams['name'] = 'from_email_address'; CRM_Core_OptionValue::getValues($grpParams, $optionValues); $maxVal = $maxWt = 1; $insertEmailAddress = TRUE; if (!empty($optionValues)) { //make existing is_default = 0 $query = "\nUPDATE civicrm_option_value\n SET is_default = 0\n WHERE option_group_id = %1"; $params = array(1 => array($fmaGroupId, 'Integer')); CRM_Core_DAO::executeQuery($query, $params); //if domain from name and email exist as name or label in option value //table need to preserve that name and label and take care that label //and name both remain unique in db. $labelValues = $nameValues = array(); foreach ($optionValues as $id => $value) { if ($value['label'] == $formEmailAddress) { $labelValues = $value; } elseif ($value['name'] == $formEmailAddress) { $nameValues = $value; } } //as we consider label so label should preserve. $updateValues = array(); if (!empty($labelValues)) { $updateValues = $labelValues; } //if matching name found need to preserve it. if (!empty($nameValues)) { //copy domain from email address as label. if (empty($updateValues)) { $updateValues = $nameValues; $updateValues['label'] = $formEmailAddress; } else { //since name is also imp so preserve it //as name for domain email address record. $updateValues['name'] = $nameValues['name']; //name is unique so drop name value record. //since we transfer this name to found label record. CRM_Core_BAO_OptionValue::del($nameValues['id']); } } if (!empty($updateValues)) { $insertEmailAddress = FALSE; //update label/name found record w/ manupulated values. $updateValues['is_active'] = $updateValues['is_default'] = 1; $optionValue = new CRM_Core_DAO_OptionValue(); $optionValue->copyValues($updateValues); $optionValue->save(); } //get the max value and wt. if ($insertEmailAddress) { $query = "\nSELECT max(ROUND(civicrm_option_value.value)) as maxVal,\n max(civicrm_option_value.weight) as maxWt\n FROM civicrm_option_value, civicrm_option_group\n WHERE civicrm_option_group.name = 'from_Email_address'\n AND civicrm_option_value.option_group_id = civicrm_option_group.id\nGROUP BY civicrm_option_group.id"; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); if ($dao->fetch()) { $maxWt += $dao->maxWt; $maxVal += $dao->maxVal; } } } if ($insertEmailAddress) { //insert domain from email address and name. $query = "\nINSERT INTO `civicrm_option_value`\n (`option_group_id`, `label`, `value`, `name` , `grouping`, `filter`, `is_default`,\n `weight`, `description`, `is_optgroup`, `is_reserved`, `is_active`, `component_id`)\n VALUES ( %1, %2, %3, %2, NULL, 0, 1, %4, 'Default domain email address and from name.', 0, 0, 1, NULL)"; $params = array(1 => array($fmaGroupId, 'Integer'), 2 => array($formEmailAddress, 'String'), 3 => array($maxVal, 'Integer'), 4 => array($maxWt, 'Integer')); CRM_Core_DAO::executeQuery($query, $params); } //drop civicrm_domain.email_name and //civicrm_domain.email_address. $query = "\nALTER TABLE `civicrm_domain`\n DROP `email_name`,\n DROP `email_address`"; CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); } }
/** * This virtual function is used to set the default values of. * various form elements * * @return array * reference to the array of default values * */ public function setDefaultValues() { $defaults = array(); $params = array(); if (isset($this->_id)) { $params['id'] = $this->_id; CRM_Core_BAO_Domain::retrieve($params, $domainDefaults); $this->_contactId = $domainDefaults['contact_id']; //get the default domain from email address. fix CRM-3552 $optionValues = array(); $grpParams['name'] = 'from_email_address'; CRM_Core_OptionValue::getValues($grpParams, $optionValues); foreach ($optionValues as $Id => $value) { if ($value['is_default'] && $value['is_active']) { $this->_fromEmailId = $Id; $list = explode('"', $value['label']); $domainDefaults['email_name'] = CRM_Utils_Array::value(1, $list); $domainDefaults['email_address'] = CRM_Utils_Mail::pluckEmailFromHeader($value['label']); break; } } unset($params['id']); $locParams = array('contact_id' => $domainDefaults['contact_id']); $this->_locationDefaults = $defaults = CRM_Core_BAO_Location::getValues($locParams); $config = CRM_Core_Config::singleton(); if (!isset($defaults['address'][1]['country_id'])) { $defaults['address'][1]['country_id'] = $config->defaultContactCountry; } if (!isset($defaults['address'][1]['state_province_id'])) { $defaults['address'][1]['state_province_id'] = $config->defaultContactStateProvince; } } $defaults = array_merge($defaults, $domainDefaults); return $defaults; }
static function loadOptionGroupDetails() { $id = CRM_Utils_Array::value('option_group_id', $_POST); $status = 'fail'; $opValues = array(); if ($id) { $groupParams['id'] = $id; CRM_Core_OptionValue::getValues($groupParams, $opValues); } $surveyId = CRM_Utils_Array::value('survey_id', $_POST); if ($surveyId) { $survey = new CRM_Campaign_DAO_Survey(); $survey->id = $surveyId; $survey->result_id = $id; if ($survey->find(TRUE)) { if ($survey->recontact_interval) { $recontactInterval = unserialize($survey->recontact_interval); foreach ($opValues as $opValId => $opVal) { if (is_numeric($recontactInterval[$opVal['label']])) { $opValues[$opValId]['interval'] = $recontactInterval[$opVal['label']]; } } } } } if (!empty($opValues)) { $status = 'success'; } $result = array('status' => $status, 'result' => $opValues); echo json_encode($result); CRM_Utils_System::civiExit(); }
/** * Will store the donor's account data * * @todo move to post processors */ function storeAccountWithContact($btx, $contact_id) { // find all reference types $reference_type_group = array('name' => 'civicrm_banking.reference_types'); $reference_types = array(); CRM_Core_OptionValue::getValues($reference_type_group, $reference_types); // gather the information $data = $btx->getDataParsed(); $references = array(); foreach ($reference_types as $reference_type) { $field_name = '_party_' . $reference_type['name']; if (!empty($data[$field_name])) { $references[$reference_type['id']] = $data[$field_name]; } } // if we don't have references, there's nothing we can do... if (empty($references)) { return; } // gather account info $account_info = array(); if (!empty($data['_party_BIC'])) { $account_info['BIC'] = $data['_party_BIC']; } if (!empty($data['_party_IBAN'])) { $account_info['country'] = substr($data['_party_IBAN'], 0, 2); } // copy all entries that start with _party_ba_ into the account info foreach ($data as $key => $value) { if ('_party_ba_' == substr($key, 0, 10)) { if (!empty($value)) { $new_key = substr($key, 10); $account_info[$new_key] = $value; } } } // find all referenced bank accounts $bank_accounts = array(); $contact_bank_account_id = NULL; $contact_bank_account_created = false; $reference2instances = array(); foreach ($references as $reference_type => $reference) { $reference2instances[$reference] = array(); $query = array('version' => 3, 'reference' => $reference, 'reference_type_id' => $reference_type); $existing = civicrm_api('BankingAccountReference', 'get', $query); if (empty($existing['is_error'])) { foreach ($existing['values'] as $account_reference) { array_push($reference2instances[$reference], $account_reference); if (!isset($bank_accounts[$account_reference['ba_id']])) { // load the bank account $ba_bao = new CRM_Banking_BAO_BankAccount(); $ba_bao->get('id', $account_reference['ba_id']); $bank_accounts[$account_reference['ba_id']] = $ba_bao; } // consider this bank account to be ours if the contact id matches if (!$contact_bank_account_id && $ba_bao->contact_id == $contact_id) { $contact_bank_account_id = $ba_bao->id; } } } } // create new account if it does not yet exist if (!$contact_bank_account_id) { $ba_bao = new CRM_Banking_BAO_BankAccount(); $ba_bao->contact_id = $contact_id; $ba_bao->description = ts("created by CiviBanking"); $ba_bao->created_date = date('YmdHis'); $ba_bao->modified_date = date('YmdHis'); $ba_bao->data_raw = NULL; $ba_bao->data_parsed = "{}"; $ba_bao->save(); $contact_bank_account_id = $ba_bao->id; $bank_accounts[$contact_bank_account_id] = $ba_bao; $contact_bank_account_created = true; } // update bank account data $ba_bao = $bank_accounts[$contact_bank_account_id]; $ba_data = $ba_bao->getDataParsed(); foreach ($account_info as $key => $value) { $ba_data[$key] = $value; } $ba_bao->setDataParsed($ba_data); $ba_bao->save(); // create references (warn if exists for another contact) foreach ($references as $reference_type => $reference) { // check the existing $reference_already_there = false; foreach ($reference2instances[$reference] as $reference_instance) { if ($reference_instance['ba_id'] == $contact_bank_account_id) { // there is already a reference for 'our' bank account $reference_already_there = true; break; } } if (!$reference_already_there) { // there was no reference to 'our' bank account -> create! $query = array('version' => 3, 'reference' => $reference, 'reference_type_id' => $reference_type, 'ba_id' => $contact_bank_account_id); $result = civicrm_api('BankingAccountReference', 'create', $query); if (!empty($result['is_error'])) { CRM_Core_Session::setStatus(ts("Couldn't create reference. Error was: '%1'", array(1 => $result['error_message'])), ts('Error'), 'alert'); } } } // finally, create some feedback if ($contact_bank_account_created) { if (count($bank_accounts) > 1) { // there are mutiple acccounts referenced by this $message = ts("The account information of this contact was saved, but it is also used by the following contacts:<br/><ul>%s</ul>"); $contacts = ""; foreach ($bank_accounts as $ba_id => $ba_bao) { if ($ba_id == $contact_bank_account_id) { continue; } $contact = civicrm_api('Contact', 'getsingle', array('version' => 3, 'id' => $ba_bao->contact_id)); if (empty($contact['is_error'])) { $url = CRM_Utils_System::url('civicrm/contact/view', 'cid=' . $ba_bao->contact_id); $contacts .= "<li><a href='{$url}'>" . $contact['display_name'] . "</a></li>"; } } CRM_Core_Session::setStatus(sprintf($message, $contacts), ts('Warning'), 'warn'); } else { CRM_Core_Session::setStatus(ts("The account information of this contact was saved."), ts('Account saved'), 'info'); } } }
/** * Browse all price set fields. * * @param null * * @return void * @access public */ function browse() { require_once 'CRM/Price/BAO/Field.php'; $priceField = array(); $priceFieldBAO =& new CRM_Price_BAO_Field(); // 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('name' => "civicrm_price_field.amount.{$priceFieldBAO->id}"); require_once 'CRM/Core/OptionValue.php'; CRM_Core_OptionValue::getValues($params, $optionValues); $priceField[$priceFieldBAO->id]['price'] = CRM_Utils_Array::value('value', array_pop($optionValues)); } $action = array_sum(array_keys($this->actionLinks())); 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 require_once 'CRM/Price/BAO/Field.php'; $htmlTypes = CRM_Price_BAO_Field::htmlTypes(); $priceField[$priceFieldBAO->id]['html_type'] = $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)); } $returnURL = CRM_Utils_System::url('civicrm/admin/price/field', "reset=1&action=browse&sid={$this->_sid}"); $filter = "price_set_id = {$this->_sid}"; require_once 'CRM/Utils/Weight.php'; CRM_Utils_Weight::addOrder($priceField, 'CRM_Price_DAO_Field', 'id', $returnURL, $filter); $this->assign('priceField', $priceField); }
/** * Browse all price fields. * * @param null * * @return void * @access public */ function browse() { $customOption = array(); $groupParams = array('name' => "civicrm_price_field.amount.{$this->_fid}"); require_once 'CRM/Core/OptionValue.php'; CRM_Core_OptionValue::getValues($groupParams, $customOption); $config =& CRM_Core_Config::singleton(); foreach ($customOption as $id => $values) { $action = array_sum(array_keys($this->actionLinks())); // update enable/disable links depending on price_field properties. 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 = "option_group_id = (SELECT id FROM civicrm_option_group WHERE name = 'civicrm_price_field.amount.{$this->_fid}')"; require_once 'CRM/Utils/Weight.php'; CRM_Utils_Weight::addOrder($customOption, 'CRM_Core_DAO_OptionValue', 'id', $returnURL, $filter); $this->assign('customOption', $customOption); }
/** * global form rule * * @param array $fields the input form values * @param array $files the uploaded files if any * @param array $self this object. * * @return true if no errors, else an array of errors * @access public * @static */ static function formRule($fields, $files, $self) { $errors = array(); //don't allow duplicate value within group. $optionValues = array(); require_once 'CRM/Core/OptionValue.php'; CRM_Core_OptionValue::getValues(array('id' => $self->_gid), $optionValues); foreach ($optionValues as $values) { if ($values['id'] != $self->_id) { if ($fields['value'] == $values['value']) { $errors['value'] = ts('Value already exist in database.'); break; } } } return empty($errors) ? true : $errors; }
/** * Retrieve a list of options for the specified field * * @param int $fieldId price field ID * @param bool $inactiveNeeded include inactive options * @param bool $reset ignore stored values\ * * @return array array of options */ public static function getOptions($fieldId, $inactiveNeeded = false, $reset = false) { static $options = array(); if ($reset || empty($options[$fieldId])) { $groupParams = array('name' => "civicrm_price_field.amount.{$fieldId}"); $values = array(); require_once 'CRM/Core/OptionValue.php'; CRM_Core_OptionValue::getValues($groupParams, $values, 'weight', !$inactiveNeeded); } return $values; }