function run() { $countries = CRM_Bic_Parser_Parser::getParserList(); $stats = civicrm_api3('Bic', 'stats'); $total_count = 0; foreach ($countries as $country) { if (isset($stats['values'][$country])) { $total_count += $stats['values'][$country]; } else { $stats['values'][$country] = 0; } } // gather the names $country_names = array(); $config = CRM_Core_Config::singleton(); $id2code = CRM_Core_PseudoConstant::countryIsoCode(); $default_country = $id2code[$config->defaultContactCountry]; $code2id = array_flip($id2code); $id2country = CRM_Core_PseudoConstant::country(FALSE, FALSE); foreach ($countries as $code) { $country_id = $code2id[$code]; $country_name = $id2country[$country_id]; $country_names[$code] = $country_name; } $this->assign('countries', $countries); $this->assign('country_names', $country_names); $this->assign('default_country', $default_country); $this->assign('stats', $stats['values']); $this->assign('total_count', $total_count); parent::run(); }
function __construct() { $this->_exposeContactID = $this->_emailField = FALSE; $this->_customGroupJoin = 'LEFT JOIN'; $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('sort_name' => array('title' => ts('Name'), 'required' => TRUE), 'id' => array('no_display' => TRUE, 'required' => TRUE), 'gender' => array()), 'filters' => array('sort_name' => array('title' => ts('Name'), 'operator' => 'like'), 'id' => array('title' => ts('Contact ID'), 'no_display' => TRUE, 'type' => CRM_Utils_Type::T_INT), 'gender' => array()), 'order_bys' => array('sort_name' => array('title' => ts('Last Name, First Name'), 'default' => '1', 'default_weight' => '0', 'default_order' => 'ASC'), 'id' => array('title' => ts('Contact ID'), 'default' => '1', 'default_weight' => '1', 'default_order' => 'ASC')), 'grouping' => array('contact-fields' => ts('Personal Details'))), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email' => array('default' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => array('no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_address' => array('dao' => 'CRM_Core_DAO_Address', 'fields' => array('city' => array('title' => ts('Work City')), 'postal_code' => array('title' => ts('Work Postal Code')), 'state_province_id' => array('title' => ts('Work State/Province')), 'country_id' => array('title' => ts('Work Country'))), 'filters' => array('city' => array('title' => ts('Work City')), 'postal_code' => array('title' => ts('Work Postal Code')), 'state_province_id' => array('title' => ts('Work State/Province'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::stateProvince()), 'country_id' => array('title' => ts('Work Country'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::country())), 'grouping' => 'contact-fields'), 'civicrm_group' => array('dao' => 'CRM_Contact_DAO_GroupContact', 'alias' => 'cgroup', 'filters' => array('gid' => array('name' => 'group_id', 'title' => ts('Group'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'group' => TRUE, 'options' => CRM_Core_PseudoConstant::group(), 'type' => CRM_Utils_Type::T_INT))), 'civicrm_hrjobcontract' => array('dao' => 'CRM_Hrjobcontract_DAO_HRJobContract', 'fields' => array('is_primary' => array('title' => ts('Job Is Primary?'), 'no_repeat' => TRUE, 'dbAlias' => 'hrjobcontract_civireport.is_primary')), 'filters' => array('is_primary' => array('title' => ts('Job Is Primary?'), 'default' => 1, 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_SELECT, 'options' => array('' => ts('Any'), '0' => ts('No'), '1' => ts('Yes'))), 'current_employee' => array('default' => NULL, 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_SELECT, 'options' => array('' => ts('ANY'), '0' => ts('No'), '1' => ts('Yes')), 'no_display' => TRUE)), 'grouping' => array('job-fields' => 'Job')), 'civicrm_hrjobcontract_revision' => array('dao' => 'CRM_Hrjobcontract_DAO_HRJobContractRevision', 'fields' => array('jobcontract_revision_id' => array('title' => ts('Revision ID'), 'no_repeat' => TRUE, 'name' => 'id', 'no_display' => TRUE), 'editor_uid' => array('title' => ts('Editor UID'), 'no_repeat' => TRUE, 'name' => 'editor_uid', 'no_display' => TRUE), 'created_date' => array('title' => ts('Created date'), 'no_repeat' => TRUE, 'name' => 'created_date', 'no_display' => TRUE), 'modified_date' => array('title' => ts('Modified date'), 'no_repeat' => TRUE, 'name' => 'modified_date', 'no_display' => TRUE), 'effective_date' => array('title' => ts('Effective date'), 'no_repeat' => TRUE, 'name' => 'effective_date', 'no_display' => TRUE), 'change_reason' => array('title' => ts('Change reason'), 'no_repeat' => TRUE, 'name' => 'change_reason', 'no_display' => TRUE), 'status' => array('title' => ts('Revision status'), 'no_repeat' => TRUE, 'name' => 'status', 'no_display' => TRUE)), 'grouping' => array('job-fields' => 'Job'), 'order_bys' => array('civicrm_hrjobcontract_revision_revision_id' => array('title' => ts('Revision Id'), 'dbAlias' => 'hrjobcontract_revision_civireport.id')), 'group_bys' => array('civicrm_hrjobcontract_revision_revision_id' => array('title' => ts('Revision Id'), 'dbAlias' => 'hrjobcontract_revision_civireport.id'))), 'civicrm_hrjobcontract_details' => array('dao' => 'CRM_Hrjobcontract_DAO_HRJobDetails', 'fields' => array('hrjobcontract_details_title' => array(), 'hrjobcontract_details_contract_type' => array(), 'hrjobcontract_details_location' => array(), 'hrjobcontract_details_position' => array(), 'hrjobcontract_details_period_start_date' => array(), 'hrjobcontract_details_period_end_date' => array()), 'filters' => array('hrjobcontract_details_title' => array(), 'hrjobcontract_details_contract_type' => array(), 'hrjobcontract_details_location' => array(), 'hrjobcontract_details_position' => array(), 'hrjobcontract_details_period_start_date' => array(), 'hrjobcontract_details_period_end_date' => array()), 'grouping' => array('job-fields' => 'Job')), 'civicrm_hrjobcontract_health' => array('dao' => 'CRM_Hrjobcontract_DAO_HRJobHealth', 'fields' => array('hrjobcontract_health_health_provider_life_insurance' => array(), 'hrjobcontract_health_life_insurance_plan_type' => array(), 'hrjobcontract_health_health_provider' => array(), 'hrjobcontract_health_health_plan_type' => array()), 'filters' => array('hrjobcontract_health_life_insurance_plan_type' => array(), 'hrjobcontract_health_health_plan_type' => array()), 'grouping' => array('job-fields' => 'Job')), 'civicrm_hrjobcontract_health_provider' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('organization_name' => array('title' => ts('Job Healthcare Provider'), 'no_repeat' => TRUE, 'no_display' => TRUE, 'required' => TRUE), 'id' => array('no_display' => TRUE, 'required' => TRUE)), 'filters' => array('organization_name' => array('title' => ts('Job Healthcare Provider'), 'operatorType' => CRM_Report_Form::OP_STRING))), 'civicrm_hrjobcontract_health_life_provider' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('display_name' => array('title' => ts('Job life insurance Provider'), 'no_repeat' => TRUE, 'no_display' => TRUE, 'required' => TRUE), 'id' => array('no_display' => TRUE, 'required' => TRUE)), 'filters' => array('display_name' => array('title' => ts('Job life insurance Provider'), 'operatorType' => CRM_Report_Form::OP_STRING))), 'civicrm_hrjobcontract_hour' => array('dao' => 'CRM_Hrjobcontract_DAO_HRJobHour', 'fields' => array('hrjobcontract_hour_hours_type' => array(), 'hrjobcontract_hour_hours_amount' => array(), 'hrjobcontract_hour_hours_unit' => array(), 'hrjobcontract_hour_hours_fte' => array()), 'filters' => array('hrjobcontract_hour_hours_type' => array(), 'hrjobcontract_hour_hours_amount' => array(), 'hrjobcontract_hour_hours_unit' => array(), 'hrjobcontract_hour_hours_fte' => array()), 'grouping' => array('job-fields' => 'Job')), 'civicrm_hrjobcontract_pay' => array('dao' => 'CRM_Hrjobcontract_DAO_HRJobPay', 'fields' => array('hrjobcontract_pay_is_paid' => array(), 'hrjobcontract_pay_pay_amount' => array(), 'hrjobcontract_pay_pay_unit' => array(), 'hrjobcontract_pay_pay_currency' => array(), 'hrjobcontract_pay_pay_annualized_est' => array()), 'filters' => array('hrjobcontract_pay_is_paid' => array(), 'hrjobcontract_pay_pay_amount' => array(), 'hrjobcontract_pay_pay_unit' => array(), 'hrjobcontract_pay_pay_annualized_est' => array()), 'grouping' => array('job-fields' => 'Job')), 'civicrm_hrjobcontract_pension' => array('dao' => 'CRM_Hrjobcontract_DAO_HRJobPension', 'fields' => array('hrjobcontract_pension_is_enrolled' => array()), 'filters' => array('hrjobcontract_pension_is_enrolled' => array()), 'grouping' => array('job-fields' => 'Job')), 'civicrm_hrjobcontract_role' => array('dao' => 'CRM_Hrjobcontract_DAO_HRJobRole', 'fields' => array('hrjobcontract_role_role_department' => array(), 'hrjobcontract_role_role_level_type' => array('name' => 'level_type', 'title' => ts('Role Level Types'), 'type' => CRM_Utils_Type::T_INT, 'grouping' => array('job-fields' => 'Job')), 'manager' => array('name' => 'manager_sort_name', 'title' => ts('Role Managers'), 'dbAlias' => 'manager.sort_name'), 'hrjob_role_manager_contact_id' => array('no_display' => TRUE, 'name' => 'manager_contact_id', 'title' => ts('Role Managers'), 'type' => CRM_Utils_Type::T_INT, 'grouping' => array('job-fields' => 'Job'))), 'filters' => array('hrjobcontract_role_role_department' => array(), 'hrjobcontract_role_role_level_type' => array()), 'grouping' => array('job-fields' => 'Job'))) + $this->addAddressFields(FALSE, TRUE); parent::__construct(); }
function run() { // Prepares variables for being sent to Smarty //Only show countries with attached information $countries = null; $stats = civicrm_api3('Bic', 'stats'); foreach ($stats['values'] as $country => $count) { $countries[] = $country; } // Get country names $country_names = null; if ($countries) { $config = CRM_Core_Config::singleton(); $country_names = array(); $id2code = CRM_Core_PseudoConstant::countryIsoCode(); $default_country = $id2code[$config->defaultContactCountry]; $code2id = array_flip($id2code); $id2country = CRM_Core_PseudoConstant::country(false, false); foreach ($countries as $code) { $country_id = $code2id[$code]; $country_name = $id2country[$country_id]; $country_names[$code] = $country_name; } } // Sends variables to Smarty $this->assign('countries', $countries); $this->assign('country_names', $country_names); $this->assign('default_country', $default_country); $this->assign('show_message', true); parent::run(); }
function __construct() { $this->_autoIncludeIndexedFieldsAsOrderBys = 1; $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('sort_name' => array('title' => ts('Contact Name'), 'required' => TRUE, 'no_repeat' => TRUE), 'first_name' => array('title' => ts('First Name')), 'last_name' => array('title' => ts('Last Name')), 'id' => array('no_display' => TRUE, 'required' => TRUE), 'contact_type' => array('title' => ts('Contact Type')), 'contact_sub_type' => array('title' => ts('Contact SubType')), 'birth_date' => array('title' => ts('Birth Date'))), 'filters' => array('sort_name' => array('title' => ts('Contact Name')), 'source' => array('title' => ts('Contact Source'), 'type' => CRM_Utils_Type::T_STRING), 'id' => array('title' => ts('Contact ID'), 'no_display' => TRUE), 'birth_date' => array('title' => ts('Birth Date'), 'operatorType' => CRM_Report_Form::OP_DATE)), 'grouping' => 'contact-fields', 'order_bys' => array('sort_name' => array('title' => ts('Last Name, First Name'), 'default' => '1', 'default_weight' => '0', 'default_order' => 'ASC'))), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email' => array('title' => ts('Email'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields', 'order_bys' => array('email' => array('title' => ts('Email')))), 'civicrm_address' => array('dao' => 'CRM_Core_DAO_Address', 'grouping' => 'contact-fields', 'fields' => array('street_address' => array('default' => TRUE), 'city' => array('default' => TRUE), 'postal_code' => NULL, 'state_province_id' => array('title' => ts('State/Province'))), 'filters' => array('country_id' => array('title' => ts('Country'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::country()), 'state_province_id' => array('title' => ts('State / Province'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::stateProvince())), 'order_bys' => array('state_province_id' => array('title' => 'State/Province'), 'city' => array('title' => 'City'), 'postal_code' => array('title' => 'Postal Code'))), 'civicrm_country' => array('dao' => 'CRM_Core_DAO_Country', 'fields' => array('name' => array('title' => 'Country', 'default' => TRUE)), 'order_bys' => array('name' => array('title' => 'Country')), 'grouping' => 'contact-fields'), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => NULL, 'phone_ext' => array('title' => ts('Phone Extension'))), 'grouping' => 'contact-fields'), 'civicrm_group' => array('dao' => 'CRM_Contact_DAO_Group', 'alias' => 'cgroup', 'filters' => array('gid' => array('name' => 'group_id', 'title' => ts('Group'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'group' => TRUE, 'options' => CRM_Core_PseudoConstant::group())))); $this->_tagFilter = TRUE; parent::__construct(); }
public function run() { CRM_Utils_System::setTitle(ts('Household Finder')); // determine result count if (!empty($_REQUEST['count'])) { if ($_REQUEST['count'] == 'all') { $result_count = 'all'; } else { $result_count = (int) $_REQUEST['count']; if ($result_count <= 0) { $result_count = 25; } } } else { $result_count = 25; } // first run the scanner $scanner = new CRM_Householdmerge_Logic_Scanner(); $proposals = $scanner->findNewHouseholds($result_count); // set the country names $countries = CRM_Core_PseudoConstant::country(); foreach ($proposals as $pid => $proposal) { foreach ($proposal['contacts'] as $contact_id => $contact) { if (!empty($contact['country_id'])) { $proposals[$pid]['contacts'][$contact_id]['country'] = $countries[$contact['country_id']]; } } } $this->assign('proposals', $proposals); $this->assign('proposals_json', json_encode($proposals)); $this->assign('result_count', $result_count); parent::run(); }
function civicrm_pseudoconstant_country($params) { $countries = CRM_Core_PseudoConstant::country(); $return = array('countries' => $countries); return $return; }
function buildQuickForm() { $contact_id = 0; $bank_accounts = array(); if (isset($_REQUEST['cid'])) { $contact_id = (int) $_REQUEST['cid']; $bank_account = new CRM_Banking_BAO_BankAccount(); $bank_account->contact_id = $contact_id; $bank_account->find(); while ($bank_account->fetch()) { $bank_account_data = $bank_account->toArray(); $bank_account_data['references'] = $bank_account->getReferences(); $bank_account_data['data_parsed'] = json_decode($bank_account->data_parsed, true); $bank_accounts[$bank_account->id] = $bank_account_data; } } $this->assign('bank_accounts', $bank_accounts); $this->assign('bank_accounts_json', json_encode($bank_accounts)); $this->assign('contact_id', $contact_id); // load all account types $option_group = civicrm_api3('OptionGroup', 'getsingle', array('name' => 'civicrm_banking.reference_types')); $reference_types = civicrm_api3('OptionValue', 'get', array('option_group_id' => $option_group['id'], 'is_reserved' => 0)); $this->assign('reference_types_json', json_encode($reference_types['values'])); $reference_type_list = array(); $this->assign('reference_types', $reference_types['values']); foreach ($reference_types['values'] as $reference_type_id => $reference_type) { $reference_type_list[$reference_type_id] = "{$reference_type['label']} ({$reference_type['name']})"; } // load countries $country_id2iso = CRM_Core_PseudoConstant::countryIsoCode(); $country_iso2id = array_flip($country_id2iso); $country_id2name = CRM_Core_PseudoConstant::country(); $countries = array('' => ts("Unknown")); foreach ($country_iso2id as $iso => $id) { if (!empty($country_id2name[$id])) { $countries[$iso] = $country_id2name[$id]; } } // load settings $this->assign('reference_normalisation', (int) CRM_Core_BAO_Setting::getItem('CiviBanking', 'reference_normalisation')); $this->assign('reference_validation', (int) CRM_Core_BAO_Setting::getItem('CiviBanking', 'reference_validation')); // ACCOUNT REFRENCE ITEMS $this->add('hidden', 'contact_id', $contact_id, true); $this->add('hidden', 'reference_id'); $reference_type = $this->add('select', 'reference_type', ts("Bank Account Type"), $reference_type_list, true); // set last value $reference_type->setSelected(CRM_Core_BAO_Setting::getItem('CiviBanking', 'account.default_reference_id')); $reference_type = $this->add('text', 'reference', ts("Bank Account Number"), array('size' => 40), true); // BANK ITEMS $this->add('hidden', 'ba_id'); $this->addElement('text', 'bic', ts("BIC"), array('size' => 40), false); $this->addElement('text', 'bank_name', ts("Bank Name"), array('size' => 40), false); $country = $this->add('select', 'country', ts("Country"), $countries, false); // set last value $country->setSelected(CRM_Core_BAO_Setting::getItem('CiviBanking', 'account.default_country')); $this->addButtons(array(array('type' => 'submit', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'), 'isDefault' => FALSE))); parent::buildQuickForm(); }
public static function optionValues(&$options, $name) { if ($name != 'chapter_match_country') { return; } $countries = CRM_Core_PseudoConstant::country(); foreach ($countries as $country_id => $country) { $options[$country_id] = $country; } }
public function testAddressFormat() { $contact = $this->callAPISuccess('contact', 'create', array('first_name' => 'Micky', 'last_name' => 'mouse', 'contact_type' => 'Individual')); $address = $this->callAPISuccess('address', 'create', array('street_address' => '1 Happy Place', 'city' => 'Miami', 'state_province' => 'Flordia', 'country' => 'United States', 'postal_code' => 33101, 'contact_id' => $contact['id'], 'location_type_id' => 5, 'is_primary' => 1)); $addressDetails = $address['values'][$address['id']]; $countries = CRM_Core_PseudoConstant::country(); $addressDetails['country'] = $countries[$addressDetails['country_id']]; $formatted_address = CRM_Utils_Address::format($addressDetails, 'mailing_format', FALSE, TRUE); $this->assertTrue((bool) strstr($formatted_address, 'UNITED STATES')); }
/** * create all common fields needed for a credit card or direct debit transaction * * @return void * @access protected */ protected function _setPaymentFields(&$form) { $bltID = $form->_bltID; $form->_fields['billing_first_name'] = array('htmlType' => 'text', 'name' => 'billing_first_name', 'title' => ts('Billing First Name'), 'cc_field' => true, 'attributes' => array('size' => 30, 'maxlength' => 60, 'autocomplete' => 'off'), 'is_required' => true); $form->_fields['billing_middle_name'] = array('htmlType' => 'text', 'name' => 'billing_middle_name', 'title' => ts('Billing Middle Name'), 'cc_field' => true, 'attributes' => array('size' => 30, 'maxlength' => 60, 'autocomplete' => 'off'), 'is_required' => false); $form->_fields['billing_last_name'] = array('htmlType' => 'text', 'name' => 'billing_last_name', 'title' => ts('Billing Last Name'), 'cc_field' => true, 'attributes' => array('size' => 30, 'maxlength' => 60, 'autocomplete' => 'off'), 'is_required' => true); $form->_fields["billing_street_address-{$bltID}"] = array('htmlType' => 'text', 'name' => "billing_street_address-{$bltID}", 'title' => ts('Street Address'), 'cc_field' => true, 'attributes' => array('size' => 30, 'maxlength' => 60, 'autocomplete' => 'off'), 'is_required' => true); $form->_fields["billing_city-{$bltID}"] = array('htmlType' => 'text', 'name' => "billing_city-{$bltID}", 'title' => ts('City'), 'cc_field' => true, 'attributes' => array('size' => 30, 'maxlength' => 60, 'autocomplete' => 'off'), 'is_required' => true); $form->_fields["billing_state_province_id-{$bltID}"] = array('htmlType' => 'select', 'name' => "billing_state_province_id-{$bltID}", 'title' => ts('State / Province'), 'cc_field' => true, 'attributes' => array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), 'is_required' => true); $form->_fields["billing_postal_code-{$bltID}"] = array('htmlType' => 'text', 'name' => "billing_postal_code-{$bltID}", 'title' => ts('Postal Code'), 'cc_field' => true, 'attributes' => array('size' => 30, 'maxlength' => 60, 'autocomplete' => 'off'), 'is_required' => true); $form->_fields["billing_country_id-{$bltID}"] = array('htmlType' => 'select', 'name' => "billing_country_id-{$bltID}", 'title' => ts('Country'), 'cc_field' => true, 'attributes' => array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), 'is_required' => true); }
/** * Function to actually build the form * * @return None * @access public */ function buildQuickForm() { $this->add('text', 'sort_name', ts('Name or email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); // select for state province $stateProvince = array('' => ts('- any state/province -')) + CRM_Core_PseudoConstant::stateProvince(); $this->addElement('select', 'state_province', ts('State/Province'), $stateProvince); // select for country $country = array('' => ts('- any country -')) + CRM_Core_PseudoConstant::country(); $this->addElement('select', 'country', ts('Country'), $country); $this->addElement('date', 'birth_date', ts('Date of birth'), CRM_Core_SelectValues::date('birth')); $this->addElement('date', 'scheduled_date_time', ts('Date and Time'), CRM_Core_SelectValues::date('datetime')); $group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant::group(); $this->addElement('select', 'group', ts('Groups'), $group); $this->addButtons(array(array('type' => 'refresh', 'name' => ts('Search'), 'isDefault' => true))); }
public function _populateOptionAndCustomGroup() { $dataValues = array('integer' => array(1, 2, 3), 'number' => array(10.11, 20.22, 30.33), 'string' => array(substr(sha1(rand()), 0, 4), substr(sha1(rand()), 0, 3), substr(sha1(rand()), 0, 2)), 'country' => array_rand(CRM_Core_PseudoConstant::country(FALSE, FALSE), 3), 'state_province' => array_rand(CRM_Core_PseudoConstant::stateProvince(FALSE, FALSE), 3), 'date' => NULL, 'contact' => NULL); foreach ($dataValues as $dataType => $values) { $this->optionGroup[$dataType] = array('values' => $values); if (!empty($values)) { $result = $this->callAPISuccess('OptionGroup', 'create', array('name' => "{$dataType}_group", 'api.option_value.create' => array('label' => "{$dataType} 1", 'value' => $values[0]), 'api.option_value.create.1' => array('label' => "{$dataType} 2", 'value' => $values[1]), 'api.option_value.create.2' => array('label' => "{$dataType} 3", 'value' => $values[2]))); $this->optionGroup[$dataType]['id'] = $result['id']; } elseif ($dataType == 'contact') { for ($i = 0; $i < 3; $i++) { $result = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'email' => substr(sha1(rand()), 0, 7) . '@yahoo.com')); $this->optionGroup[$dataType]['values'][$i] = $result['id']; } } $this->ids[$dataType] = $this->entityCustomGroupWithSingleFieldCreate("{$dataType} Custom Group", 'Contacts'); } }
/** * Build the form object. * * * @param CRM_Core_Form $form * @param $proxSearch * * @return void */ public function buildQuickForm($form, $proxSearch) { // is proximity search required (2) or optional (1)? $proxRequired = $proxSearch == 2 ? TRUE : FALSE; $form->assign('proximity_search', TRUE); $form->add('text', 'prox_street_address', ts('Street Address'), NULL, FALSE); $form->add('text', 'prox_city', ts('City'), NULL, FALSE); $form->add('text', 'prox_postal_code', ts('Postal Code'), NULL, FALSE); $form->addChainSelect('prox_state_province_id', array('required' => $proxRequired)); $country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(); $form->add('select', 'prox_country_id', ts('Country'), $country, $proxRequired); $form->add('text', 'prox_distance', ts('Distance'), NULL, $proxRequired); $proxUnits = array('km' => ts('km'), 'miles' => ts('miles')); $form->add('select', 'prox_distance_unit', ts('Units'), $proxUnits, $proxRequired); // prox_distance_unit $form->addFormRule(array('CRM_Contact_Form_Task_ProximityCommon', 'formRule'), $form); }
public function buildQuickForm() { $config =& CRM_Core_Config::singleton(); $this->add('select', 'country_id', ts('Country'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::country()); $countryID = isset($_POST['country_id']) ? $_POST['country_id'] : null; if (!$countryID) { $countryID = isset($this->_params['country_id']) ? $this->_params['country_id'] : null; } if ($countryID) { $this->add('select', 'state_province_id', ts('State'), array('' => ts('- select a state -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryID)); } else { $this->add('select', 'state_province_id', ts('State'), array('' => ts('- select a country first -'))); } $stateCountryURL = CRM_Utils_System::url('civicrm/ajax/jqState'); $this->assign('stateCountryURL', $stateCountryURL); $this->addButtons(array(array('type' => 'refresh', 'name' => ts('Search'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); }
/** * Validate a value against a CustomField type * * @param string $type The type of the data * @param string $value The data to be validated * * @return boolean True if the value is of the specified type * @access public * @static */ public static function typecheck($type, $value) { require_once 'CRM/Utils/Rule.php'; switch ($type) { case 'Memo': return true; case 'String': return CRM_Utils_Rule::string($value); case 'Int': return CRM_Utils_Rule::integer($value); case 'Float': case 'Money': return CRM_Utils_Rule::numeric($value); case 'Date': return CRM_Utils_Rule::date($value); case 'Boolean': return CRM_Utils_Rule::boolean($value); case 'StateProvince': //fix for multi select state, CRM-3437 $valid = false; $mulValues = explode(',', $value); foreach ($mulValues as $key => $state) { $valid = array_key_exists(strtolower(trim($state)), array_change_key_case(array_flip(CRM_Core_PseudoConstant::stateProvinceAbbreviation()), CASE_LOWER)) || array_key_exists(strtolower(trim($state)), array_change_key_case(array_flip(CRM_Core_PseudoConstant::stateProvince()), CASE_LOWER)); if (!$valid) { break; } } return $valid; case 'Country': //fix multi select country, CRM-3437 $valid = false; $mulValues = explode(',', $value); foreach ($mulValues as $key => $country) { $valid = array_key_exists(strtolower(trim($country)), array_change_key_case(array_flip(CRM_Core_PseudoConstant::countryIsoCode()), CASE_LOWER)) || array_key_exists(strtolower(trim($country)), array_change_key_case(array_flip(CRM_Core_PseudoConstant::country()), CASE_LOWER)); if (!$valid) { break; } } return $valid; case 'Link': return CRM_Utils_Rule::url($value); } return false; }
function alterDisplay(&$rows) { // custom code to alter rows $genderList = CRM_Core_PseudoConstant::gender(); $entryFound = false; foreach ($rows as $rowNum => $row) { // handle state province if (array_key_exists('civicrm_address_state_province_id', $row)) { if ($value = $row['civicrm_address_state_province_id']) { $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value); } $entryFound = true; } // handle country if (array_key_exists('civicrm_address_country_id', $row)) { if ($value = $row['civicrm_address_country_id']) { $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value); } $entryFound = true; } // Handle contactType if (!empty($row[$this->_coreInfoTable . '_' . $this->_coreTypeCol])) { $rows[$rowNum][$this->_coreInfoTable . '_' . $this->_coreTypeCol] = $this->type2str($rows[$rowNum][$this->_coreInfoTable . '_' . $this->_coreTypeCol]); $entryFound = true; } // date of birth to age if (!empty($row['civicrm_contact_birth_date'])) { $rows[$rowNum]['civicrm_contact_birth_date'] = $this->dob2age($row['civicrm_contact_birth_date']); $entryFound = true; } // gender label if (!empty($row['civicrm_contact_gender_id'])) { $rows[$rowNum]['civicrm_contact_gender_id'] = $genderList[$row['civicrm_contact_gender_id']]; $entryFound = true; } if ($this->_outputMode != 'html' && !empty($row[$this->_coreInfoTable . '_' . $this->_coreOtherCol])) { $rows[$rowNum]['civicrm_contact_display_name'] .= "<br />" . $row[$this->_coreInfoTable . '_' . $this->_coreOtherCol]; $entryFound = true; } // skip looking further in rows, if first row itself doesn't // have the column we need if (!$entryFound) { break; } } $columnOrder = array('civicrm_phone_phone', 'civicrm_contact_display_name', 'civicrm_address_street_address', 'civicrm_contact_birth_date', 'civicrm_contact_gender_id', $this->_demoTable . '_' . $this->_demoLangCol, $this->_coreInfoTable . '_' . $this->_coreTypeCol, 'civicrm_contact_id'); if ($this->_outputMode == 'print' || $this->_outputMode == 'pdf') { $this->_columnHeaders = array('civicrm_phone_phone' => array('title' => 'PHONE', 'type' => CRM_Utils_Type::T_STRING, 'class' => 'width=68'), 'civicrm_contact_display_name' => array('title' => 'NAME', 'type' => CRM_Utils_Type::T_STRING, 'class' => 'width=83'), 'civicrm_address_street_address' => array('title' => 'ADDRESS', 'type' => CRM_Utils_Type::T_STRING, 'class' => 'width=117'), 'civicrm_contact_birth_date' => array('title' => 'AGE', 'type' => CRM_Utils_Type::T_STRING, 'class' => 'width=25'), 'civicrm_contact_gender_id' => array('title' => 'SEX', 'type' => CRM_Utils_Type::T_STRING, 'class' => 'width=18'), $this->_demoTable . '_' . $this->_demoLangCol => array('title' => 'Lang', 'type' => CRM_Utils_Type::T_STRING, 'class' => 'width=27'), $this->_coreInfoTable . '_' . $this->_coreTypeCol => array('title' => 'Contact Type', 'type' => CRM_Utils_Type::T_STRING, 'class' => 'width=48'), 'notes' => array('title' => 'NOTES', 'type' => CRM_Utils_Type::T_STRING, 'class' => 'width=48'), 'response_codes' => array('title' => 'RESPONSE CODES', 'type' => CRM_Utils_Type::T_STRING, 'class' => 'width=91'), 'status' => array('title' => 'STATUS', 'type' => CRM_Utils_Type::T_STRING, 'class' => 'width=70'), 'civicrm_contact_id' => array('title' => 'ID', 'type' => CRM_Utils_Type::T_STRING, 'class' => 'width=100')); $newRows = array(); foreach ($columnOrder as $col) { foreach ($rows as $rowNum => $row) { $newRows[$rowNum][$col] = $row[$col]; $newRows[$rowNum]['notes'] = ' '; $newRows[$rowNum]['status'] = 'NH MV D WN'; $newRows[$rowNum]['response_codes'] = ' Q1 Y N U D<br /> Q2 Y N U D<br /> Q3 Y N U D<br /> Q4 Y N U D'; } } $rows = $newRows; $this->assign('pageTotal', ceil(count($newRows) / 7)); } else { // make sure column order is same as in print mode $tempHeaders = $this->_columnHeaders; $this->_columnHeaders = array(); foreach ($columnOrder as $col) { if (array_key_exists($col, $tempHeaders)) { $this->_columnHeaders[$col] = $tempHeaders[$col]; unset($tempHeaders[$col]); } } $this->_columnHeaders = $this->_columnHeaders + $tempHeaders; } }
/** * function to check if an error in Core( non-custom fields ) field * * @param String $errorMessage A string containing all the error-fields. * * @access public */ function isErrorInCoreData($params, &$errorMessage) { require_once 'CRM/Core/OptionGroup.php'; foreach ($params as $key => $value) { if ($value) { $session =& CRM_Core_Session::singleton(); $dateType = $session->get("dateTypes"); switch ($key) { case 'birth_date': if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) { if (!CRM_Utils_Rule::date($params[$key])) { self::addToErrorMsg(ts('Birth Date'), $errorMessage); } } else { self::addToErrorMsg(ts('Birth-Date'), $errorMessage); } break; case 'deceased_date': if (CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key)) { if (!CRM_Utils_Rule::date($params[$key])) { self::addToErrorMsg(ts('Deceased Date'), $errorMessage); } } else { self::addToErrorMsg(ts('Deceased Date'), $errorMessage); } break; case 'is_deceased': if (CRM_Utils_String::strtoboolstr($value) === false) { self::addToErrorMsg(ts('Is Deceased'), $errorMessage); } break; case 'gender': if (!self::checkGender($value)) { self::addToErrorMsg(ts('Gender'), $errorMessage); } break; case 'preferred_communication_method': $preffComm = array(); $preffComm = explode(',', $value); foreach ($preffComm as $v) { if (!self::in_value(trim($v), CRM_Core_PseudoConstant::pcm())) { self::addToErrorMsg(ts('Preferred Communication Method'), $errorMessage); } } break; case 'preferred_mail_format': if (!array_key_exists(strtolower($value), array_change_key_case(CRM_Core_SelectValues::pmf(), CASE_LOWER))) { self::addToErrorMsg(ts('Preferred Mail Format'), $errorMessage); } break; case 'individual_prefix': if (!self::in_value($value, CRM_Core_PseudoConstant::individualPrefix())) { self::addToErrorMsg(ts('Individual Prefix'), $errorMessage); } break; case 'individual_suffix': if (!self::in_value($value, CRM_Core_PseudoConstant::individualSuffix())) { self::addToErrorMsg(ts('Individual Suffix'), $errorMessage); } break; case 'state_province': if (!empty($value)) { foreach ($value as $stateValue) { if ($stateValue['state_province']) { if (self::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvinceAbbreviation()) || self::in_value($stateValue['state_province'], CRM_Core_PseudoConstant::stateProvince())) { continue; } else { self::addToErrorMsg(ts('State / Province'), $errorMessage); } } } } break; case 'country': if (!empty($value)) { foreach ($value as $stateValue) { if ($stateValue['country']) { CRM_Core_PseudoConstant::populate($countryNames, 'CRM_Core_DAO_Country', true, 'name', 'is_active'); CRM_Core_PseudoConstant::populate($countryIsoCodes, 'CRM_Core_DAO_Country', true, 'iso_code'); $config =& CRM_Core_Config::singleton(); $limitCodes = $config->countryLimit(); //If no country is selected in //localization then take all countries if (empty($limitCodes)) { $limitCodes = $countryIsoCodes; } if (self::in_value($stateValue['country'], $limitCodes) || self::in_value($stateValue['country'], CRM_Core_PseudoConstant::country())) { continue; } else { if (self::in_value($stateValue['country'], $countryIsoCodes) || self::in_value($stateValue['country'], $countryNames)) { self::addToErrorMsg(ts('Country input value is in table but not "available": "This Country is valid but is NOT in the list of Available Countries currently configured for your site. This can be viewed and modifed from Global Settings >> Localization." '), $errorMessage); } else { self::addToErrorMsg(ts('Country input value not in country table: "The Country value appears to be invalid. It does not match any value in CiviCRM table of countries."'), $errorMessage); } } } } } break; case 'geo_code_1': if (!empty($value)) { foreach ($value as $codeValue) { if ($codeValue['geo_code_1']) { if (CRM_Utils_Rule::numeric($codeValue['geo_code_1'])) { continue; } else { self::addToErrorMsg(ts('Geo code 1'), $errorMessage); } } } } break; case 'geo_code_2': if (!empty($value)) { foreach ($value as $codeValue) { if ($codeValue['geo_code_2']) { if (CRM_Utils_Rule::numeric($codeValue['geo_code_2'])) { continue; } else { self::addToErrorMsg(ts('Geo code 2'), $errorMessage); } } } } break; //check for any error in email/postal greeting, addressee, //custom email/postal greeting, custom addressee, CRM-4575 //check for any error in email/postal greeting, addressee, //custom email/postal greeting, custom addressee, CRM-4575 case 'email_greeting': $emailGreetingFilter = array('contact_type' => $this->_contactType, 'greeting_type' => 'email_greeting'); if (!self::in_value($value, CRM_Core_PseudoConstant::greeting($emailGreetingFilter))) { self::addToErrorMsg(ts('Email Greeting must be one of the configured format options. Check Administer >> Option Lists >> Email Greetings for valid values'), $errorMessage); } break; case 'postal_greeting': $postalGreetingFilter = array('contact_type' => $this->_contactType, 'greeting_type' => 'postal_greeting'); if (!self::in_value($value, CRM_Core_PseudoConstant::greeting($postalGreetingFilter))) { self::addToErrorMsg(ts('Postal Greeting must be one of the configured format options. Check Administer >> Option Lists >> Postal Greetings for valid values'), $errorMessage); } break; case 'addressee': $addresseeFilter = array('contact_type' => $this->_contactType, 'greeting_type' => 'addressee'); if (!self::in_value($value, CRM_Core_PseudoConstant::greeting($addresseeFilter))) { self::addToErrorMsg(ts('Addressee must be one of the configured format options. Check Administer >> Option Lists >> Addressee for valid values'), $errorMessage); } break; case 'email_greeting_custom': if (array_key_exists('email_greeting', $params)) { $emailGreetingLabel = key(CRM_Core_OptionGroup::values('email_greeting', true, null, null, 'AND v.name = "Customized"')); if (CRM_Utils_Array::value('email_greeting', $params) != $emailGreetingLabel) { self::addToErrorMsg(ts('Email Greeting - Custom'), $errorMessage); } } break; case 'postal_greeting_custom': if (array_key_exists('postal_greeting', $params)) { $postalGreetingLabel = key(CRM_Core_OptionGroup::values('postal_greeting', true, null, null, 'AND v.name = "Customized"')); if (CRM_Utils_Array::value('postal_greeting', $params) != $postalGreetingLabel) { self::addToErrorMsg(ts('Postal Greeting - Custom'), $errorMessage); } } break; case 'addressee_custom': if (array_key_exists('addressee', $params)) { $addresseeLabel = key(CRM_Core_OptionGroup::values('addressee', true, null, null, 'AND v.name = "Customized"')); if (CRM_Utils_Array::value('addressee', $params) != $addresseeLabel) { self::addToErrorMsg(ts('Addressee - Custom'), $errorMessage); } } break; case 'home_URL': if (CRM_Utils_Rule::url($value) === false) { self::addToErrorMsg(ts('Website'), $errorMessage); } break; case 'do_not_email': case 'do_not_phone': case 'do_not_mail': case 'do_not_sms': case 'do_not_trade': if (CRM_Utils_Rule::boolean($value) == false) { $key = ucwords(str_replace("_", " ", $key)); self::addToErrorMsg($key, $errorMessage); } break; case 'email': if (is_array($value)) { foreach ($value as $values) { if (CRM_Utils_Array::value('email', $values) && !CRM_Utils_Rule::email($values['email'])) { self::addToErrorMsg($key, $errorMessage); break; } } } break; default: if (is_array($params[$key]) && isset($params[$key]["contact_type"])) { //check for any relationship data ,FIX ME self::isErrorInCoreData($params[$key], $errorMessage); } } } } }
/** * Test case for resolveDefaults( ). * * Test all pseudoConstant, stateProvince, country. */ public function testResolveDefaults() { $params = array('prefix_id' => 3, 'suffix_id' => 2, 'gender_id' => 2, 'birth_date' => '1983-12-13'); $params['address'][1] = array('location_type_id' => 1, 'is_primary' => 1, 'country_id' => 1228, 'state_province_id' => 1004); CRM_Contact_BAO_Contact::resolveDefaults($params); //check the resolve values. $genders = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); $this->assertEquals($genders[$params['gender_id']], $params['gender'], 'Check for gender.'); $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'); $this->assertEquals($prefix[$params['prefix_id']], $params['prefix'], 'Check for prefix.'); $suffix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id'); $this->assertEquals($suffix[$params['suffix_id']], $params['suffix'], 'Check for suffix.'); $this->assertEquals(CRM_Core_PseudoConstant::stateProvince($params['address'][1]['state_province_id']), $params['address'][1]['state_province'], 'Check for state province.'); $this->assertEquals(CRM_Core_PseudoConstant::country($params['address'][1]['country_id']), $params['address'][1]['country'], 'Check for country.'); }
function alterDisplay(&$rows) { // custom code to alter rows $entryFound = FALSE; foreach ($rows as $rowNum => $row) { // make count columns point to detail report // convert display name to links if (array_key_exists('civicrm_contact_sort_name', $row) && array_key_exists('civicrm_contact_id', $row)) { $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $row['civicrm_contact_id'], $this->_absoluteUrl); $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url; $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact details for this contact."); $entryFound = TRUE; } // handle gender if (array_key_exists('civicrm_contact_gender_id', $row)) { if ($value = $row['civicrm_contact_gender_id']) { $rows[$rowNum]['civicrm_contact_gender_id'] = $this->_genders[$value]; } $entryFound = TRUE; } // handle country if (array_key_exists('civicrm_address_country_id', $row)) { if ($value = $row['civicrm_address_country_id']) { $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value, FALSE); } $entryFound = TRUE; } if (array_key_exists('civicrm_address_state_province_id', $row)) { if ($value = $row['civicrm_address_state_province_id']) { $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, FALSE); } $entryFound = TRUE; } // handle custom fields foreach ($row as $k => $r) { if (substr($k, 0, 13) == 'civicrm_value' || substr($k, 0, 12) == 'custom_value') { if ($r || $r == '0') { if ($newval = $this->getCustomFieldLabel($k, $r)) { $rows[$rowNum][$k] = $newval; } } $entryFound = TRUE; } } // skip looking further in rows, if first row itself doesn't // have the column we need if (!$entryFound) { break; } } }
function alterDisplay(&$rows) { // custom code to alter rows $checkList = array(); $entryFound = false; $display_flag = $prev_cid = $cid = 0; $contributionTypes = CRM_Contribute_PseudoConstant::contributionType(); foreach ($rows as $rowNum => $row) { if (!empty($this->_noRepeats) && $this->_outputMode != 'csv') { // don't repeat contact details if its same as the previous row if (array_key_exists('civicrm_contact_id', $row)) { if ($cid = $row['civicrm_contact_id']) { if ($rowNum == 0) { $prev_cid = $cid; } else { if ($prev_cid == $cid) { $display_flag = 1; $prev_cid = $cid; } else { $display_flag = 0; $prev_cid = $cid; } } if ($display_flag) { foreach ($row as $colName => $colVal) { if (in_array($colName, $this->_noRepeats)) { unset($rows[$rowNum][$colName]); } } } $entryFound = true; } } } // handle state province if (array_key_exists('civicrm_address_state_province_id', $row)) { if ($value = $row['civicrm_address_state_province_id']) { $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, false); $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail', "reset=1&force=1&" . "state_province_id_op=in&state_province_id_value={$value}", $this->_absoluteUrl, $this->_id); $rows[$rowNum]['civicrm_address_state_province_id_link'] = $url; $rows[$rowNum]['civicrm_address_state_province_id_hover'] = ts("List all contribution(s) for this State."); } $entryFound = true; } // handle country if (array_key_exists('civicrm_address_country_id', $row)) { if ($value = $row['civicrm_address_country_id']) { $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value, false); $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail', "reset=1&force=1&" . "country_id_op=in&country_id_value={$value}", $this->_absoluteUrl, $this->_id); $rows[$rowNum]['civicrm_address_country_id_link'] = $url; $rows[$rowNum]['civicrm_address_country_id_hover'] = ts("List all contribution(s) for this Country."); } $entryFound = true; } // convert display name to links if (array_key_exists('civicrm_contact_display_name', $row) && CRM_Utils_Array::value('civicrm_contact_display_name', $rows[$rowNum]) && array_key_exists('civicrm_contact_id', $row)) { $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $row['civicrm_contact_id'], $this->_absoluteUrl); $rows[$rowNum]['civicrm_contact_display_name_link'] = $url; $rows[$rowNum]['civicrm_contact_display_name_hover'] = ts("View Contact Summary for this Contact."); } if ($value = CRM_Utils_Array::value('civicrm_contribution_contribution_type_id', $row)) { $rows[$rowNum]['civicrm_contribution_contribution_type_id'] = $contributionTypes[$value]; $entryFound = true; } // skip looking further in rows, if first row itself doesn't // have the column we need if (!$entryFound) { break; } $lastKey = $rowNum; } }
/** * Build the form * * @access public * * @return void */ function buildQuickForm($form, $proxSearch) { // is proximity search required (2) or optional (1)? $proxRequired = $proxSearch == 2 ? TRUE : FALSE; $form->assign('proximity_search', TRUE); $form->add('text', 'prox_street_address', ts('Street Address'), NULL, FALSE); $form->add('text', 'prox_city', ts('City'), NULL, FALSE); $form->add('text', 'prox_postal_code', ts('Postal Code'), NULL, FALSE); $defaults = self::setDefaultValues($form); if (CRM_Utils_Array::value('prox_country_id', $defaults)) { $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($defaults['prox_country_id']); } else { $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(); } $form->add('select', 'prox_state_province_id', ts('State/Province'), $stateProvince, $proxRequired); $country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(); $form->add('select', 'prox_country_id', ts('Country'), $country, $proxRequired); $form->add('text', 'prox_distance', ts('Distance'), NULL, $proxRequired); $proxUnits = array('km' => ts('km'), 'miles' => ts('miles')); $form->add('select', 'prox_distance_unit', ts('Units'), $proxUnits, $proxRequired); // prox_distance_unit // state country js, CRM-5233 $stateCountryMap = array(); $stateCountryMap[] = array('state_province' => 'prox_state_province_id', 'country' => 'prox_country_id'); CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults); $form->addFormRule(array('CRM_Contact_Form_Task_ProximityCommon', 'formRule'), $form); }
/** * @param int $id * @param $title * @param null $required * @param null $extra */ public function addCountry($id, $title, $required = NULL, $extra = NULL) { $this->addElement('select', $id, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $extra); if ($required) { $this->addRule($id, ts('Please select %1', array(1 => $title)), 'required'); } }
/** * Provide cached default country name * * @param * * @return string */ public function defaultContactCountryName() { static $cachedContactCountryName = NULL; if (!$cachedContactCountryName) { $countryCodes = CRM_Core_PseudoConstant::country(); $cachedContactCountryName = $countryCodes[$this->defaultContactCountry]; } return $cachedContactCountryName; }
/** * Function to build the array for display the profile fields * * @param array $params key value. * @param int $gid profile Id * @param array $groupTitle Profile Group Title. * @param array $values formatted array of key value * * @return None * @access public */ function displayProfile(&$params, $gid, &$groupTitle, &$values) { if ($gid) { require_once 'CRM/Core/BAO/UFGroup.php'; require_once 'CRM/Profile/Form.php'; require_once 'CRM/Event/PseudoConstant.php'; $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); if ($contactID) { if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $contactID)) { $fields = CRM_Core_BAO_UFGroup::getFields($gid, false, CRM_Core_Action::VIEW); } } else { $fields = CRM_Core_BAO_UFGroup::getFields($gid, false, CRM_Core_Action::ADD); } if (is_array($fields)) { // unset any email-* fields since we already collect it, CRM-2888 foreach (array_keys($fields) as $fieldName) { if (substr($fieldName, 0, 6) == 'email-') { unset($fields[$fieldName]); } } } foreach ($fields as $v) { if (CRM_Utils_Array::value('groupTitle', $v)) { $groupTitle['groupTitle'] = $v["groupTitle"]; break; } } $config = CRM_Core_Config::singleton(); require_once 'CRM/Core/PseudoConstant.php'; $locationTypes = $imProviders = array(); $locationTypes = CRM_Core_PseudoConstant::locationType(); $imProviders = CRM_Core_PseudoConstant::IMProvider(); //start of code to set the default values foreach ($fields as $name => $field) { $index = $field['title']; $customFieldName = null; if ($name === 'organization_name') { $values[$index] = $params[$name]; } if ('state_province' == substr($name, 0, 14)) { if ($params[$name]) { $values[$index] = CRM_Core_PseudoConstant::stateProvince($params[$name]); } else { $values[$index] = ''; } } else { if ('country' == substr($name, 0, 7)) { if ($params[$name]) { $values[$index] = CRM_Core_PseudoConstant::country($params[$name]); } else { $values[$index] = ''; } } else { if ('county' == substr($name, 0, 6)) { if ($params[$name]) { $values[$index] = CRM_Core_PseudoConstant::county($params[$name]); } else { $values[$index] = ''; } } else { if ('gender' == substr($name, 0, 6)) { $gender = CRM_Core_PseudoConstant::gender(); $values[$index] = $gender[$params[$name]]; } else { if ('individual_prefix' == substr($name, 0, 17)) { $prefix = CRM_Core_PseudoConstant::individualPrefix(); $values[$index] = $prefix[$params[$name]]; } else { if ('individual_suffix' == substr($name, 0, 17)) { $suffix = CRM_Core_PseudoConstant::individualSuffix(); $values[$index] = $suffix[$params[$name]]; } else { if (in_array($name, array('addressee', 'email_greeting', 'postal_greeting'))) { $filterCondition = array('greeting_type' => $name); $greeting =& CRM_Core_PseudoConstant::greeting($filterCondition); $values[$index] = $greeting[$params[$name]]; } else { if ($name === 'preferred_communication_method') { $communicationFields = CRM_Core_PseudoConstant::pcm(); $pref = array(); $compref = array(); $pref = $params[$name]; if (is_array($pref)) { foreach ($pref as $k => $v) { if ($v) { $compref[] = $communicationFields[$k]; } } } $values[$index] = implode(",", $compref); } else { if ($name == 'group') { require_once 'CRM/Contact/BAO/GroupContact.php'; $groups = CRM_Contact_BAO_GroupContact::getGroupList(); $title = array(); foreach ($params[$name] as $gId => $dontCare) { if ($dontCare) { $title[] = $groups[$gId]; } } $values[$index] = implode(', ', $title); } else { if ($name == 'tag') { require_once 'CRM/Core/BAO/EntityTag.php'; $entityTags = $params[$name]; $allTags =& CRM_Core_PseudoConstant::tag(); $title = array(); if (is_array($entityTags)) { foreach ($entityTags as $tagId => $dontCare) { $title[] = $allTags[$tagId]; } } $values[$index] = implode(', ', $title); } else { if ('participant_role_id' == $name) { $roles = CRM_Event_PseudoConstant::participantRole(); $values[$index] = $roles[$params[$name]]; } else { if ('participant_status_id' == $name) { $status = CRM_Event_PseudoConstant::participantStatus(); $values[$index] = $status[$params[$name]]; } else { if (strpos($name, '-') !== false) { list($fieldName, $id) = CRM_Utils_System::explode('-', $name, 2); $detailName = str_replace(' ', '_', $name); if (in_array($fieldName, array('state_province', 'country', 'county'))) { $values[$index] = $params[$detailName]; $idx = $detailName . '_id'; $values[$index] = $params[$idx]; } else { if ($fieldName == 'im') { $providerName = null; if ($providerId = $detailName . '-provider_id') { $providerName = CRM_Utils_Array::value($params[$providerId], $imProviders); } if ($providerName) { $values[$index] = $params[$detailName] . " (" . $providerName . ")"; } else { $values[$index] = $params[$detailName]; } } else { $values[$index] = $params[$detailName]; } } } else { if (substr($name, 0, 7) === 'do_not_' or substr($name, 0, 3) === 'is_') { if ($params[$name]) { $values[$index] = '[ x ]'; } } else { require_once 'CRM/Core/BAO/CustomField.php'; if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) { $query = "\nSELECT html_type, data_type\nFROM civicrm_custom_field\nWHERE id = {$cfID}\n"; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); $dao->fetch(); $htmlType = $dao->html_type; $dataType = $dao->data_type; if ($htmlType == 'File') { //$fileURL = CRM_Core_BAO_CustomField::getFileURL( $contactID, $cfID ); //$params[$index] = $values[$index] = $fileURL['file_url']; $values[$index] = $params[$index]; } else { if ($dao->data_type == 'Int' || $dao->data_type == 'Boolean') { $customVal = (int) $params[$name]; } else { if ($dao->data_type == 'Float') { $customVal = (double) $params[$name]; } else { if ($dao->data_type == 'Date') { $date = CRM_Utils_Date::format($params[$name], null, 'invalidDate'); if ($date != 'invalidDate') { $customVal = $date; } } else { $customVal = $params[$name]; } } } //take the custom field options $returnProperties = array($name => 1); require_once 'CRM/Contact/BAO/Query.php'; $query = new CRM_Contact_BAO_Query($params, $returnProperties, $fields); $options =& $query->_options; $displayValue = CRM_Core_BAO_CustomField::getDisplayValue($customVal, $cfID, $options); //Hack since we dont have function to check empty. //FIXME in 2.3 using crmIsEmptyArray() $customValue = true; if (is_array($customVal) && is_array($displayValue)) { $customValue = array_diff($customVal, $displayValue); } //use difference of arrays if (empty($customValue) || !$customValue) { $values[$index] = ''; } else { $values[$index] = $displayValue; } if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $cfID, 'is_search_range')) { $customFieldName = "{$name}_from"; } } } else { if ($name == 'home_URL' && !empty($params[$name])) { $url = CRM_Utils_System::fixURL($params[$name]); $values[$index] = "<a href=\"{$url}\">{$params[$name]}</a>"; } else { if (in_array($name, array('birth_date', 'deceased_date', 'participant_register_date'))) { require_once 'CRM/Utils/Date.php'; $values[$index] = CRM_Utils_Date::customFormat(CRM_Utils_Date::format($params[$name])); } else { $values[$index] = $params[$name]; } } } } } } } } } } } } } } } } } } } }
function alterDisplay(&$rows) { if ($this->_outputMode == 'print' || $this->_outputMode == 'pdf') { $this->executePrintmode($rows); return; } // custom code to alter rows //var_dump($rows); $genderList = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); $entryFound = FALSE; foreach ($rows as $rowNum => $row) { // handle state province if (array_key_exists('civicrm_address_state_province_id', $row)) { if ($value = $row['civicrm_address_state_province_id']) { $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value); } $entryFound = TRUE; } // handle country if (array_key_exists('civicrm_address_country_id', $row)) { if ($value = $row['civicrm_address_country_id']) { $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value); } $entryFound = TRUE; } // Handle contactType if (!empty($row[$this->_coreInfoTable . '_' . $this->_coreTypeCol])) { $rows[$rowNum][$this->_coreInfoTable . '_' . $this->_coreTypeCol] = $this->hexOne2str($rows[$rowNum][$this->_coreInfoTable . '_' . $this->_coreTypeCol]); $entryFound = TRUE; } // date of birth to age if (!empty($row['civicrm_contact_birth_date'])) { $rows[$rowNum]['civicrm_contact_birth_date'] = $this->dob2age($row['civicrm_contact_birth_date'] . " 00:00:00"); $entryFound = TRUE; } // gender label if (!empty($row['civicrm_contact_gender_id'])) { $rows[$rowNum]['civicrm_contact_gender_id'] = $genderList[$row['civicrm_contact_gender_id']]; $entryFound = TRUE; } // Abbreviate party registration to first letter if (!empty($row["{$this->_voterInfoTable}_{$this->_partyCol}"])) { $rows[$rowNum]["{$this->_voterInfoTable}_{$this->_partyCol}"] = substr($row["{$this->_voterInfoTable}_{$this->_partyCol}"], 0, 1); $entryFound = TRUE; } // skip looking further in rows, if first row itself doesn't // have the column we need if (!$entryFound) { break; } } // make sure column order is same as in print mode $columnOrder = array('civicrm_address_street_number', 'civicrm_address_street_unit', 'civicrm_contact_display_name', 'civicrm_phone_phone', 'civicrm_contact_birth_date', 'civicrm_contact_gender_id', $this->_demoTable . '_' . $this->_demoLangCol, $this->_voterInfoTable . '_' . $this->_partyCol, $this->_voterInfoTable . '_' . $this->_vhCol, $this->_coreInfoTable . '_' . $this->_coreTypeCol, 'civicrm_contact_id'); $tempHeaders = $this->_columnHeaders; $this->_columnHeaders = array(); foreach ($columnOrder as $col) { if (array_key_exists($col, $tempHeaders)) { $this->_columnHeaders[$col] = $tempHeaders[$col]; unset($tempHeaders[$col]); } } $this->_columnHeaders = $this->_columnHeaders + $tempHeaders; }
/** * Alter display of rows. * * Iterate through the rows retrieved via SQL and make changes for display purposes, * such as rendering contacts as links. * * @param array $rows * Rows generated by SQL, with an array for each row. */ public function alterDisplay(&$rows) { list($from1, $to1) = $this->getFromTo(CRM_Utils_Array::value("receive_date1_relative", $this->_params), CRM_Utils_Array::value("receive_date1_from", $this->_params), CRM_Utils_Array::value("receive_date1_to", $this->_params)); list($from2, $to2) = $this->getFromTo(CRM_Utils_Array::value("receive_date2_relative", $this->_params), CRM_Utils_Array::value("receive_date2_from", $this->_params), CRM_Utils_Array::value("receive_date2_to", $this->_params)); $dateUrl = ""; if ($from1) { $dateUrl .= "receive_date1_from={$from1}&"; } if ($to1) { $dateUrl .= "receive_date1_to={$to1}&"; } if ($from2) { $dateUrl .= "receive_date2_from={$from2}&"; } if ($to2) { $dateUrl .= "receive_date2_to={$to2}&"; } foreach ($rows as $rowNum => $row) { // handle country if (array_key_exists('address_civireport_country_id', $row)) { if ($value = $row['address_civireport_country_id']) { $rows[$rowNum]['address_civireport_country_id'] = CRM_Core_PseudoConstant::country($value, FALSE); $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail', "reset=1&force=1&" . "country_id_op=in&country_id_value={$value}&" . "{$dateUrl}", $this->_absoluteUrl, $this->_id, $this->_drilldownReport); $rows[$rowNum]['address_civireport_country_id_link'] = $url; $rows[$rowNum]['address_civireport_country_id_hover'] = ts("View contributions for this Country."); } } // handle state province if (array_key_exists('address_civireport_state_province_id', $row)) { if ($value = $row['address_civireport_state_province_id']) { $rows[$rowNum]['address_civireport_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, FALSE); $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail', "reset=1&force=1&" . "state_province_id_op=in&state_province_id_value={$value}&" . "{$dateUrl}", $this->_absoluteUrl, $this->_id, $this->_drilldownReport); $rows[$rowNum]['address_civireport_state_province_id_link'] = $url; $rows[$rowNum]['address_civireport_state_province_id_hover'] = ts("View repeatDetails for this state."); } } // convert display name to links if (array_key_exists('contact_civireport_sort_name', $row) && array_key_exists('contact_civireport_id', $row)) { $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail', 'reset=1&force=1&id_op=eq&id_value=' . $row['contact_civireport_id'], $this->_absoluteUrl, $this->_id, $this->_drilldownReport); $rows[$rowNum]['contact_civireport_sort_name_link'] = $url; $rows[$rowNum]['contact_civireport_sort_name_hover'] = ts("View Contribution details for this contact"); } } // foreach ends }
/** * Alter display of rows. * * Iterate through the rows retrieved via SQL and make changes for display purposes, * such as rendering contacts as links. * * @param array $rows * Rows generated by SQL, with an array for each row. */ public function alterDisplay(&$rows) { $entryFound = FALSE; $eventType = CRM_Core_OptionGroup::values('event_type'); $financialTypes = CRM_Contribute_PseudoConstant::financialType(); $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(); $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument(); foreach ($rows as $rowNum => $row) { // make count columns point to detail report // convert display name to links if (array_key_exists('civicrm_participant_event_id', $row)) { $eventId = $row['civicrm_participant_event_id']; if ($eventId) { $rows[$rowNum]['civicrm_participant_event_id'] = CRM_Event_PseudoConstant::event($eventId, FALSE); $url = CRM_Report_Utils_Report::getNextUrl('event/income', 'reset=1&force=1&id_op=in&id_value=' . $eventId, $this->_absoluteUrl, $this->_id, $this->_drilldownReport); $rows[$rowNum]['civicrm_participant_event_id_link'] = $url; $rows[$rowNum]['civicrm_participant_event_id_hover'] = ts("View Event Income Details for this Event"); } $entryFound = TRUE; } // handle event type id $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_event_event_type_id', $rowNum, $eventType); // handle participant status id if (array_key_exists('civicrm_participant_status_id', $row)) { $statusId = $row['civicrm_participant_status_id']; if ($statusId) { $rows[$rowNum]['civicrm_participant_status_id'] = CRM_Event_PseudoConstant::participantStatus($statusId, FALSE, 'label'); } $entryFound = TRUE; } // handle participant role id if (array_key_exists('civicrm_participant_role_id', $row)) { $roleId = $row['civicrm_participant_role_id']; if ($roleId) { $roles = explode(CRM_Core_DAO::VALUE_SEPARATOR, $roleId); $roleId = array(); foreach ($roles as $role) { $roleId[$role] = CRM_Event_PseudoConstant::participantRole($role, FALSE); } $rows[$rowNum]['civicrm_participant_role_id'] = implode(', ', $roleId); } $entryFound = TRUE; } // Handel value seperator in Fee Level if (array_key_exists('civicrm_participant_participant_fee_level', $row)) { $feeLevel = $row['civicrm_participant_participant_fee_level']; if ($feeLevel) { CRM_Event_BAO_Participant::fixEventLevel($feeLevel); $rows[$rowNum]['civicrm_participant_participant_fee_level'] = $feeLevel; } $entryFound = TRUE; } // Convert display name to link $displayName = CRM_Utils_Array::value('civicrm_contact_sort_name_linked', $row); $cid = CRM_Utils_Array::value('civicrm_contact_id', $row); $id = CRM_Utils_Array::value('civicrm_participant_participant_record', $row); if ($displayName && $cid && $id) { $url = CRM_Report_Utils_Report::getNextUrl('contact/detail', "reset=1&force=1&id_op=eq&id_value={$cid}", $this->_absoluteUrl, $this->_id, $this->_drilldownReport); $viewUrl = CRM_Utils_System::url("civicrm/contact/view/participant", "reset=1&id={$id}&cid={$cid}&action=view&context=participant"); $contactTitle = ts('View Contact Details'); $participantTitle = ts('View Participant Record'); $rows[$rowNum]['civicrm_contact_sort_name_linked'] = "<a title='{$contactTitle}' href={$url}>{$displayName}</a>"; if ($this->_outputMode !== 'csv') { $rows[$rowNum]['civicrm_contact_sort_name_linked'] .= "<span style='float: right;'><a title='{$participantTitle}' href={$viewUrl}>" . ts('View') . "</a></span>"; } $entryFound = TRUE; } // Handle country id if (array_key_exists('civicrm_address_country_id', $row)) { $countryId = $row['civicrm_address_country_id']; if ($countryId) { $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($countryId, TRUE); } $entryFound = TRUE; } // Handle state/province id if (array_key_exists('civicrm_address_state_province_id', $row)) { $provinceId = $row['civicrm_address_state_province_id']; if ($provinceId) { $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($provinceId, TRUE); } $entryFound = TRUE; } // Handle employer id if (array_key_exists('civicrm_contact_employer_id', $row)) { $employerId = $row['civicrm_contact_employer_id']; if ($employerId) { $rows[$rowNum]['civicrm_contact_employer_id'] = CRM_Contact_BAO_Contact::displayName($employerId); $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $employerId, $this->_absoluteUrl); $rows[$rowNum]['civicrm_contact_employer_id_link'] = $url; $rows[$rowNum]['civicrm_contact_employer_id_hover'] = ts('View Contact Summary for this Contact.'); } } // Convert campaign_id to campaign title $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_participant_campaign_id', $rowNum, $this->activeCampaigns); // handle contribution status $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_contribution_contribution_status_id', $rowNum, $contributionStatus); // handle payment instrument $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_contribution_payment_instrument_id', $rowNum, $paymentInstruments); // handle financial type $this->_initBasicRow($rows, $entryFound, $row, 'civicrm_contribution_financial_type_id', $rowNum, $financialTypes); $entryFound = $this->alterDisplayContactFields($row, $rows, $rowNum, 'event/participantListing', 'View Event Income Details') ? TRUE : $entryFound; // display birthday in the configured custom format if (array_key_exists('civicrm_contact_birth_date', $row)) { $birthDate = $row['civicrm_contact_birth_date']; if ($birthDate) { $rows[$rowNum]['civicrm_contact_birth_date'] = CRM_Utils_Date::customFormat($birthDate, '%Y%m%d'); } $entryFound = TRUE; } // skip looking further in rows, if first row itself doesn't // have the column we need if (!$entryFound) { break; } } }
function alterDisplay(&$rows) { $totalStatistics = $grantStatistics = array(); $totalStatistics = parent::statistics($rows); $awardedGrantsAmount = $grantsReceived = $totalAmount = $awardedGrants = $grantReportsReceived = 0; $grantStatistics = array(); $grantTypes = CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'grant_type_id'); $countries = CRM_Core_PseudoConstant::country(); $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); $grantAmountTotal = "\nSELECT COUNT({$this->_aliases['civicrm_grant']}.id) as count ,\n SUM({$this->_aliases['civicrm_grant']}.amount_total) as totalAmount\n {$this->_from} "; if (!empty($this->_whereClause)) { $grantAmountTotal .= " {$this->_whereClause}"; } $result = CRM_Core_DAO::executeQuery($grantAmountTotal); while ($result->fetch()) { $grantsReceived = $result->count; $totalAmount = $result->totalAmount; } if (!$grantsReceived) { return; } $grantAmountAwarded = "\nSELECT COUNT({$this->_aliases['civicrm_grant']}.id) as count ,\n SUM({$this->_aliases['civicrm_grant']}.amount_granted) as grantedAmount,\n SUM({$this->_aliases['civicrm_grant']}.amount_total) as totalAmount\n {$this->_from} "; if (!empty($this->_where)) { $grantAmountAwarded .= " {$this->_where}"; } $values = CRM_Core_DAO::executeQuery($grantAmountAwarded); while ($values->fetch()) { $awardedGrants = $values->count; $awardedGrantsAmount = $values->totalAmount; $amountGranted = $values->grantedAmount; } foreach ($rows as $key => $values) { if (CRM_Utils_Array::value('civicrm_grant_grant_report_received', $values)) { $grantReportsReceived++; } if (CRM_Utils_Array::value('civicrm_grant_grant_type_id', $values)) { $grantType = CRM_Utils_Array::value($values['civicrm_grant_grant_type_id'], $grantTypes); $grantStatistics['civicrm_grant_grant_type_id']['title'] = ts('By Grant Type'); self::getStatistics($grantStatistics['civicrm_grant_grant_type_id'], $grantType, $values, $awardedGrants, $awardedGrantsAmount); } if (array_key_exists('civicrm_world_region_name', $values)) { $region = CRM_Utils_Array::value('civicrm_world_region_name', $values); $region = $region ? $region : 'Unassigned'; $grantStatistics['civicrm_world_region_name']['title'] = ts('By Region'); self::getStatistics($grantStatistics['civicrm_world_region_name'], $region, $values, $awardedGrants, $awardedGrantsAmount); } if (array_key_exists('civicrm_address_country_id', $values)) { $country = CRM_Utils_Array::value($values['civicrm_address_country_id'], $countries); $country = $country ? $country : 'Unassigned'; $grantStatistics['civicrm_address_country_id']['title'] = ts('By Country'); self::getStatistics($grantStatistics['civicrm_address_country_id'], $country, $values, $awardedGrants, $awardedGrantsAmount); } if ($type = CRM_Utils_Array::value('civicrm_contact_contact_type', $values)) { $grantStatistics['civicrm_contact_contact_type']['title'] = ts('By Contact Type'); $title = "Total Number of {$type}(s)"; self::getStatistics($grantStatistics['civicrm_contact_contact_type'], $title, $values, $awardedGrants, $awardedGrantsAmount); } if (array_key_exists('civicrm_contact_gender_id', $values)) { $genderLabel = CRM_Utils_Array::value($values['civicrm_contact_gender_id'], $gender); $genderLabel = $genderLabel ? $genderLabel : 'Unassigned'; $grantStatistics['civicrm_contact_gender_id']['title'] = ts('By Gender'); self::getStatistics($grantStatistics['civicrm_contact_gender_id'], $genderLabel, $values, $awardedGrants, $awardedGrantsAmount); } foreach ($values as $customField => $customValue) { if (strstr($customField, 'civicrm_value_')) { $customFieldTitle = CRM_Utils_Array::value('title', $this->_columnHeaders[$customField]); $customGroupTitle = explode('_custom', strstr($customField, 'civicrm_value_')); $customGroupTitle = $this->_columns[$customGroupTitle[0]]['group_title']; $grantStatistics[$customGroupTitle]['title'] = ts('By %1', array(1 => $customGroupTitle)); $customData = $customValue ? FALSE : TRUE; self::getStatistics($grantStatistics[$customGroupTitle], $customFieldTitle, $values, $awardedGrants, $awardedGrantsAmount, $customData); } } } $totalStatistics['total_statistics'] = array('grants_received' => array('title' => ts('Grant Requests Received'), 'count' => $grantsReceived, 'amount' => $totalAmount), 'grants_awarded' => array('title' => ts('Grants Awarded'), 'count' => $awardedGrants, 'amount' => $amountGranted), 'grants_report_received' => array('title' => ts('Grant Reports Received'), 'count' => $grantReportsReceived)); $this->assign('totalStatistics', $totalStatistics); $this->assign('grantStatistics', $grantStatistics); if ($this->_outputMode == 'csv' || $this->_outputMode == 'pdf') { $row = array(); $this->_columnHeaders = array('civicrm_grant_total_grants' => array('title' => ts('Summary')), 'civicrm_grant_count' => array('title' => ts('Count')), 'civicrm_grant_amount' => array('title' => ts('Amount'))); foreach ($totalStatistics['total_statistics'] as $title => $value) { $row[] = array('civicrm_grant_total_grants' => $value['title'], 'civicrm_grant_count' => $value['count'], 'civicrm_grant_amount' => $value['amount']); } if (!empty($grantStatistics)) { foreach ($grantStatistics as $key => $value) { $row[] = array('civicrm_grant_total_grants' => $value['title'], 'civicrm_grant_count' => ts('Number of Grants') . ' (%)', 'civicrm_grant_amount' => ts('Total Amount') . ' (%)'); foreach ($value['value'] as $field => $values) { foreach ($values['currency'] as $currency => $amount) { $totalAmount[$currency] = $currency . $amount['value'] . "({$values['percentage']}%)"; } $totalAmt = implode(', ', $totalAmount); $count = (bool) CRM_Utils_Array::value('count', $values, 0) ? $values['count'] . " ({$values['percentage']}%)" : ''; $row[] = array('civicrm_grant_total_grants' => $field, 'civicrm_grant_count' => $count, 'civicrm_grant_amount' => $totalAmt); } } } $rows = $row; } }
/** * Get the list the export fields. * * @param int $selectAll * User preference while export. * @param array $ids * Contact ids. * @param array $params * Associated array of fields. * @param string $order * Order by clause. * @param array $fields * Associated array of fields. * @param array $moreReturnProperties * Additional return fields. * @param int $exportMode * Export mode. * @param string $componentClause * Component clause. * @param string $componentTable * Component table. * @param bool $mergeSameAddress * Merge records if they have same address. * @param bool $mergeSameHousehold * Merge records if they belong to the same household. * * @param array $exportParams * @param string $queryOperator * */ public static function exportComponents($selectAll, $ids, $params, $order = NULL, $fields = NULL, $moreReturnProperties = NULL, $exportMode = CRM_Export_Form_Select::CONTACT_EXPORT, $componentClause = NULL, $componentTable = NULL, $mergeSameAddress = FALSE, $mergeSameHousehold = FALSE, $exportParams = array(), $queryOperator = 'AND') { $headerRows = $returnProperties = array(); $primary = $paymentFields = $selectedPaymentFields = FALSE; $origFields = $fields; $relationField = NULL; $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'); $contactRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE, 'name', FALSE); $queryMode = self::getQueryMode($exportMode); if ($fields) { //construct return properties $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); $locationTypeFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'geo_code_1', 'geo_code_2', 'state_province', 'country', 'phone', 'email', 'im'); foreach ($fields as $key => $value) { $phoneTypeId = $imProviderId = NULL; $relationshipTypes = $fieldName = CRM_Utils_Array::value(1, $value); if (!$fieldName) { continue; } // get phoneType id and IM service provider id separately if ($fieldName == 'phone') { $phoneTypeId = CRM_Utils_Array::value(3, $value); } elseif ($fieldName == 'im') { $imProviderId = CRM_Utils_Array::value(3, $value); } if (array_key_exists($relationshipTypes, $contactRelationshipTypes)) { if (!empty($value[2])) { $relationField = CRM_Utils_Array::value(2, $value); if (trim(CRM_Utils_Array::value(3, $value))) { $relLocTypeId = CRM_Utils_Array::value(3, $value); } else { $relLocTypeId = 'Primary'; } if ($relationField == 'phone') { $relPhoneTypeId = CRM_Utils_Array::value(4, $value); } elseif ($relationField == 'im') { $relIMProviderId = CRM_Utils_Array::value(4, $value); } } elseif (!empty($value[4])) { $relationField = CRM_Utils_Array::value(4, $value); $relLocTypeId = CRM_Utils_Array::value(5, $value); if ($relationField == 'phone') { $relPhoneTypeId = CRM_Utils_Array::value(6, $value); } elseif ($relationField == 'im') { $relIMProviderId = CRM_Utils_Array::value(6, $value); } } } $contactType = CRM_Utils_Array::value(0, $value); $locTypeId = CRM_Utils_Array::value(2, $value); if ($relationField) { if (in_array($relationField, $locationTypeFields) && is_numeric($relLocTypeId)) { if ($relPhoneTypeId) { $returnProperties[$relationshipTypes]['location'][$locationTypes[$relLocTypeId]]['phone-' . $relPhoneTypeId] = 1; } elseif ($relIMProviderId) { $returnProperties[$relationshipTypes]['location'][$locationTypes[$relLocTypeId]]['im-' . $relIMProviderId] = 1; } else { $returnProperties[$relationshipTypes]['location'][$locationTypes[$relLocTypeId]][$relationField] = 1; } $relPhoneTypeId = $relIMProviderId = NULL; } else { $returnProperties[$relationshipTypes][$relationField] = 1; } } elseif (is_numeric($locTypeId)) { if ($phoneTypeId) { $returnProperties['location'][$locationTypes[$locTypeId]]['phone-' . $phoneTypeId] = 1; } elseif ($imProviderId) { $returnProperties['location'][$locationTypes[$locTypeId]]['im-' . $imProviderId] = 1; } else { $returnProperties['location'][$locationTypes[$locTypeId]][$fieldName] = 1; } } else { //hack to fix component fields //revert mix of event_id and title if ($fieldName == 'event_id') { $returnProperties['event_id'] = 1; } elseif ($exportMode == CRM_Export_Form_Select::EVENT_EXPORT && array_key_exists($fieldName, self::componentPaymentFields())) { $selectedPaymentFields = TRUE; $paymentTableId = 'participant_id'; $returnProperties[$fieldName] = 1; } else { $returnProperties[$fieldName] = 1; } } } $returnProperties[self::defaultReturnProperty($exportMode)] = 1; } else { $primary = TRUE; $fields = CRM_Contact_BAO_Contact::exportableFields('All', TRUE, TRUE); foreach ($fields as $key => $var) { if ($key && substr($key, 0, 6) != 'custom') { //for CRM=952 $returnProperties[$key] = 1; } } if ($primary) { $returnProperties['location_type'] = 1; $returnProperties['im_provider'] = 1; $returnProperties['phone_type_id'] = 1; $returnProperties['provider_id'] = 1; $returnProperties['current_employer'] = 1; } $extraReturnProperties = array(); $paymentFields = FALSE; switch ($queryMode) { case CRM_Contact_BAO_Query::MODE_EVENT: $paymentFields = TRUE; $paymentTableId = 'participant_id'; break; case CRM_Contact_BAO_Query::MODE_MEMBER: $paymentFields = TRUE; $paymentTableId = 'membership_id'; break; case CRM_Contact_BAO_Query::MODE_PLEDGE: $extraReturnProperties = CRM_Pledge_BAO_Query::extraReturnProperties($queryMode); $paymentFields = TRUE; $paymentTableId = 'pledge_payment_id'; break; case CRM_Contact_BAO_Query::MODE_CASE: $extraReturnProperties = CRM_Case_BAO_Query::extraReturnProperties($queryMode); break; } if ($queryMode != CRM_Contact_BAO_Query::MODE_CONTACTS) { $componentReturnProperties = CRM_Contact_BAO_Query::defaultReturnProperties($queryMode); if ($queryMode == CRM_Contact_BAO_Query::MODE_CONTRIBUTE) { // soft credit columns are not automatically populated, because contribution search doesn't require them by default $componentReturnProperties = array_merge($componentReturnProperties, CRM_Contribute_BAO_Query::softCreditReturnProperties(TRUE)); } $returnProperties = array_merge($returnProperties, $componentReturnProperties); if (!empty($extraReturnProperties)) { $returnProperties = array_merge($returnProperties, $extraReturnProperties); } // unset non exportable fields for components $nonExpoFields = array('groups', 'tags', 'notes', 'contribution_status_id', 'pledge_status_id', 'pledge_payment_status_id'); foreach ($nonExpoFields as $value) { unset($returnProperties[$value]); } } } if ($mergeSameAddress) { //make sure the addressee fields are selected //while using merge same address feature $returnProperties['addressee'] = 1; $returnProperties['postal_greeting'] = 1; $returnProperties['email_greeting'] = 1; $returnProperties['street_name'] = 1; $returnProperties['household_name'] = 1; $returnProperties['street_address'] = 1; $returnProperties['city'] = 1; $returnProperties['state_province'] = 1; // some columns are required for assistance incase they are not already present $exportParams['merge_same_address']['temp_columns'] = array(); $tempColumns = array('id', 'master_id', 'state_province_id', 'postal_greeting_id', 'addressee_id'); foreach ($tempColumns as $column) { if (!array_key_exists($column, $returnProperties)) { $returnProperties[$column] = 1; $column = $column == 'id' ? 'civicrm_primary_id' : $column; $exportParams['merge_same_address']['temp_columns'][$column] = 1; } } } if (!$selectAll && $componentTable && !empty($exportParams['additional_group'])) { // If an Additional Group is selected, then all contacts in that group are // added to the export set (filtering out duplicates). $query = "\nINSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_contact gc WHERE gc.group_id = {$exportParams['additional_group']} ON DUPLICATE KEY UPDATE {$componentTable}.contact_id = gc.contact_id"; CRM_Core_DAO::executeQuery($query); } if ($moreReturnProperties) { // fix for CRM-7066 if (!empty($moreReturnProperties['group'])) { unset($moreReturnProperties['group']); $moreReturnProperties['groups'] = 1; } $returnProperties = array_merge($returnProperties, $moreReturnProperties); } $exportParams['postal_mailing_export']['temp_columns'] = array(); if ($exportParams['exportOption'] == 2 && isset($exportParams['postal_mailing_export']) && CRM_Utils_Array::value('postal_mailing_export', $exportParams['postal_mailing_export']) == 1) { $postalColumns = array('is_deceased', 'do_not_mail', 'street_address', 'supplemental_address_1'); foreach ($postalColumns as $column) { if (!array_key_exists($column, $returnProperties)) { $returnProperties[$column] = 1; $exportParams['postal_mailing_export']['temp_columns'][$column] = 1; } } } // rectify params to what proximity search expects if there is a value for prox_distance // CRM-7021 if (!empty($params)) { CRM_Contact_BAO_ProximityQuery::fixInputParams($params); } $query = new CRM_Contact_BAO_Query($params, $returnProperties, NULL, FALSE, FALSE, $queryMode, FALSE, TRUE, TRUE, NULL, $queryOperator); //sort by state //CRM-15301 $query->_sort = $order; list($select, $from, $where, $having) = $query->query(); if ($mergeSameHousehold == 1) { if (!$returnProperties['id']) { $returnProperties['id'] = 1; } //also merge Head of Household $relationKeyMOH = CRM_Utils_Array::key('Household Member of', $contactRelationshipTypes); $relationKeyHOH = CRM_Utils_Array::key('Head of Household for', $contactRelationshipTypes); foreach ($returnProperties as $key => $value) { if (!array_key_exists($key, $contactRelationshipTypes)) { $returnProperties[$relationKeyMOH][$key] = $value; $returnProperties[$relationKeyHOH][$key] = $value; } } unset($returnProperties[$relationKeyMOH]['location_type']); unset($returnProperties[$relationKeyMOH]['im_provider']); unset($returnProperties[$relationKeyHOH]['location_type']); unset($returnProperties[$relationKeyHOH]['im_provider']); } $allRelContactArray = $relationQuery = array(); foreach ($contactRelationshipTypes as $rel => $dnt) { if ($relationReturnProperties = CRM_Utils_Array::value($rel, $returnProperties)) { $allRelContactArray[$rel] = array(); // build Query for each relationship $relationQuery[$rel] = new CRM_Contact_BAO_Query(NULL, $relationReturnProperties, NULL, FALSE, FALSE, $queryMode); list($relationSelect, $relationFrom, $relationWhere, $relationHaving) = $relationQuery[$rel]->query(); list($id, $direction) = explode('_', $rel, 2); // identify the relationship direction $contactA = 'contact_id_a'; $contactB = 'contact_id_b'; if ($direction == 'b_a') { $contactA = 'contact_id_b'; $contactB = 'contact_id_a'; } if ($exportMode == CRM_Export_Form_Select::CONTACT_EXPORT) { $relIDs = $ids; } elseif ($exportMode == CRM_Export_Form_Select::ACTIVITY_EXPORT) { $sourceID = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_ActivityContact', 'record_type_id', 'Activity Source'); $query = "SELECT contact_id FROM civicrm_activity_contact\n WHERE activity_id IN ( " . implode(',', $ids) . ") AND\n record_type_id = {$sourceID}"; $dao = CRM_Core_DAO::executeQuery($query); while ($dao->fetch()) { $relIDs[] = $dao->contact_id; } } else { $component = self::exportComponent($exportMode); if ($exportMode == CRM_Export_Form_Select::CASE_EXPORT) { $relIDs = CRM_Case_BAO_Case::retrieveContactIdsByCaseId($ids); } else { $relIDs = CRM_Core_DAO::getContactIDsFromComponent($ids, $component); } } $relationshipJoin = $relationshipClause = ''; if (!$selectAll && $componentTable) { $relationshipJoin = " INNER JOIN {$componentTable} ctTable ON ctTable.contact_id = {$contactA}"; } elseif (!empty($relIDs)) { $relID = implode(',', $relIDs); $relationshipClause = " AND crel.{$contactA} IN ( {$relID} )"; } $relationFrom = " {$relationFrom}\n INNER JOIN civicrm_relationship crel ON crel.{$contactB} = contact_a.id AND crel.relationship_type_id = {$id}\n {$relationshipJoin} "; //check for active relationship status only $today = date('Ymd'); $relationActive = " AND (crel.is_active = 1 AND ( crel.end_date is NULL OR crel.end_date >= {$today} ) )"; $relationWhere = " WHERE contact_a.is_deleted = 0 {$relationshipClause} {$relationActive}"; $relationGroupBy = " GROUP BY crel.{$contactA}"; $relationSelect = "{$relationSelect}, {$contactA} as refContact "; $relationQueryString = "{$relationSelect} {$relationFrom} {$relationWhere} {$relationHaving} {$relationGroupBy}"; $allRelContactDAO = CRM_Core_DAO::executeQuery($relationQueryString); while ($allRelContactDAO->fetch()) { //FIX Me: Migrate this to table rather than array // build the array of all related contacts $allRelContactArray[$rel][$allRelContactDAO->refContact] = clone $allRelContactDAO; } $allRelContactDAO->free(); } } // make sure the groups stuff is included only if specifically specified // by the fields param (CRM-1969), else we limit the contacts outputted to only // ones that are part of a group if (!empty($returnProperties['groups'])) { $oldClause = "( contact_a.id = civicrm_group_contact.contact_id )"; $newClause = " ( {$oldClause} AND ( civicrm_group_contact.status = 'Added' OR civicrm_group_contact.status IS NULL ) )"; // total hack for export, CRM-3618 $from = str_replace($oldClause, $newClause, $from); } if (!$selectAll && $componentTable) { $from .= " INNER JOIN {$componentTable} ctTable ON ctTable.contact_id = contact_a.id "; } elseif ($componentClause) { if (empty($where)) { $where = "WHERE {$componentClause}"; } else { $where .= " AND {$componentClause}"; } } // CRM-13982 - check if is deleted $excludeTrashed = TRUE; foreach ($params as $value) { if ($value[0] == 'contact_is_deleted') { $excludeTrashed = FALSE; } } $trashClause = $excludeTrashed ? "contact_a.is_deleted != 1" : "( 1 )"; if (empty($where)) { $where = "WHERE {$trashClause}"; } else { $where .= " AND {$trashClause}"; } $queryString = "{$select} {$from} {$where} {$having}"; $groupBy = ""; if (!empty($returnProperties['tags']) || !empty($returnProperties['groups']) || CRM_Utils_Array::value('notes', $returnProperties) || $queryMode & CRM_Contact_BAO_Query::MODE_CONTACTS && $query->_useGroupBy) { $groupBy = " GROUP BY contact_a.id"; } switch ($exportMode) { case CRM_Export_Form_Select::CONTRIBUTE_EXPORT: $groupBy = 'GROUP BY civicrm_contribution.id'; if (CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled()) { // especial group by when soft credit columns are included $groupBy = 'GROUP BY contribution_search_scredit_combined.id, contribution_search_scredit_combined.scredit_id'; } break; case CRM_Export_Form_Select::EVENT_EXPORT: $groupBy = 'GROUP BY civicrm_participant.id'; break; case CRM_Export_Form_Select::MEMBER_EXPORT: $groupBy = " GROUP BY civicrm_membership.id"; break; } if ($queryMode & CRM_Contact_BAO_Query::MODE_ACTIVITY) { $groupBy = " GROUP BY civicrm_activity.id "; } $queryString .= $groupBy; // always add contact_a.id to the ORDER clause // so the order is deterministic //CRM-15301 if (strpos('contact_a.id', $order) === FALSE) { $order .= ", contact_a.id"; } if ($order) { list($field, $dir) = explode(' ', $order, 2); $field = trim($field); if (!empty($returnProperties[$field])) { //CRM-15301 $queryString .= " ORDER BY {$order}"; } } $multipleSelectFields = array('preferred_communication_method' => 1); $addPaymentHeader = FALSE; $paymentDetails = array(); if ($paymentFields || $selectedPaymentFields) { // get payment related in for event and members $paymentDetails = CRM_Contribute_BAO_Contribution::getContributionDetails($exportMode, $ids); //get all payment headers. // If we haven't selected specific payment fields, load in all the // payment headers. if (!$selectedPaymentFields) { $paymentHeaders = self::componentPaymentFields(); if (!empty($paymentDetails)) { $addPaymentHeader = TRUE; } } else { $paymentHeaders = array(); } $nullContributionDetails = array_fill_keys(array_keys($paymentHeaders), NULL); } $componentDetails = $headerRows = $sqlColumns = array(); $setHeader = TRUE; $rowCount = self::EXPORT_ROW_COUNT; $offset = 0; // we write to temp table often to avoid using too much memory $tempRowCount = 100; $count = -1; // for CRM-3157 purposes $i18n = CRM_Core_I18n::singleton(); $outputColumns = array(); //@todo - it would be clearer to start defining output columns earlier in this function rather than stick with return properties until this point // as the array is not actually 'returnProperties' after the sql query is formed - making the alterations to it confusing foreach ($returnProperties as $key => $value) { $outputColumns[$key] = $value; } while (1) { $limitQuery = "{$queryString} LIMIT {$offset}, {$rowCount}"; $dao = CRM_Core_DAO::executeQuery($limitQuery); if ($dao->N <= 0) { break; } while ($dao->fetch()) { $count++; $row = array(); //convert the pseudo constants // CRM-14398 there is problem in this architecture that is not easily solved. For now we are using the cloned // temporary iterationDAO object to get around it. // the issue is that the convertToPseudoNames function is adding additional properties (e.g for campaign) to the DAO object // these additional properties are NOT reset when the $dao cycles through the while loop // nor are they overwritten as they are not in the loop // the convertToPseudoNames will not adequately over-write them either as it doesn't 'kick-in' unless the // relevant property is set. // It may be that a long-term fix could be introduced there - however, it's probably necessary to figure out how to test the // export class before tackling a better architectural fix $iterationDAO = clone $dao; $query->convertToPseudoNames($iterationDAO); //first loop through output columns so that we return what is required, and in same order. $relationshipField = 0; foreach ($outputColumns as $field => $value) { //we should set header only once if ($setHeader) { $sqlDone = FALSE; // Split campaign into 2 fields for id and title if (substr($field, -14) == 'campaign_title') { $headerRows[] = ts('Campaign Title'); } elseif (substr($field, -11) == 'campaign_id') { $headerRows[] = ts('Campaign ID'); } elseif (isset($query->_fields[$field]['title'])) { $headerRows[] = $query->_fields[$field]['title']; } elseif ($field == 'phone_type_id') { $headerRows[] = ts('Phone Type'); } elseif ($field == 'provider_id') { $headerRows[] = ts('IM Service Provider'); } elseif (is_array($value) && $field == 'location') { // fix header for location type case foreach ($value as $ltype => $val) { foreach (array_keys($val) as $fld) { $type = explode('-', $fld); $hdr = "{$ltype}-" . $query->_fields[$type[0]]['title']; if (!empty($type[1])) { if (CRM_Utils_Array::value(0, $type) == 'phone') { $hdr .= "-" . CRM_Utils_Array::value($type[1], $phoneTypes); } elseif (CRM_Utils_Array::value(0, $type) == 'im') { $hdr .= "-" . CRM_Utils_Array::value($type[1], $imProviders); } } $headerRows[] = $hdr; self::sqlColumnDefn($query, $sqlColumns, $hdr); } $sqlDone = TRUE; } } elseif (substr($field, 0, 5) == 'case_') { if ($query->_fields['case'][$field]['title']) { $headerRows[] = $query->_fields['case'][$field]['title']; } elseif ($query->_fields['activity'][$field]['title']) { $headerRows[] = $query->_fields['activity'][$field]['title']; } } elseif (array_key_exists($field, $contactRelationshipTypes)) { $relName = $field; foreach ($value as $relationField => $relationValue) { // below block is same as primary block (duplicate) if (isset($relationQuery[$field]->_fields[$relationField]['title'])) { if ($relationQuery[$field]->_fields[$relationField]['name'] == 'name') { $headerName = $field . '-' . $relationField; } else { if ($relationField == 'current_employer') { $headerName = $field . '-' . 'current_employer'; } else { $headerName = $field . '-' . $relationQuery[$field]->_fields[$relationField]['name']; } } $headerRows[] = $headerName; self::sqlColumnDefn($query, $sqlColumns, $headerName); } elseif ($relationField == 'phone_type_id') { $headerName = $field . '-' . 'Phone Type'; $headerRows[] = $headerName; self::sqlColumnDefn($query, $sqlColumns, $headerName); } elseif ($relationField == 'provider_id') { $headerName = $field . '-' . 'Im Service Provider'; $headerRows[] = $headerName; self::sqlColumnDefn($query, $sqlColumns, $headerName); } elseif ($relationField == 'state_province_id') { $headerName = $field . '-' . 'state_province_id'; $headerRows[] = $headerName; self::sqlColumnDefn($query, $sqlColumns, $headerName); } elseif (is_array($relationValue) && $relationField == 'location') { // fix header for location type case foreach ($relationValue as $ltype => $val) { foreach (array_keys($val) as $fld) { $type = explode('-', $fld); $hdr = "{$ltype}-" . $relationQuery[$field]->_fields[$type[0]]['title']; if (!empty($type[1])) { if (CRM_Utils_Array::value(0, $type) == 'phone') { $hdr .= "-" . CRM_Utils_Array::value($type[1], $phoneTypes); } elseif (CRM_Utils_Array::value(0, $type) == 'im') { $hdr .= "-" . CRM_Utils_Array::value($type[1], $imProviders); } } $headerName = $field . '-' . $hdr; $headerRows[] = $headerName; self::sqlColumnDefn($query, $sqlColumns, $headerName); } } } } } elseif ($selectedPaymentFields && array_key_exists($field, self::componentPaymentFields())) { $headerRows[] = CRM_Utils_Array::value($field, self::componentPaymentFields()); } else { $headerRows[] = $field; } if (!$sqlDone) { self::sqlColumnDefn($query, $sqlColumns, $field); } } // add im_provider to $dao object if ($field == 'im_provider' && property_exists($iterationDAO, 'provider_id')) { $iterationDAO->im_provider = $iterationDAO->provider_id; } //build row values (data) $fieldValue = NULL; if (property_exists($iterationDAO, $field)) { $fieldValue = $iterationDAO->{$field}; // to get phone type from phone type id if ($field == 'phone_type_id' && isset($phoneTypes[$fieldValue])) { $fieldValue = $phoneTypes[$fieldValue]; } elseif ($field == 'provider_id' || $field == 'im_provider') { $fieldValue = CRM_Utils_Array::value($fieldValue, $imProviders); } elseif ($field == 'master_id') { $masterAddressId = NULL; if (isset($iterationDAO->master_id)) { $masterAddressId = $iterationDAO->master_id; } // get display name of contact that address is shared. $fieldValue = CRM_Contact_BAO_Contact::getMasterDisplayName($masterAddressId, $iterationDAO->contact_id); } } if ($field == 'id') { $row[$field] = $iterationDAO->contact_id; // special case for calculated field } elseif ($field == 'source_contact_id') { $row[$field] = $iterationDAO->contact_id; } elseif ($field == 'pledge_balance_amount') { $row[$field] = $iterationDAO->pledge_amount - $iterationDAO->pledge_total_paid; // special case for calculated field } elseif ($field == 'pledge_next_pay_amount') { $row[$field] = $iterationDAO->pledge_next_pay_amount + $iterationDAO->pledge_outstanding_amount; } elseif (is_array($value) && $field == 'location') { // fix header for location type case foreach ($value as $ltype => $val) { foreach (array_keys($val) as $fld) { $type = explode('-', $fld); $fldValue = "{$ltype}-" . $type[0]; // CRM-14076 - fix label to work as the query object expects // FIXME: We should not be using labels as keys! $daoField = CRM_Utils_String::munge($ltype) . '-' . $type[0]; if (!empty($type[1])) { $fldValue .= "-" . $type[1]; $daoField .= "-" . $type[1]; } // CRM-3157: localise country, region (both have ‘country’ context) and state_province (‘province’ context) switch ($fld) { case 'country': case 'world_region': $row[$fldValue] = $i18n->crm_translate($iterationDAO->{$daoField}, array('context' => 'country')); break; case 'state_province': $row[$fldValue] = $i18n->crm_translate($iterationDAO->{$daoField}, array('context' => 'province')); break; case 'im_provider': $imFieldvalue = $daoField . "-provider_id"; $row[$fldValue] = CRM_Utils_Array::value($iterationDAO->{$imFieldvalue}, $imProviders); break; default: $row[$fldValue] = $iterationDAO->{$daoField}; break; } } } } elseif (array_key_exists($field, $contactRelationshipTypes)) { $relDAO = CRM_Utils_Array::value($iterationDAO->contact_id, $allRelContactArray[$field]); $relationQuery[$field]->convertToPseudoNames($relDAO); foreach ($value as $relationField => $relationValue) { if (is_object($relDAO) && property_exists($relDAO, $relationField)) { $fieldValue = $relDAO->{$relationField}; if ($relationField == 'phone_type_id') { $fieldValue = $phoneTypes[$relationValue]; } elseif ($relationField == 'provider_id') { $fieldValue = CRM_Utils_Array::value($relationValue, $imProviders); } elseif (is_object($relDAO) && in_array($relationField, array('email_greeting', 'postal_greeting', 'addressee'))) { //special case for greeting replacement $fldValue = "{$relationField}_display"; $fieldValue = $relDAO->{$fldValue}; } } elseif (is_object($relDAO) && $relationField == 'state_province') { $fieldValue = CRM_Core_PseudoConstant::stateProvince($relDAO->state_province_id); } elseif (is_object($relDAO) && $relationField == 'country') { $fieldValue = CRM_Core_PseudoConstant::country($relDAO->country_id); } else { $fieldValue = ''; } $field = $field . '_'; if (array_key_exists($relationField, $multipleSelectFields)) { $param = array($relationField => $fieldValue); $names = array($relationField => array('newName' => $relationField, 'groupName' => $relationField)); CRM_Core_OptionGroup::lookupValues($param, $names, FALSE); $fieldValue = $param[$relationField]; } if (is_object($relDAO) && $relationField == 'id') { $row[$field . $relationField] = $relDAO->contact_id; } elseif (is_array($relationValue) && $relationField == 'location') { foreach ($relationValue as $ltype => $val) { foreach (array_keys($val) as $fld) { $type = explode('-', $fld); $fldValue = "{$ltype}-" . $type[0]; if (!empty($type[1])) { $fldValue .= "-" . $type[1]; } // CRM-3157: localise country, region (both have ‘country’ context) // and state_province (‘province’ context) switch (TRUE) { case !is_object($relDAO): $row[$field . '_' . $fldValue] = ''; break; case in_array('country', $type): case in_array('world_region', $type): $row[$field . '_' . $fldValue] = $i18n->crm_translate($relDAO->{$fldValue}, array('context' => 'country')); break; case in_array('state_province', $type): $row[$field . '_' . $fldValue] = $i18n->crm_translate($relDAO->{$fldValue}, array('context' => 'province')); break; default: $row[$field . '_' . $fldValue] = $relDAO->{$fldValue}; break; } } } } elseif (isset($fieldValue) && $fieldValue != '') { //check for custom data if ($cfID = CRM_Core_BAO_CustomField::getKeyID($relationField)) { $row[$field . $relationField] = CRM_Core_BAO_CustomField::getDisplayValue($fieldValue, $cfID, $relationQuery[$field]->_options); } else { //normal relationship fields // CRM-3157: localise country, region (both have ‘country’ context) and state_province (‘province’ context) switch ($relationField) { case 'country': case 'world_region': $row[$field . $relationField] = $i18n->crm_translate($fieldValue, array('context' => 'country')); break; case 'state_province': $row[$field . $relationField] = $i18n->crm_translate($fieldValue, array('context' => 'province')); break; default: $row[$field . $relationField] = $fieldValue; break; } } } else { // if relation field is empty or null $row[$field . $relationField] = ''; } } } elseif (isset($fieldValue) && $fieldValue != '') { //check for custom data if ($cfID = CRM_Core_BAO_CustomField::getKeyID($field)) { $row[$field] = CRM_Core_BAO_CustomField::getDisplayValue($fieldValue, $cfID, $query->_options); } elseif (array_key_exists($field, $multipleSelectFields)) { //option group fixes $paramsNew = array($field => $fieldValue); if ($field == 'test_tutoring') { $name = array($field => array('newName' => $field, 'groupName' => 'test')); // for readers group } elseif (substr($field, 0, 4) == 'cmr_') { $name = array($field => array('newName' => $field, 'groupName' => substr($field, 0, -3))); } else { $name = array($field => array('newName' => $field, 'groupName' => $field)); } CRM_Core_OptionGroup::lookupValues($paramsNew, $name, FALSE); $row[$field] = $paramsNew[$field]; } elseif (in_array($field, array('email_greeting', 'postal_greeting', 'addressee'))) { //special case for greeting replacement $fldValue = "{$field}_display"; $row[$field] = $iterationDAO->{$fldValue}; } else { //normal fields with a touch of CRM-3157 switch ($field) { case 'country': case 'world_region': $row[$field] = $i18n->crm_translate($fieldValue, array('context' => 'country')); break; case 'state_province': $row[$field] = $i18n->crm_translate($fieldValue, array('context' => 'province')); break; case 'gender': case 'preferred_communication_method': case 'preferred_mail_format': case 'communication_style': $row[$field] = $i18n->crm_translate($fieldValue); break; default: $row[$field] = $fieldValue; break; } } } elseif ($selectedPaymentFields && array_key_exists($field, self::componentPaymentFields())) { $paymentData = CRM_Utils_Array::value($iterationDAO->{$paymentTableId}, $paymentDetails); $payFieldMapper = array('componentPaymentField_total_amount' => 'total_amount', 'componentPaymentField_contribution_status' => 'contribution_status', 'componentPaymentField_payment_instrument' => 'pay_instru', 'componentPaymentField_transaction_id' => 'trxn_id', 'componentPaymentField_received_date' => 'receive_date'); $row[$field] = CRM_Utils_Array::value($payFieldMapper[$field], $paymentData, ''); } else { // if field is empty or null $row[$field] = ''; } } // add payment headers if required if ($addPaymentHeader && $paymentFields) { $headerRows = array_merge($headerRows, $paymentHeaders); foreach (array_keys($paymentHeaders) as $paymentHdr) { self::sqlColumnDefn($query, $sqlColumns, $paymentHdr); } } if ($setHeader) { $exportTempTable = self::createTempTable($sqlColumns); } //build header only once $setHeader = FALSE; // If specific payment fields have been selected for export, payment // data will already be in $row. Otherwise, add payment related // information, if appropriate. if ($addPaymentHeader) { if (!$selectedPaymentFields) { if ($paymentFields) { $paymentData = CRM_Utils_Array::value($row[$paymentTableId], $paymentDetails); if (!is_array($paymentData) || empty($paymentData)) { $paymentData = $nullContributionDetails; } $row = array_merge($row, $paymentData); } elseif (!empty($paymentDetails)) { $row = array_merge($row, $nullContributionDetails); } } } //remove organization name for individuals if it is set for current employer if (!empty($row['contact_type']) && $row['contact_type'] == 'Individual' && array_key_exists('organization_name', $row)) { $row['organization_name'] = ''; } // add component info // write the row to a file $componentDetails[] = $row; // output every $tempRowCount rows if ($count % $tempRowCount == 0) { self::writeDetailsToTable($exportTempTable, $componentDetails, $sqlColumns); $componentDetails = array(); } } $dao->free(); $offset += $rowCount; } if ($exportTempTable) { self::writeDetailsToTable($exportTempTable, $componentDetails, $sqlColumns); // do merge same address and merge same household processing if ($mergeSameAddress) { self::mergeSameAddress($exportTempTable, $headerRows, $sqlColumns, $exportParams); } // merge the records if they have corresponding households if ($mergeSameHousehold) { self::mergeSameHousehold($exportTempTable, $headerRows, $sqlColumns, $relationKeyMOH); self::mergeSameHousehold($exportTempTable, $headerRows, $sqlColumns, $relationKeyHOH); } // fix the headers for rows with relationship type if (!empty($relName)) { self::manipulateHeaderRows($headerRows, $contactRelationshipTypes); } // if postalMailing option is checked, exclude contacts who are deceased, have // "Do not mail" privacy setting, or have no street address if (isset($exportParams['postal_mailing_export']['postal_mailing_export']) && $exportParams['postal_mailing_export']['postal_mailing_export'] == 1) { self::postalMailingFormat($exportTempTable, $headerRows, $sqlColumns, $exportMode); } // call export hook CRM_Utils_Hook::export($exportTempTable, $headerRows, $sqlColumns, $exportMode); // now write the CSV file self::writeCSVFromTable($exportTempTable, $headerRows, $sqlColumns, $exportMode); // delete the export temp table and component table $sql = "DROP TABLE IF EXISTS {$exportTempTable}"; CRM_Core_DAO::executeQuery($sql); CRM_Utils_System::civiExit(); } else { CRM_Core_Error::fatal(ts('No records to export')); } }
function alterCountryID($value, &$row, $selectedfield, $criteriaFieldName) { $url = CRM_Utils_System::url(CRM_Utils_System::currentPath(), "reset=1&force=1&{$criteriaFieldName}_op=in&{$criteriaFieldName}_value={$value}", $this->_absoluteUrl); $row[$selectedfield . '_link'] = $url; $row[$selectedfield . '_hover'] = ts("%1 for this country.", array(1 => $value)); $countries = CRM_Core_PseudoConstant::country($value, FALSE); if (!is_array($countries)) { return $countries; } }