function __construct() { $this->case_statuses = CRM_Case_PseudoConstant::caseStatus(); $this->case_types = CRM_Case_PseudoConstant::caseType(); $rels = CRM_Core_PseudoConstant::relationshipType(); foreach ($rels as $relid => $v) { $this->rel_types[$relid] = $v['label_b_a']; } $this->_columns = array('civicrm_case' => array('dao' => 'CRM_Case_DAO_Case', 'fields' => array('id' => array('title' => ts('Case ID'), 'no_display' => true, 'required' => true), 'subject' => array('title' => ts('Subject'), 'required' => true), 'start_date' => array('title' => ts('Start Date')), 'end_date' => array('title' => ts('End Date')), 'status_id' => array('title' => ts('Case Status')), 'case_type_id' => array('title' => ts('Case Type'))), 'filters' => array('start_date' => array('title' => ts('Start Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE), 'end_date' => array('title' => ts('End Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE), 'status_id' => array('title' => ts('Case Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->case_statuses), 'case_type_id' => array('title' => ts('Case Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->case_types))), 'civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('display_name' => array('title' => ts('Client Name'), 'required' => true), 'id' => array('no_display' => true, 'required' => true)), 'filters' => array('display_name' => array('title' => ts('Client Name')))), 'civicrm_relationship' => array('dao' => 'CRM_Contact_DAO_Relationship', 'fields' => array('relationship_type_id' => array('title' => ts('Case Role'))), 'filters' => array('relationship_type_id' => array('title' => ts('Case Role'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->rel_types))), 'civicrm_relationship_type' => array('dao' => 'CRM_Contact_DAO_RelationshipType'), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email' => array('title' => ts('Email'), 'no_repeat' => true)), 'grouping' => 'contact-fields'), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => array('title' => ts('Phone'), 'no_repeat' => true)), 'grouping' => 'contact-fields'), 'civicrm_address' => array('dao' => 'CRM_Core_DAO_Address', 'fields' => array('street_address' => null, 'state_province_id' => array('title' => ts('State/Province')), 'country_id' => array('title' => ts('Country'))), 'grouping' => 'contact-fields', 'filters' => array('country_id' => array('title' => ts('Country'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::country()), 'state_province_id' => array('title' => ts('State/Province'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::stateProvince()))), 'civicrm_worldregion' => array('dao' => 'CRM_Core_DAO_Worldregion', 'filters' => array('worldregion_id' => array('name' => 'id', 'title' => ts('WorldRegion'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::worldRegion()))), 'civicrm_country' => array('dao' => 'CRM_Core_DAO_Country'), 'civicrm_activity' => array('dao' => 'CRM_Activity_DAO_Activity', 'fields' => array('activity_subject' => array('name' => 'subject', 'title' => ts('Activity Subject'), 'no_display' => true)), 'filters' => array('activity_date_time' => array('title' => ts('Last Action Date'), 'operatorType' => CRM_Report_Form::OP_DATE))), 'civicrm_case_contact' => array('dao' => 'CRM_Case_DAO_CaseContact')); $this->_options = array('my_cases' => array('title' => ts('My Cases'), 'type' => 'checkbox')); parent::__construct(); }
/** * */ function __construct() { $this->case_statuses = CRM_Case_PseudoConstant::caseStatus(); $this->case_types = CRM_Case_PseudoConstant::caseType(); $rels = CRM_Core_PseudoConstant::relationshipType(); foreach ($rels as $relid => $v) { $this->rel_types[$relid] = $v['label_b_a']; } $this->deleted_labels = array('' => ts('- select -'), 0 => ts('No'), 1 => ts('Yes')); $this->caseActivityTypes = array(); foreach (CRM_Case_PseudoConstant::caseActivityType() as $typeDetail) { $this->caseActivityTypes[$typeDetail['id']] = $typeDetail['label']; } $this->_columns = array('civicrm_case' => array('dao' => 'CRM_Case_DAO_Case', 'fields' => array('id' => array('title' => ts('Case ID'), 'no_display' => TRUE, 'required' => TRUE), 'subject' => array('title' => ts('Subject'), 'required' => TRUE), 'start_date' => array('title' => ts('Start Date'), 'type' => CRM_Utils_Type::T_DATE), 'end_date' => array('title' => ts('End Date'), 'type' => CRM_Utils_Type::T_DATE), 'status_id' => array('title' => ts('Case Status')), 'case_type_id' => array('title' => ts('Case Type')), 'is_deleted' => array('title' => ts('Deleted?'), 'default' => FALSE, 'type' => CRM_Utils_Type::T_INT)), 'filters' => array('start_date' => array('title' => ts('Start Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE), 'end_date' => array('title' => ts('End Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE), 'status_id' => array('title' => ts('Case Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->case_statuses), 'case_type_id' => array('title' => ts('Case Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->case_types), 'is_deleted' => array('title' => ts('Deleted?'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_SELECT, 'options' => $this->deleted_labels, 'default' => 0))), 'civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('client_sort_name' => array('name' => 'sort_name', 'title' => ts('Client Name'), 'required' => TRUE), 'id' => array('no_display' => TRUE, 'required' => TRUE)), 'filters' => array('sort_name' => array('title' => ts('Client Name')))), 'civicrm_relationship' => array('dao' => 'CRM_Contact_DAO_Relationship', 'fields' => array('case_role' => array('name' => 'relationship_type_id', 'title' => ts('Case Role(s)'))), 'filters' => array('case_role' => array('name' => 'relationship_type_id', 'title' => ts('Case Role(s)'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->rel_types))), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email' => array('title' => ts('Email'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => array('title' => ts('Phone'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_address' => array('dao' => 'CRM_Core_DAO_Address', 'fields' => array('street_address' => NULL, 'state_province_id' => array('title' => ts('State/Province')), 'country_id' => array('title' => ts('Country'))), 'grouping' => 'contact-fields', 'filters' => array('country_id' => array('title' => ts('Country'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::country()), 'state_province_id' => array('title' => ts('State/Province'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::stateProvince()))), 'civicrm_worldregion' => array('dao' => 'CRM_Core_DAO_Worldregion', 'filters' => array('worldregion_id' => array('name' => 'id', 'title' => ts('WorldRegion'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::worldRegion()))), 'civicrm_country' => array('dao' => 'CRM_Core_DAO_Country'), 'civicrm_activity_last' => array('dao' => 'CRM_Activity_DAO_Activity', 'filters' => array('last_activity_date_time' => array('name' => 'activity_date_time', 'title' => ts('Last Action Date'), 'operatorType' => CRM_Report_Form::OP_DATE)), 'alias' => 'civireport_activity_last'), 'civicrm_activity_last_completed' => array('dao' => 'CRM_Activity_DAO_Activity', 'fields' => array('last_completed_activity_subject' => array('name' => 'subject', 'title' => ts('Subject of the last completed activity in the case')), 'last_completed_activity_type' => array('name' => 'activity_type_id', 'title' => ts('Activity type of the last completed activity'))))); $this->_options = array('my_cases' => array('title' => ts('My Cases'), 'type' => 'checkbox')); parent::__construct(); }
/** * returns all the rows in the given offset and rowCount * * @param enum $action the action being performed * @param int $offset the row number to start from * @param int $rowCount the number of rows to return * @param string $sort the sql string that describes the sort order * @param enum $output what should the result set include (web/email/csv) * * @return int the total number of rows for this action */ function &getRows($action, $offset, $rowCount, $sort, $output = NULL) { $config = CRM_Core_Config::singleton(); if (($output == CRM_Core_Selector_Controller::EXPORT || $output == CRM_Core_Selector_Controller::SCREEN) && $this->_formValues['radio_ts'] == 'ts_sel') { $includeContactIds = TRUE; } else { $includeContactIds = FALSE; } // note the formvalues were given by CRM_Contact_Form_Search to us // and contain the search criteria (parameters) // note that the default action is basic if ($rowCount) { $cacheKey = $this->buildPrevNextCache($sort); $result = $this->_query->getCachedContacts($cacheKey, $offset, $rowCount, $includeContactIds); } else { $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, $includeContactIds); } // process the result of the query $rows = array(); $permissions = array(CRM_Core_Permission::getPermission()); if (CRM_Core_Permission::check('delete contacts')) { $permissions[] = CRM_Core_Permission::DELETE; } $mask = CRM_Core_Action::mask($permissions); // mask value to hide map link if there are not lat/long $mapMask = $mask & 4095; if ($this->_searchContext == 'smog') { $gc = CRM_Core_SelectValues::groupContactStatus(); } if ($this->_ufGroupID) { $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); $names = array(); static $skipFields = array('group', 'tag'); foreach ($this->_fields as $key => $field) { if (!empty($field['in_selector']) && !in_array($key, $skipFields)) { if (strpos($key, '-') !== FALSE) { list($fieldName, $id, $type) = CRM_Utils_System::explode('-', $key, 3); if ($id == 'Primary') { $locationTypeName = 1; } else { $locationTypeName = CRM_Utils_Array::value($id, $locationTypes); if (!$locationTypeName) { continue; } } $locationTypeName = str_replace(' ', '_', $locationTypeName); if (in_array($fieldName, array('phone', 'im', 'email'))) { if ($type) { $names[] = "{$locationTypeName}-{$fieldName}-{$type}"; } else { $names[] = "{$locationTypeName}-{$fieldName}"; } } else { $names[] = "{$locationTypeName}-{$fieldName}"; } } else { $names[] = $field['name']; } } } $names[] = "status"; } elseif (!empty($this->_returnProperties)) { $names = self::makeProperties($this->_returnProperties); } else { $names = self::$_properties; } $multipleSelectFields = array('preferred_communication_method' => 1); $links = self::links($this->_context, $this->_contextMenu, $this->_key); //check explicitly added contact to a Smart Group. $groupID = CRM_Utils_Array::key('1', $this->_formValues['group']); $pseudoconstants = array(); // for CRM-3157 purposes if (in_array('world_region', $names)) { $pseudoconstants['world_region'] = array('dbName' => 'world_region_id', 'values' => CRM_Core_PseudoConstant::worldRegion()); } $seenIDs = array(); while ($result->fetch()) { $row = array(); $this->_query->convertToPseudoNames($result); // the columns we are interested in foreach ($names as $property) { if ($property == 'status') { continue; } if ($cfID = CRM_Core_BAO_CustomField::getKeyID($property)) { $row[$property] = CRM_Core_BAO_CustomField::getDisplayValue($result->{$property}, $cfID, $this->_options, $result->contact_id); } elseif ($multipleSelectFields && array_key_exists($property, $multipleSelectFields)) { $key = $property; $paramsNew = array($key => $result->{$property}); $name = array($key => array('newName' => $key, 'groupName' => $key)); CRM_Core_OptionGroup::lookupValues($paramsNew, $name, FALSE); $row[$key] = $paramsNew[$key]; } elseif (strpos($property, '-im')) { $row[$property] = $result->{$property}; if (!empty($result->{$property})) { $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'); $providerId = $property . "-provider_id"; $providerName = $imProviders[$result->{$providerId}]; $row[$property] = $result->{$property} . " ({$providerName})"; } } elseif (in_array($property, array('addressee', 'email_greeting', 'postal_greeting'))) { $greeting = $property . '_display'; $row[$property] = $result->{$greeting}; } elseif (isset($pseudoconstants[$property])) { $row[$property] = CRM_Utils_Array::value($result->{$pseudoconstants[$property]['dbName']}, $pseudoconstants[$property]['values']); } elseif (strpos($property, '-url') !== FALSE) { $websiteUrl = ''; $websiteKey = 'website-1'; $propertyArray = explode('-', $property); $websiteFld = $websiteKey . '-' . array_pop($propertyArray); if (!empty($result->{$websiteFld})) { $websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'); $websiteType = $websiteTypes[$result->{"{$websiteKey}-website_type_id"}]; $websiteValue = $result->{$websiteFld}; $websiteUrl = "<a href=\"{$websiteValue}\">{$websiteValue} ({$websiteType})</a>"; } $row[$property] = $websiteUrl; } else { $row[$property] = isset($result->{$property}) ? $result->{$property} : NULL; } } if (!empty($result->postal_code_suffix)) { $row['postal_code'] .= "-" . $result->postal_code_suffix; } if ($output != CRM_Core_Selector_Controller::EXPORT && $this->_searchContext == 'smog') { if (empty($result->status) && $groupID) { $contactID = $result->contact_id; if ($contactID) { $gcParams = array('contact_id' => $contactID, 'group_id' => $groupID); $gcDefaults = array(); CRM_Core_DAO::commonRetrieve('CRM_Contact_DAO_GroupContact', $gcParams, $gcDefaults); if (empty($gcDefaults)) { $row['status'] = ts('Smart'); } else { $row['status'] = $gc[$gcDefaults['status']]; } } else { $row['status'] = NULL; } } else { $row['status'] = $gc[$result->status]; } } if ($output != CRM_Core_Selector_Controller::EXPORT) { $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->contact_id; if (!empty($this->_formValues['deleted_contacts']) && CRM_Core_Permission::check('access deleted contacts')) { $links = array(array('name' => ts('View'), 'url' => 'civicrm/contact/view', 'qs' => 'reset=1&cid=%%id%%', 'class' => 'no-popup', 'title' => ts('View Contact Details')), array('name' => ts('Restore'), 'url' => 'civicrm/contact/view/delete', 'qs' => 'reset=1&cid=%%id%%&restore=1', 'title' => ts('Restore Contact'))); if (CRM_Core_Permission::check('delete contacts')) { $links[] = array('name' => ts('Delete Permanently'), 'url' => 'civicrm/contact/view/delete', 'qs' => 'reset=1&cid=%%id%%&skip_undelete=1', 'title' => ts('Permanently Delete Contact')); } $row['action'] = CRM_Core_Action::formLink($links, NULL, array('id' => $result->contact_id), ts('more'), FALSE, 'contact.selector.row', 'Contact', $result->contact_id); } elseif (is_numeric(CRM_Utils_Array::value('geo_code_1', $row)) || $config->mapGeoCoding && !empty($row['city']) && CRM_Utils_Array::value('state_province', $row)) { $row['action'] = CRM_Core_Action::formLink($links, $mask, array('id' => $result->contact_id), ts('more'), FALSE, 'contact.selector.row', 'Contact', $result->contact_id); } else { $row['action'] = CRM_Core_Action::formLink($links, $mapMask, array('id' => $result->contact_id), ts('more'), FALSE, 'contact.selector.row', 'Contact', $result->contact_id); } // allow components to add more actions CRM_Core_Component::searchAction($row, $result->contact_id); $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id); $row['contact_type_orig'] = $result->contact_sub_type ? $result->contact_sub_type : $result->contact_type; $row['contact_sub_type'] = $result->contact_sub_type ? CRM_Contact_BAO_ContactType::contactTypePairs(FALSE, $result->contact_sub_type, ', ') : $result->contact_sub_type; $row['contact_id'] = $result->contact_id; $row['sort_name'] = $result->sort_name; if (array_key_exists('id', $row)) { $row['id'] = $result->contact_id; } } // Dedupe contacts if (in_array($row['contact_id'], $seenIDs) === FALSE) { $seenIDs[] = $row['contact_id']; $rows[] = $row; } } return $rows; }
function __construct() { $this->_columns = array('civicrm_grant' => array('dao' => 'CRM_Grant_DAO_Grant', 'fields' => array('summary_statistics' => array('name' => 'id', 'title' => ts('Summary Statistics'), 'required' => TRUE), 'grant_type_id' => array('name' => 'grant_type_id', 'title' => ts('By Grant Type')), 'status_id' => array('no_display' => TRUE, 'required' => TRUE), 'amount_total' => array('no_display' => TRUE, 'required' => TRUE), 'grant_report_received' => array('no_display' => TRUE, 'required' => TRUE), 'currency' => array('no_display' => TRUE, 'required' => TRUE)), 'filters' => array('application_received_date' => array('name' => 'application_received_date', 'title' => ts('Application Received'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE), 'decision_date' => array('name' => 'decision_date', 'title' => ts('Grant Decision'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE), 'money_transfer_date' => array('name' => 'money_transfer_date', 'title' => ts('Money Transferred'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE), 'grant_due_date' => array('name' => 'grant_due_date', 'title' => ts('Grant Report Due'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE), 'grant_type' => array('name' => 'grant_type_id', 'title' => ts('Grant Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'grant_type_id')), 'status_id' => array('name' => 'status_id', 'title' => ts('Grant Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'status_id')), 'amount_requested' => array('name' => 'amount_requested', 'title' => ts('Amount Requested'), 'type' => CRM_Utils_Type::T_MONEY), 'amount_granted' => array('name' => 'amount_granted', 'title' => ts('Amount Granted')), 'grant_report_received' => array('name' => 'grant_report_received', 'title' => ts('Report Received'), 'operatorType' => CRM_Report_Form::OP_SELECT, 'options' => array('' => ts('- select -'), 0 => ts('No'), 1 => ts('Yes'))))), 'civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('id' => array('required' => TRUE, 'no_display' => TRUE), 'gender_id' => array('name' => 'gender_id', 'title' => ts('By Gender')), 'contact_type' => array('name' => 'contact_type', 'title' => ts('By Contact Type'))), 'filters' => array('gender_id' => array('name' => 'gender_id', 'title' => ts('Gender'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id')), 'contact_type' => array('name' => 'contact_type', 'title' => ts('Contact Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contact_BAO_ContactType::basicTypePairs())), 'grouping' => 'contact-fields'), 'civicrm_world_region' => array('dao' => 'CRM_Core_DAO_Worldregion', 'fields' => array('id' => array('no_display' => TRUE), 'name' => array('name' => 'name', 'title' => ts('By World Region'))), 'filters' => array('region_id' => array('name' => 'id', 'title' => ts('World Region'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::worldRegion()))), 'civicrm_address' => array('dao' => 'CRM_Core_DAO_Address', 'fields' => array('country_id' => array('name' => 'country_id', 'title' => ts('By Country'))), 'filters' => array('country_id' => array('title' => ts('Country'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::country())))); parent::__construct(); }
function restWhere(&$values) { list($name, $op, $value, $grouping, $wildcard) = $values; if (!CRM_Utils_Array::value($grouping, $this->_where)) { $this->_where[$grouping] = array(); } $multipleFields = array('url'); //check if the location type exits for fields $lType = ''; $locType = array(); $locType = explode('-', $name); if (!in_array($locType[0], $multipleFields)) { //add phone type if exists if (isset($locType[2]) && $locType[2]) { $locType[2] = CRM_Core_DAO::escapeString($locType[2]); } } $field = CRM_Utils_Array::value($name, $this->_fields); if (!$field) { $field = CRM_Utils_Array::value($locType[0], $this->_fields); if (!$field) { return; } } $setTables = TRUE; $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower'; if (substr($name, 0, 14) === 'state_province') { if (isset($locType[1]) && is_numeric($locType[1])) { $setTables = FALSE; //get the location name $locationType = CRM_Core_PseudoConstant::locationType(); list($tName, $fldName) = self::getLocationTableName($field['where'], $locType); $this->_whereTables[$tName] = $this->_tables[$tName]; $where = "`{$tName}`.{$fldName}"; } else { $where = $field['where']; } $wc = $op != 'LIKE' ? "LOWER({$where})" : $where; if (is_numeric($value)) { $where = str_replace('.name', '.id', $where); $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive'); $states = CRM_Core_PseudoConstant::stateProvince(); $value = $states[(int) $value]; } else { $wc = $op != 'LIKE' ? "LOWER({$where})" : $where; $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String'); } if (!$lType) { $this->_qill[$grouping][] = ts('State') . " {$op} '{$value}'"; } else { $this->_qill[$grouping][] = ts('State') . " ({$lType}) {$op} '{$value}'"; } } elseif (substr($name, 0, 7) === 'country') { if (isset($locType[1]) && is_numeric($locType[1])) { $setTables = FALSE; //get the location name $locationType = CRM_Core_PseudoConstant::locationType(); list($tName, $fldName) = self::getLocationTableName($field['where'], $locType); $this->_whereTables[$tName] = $this->_tables[$tName]; $where = "`{$tName}`.{$fldName}"; } else { $where = $field['where']; } if (is_numeric($value)) { $where = str_replace('.name', '.id', $where); $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive'); $countries = CRM_Core_PseudoConstant::country(); $value = $countries[(int) $value]; } else { $wc = $op != 'LIKE' ? "LOWER({$where})" : $where; $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String'); } if (!$lType) { $this->_qill[$grouping][] = ts('Country') . " {$op} '{$value}'"; } else { $this->_qill[$grouping][] = ts('Country') . " ({$lType}) {$op} '{$value}'"; } } elseif (substr($name, 0, 6) === 'county') { if (isset($locType[1]) && is_numeric($locType[1])) { $setTables = FALSE; //get the location name $locationType = CRM_Core_PseudoConstant::locationType(); list($tName, $fldName) = self::getLocationTableName($field['where'], $locType); $this->_whereTables[$tName] = $this->_tables[$tName]; $where = "`{$tName}`.{$fldName}"; } else { $where = $field['where']; } if (is_numeric($value)) { $where = str_replace('.name', '.id', $where); $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive'); $counties = CRM_Core_PseudoConstant::county(); $value = $counties[(int) $value]; } else { $wc = $op != 'LIKE' ? "LOWER({$where})" : $where; $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String'); } if (!$lType) { $this->_qill[$grouping][] = ts('County') . " {$op} '{$value}'"; } else { $this->_qill[$grouping][] = ts('County') . " ({$lType}) {$op} '{$value}'"; } } elseif ($name === 'world_region') { $worldRegions = CRM_Core_PseudoConstant::worldRegion(); if (is_numeric($value)) { $value = $worldRegions[(int) $value]; } $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}"; $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String'); $this->_qill[$grouping][] = ts('World Region') . " {$op} '{$value}'"; } elseif ($name === 'individual_prefix') { $individualPrefixs = CRM_Core_PseudoConstant::individualPrefix(); if (is_numeric($value)) { $value = $individualPrefixs[(int) $value]; } $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}"; $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String'); $this->_qill[$grouping][] = ts('Individual Prefix') . " {$op} '{$value}'"; } elseif ($name === 'individual_suffix') { $individualSuffixs = CRM_Core_PseudoConstant::individualsuffix(); if (is_numeric($value)) { $value = $individualSuffixs[(int) $value]; } $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}"; $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String'); $this->_qill[$grouping][] = ts('Individual Suffix') . " {$op} '{$value}'"; } elseif ($name === 'gender') { $genders = CRM_Core_PseudoConstant::gender(); if (is_numeric($value)) { $value = $genders[(int) $value]; } $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}"; $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String'); $this->_qill[$grouping][] = ts('Gender') . " {$op} '{$value}'"; self::$_openedPanes['Demographics'] = TRUE; } elseif ($name === 'birth_date') { $date = CRM_Utils_Date::processDate($value); $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date); if ($date) { $date = CRM_Utils_Date::customFormat($date); $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\""; } else { $this->_qill[$grouping][] = "{$field['title']} {$op}"; } self::$_openedPanes['Demographics'] = TRUE; } elseif ($name === 'deceased_date') { $date = CRM_Utils_Date::processDate($value); $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date); if ($date) { $date = CRM_Utils_Date::customFormat($date); $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\""; } else { $this->_qill[$grouping][] = "{$field['title']} {$op}"; } self::$_openedPanes['Demographics'] = TRUE; } elseif ($name === 'is_deceased') { $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $value); $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\""; self::$_openedPanes['Demographics'] = TRUE; } elseif ($name === 'contact_id') { if (is_int($value)) { $this->_where[$grouping][] = self::buildClause($field['where'], $op, $value); $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}"; } } elseif ($name === 'name') { $value = $strtolower(CRM_Core_DAO::escapeString($value)); if ($wildcard) { $value = "%{$value}%"; $op = 'LIKE'; } $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}"; $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}'"); $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\""; } elseif ($name === 'current_employer') { $value = $strtolower(CRM_Core_DAO::escapeString($value)); if ($wildcard) { $value = "%{$value}%"; $op = 'LIKE'; } $wc = $op != 'LIKE' ? "LOWER(contact_a.organization_name)" : "contact_a.organization_name"; $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}' AND contact_a.contact_type ='Individual'"); $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\""; } elseif ($name === 'email_greeting') { $filterCondition = array('greeting_type' => 'email_greeting'); $emailGreetings = CRM_Core_PseudoConstant::greeting($filterCondition); if (is_numeric($value)) { $value = $emailGreetings[(int) $value]; } $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}"; $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String'); $this->_qill[$grouping][] = ts('Email Greeting') . " {$op} '{$value}'"; } elseif ($name === 'postal_greeting') { $filterCondition = array('greeting_type' => 'postal_greeting'); $postalGreetings = CRM_Core_PseudoConstant::greeting($filterCondition); if (is_numeric($value)) { $value = $postalGreetings[(int) $value]; } $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}"; $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String'); $this->_qill[$grouping][] = ts('Postal Greeting') . " {$op} '{$value}'"; } elseif ($name === 'addressee') { $filterCondition = array('greeting_type' => 'addressee'); $addressee = CRM_Core_PseudoConstant::greeting($filterCondition); if (is_numeric($value)) { $value = $addressee[(int) $value]; } $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}"; $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String'); $this->_qill[$grouping][] = ts('Addressee') . " {$op} '{$value}'"; } elseif (substr($name, 0, 4) === 'url-') { $tName = 'civicrm_website'; $this->_whereTables[$tName] = $this->_tables[$tName] = "\nLEFT JOIN civicrm_website ON ( civicrm_website.contact_id = contact_a.id )"; $value = $strtolower(CRM_Core_DAO::escapeString($value)); if ($wildcard) { $value = "%{$value}%"; $op = 'LIKE'; } $wc = 'civicrm_website.url'; $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}'"); $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\""; } elseif ($name === 'contact_is_deleted') { $this->_where[$grouping][] = self::buildClause("contact_a.is_deleted", $op, $value); $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\""; } else { // sometime the value is an array, need to investigate and fix if (is_array($value)) { CRM_Core_Error::fatal(); } if (!empty($field['where'])) { if ($op != 'IN') { $value = $strtolower(CRM_Core_DAO::escapeString($value)); } if ($wildcard) { $value = "'%{$value}%'"; $op = 'LIKE'; } if (isset($locType[1]) && is_numeric($locType[1])) { $setTables = FALSE; //get the location name $locationType = CRM_Core_PseudoConstant::locationType(); list($tName, $fldName) = self::getLocationTableName($field['where'], $locType); $where = "`{$tName}`.{$fldName}"; $this->_where[$grouping][] = self::buildClause("LOWER({$where})", $op, $value); $this->_whereTables[$tName] = $this->_tables[$tName]; $this->_qill[$grouping][] = "{$field['title']} {$op} '{$value}'"; } else { list($tableName, $fieldName) = explode('.', $field['where'], 2); if ($tableName == 'civicrm_contact') { $fieldName = "LOWER(contact_a.{$fieldName})"; } else { if ($op != 'IN' && !is_numeric($value)) { $fieldName = "LOWER({$field['where']})"; } else { $fieldName = "{$field['where']}"; } } $type = NULL; if (CRM_Utils_Array::value('type', $field)) { $type = CRM_Utils_Type::typeToString($field['type']); } $this->_where[$grouping][] = self::buildClause($fieldName, $op, $value, $type); $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}"; } } } if ($setTables) { list($tableName, $fieldName) = explode('.', $field['where'], 2); if (isset($tableName)) { $this->_tables[$tableName] = 1; $this->_whereTables[$tableName] = 1; } } }
/** * Get options for a given address field. * @see CRM_Core_DAO::buildOptions * * TODO: Should we always assume chainselect? What fn should be responsible for controlling that flow? * TODO: In context of chainselect, what to return if e.g. a country has no states? * * @param string $fieldName * @param string $context * @see CRM_Core_DAO::buildOptionsContext * @param array $props * whatever is known about this dao object. * * @return array|bool */ public static function buildOptions($fieldName, $context = NULL, $props = array()) { $params = array(); // Special logic for fields whose options depend on context or properties switch ($fieldName) { // Filter state_province list based on chosen country or site defaults case 'state_province_id': if (empty($props['country_id'])) { $config = CRM_Core_Config::singleton(); if (!empty($config->provinceLimit)) { $props['country_id'] = $config->provinceLimit; } else { $props['country_id'] = $config->defaultContactCountry; } } if (!empty($props['country_id']) && $context !== 'validate') { $params['condition'] = 'country_id IN (' . implode(',', (array) $props['country_id']) . ')'; } break; // Filter country list based on site defaults // Filter country list based on site defaults case 'country_id': if ($context != 'get' && $context != 'validate') { $config = CRM_Core_Config::singleton(); if (!empty($config->countryLimit) && is_array($config->countryLimit)) { $params['condition'] = 'id IN (' . implode(',', $config->countryLimit) . ')'; } } break; // Filter county list based on chosen state // Filter county list based on chosen state case 'county_id': if (!empty($props['state_province_id'])) { $params['condition'] = 'state_province_id IN (' . implode(',', (array) $props['state_province_id']) . ')'; } break; // Not a real field in this entity // Not a real field in this entity case 'world_region': return CRM_Core_PseudoConstant::worldRegion(); } return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context); }
/** * Build qill for field. * * Qill refers to the query detail visible on the UI. * * @param string $daoName * @param string $fieldName * @param mixed $fieldValue * @param string $op * @param array $pseudoExtraParam * @param int $type * Type of the field per CRM_Utils_Type * * @return array */ public static function buildQillForFieldValue($daoName, $fieldName, $fieldValue, $op, $pseudoExtraParam = array(), $type = CRM_Utils_Type::T_STRING) { $qillOperators = CRM_Core_SelectValues::getSearchBuilderOperators(); // if Operator chosen is NULL/EMPTY then if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE) { return array(CRM_Utils_Array::value($op, $qillOperators, $op), ''); } if ($fieldName == 'activity_type_id') { $pseudoOptions = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE); } elseif ($fieldName == 'country_id') { $pseduoOptions = CRM_Core_PseudoConstant::country(); } elseif ($fieldName == 'county_id') { $pseduoOptions = CRM_Core_PseudoConstant::county(); } elseif ($fieldName == 'world_region') { $pseduoOptions = CRM_Core_PseudoConstant::worldRegion(); } elseif ($daoName == 'CRM_Event_DAO_Event' && $fieldName == 'id') { $pseudoOptions = CRM_Event_BAO_Event::getEvents(0, $fieldValue, TRUE, TRUE, TRUE); } elseif ($fieldName == 'contribution_product_id') { $pseudoOptions = CRM_Contribute_PseudoConstant::products(); } elseif ($daoName == 'CRM_Contact_DAO_Group' && $fieldName == 'id') { $pseudoOptions = CRM_Core_PseudoConstant::group(); } elseif ($fieldName == 'country_id') { $pseudoOptions = CRM_Core_PseudoConstant::country(); } elseif ($daoName) { $pseudoOptions = CRM_Core_PseudoConstant::get($daoName, $fieldName, $pseudoExtraParam); } //API usually have fieldValue format as array(operator => array(values)), //so we need to separate operator out of fieldValue param if (is_array($fieldValue) && in_array(key($fieldValue), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) { $op = key($fieldValue); $fieldValue = $fieldValue[$op]; } if (is_array($fieldValue)) { $qillString = array(); if (!empty($pseudoOptions)) { foreach ((array) $fieldValue as $val) { $qillString[] = CRM_Utils_Array::value($val, $pseudoOptions, $val); } $fieldValue = implode(', ', $qillString); } else { if ($type == CRM_Utils_Type::T_DATE) { foreach ($fieldValue as $index => $value) { $fieldValue[$index] = CRM_Utils_Date::customFormat($value); } } $separator = ', '; // @todo - this is a bit specific (one operator). // However it is covered by a unit test so can be altered later with // some confidence. if ($op == 'BETWEEN') { $separator = ' AND '; } $fieldValue = implode($separator, $fieldValue); } } elseif (!empty($pseudoOptions) && array_key_exists($fieldValue, $pseudoOptions)) { $fieldValue = $pseudoOptions[$fieldValue]; } elseif ($type === CRM_Utils_Type::T_DATE) { $fieldValue = CRM_Utils_Date::customFormat($fieldValue); } return array(CRM_Utils_Array::value($op, $qillOperators, $op), $fieldValue); }
/** * @param $values * * @throws Exception */ public function restWhere(&$values) { $name = CRM_Utils_Array::value(0, $values); $op = CRM_Utils_Array::value(1, $values); $value = CRM_Utils_Array::value(2, $values); $grouping = CRM_Utils_Array::value(3, $values); $wildcard = CRM_Utils_Array::value(4, $values); if (isset($grouping) && empty($this->_where[$grouping])) { $this->_where[$grouping] = array(); } $multipleFields = array('url'); //check if the location type exits for fields $lType = ''; $locType = explode('-', $name); if (!in_array($locType[0], $multipleFields)) { //add phone type if exists if (isset($locType[2]) && $locType[2]) { $locType[2] = CRM_Core_DAO::escapeString($locType[2]); } } $field = CRM_Utils_Array::value($name, $this->_fields); if (!$field) { $field = CRM_Utils_Array::value($locType[0], $this->_fields); if (!$field) { return; } } $setTables = TRUE; $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower'; $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); if (substr($name, 0, 14) === 'state_province') { if (isset($locType[1]) && is_numeric($locType[1])) { $setTables = FALSE; $aName = "{$locationType[$locType[1]]}-address"; $where = "`{$aName}`.state_province_id"; } else { $where = "civicrm_address.state_province_id"; } $states = CRM_Core_PseudoConstant::stateProvince(); if (is_numeric($value)) { $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive'); $value = $states[(int) $value]; } else { $intVal = CRM_Utils_Array::key($value, $states); $this->_where[$grouping][] = self::buildClause($where, $op, $intVal, 'Positive'); } if (!$lType) { $this->_qill[$grouping][] = ts('State') . " {$op} '{$value}'"; } else { $this->_qill[$grouping][] = ts('State') . " ({$lType}) {$op} '{$value}'"; } } elseif (!empty($field['pseudoconstant'])) { $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', $field['name']), $field, $field['title'], 'String', TRUE); if ($name == 'gender_id') { self::$_openedPanes[ts('Demographics')] = TRUE; } } elseif (substr($name, 0, 7) === 'country') { if (isset($locType[1]) && is_numeric($locType[1])) { $setTables = FALSE; $aName = "{$locationType[$locType[1]]}-address"; $where = "`{$aName}`.country_id"; } else { $where = "civicrm_address.country_id"; } $countries = CRM_Core_PseudoConstant::country(); if (is_numeric($value)) { $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive'); $value = $countries[(int) $value]; } else { $intVal = CRM_Utils_Array::key($value, $countries); $this->_where[$grouping][] = self::buildClause($where, $op, $intVal, 'Positive'); } if (!$lType) { $this->_qill[$grouping][] = ts('Country') . " {$op} '{$value}'"; } else { $this->_qill[$grouping][] = ts('Country') . " ({$lType}) {$op} '{$value}'"; } } elseif (substr($name, 0, 6) === 'county') { if (isset($locType[1]) && is_numeric($locType[1])) { $setTables = FALSE; $aName = "{$locationType[$locType[1]]}-address"; $where = "`{$aName}`.county_id"; } else { $where = "civicrm_address.county_id"; } $counties = CRM_Core_PseudoConstant::county(); if (is_numeric($value)) { $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive'); $value = $counties[(int) $value]; } else { $intVal = CRM_Utils_Array::key($value, $counties); $this->_where[$grouping][] = self::buildClause($where, $op, $intVal, 'Positive'); } if (!$lType) { $this->_qill[$grouping][] = ts('County') . " {$op} '{$value}'"; } else { $this->_qill[$grouping][] = ts('County') . " ({$lType}) {$op} '{$value}'"; } } elseif ($name === 'world_region') { $field['where'] = 'civicrm_worldregion.id'; $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::worldRegion(), $field, ts('World Region'), 'Positive', TRUE); } elseif ($name === 'is_deceased') { $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $value); $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\""; self::$_openedPanes[ts('Demographics')] = TRUE; } elseif ($name === 'created_date' || $name === 'modified_date' || $name === 'deceased_date' || $name === 'birth_date') { $appendDateTime = TRUE; if ($name === 'deceased_date' || $name === 'birth_date') { $appendDateTime = FALSE; self::$_openedPanes[ts('Demographics')] = TRUE; } $this->dateQueryBuilder($values, 'contact_a', $name, $name, $field['title'], $appendDateTime); } elseif ($name === 'contact_id') { if (is_int($value)) { $this->_where[$grouping][] = self::buildClause($field['where'], $op, $value); $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}"; } } elseif ($name === 'name') { $value = $strtolower(CRM_Core_DAO::escapeString($value)); if ($wildcard) { $value = "%{$value}%"; $op = 'LIKE'; } $wc = self::caseImportant($op) ? "LOWER({$field['where']})" : "{$field['where']}"; $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}'"); $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\""; } elseif ($name === 'current_employer') { $value = $strtolower(CRM_Core_DAO::escapeString($value)); if ($wildcard) { $value = "%{$value}%"; $op = 'LIKE'; } $wc = self::caseImportant($op) ? "LOWER(contact_a.organization_name)" : "contact_a.organization_name"; $ceWhereClause = self::buildClause($wc, $op, $value); $ceWhereClause .= " AND contact_a.contact_type = 'Individual'"; $this->_where[$grouping][] = $ceWhereClause; $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\""; } elseif ($name === 'email_greeting') { $filterCondition = array('greeting_type' => 'email_greeting'); $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Email Greeting')); } elseif ($name === 'postal_greeting') { $filterCondition = array('greeting_type' => 'postal_greeting'); $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Postal Greeting')); } elseif ($name === 'addressee') { $filterCondition = array('greeting_type' => 'addressee'); $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Addressee')); } elseif (substr($name, 0, 4) === 'url-') { $tName = 'civicrm_website'; $this->_whereTables[$tName] = $this->_tables[$tName] = "\nLEFT JOIN civicrm_website ON ( civicrm_website.contact_id = contact_a.id )"; $value = $strtolower(CRM_Core_DAO::escapeString($value)); if ($wildcard) { $value = "%{$value}%"; $op = 'LIKE'; } $wc = 'civicrm_website.url'; $this->_where[$grouping][] = $d = self::buildClause($wc, $op, $value); $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\""; } elseif ($name === 'contact_is_deleted') { $this->_where[$grouping][] = self::buildClause("contact_a.is_deleted", $op, $value); $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\""; } elseif (!empty($field['where'])) { $type = NULL; if (!empty($field['type'])) { $type = CRM_Utils_Type::typeToString($field['type']); } list($tableName, $fieldName) = explode('.', $field['where'], 2); if (isset($locType[1]) && is_numeric($locType[1])) { $setTables = FALSE; //get the location name list($tName, $fldName) = self::getLocationTableName($field['where'], $locType); $fieldName = "LOWER(`{$tName}`.{$fldName})"; // we set both _tables & whereTables because whereTables doesn't seem to do what the name implies it should $this->_tables[$tName] = $this->_whereTables[$tName] = 1; } else { if ($tableName == 'civicrm_contact') { $fieldName = "LOWER(contact_a.{$fieldName})"; } else { if ($op != 'IN' && !is_numeric($value)) { $fieldName = "LOWER({$field['where']})"; } else { $fieldName = "{$field['where']}"; } } } list($qillop, $qillVal) = self::buildQillForFieldValue(NULL, $field['title'], $value, $op); $this->_qill[$grouping][] = "{$field['title']} {$qillop} '{$qillVal}'"; if (is_array($value)) { // traditionally an array being passed has been a fatal error. We can take advantage of this to add support // for api style operators for functions that hit this point without worrying about regression // (the previous comments indicated the condition for hitting this point were unknown // per CRM-14743 we are adding modified_date & created_date operator support $operations = array_keys($value); foreach ($operations as $operator) { if (!in_array($operator, CRM_Core_DAO::acceptedSQLOperators())) { //Via Contact get api value is not in array(operator => array(values)) format ONLY for IN/NOT IN operators //so this condition will satisfy the search for now if (strstr('IN', $op)) { $value = array($op => $value); } else { CRM_Core_Error::fatal(ts("%1 is not a valid operator", array(1 => $operator))); } } } $this->_where[$grouping][] = CRM_Core_DAO::createSQLFilter($fieldName, $value, $type); } else { if ($op != 'IN') { $value = $strtolower($value); } if ($wildcard) { $value = "%{$value}%"; $op = 'LIKE'; } $this->_where[$grouping][] = self::buildClause($fieldName, $op, $value, $type); } } if ($setTables && isset($field['where'])) { list($tableName, $fieldName) = explode('.', $field['where'], 2); if (isset($tableName)) { $this->_tables[$tableName] = 1; $this->_whereTables[$tableName] = 1; } } }
/** * Add profile field to a form. * * @param CRM_Core_Form $form * @param array $field * Properties. * @param int $mode * Profile mode. * @param int $contactId * @param bool $online * @param string $usedFor * For building up prefixed fieldname for special cases (e.g. onBehalf, Honor). * @param int $rowNumber * @param string $prefix * * @return null */ public static function buildProfile(&$form, &$field, $mode, $contactId = NULL, $online = FALSE, $usedFor = NULL, $rowNumber = NULL, $prefix = '') { $defaultValues = array(); $fieldName = $field['name']; $title = $field['title']; $attributes = $field['attributes']; $rule = $field['rule']; $view = $field['is_view']; $required = $mode == CRM_Profile_Form::MODE_SEARCH ? FALSE : $field['is_required']; $search = $mode == CRM_Profile_Form::MODE_SEARCH ? TRUE : FALSE; $isShared = CRM_Utils_Array::value('is_shared', $field, 0); // do not display view fields in drupal registration form // CRM-4632 if ($view && $mode == CRM_Profile_Form::MODE_REGISTER) { return NULL; } if ($usedFor == 'onbehalf') { $name = "onbehalf[{$fieldName}]"; } elseif ($usedFor == 'honor') { $name = "honor[{$fieldName}]"; } elseif ($contactId && !$online) { $name = "field[{$contactId}][{$fieldName}]"; } elseif ($rowNumber) { $name = "field[{$rowNumber}][{$fieldName}]"; } elseif (!empty($prefix)) { $name = $prefix . "[{$fieldName}]"; } else { $name = $fieldName; } $selectAttributes = array('class' => 'crm-select2', 'placeholder' => TRUE); if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) { $deleteExtra = json_encode(ts('Are you sure you want to delete contact image.')); $deleteURL = array(CRM_Core_Action::DELETE => array('name' => ts('Delete Contact Image'), 'url' => 'civicrm/contact/image', 'qs' => 'reset=1&id=%%id%%&gid=%%gid%%&action=delete', 'extra' => 'onclick = "' . htmlspecialchars("if (confirm({$deleteExtra})) this.href+='&confirmed=1'; else return false;") . '"')); $deleteURL = CRM_Core_Action::formLink($deleteURL, CRM_Core_Action::DELETE, array('id' => $form->get('id'), 'gid' => $form->get('gid')), ts('more'), FALSE, 'contact.profileimage.delete', 'Contact', $form->get('id')); $form->assign('deleteURL', $deleteURL); } $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE); if (substr($fieldName, 0, 14) === 'state_province') { $form->addChainSelect($name, array('label' => $title, 'required' => $required)); $config = CRM_Core_Config::singleton(); if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactStateProvince) { $defaultValues[$name] = $config->defaultContactStateProvince; $form->setDefaults($defaultValues); } } elseif (substr($fieldName, 0, 7) === 'country') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required, $selectAttributes); $config = CRM_Core_Config::singleton(); if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactCountry) { $defaultValues[$name] = $config->defaultContactCountry; $form->setDefaults($defaultValues); } } elseif (substr($fieldName, 0, 6) === 'county') { if ($addressOptions['county']) { $form->addChainSelect($name, array('label' => $title, 'required' => $required)); } } elseif (substr($fieldName, 0, 9) === 'image_URL') { $form->add('file', $name, $title, $attributes, $required); $form->addUploadElement($name); } elseif (substr($fieldName, 0, 2) === 'im') { $form->add('text', $name, $title, $attributes, $required); if (!$contactId) { if ($usedFor) { if (substr($name, -1) == ']') { $providerName = substr($name, 0, -1) . '-provider_id]'; } $form->add('select', $providerName, NULL, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required); } else { $form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required); } if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) { $form->freeze($name . '-provider_id'); } } } elseif ($fieldName === 'birth_date' || $fieldName === 'deceased_date') { $form->addDate($name, $title, $required, array('formatType' => 'birth')); } elseif (in_array($fieldName, array('membership_start_date', 'membership_end_date', 'join_date'))) { $form->addDate($name, $title, $required, array('formatType' => 'activityDate')); } elseif (CRM_Utils_Array::value('name', $field) == 'membership_type') { list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo(); $sel =& $form->addElement('hierselect', $name, $title); $select = array('' => ts('- select -')); if (count($orgInfo) == 1 && $field['is_required']) { // we only have one org - so we should default to it. Not sure about defaulting to first type // as it could be missed - so adding a select // however, possibly that is more similar to the membership form if (count($types[1]) > 1) { $types[1] = $select + $types[1]; } } else { $orgInfo = $select + $orgInfo; } $sel->setOptions(array($orgInfo, $types)); } elseif (CRM_Utils_Array::value('name', $field) == 'membership_status') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), $required); } elseif (in_array($fieldName, array('gender_id', 'communication_style_id'))) { $options = array(); $pseudoValues = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', $fieldName); foreach ($pseudoValues as $key => $var) { $options[$key] = $form->createElement('radio', NULL, ts($title), $var, $key); } $group = $form->addGroup($options, $name, $title); if ($required) { $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required'); } else { $group->setAttribute('allowClear', TRUE); } } elseif ($fieldName === 'prefix_id' || $fieldName === 'suffix_id') { $form->addSelect($name, array('label' => $title, 'entity' => 'contact', 'field' => $fieldName, 'class' => 'six', 'placeholder' => ''), $required); } elseif ($fieldName === 'contact_sub_type') { $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field); if ($usedFor == 'onbehalf') { $profileType = 'Organization'; } elseif ($usedFor == 'honor') { $profileType = CRM_Core_BAO_UFField::getProfileType($form->_params['honoree_profile_id']); } else { $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL; if ($profileType == 'Contact') { $profileType = 'Individual'; } } $setSubtype = FALSE; if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $setSubtype = $profileType; $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } $subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array(); if ($setSubtype) { $subtypeList = array(); $subtypeList[$setSubtype] = $subtypes[$setSubtype]; } else { $subtypeList = $subtypes; } $form->add('select', $name, $title, $subtypeList, $required, array('class' => 'crm-select2', 'multiple' => TRUE)); } elseif (in_array($fieldName, CRM_Contact_BAO_Contact::$_greetingTypes)) { //add email greeting, postal greeting, addressee, CRM-4575 $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field); $profileType = CRM_Core_BAO_UFField::getProfileType($gId, TRUE, FALSE, TRUE); if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) { $profileType = 'Individual'; } if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } $greeting = array('contact_type' => $profileType, 'greeting_type' => $fieldName); $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($greeting), $required); // add custom greeting element $form->add('text', $fieldName . '_custom', ts('Custom %1', array(1 => ucwords(str_replace('_', ' ', $fieldName)))), NULL, FALSE); } elseif ($fieldName === 'preferred_communication_method') { $communicationFields = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method'); foreach ($communicationFields as $key => $var) { if ($key == '') { continue; } $communicationOptions[] = $form->createElement('checkbox', $key, NULL, $var); } $form->addGroup($communicationOptions, $name, $title, '<br/>'); } elseif ($fieldName === 'preferred_mail_format') { $form->add('select', $name, $title, CRM_Core_SelectValues::pmf()); } elseif ($fieldName === 'preferred_language') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contact_BAO_Contact::buildOptions('preferred_language')); } elseif ($fieldName == 'external_identifier') { $form->add('text', $name, $title, $attributes, $required); $contID = $contactId; if (!$contID) { $contID = $form->get('id'); } $form->addRule($name, ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $contID, 'external_identifier')); } elseif ($fieldName === 'group') { CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, TRUE, $required, $title, NULL, $name); } elseif ($fieldName === 'tag') { CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::TAG, FALSE, $required, NULL, $title, $name); } elseif (substr($fieldName, 0, 4) === 'url-') { $form->add('text', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), $required); $form->addRule($name, ts('Enter a valid web address beginning with \'http://\' or \'https://\'.'), 'url'); } elseif (substr($fieldName, -4) == 'note') { $form->add('textarea', $name, $title, $attributes, $required); } elseif (substr($fieldName, 0, 6) === 'custom') { $customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName); if ($customFieldID) { CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title); } } elseif (substr($fieldName, 0, 14) === 'address_custom') { list($fName, $locTypeId) = CRM_Utils_System::explode('-', $fieldName, 2); $customFieldID = CRM_Core_BAO_CustomField::getKeyID(substr($fName, 8)); if ($customFieldID) { CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title); } } elseif (in_array($fieldName, array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } elseif ($fieldName == 'send_receipt') { $form->addElement('checkbox', $name, $title); } elseif ($fieldName == 'soft_credit') { $form->addEntityRef("soft_credit_contact_id[{$rowNumber}]", ts('Soft Credit To'), array('create' => TRUE)); $form->addMoney("soft_credit_amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE); } elseif ($fieldName == 'product_name') { list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo(); $sel =& $form->addElement('hierselect', $name, $title); $products = array('0' => ts('- select -')) + $products; $sel->setOptions(array($products, $options)); } elseif ($fieldName == 'payment_instrument') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required); } elseif ($fieldName == 'financial_type') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType(), $required); } elseif ($fieldName == 'contribution_status_id') { $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(); $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); foreach (array('In Progress', 'Overdue', 'Refunded') as $suppress) { unset($contributionStatuses[CRM_Utils_Array::key($suppress, $statusName)]); } $form->add('select', $name, $title, array('' => ts('- select -')) + $contributionStatuses, $required); } elseif ($fieldName == 'soft_credit_type') { $name = "soft_credit_type[{$rowNumber}]"; $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_OptionGroup::values("soft_credit_type")); //CRM-15350: choose SCT field default value as 'Gift' for membership use //else (for contribution), use configured SCT default value $SCTDefaultValue = CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"); if ($field['field_type'] == 'Membership') { $SCTDefaultValue = CRM_Core_OptionGroup::getValue('soft_credit_type', 'Gift', 'name'); } $form->addElement('hidden', 'sct_default_id', $SCTDefaultValue, array('id' => 'sct_default_id')); } elseif ($fieldName == 'currency') { $form->addCurrency($name, $title, $required); } elseif ($fieldName == 'contribution_page_id') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage(), $required, 'class="big"'); } elseif ($fieldName == 'participant_register_date') { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } elseif ($fieldName == 'activity_status_id') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::activityStatus(), $required); } elseif ($fieldName == 'activity_engagement_level') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Campaign_PseudoConstant::engagementLevel(), $required); } elseif ($fieldName == 'activity_date_time') { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } elseif ($fieldName == 'participant_status') { $cond = NULL; if ($online == TRUE) { $cond = 'visibility_id = 1'; } $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(NULL, $cond, 'label'), $required); } elseif ($fieldName == 'participant_role') { if (!empty($field['is_multiple'])) { $form->addCheckBox($name, $title, CRM_Event_PseudoConstant::participantRole(), NULL, NULL, NULL, NULL, ' ', TRUE); } else { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), $required); } } elseif ($fieldName == 'world_region') { $form->add('select', $name, $title, CRM_Core_PseudoConstant::worldRegion(), $required, $selectAttributes); } elseif ($fieldName == 'signature_html') { $form->add('wysiwyg', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName)); } elseif ($fieldName == 'signature_text') { $form->add('textarea', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName)); } elseif (substr($fieldName, -11) == 'campaign_id') { if (CRM_Campaign_BAO_Campaign::isCampaignEnable()) { $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(CRM_Utils_Array::value($contactId, $form->_componentCampaigns)); $form->add('select', $name, $title, array('' => ts('- select -')) + $campaigns, $required, 'class="crm-select2 big"'); } } elseif ($fieldName == 'activity_details') { $form->add('wysiwyg', $fieldName, $title, array('rows' => 4, 'cols' => 60), $required); } elseif ($fieldName == 'activity_duration') { $form->add('text', $name, $title, $attributes, $required); $form->addRule($name, ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger'); } else { if (substr($fieldName, 0, 3) === 'is_' or substr($fieldName, 0, 7) === 'do_not_') { $form->add('advcheckbox', $name, $title, $attributes, $required); } else { $form->add('text', $name, $title, $attributes, $required); } } static $hiddenSubtype = FALSE; if (!$hiddenSubtype && CRM_Contact_BAO_ContactType::isaSubType($field['field_type'])) { // In registration mode params are submitted via POST and we don't have any clue // about profile-id or the profile-type (which could be a subtype) // To generalize the behavior and simplify the process, // lets always add the hidden //subtype value if there is any, and we won't have to // compute it while processing. if ($usedFor) { $form->addElement('hidden', $usedFor . '[contact_sub_type]', $field['field_type']); } else { $form->addElement('hidden', 'contact_sub_type_hidden', $field['field_type']); } $hiddenSubtype = TRUE; } if ($view && $mode != CRM_Profile_Form::MODE_SEARCH || $isShared) { $form->freeze($name); } //add the rules if (in_array($fieldName, array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) { $form->addRule($name, ts('Please enter a valid amount.'), 'money'); } if ($rule) { if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) { $form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule); } } }
static function location(&$form) { $form->addElement('hidden', 'hidden_location', 1); require_once 'CRM/Core/BAO/Preferences.php'; $addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true); $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address'); $elements = array('street_address' => array(ts('Street Address'), $attributes['street_address'], null, null), 'city' => array(ts('City'), $attributes['city'], null, null), 'postal_code' => array(ts('Zip / Postal Code'), $attributes['postal_code'], null, null), 'county' => array(ts('County'), $attributes['county_id'], 'county', false), 'state_province' => array(ts('State / Province'), $attributes['state_province_id'], 'stateProvince', true), 'country' => array(ts('Country'), $attributes['country_id'], 'country', false), 'address_name' => array(ts('Address Name'), $attributes['address_name'], null, null)); foreach ($elements as $name => $v) { list($title, $attributes, $select, $multiSelect) = $v; if (!$addressOptions[$name]) { continue; } if (!$attributes) { $attributes = $attributes[$name]; } if ($select) { $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select(); $element = $form->addElement('select', $name, $title, $selectElements); if ($multiSelect) { $element->setMultiple(true); } } else { $form->addElement('text', $name, $title, $attributes); } if ($addressOptions['postal_code']) { $form->addElement('text', 'postal_code_low', ts('Range-From'), CRM_Utils_Array::value('postal_code', $attributes)); $form->addElement('text', 'postal_code_high', ts('To'), CRM_Utils_Array::value('postal_code', $attributes)); } // select for state province $stateProvince = array('' => ts('- any state/province -')) + CRM_Core_PseudoConstant::stateProvince(); } $worldRegions = array('' => ts('- any region -')) + CRM_Core_PseudoConstant::worldRegion(); $form->addElement('select', 'world_region', ts('World Region'), $worldRegions); // checkboxes for location type $location_type = array(); $locationType = CRM_Core_PseudoConstant::locationType(); foreach ($locationType as $locationTypeID => $locationTypeName) { $location_type[] = HTML_QuickForm::createElement('checkbox', $locationTypeID, null, $locationTypeName); } $form->addGroup($location_type, 'location_type', ts('Location Types'), ' '); }
/** * Function to build profile form * * @params object $form form object * @params array $field array field properties * @params int $mode profile mode * @params int $contactID contact id * * @return null * @static * @access public */ static function buildProfile(&$form, &$field, $mode, $contactId = null, $online = false) { require_once "CRM/Profile/Form.php"; require_once "CRM/Core/OptionGroup.php"; require_once 'CRM/Core/BAO/UFField.php'; require_once 'CRM/Contact/BAO/ContactType.php'; $defaultValues = array(); $fieldName = $field['name']; $title = $field['title']; $attributes = $field['attributes']; $rule = $field['rule']; $view = $field['is_view']; $required = $mode == CRM_Profile_Form::MODE_SEARCH ? false : $field['is_required']; $search = $mode == CRM_Profile_Form::MODE_SEARCH ? true : false; // do not display view fields in drupal registration form // CRM-4632 if ($view && $mode == CRM_Profile_Form::MODE_REGISTER) { return; } if ($contactId && !$online) { $name = "field[{$contactId}][{$fieldName}]"; } else { $name = $fieldName; } require_once 'CRM/Core/BAO/Preferences.php'; $addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true); if (substr($fieldName, 0, 14) === 'state_province') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required); } else { if (substr($fieldName, 0, 7) === 'country') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required); $config =& CRM_Core_Config::singleton(); if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactCountry) { $defaultValues[$name] = $config->defaultContactCountry; $form->setDefaults($defaultValues); } } else { if (substr($fieldName, 0, 6) === 'county') { if ($addressOptions['county']) { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::county(), $required); } } else { if (substr($fieldName, 0, 2) === 'im') { if (!$contactId) { $form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::IMProvider(), $required); if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) { $form->freeze($name . "-provider_id"); } } $form->add('text', $name, $title, $attributes, $required); } else { if ($fieldName === 'birth_date' || $fieldName === 'deceased_date') { $form->addDate($name, $title, $required, array('formatType' => 'birth')); } else { if (in_array($fieldName, array("membership_start_date", "membership_end_date", "join_date"))) { $form->addDate($name, $title, $required, array('formatType' => 'custom')); } else { if ($field['name'] == 'membership_type_id') { require_once 'CRM/Member/PseudoConstant.php'; $form->add('select', 'membership_type_id', $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipType(), $required); } else { if ($field['name'] == 'status_id') { require_once 'CRM/Member/PseudoConstant.php'; $form->add('select', 'status_id', $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(), $required); } else { if ($fieldName === 'gender') { $genderOptions = array(); $gender = CRM_Core_PseudoConstant::gender(); foreach ($gender as $key => $var) { $genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key); } $form->addGroup($genderOptions, $name, $title); if ($required) { $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required'); } } else { if ($fieldName === 'individual_prefix') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required); } else { if ($fieldName === 'individual_suffix') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required); } else { if ($fieldName === 'contact_sub_type') { $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $form->_fields[$fieldName]); $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : null; $setSubtype = false; if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $setSubtype = $profileType; $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } $subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array(); if ($setSubtype) { $subtypeList = array(); $subtypeList[$setSubtype] = $subtypes[$setSubtype]; } else { $subtypeList = array('' => ts('- select -')) + $subtypes; } $form->add('select', $name, $title, $subtypeList, $required); } else { if (in_array($fieldName, array('email_greeting', 'postal_greeting', 'addressee'))) { //add email greeting, postal greeting, addressee, CRM-4575 $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field); $profileType = CRM_Core_BAO_UFField::getProfileType($gId, true, false, true); if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) { $profileType = 'Individual'; } if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } if ($fieldName == 'email_greeting') { $emailGreeting = array('contact_type' => $profileType, 'greeting_type' => 'email_greeting'); $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($emailGreeting), $required); // adding custom email greeting element alongwith email greeting $form->add('text', 'email_greeting_custom', ts('Custom Email Greeting'), null, false); } else { if ($fieldName === 'postal_greeting') { $postalGreeting = array('contact_type' => $profileType, 'greeting_type' => 'postal_greeting'); $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($postalGreeting), $required); // adding custom postal greeting element alongwith postal greeting $form->add('text', 'postal_greeting_custom', ts('Custom Postal Greeting'), null, false); } else { if ($fieldName === 'addressee') { $addressee = array('contact_type' => $profileType, 'greeting_type' => 'addressee'); $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($addressee), $required); // adding custom addressee element alongwith addressee type $form->add('text', 'addressee_custom', ts('Custom Addressee'), null, false); } } } } else { if ($fieldName === 'preferred_communication_method') { $communicationFields = CRM_Core_PseudoConstant::pcm(); foreach ($communicationFields as $key => $var) { if ($key == '') { continue; } $communicationOptions[] =& HTML_QuickForm::createElement('checkbox', $key, null, $var); } $form->addGroup($communicationOptions, $name, $title, '<br/>'); } else { if ($fieldName === 'preferred_mail_format') { $form->add('select', $name, $title, CRM_Core_SelectValues::pmf()); } else { if ($fieldName == 'external_identifier') { $form->add('text', $name, $title, $attributes, $required); $contID = $contactId; if (!$contID) { $contID = $form->get('id'); } $form->addRule($name, ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $contID, 'external_identifier')); } else { if ($fieldName === 'group') { require_once 'CRM/Contact/Form/Edit/TagsAndGroups.php'; CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, true, $required, $title, null, $name); } else { if ($fieldName === 'tag') { require_once 'CRM/Contact/Form/Edit/TagsAndGroups.php'; CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::TAG, false, $required, null, $title, $name); } else { if ($fieldName === 'home_URL') { $form->addElement('text', $name, $title, array_merge(CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'home_URL'), array('onfocus' => "if (!this.value) this.value='http://'; else return false", 'onblur' => "if ( this.value == 'http://') this.value=''; else return false"))); $form->addRule($name, ts('Enter a valid Website.'), 'url'); } else { if (substr($fieldName, 0, 6) === 'custom') { $customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName); if ($customFieldID) { CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, false, $required, $search, $title); } } else { if (in_array($fieldName, array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) { $form->addDate($name, $title, $required, array('formatType' => 'custom')); } else { if ($fieldName == 'payment_instrument') { require_once "CRM/Contribute/PseudoConstant.php"; $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required); } else { if ($fieldName == 'contribution_type') { require_once "CRM/Contribute/PseudoConstant.php"; $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType(), $required); } else { if ($fieldName == 'contribution_status_id') { require_once "CRM/Contribute/PseudoConstant.php"; $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionStatus(), $required); } else { if ($fieldName == 'participant_register_date') { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } else { if ($fieldName == 'participant_status_id') { require_once "CRM/Event/PseudoConstant.php"; $cond = null; if ($online == true) { $cond = "visibility_id = 1"; } $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(null, $cond), $required); } else { if ($fieldName == 'participant_role_id') { require_once "CRM/Event/PseudoConstant.php"; $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), $required); } else { if ($fieldName == 'scholarship_type_id') { $form->add('select', $name, $title, array("" => "-- Select -- ") + array_flip(CRM_Core_OptionGroup::values('scholarship_type', true))); } else { if ($fieldName == 'applicant_status_id') { $form->add('select', $name, $title, array("" => "-- Select -- ") + array_flip(CRM_Core_OptionGroup::values('applicant_status', true))); } else { if ($fieldName == 'highschool_gpa_id') { $form->add('select', $name, $title, array("" => "-- Select -- ") + CRM_Core_OptionGroup::values('highschool_gpa')); } else { if ($fieldName == 'world_region') { require_once "CRM/Core/PseudoConstant.php"; $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::worldRegion(), $required); } else { $processed = false; if (CRM_Core_Permission::access('Quest', false)) { require_once 'CRM/Quest/BAO/Student.php'; $processed = CRM_Quest_BAO_Student::buildStudentForm($form, $fieldName, $title, $contactId); } if (!$processed) { if (substr($fieldName, 0, 3) === 'is_' or substr($fieldName, 0, 7) === 'do_not_') { $form->add('checkbox', $name, $title, $attributes, $required); } else { $form->add('text', $name, $title, $attributes, $required); } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } static $hiddenSubtype = false; if (!$hiddenSubtype && CRM_Contact_BAO_ContactType::isaSubType($field['field_type'])) { // In registration mode params are submitted via POST and we don't have any clue // about profile-id or the profile-type (which could be a subtype) // To generalize the behavior and simplify the process, // lets always add the hidden //subtype value if there is any, and we won't have to // compute it while processing. $form->addElement('hidden', 'contact_sub_type_hidden', $field['field_type']); $hiddenSubtype = true; } if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) { $form->freeze($name); } //add the rules if (in_array($fieldName, array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) { $form->addRule($name, ts('Please enter a valid amount.'), 'money'); } if ($rule) { if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) { $form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule); } } }
/** * Function to build profile form * * @params object $form form object * @params array $field array field properties * @params int $mode profile mode * @params int $contactID contact id * * @return null * @static * @access public */ static function buildProfile(&$form, &$field, $mode, $contactId = NULL, $online = FALSE, $onBehalf = FALSE, $rowNumber = NULL, $prefix = '') { $defaultValues = array(); $fieldName = $field['name']; $title = $field['title']; $attributes = $field['attributes']; $rule = $field['rule']; $view = $field['is_view']; $required = $mode == CRM_Profile_Form::MODE_SEARCH ? FALSE : $field['is_required']; $search = $mode == CRM_Profile_Form::MODE_SEARCH ? TRUE : FALSE; $isShared = CRM_Utils_Array::value('is_shared', $field, 0); // do not display view fields in drupal registration form // CRM-4632 if ($view && $mode == CRM_Profile_Form::MODE_REGISTER) { return; } if ($onBehalf) { $name = "onbehalf[{$fieldName}]"; } elseif ($contactId && !$online) { $name = "field[{$contactId}][{$fieldName}]"; } elseif ($rowNumber) { $name = "field[{$rowNumber}][{$fieldName}]"; } elseif (!empty($prefix)) { $name = $prefix . "[{$fieldName}]"; } else { $name = $fieldName; } if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) { $deleteExtra = ts('Are you sure you want to delete contact image.'); $deleteURL = array(CRM_Core_Action::DELETE => array('name' => ts('Delete Contact Image'), 'url' => 'civicrm/contact/image', 'qs' => 'reset=1&id=%%id%%&gid=%%gid%%&action=delete', 'extra' => 'onclick = "if (confirm( \'' . $deleteExtra . '\' ) ) this.href+=\'&confirmed=1\'; else return false;"')); $deleteURL = CRM_Core_Action::formLink($deleteURL, CRM_Core_Action::DELETE, array('id' => $form->get('id'), 'gid' => $form->get('gid'))); $form->assign('deleteURL', $deleteURL); } $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE); if (substr($fieldName, 0, 14) === 'state_province') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required); } elseif (substr($fieldName, 0, 7) === 'country') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required); $config = CRM_Core_Config::singleton(); if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactCountry) { $defaultValues[$name] = $config->defaultContactCountry; $form->setDefaults($defaultValues); } } elseif (substr($fieldName, 0, 6) === 'county') { if ($addressOptions['county']) { $form->add('select', $name, $title, array('' => ts('- select state -')), $required); } } elseif (substr($fieldName, 0, 9) === 'image_URL') { $form->add('file', $name, $title, $attributes, $required); $form->addUploadElement($name); } elseif (substr($fieldName, 0, 2) === 'im') { $form->add('text', $name, $title, $attributes, $required); if (!$contactId) { if ($onBehalf) { if (substr($name, -1) == ']') { $providerName = substr($name, 0, -1) . '-provider_id]'; } $form->add('select', $providerName, NULL, array('' => ts('- select -')) + CRM_Core_PseudoConstant::IMProvider(), $required); } else { $form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::IMProvider(), $required); } if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) { $form->freeze($name . '-provider_id'); } } } elseif ($fieldName === 'birth_date' || $fieldName === 'deceased_date') { $form->addDate($name, $title, $required, array('formatType' => 'birth')); } elseif (in_array($fieldName, array('membership_start_date', 'membership_end_date', 'join_date'))) { $form->addDate($name, $title, $required, array('formatType' => 'custom')); } elseif ($field['name'] == 'membership_type') { list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo(); $sel =& $form->addElement('hierselect', $name, $title); $select = array('' => ts('- select -')); $sel->setOptions(array($select + $orgInfo, $types)); } elseif ($field['name'] == 'membership_status') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), $required); } elseif ($fieldName === 'gender') { $genderOptions = array(); $gender = CRM_Core_PseudoConstant::gender(); foreach ($gender as $key => $var) { $genderOptions[$key] = $form->createElement('radio', NULL, ts('Gender'), $var, $key); } $form->addGroup($genderOptions, $name, $title); if ($required) { $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required'); } } elseif ($fieldName === 'individual_prefix') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required); } elseif ($fieldName === 'individual_suffix') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required); } elseif ($fieldName === 'contact_sub_type') { $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $form->_fields[$fieldName]); if ($onBehalf) { $profileType = 'Organization'; } else { $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL; } $setSubtype = FALSE; if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $setSubtype = $profileType; $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } $subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array(); if ($setSubtype) { $subtypeList = array(); $subtypeList[$setSubtype] = $subtypes[$setSubtype]; } else { $subtypeList = $subtypes; } $sel = $form->add('select', $name, $title, $subtypeList, $required); $sel->setMultiple(TRUE); } elseif (in_array($fieldName, CRM_Contact_BAO_Contact::$_greetingTypes)) { //add email greeting, postal greeting, addressee, CRM-4575 $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field); $profileType = CRM_Core_BAO_UFField::getProfileType($gId, TRUE, FALSE, TRUE); if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) { $profileType = 'Individual'; } if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } $greeting = array('contact_type' => $profileType, 'greeting_type' => $fieldName); $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($greeting), $required); // add custom greeting element $form->add('text', $fieldName . '_custom', ts('Custom %1', array(1 => ucwords(str_replace('_', ' ', $fieldName)))), NULL, FALSE); } elseif ($fieldName === 'preferred_communication_method') { $communicationFields = CRM_Core_PseudoConstant::pcm(); foreach ($communicationFields as $key => $var) { if ($key == '') { continue; } $communicationOptions[] = $form->createElement('checkbox', $key, NULL, $var); } $form->addGroup($communicationOptions, $name, $title, '<br/>'); } elseif ($fieldName === 'preferred_mail_format') { $form->add('select', $name, $title, CRM_Core_SelectValues::pmf()); } elseif ($fieldName === 'preferred_language') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::languages()); } elseif ($fieldName == 'external_identifier') { $form->add('text', $name, $title, $attributes, $required); $contID = $contactId; if (!$contID) { $contID = $form->get('id'); } $form->addRule($name, ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $contID, 'external_identifier')); } elseif ($fieldName === 'group') { CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, TRUE, $required, $title, NULL, $name); } elseif ($fieldName === 'tag') { CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::TAG, FALSE, $required, NULL, $title, $name); } elseif (substr($fieldName, 0, 4) === 'url-') { $form->addElement('text', $name, $title, array_merge(CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), array('onfocus' => "if (!this.value) { this.value='http://';} else return false", 'onblur' => "if ( this.value == 'http://') { this.value='';} else return false"))); $form->addRule($name, ts('Enter a valid Website.'), 'url'); //Website type select if ($onBehalf) { if (substr($name, -1) == ']') { $websiteTypeName = substr($name, 0, -1) . '-website_type_id]'; } $form->addElement('select', $websiteTypeName, NULL, CRM_Core_PseudoConstant::websiteType()); } else { $form->addElement('select', $name . '-website_type_id', NULL, CRM_Core_PseudoConstant::websiteType()); } // added because note appeared as a standard text input } elseif ($fieldName == 'note') { $form->add('textarea', $name, $title, $attributes, $required); } elseif (substr($fieldName, 0, 6) === 'custom') { $customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName); if ($customFieldID) { CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title); } } elseif (substr($fieldName, 0, 14) === 'address_custom') { list($fName, $locTypeId) = CRM_Utils_System::explode('-', $fieldName, 2); $customFieldID = CRM_Core_BAO_CustomField::getKeyID(substr($fName, 8)); if ($customFieldID) { CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title); } } elseif (in_array($fieldName, array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } elseif ($fieldName == 'send_receipt') { $form->addElement('checkbox', $name, $title); } elseif ($fieldName == 'soft_credit') { CRM_Contact_Form_NewContact::buildQuickForm($form, $rowNumber, NULL, FALSE, 'soft_credit_'); } elseif ($fieldName == 'product_name') { list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo(); $sel =& $form->addElement('hierselect', $name, $title); $products = array('0' => ts('- select -')) + $products; $sel->setOptions(array($products, $options)); } elseif ($fieldName == 'payment_instrument') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required); } elseif ($fieldName == 'contribution_type') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType(), $required); } elseif ($fieldName == 'contribution_status_id') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionStatus(), $required); } elseif ($fieldName == 'currency') { $form->addCurrency($name, $title, $required); } elseif ($fieldName == 'contribution_page_id') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage(), $required, 'class="big"'); } elseif ($fieldName == 'participant_register_date') { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } elseif ($fieldName == 'activity_status_id') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::activityStatus(), $required); } elseif ($fieldName == 'activity_engagement_level') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Campaign_PseudoConstant::engagementLevel(), $required); } elseif ($fieldName == 'activity_date_time') { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } elseif ($fieldName == 'participant_status') { $cond = NULL; if ($online == TRUE) { $cond = 'visibility_id = 1'; } $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(NULL, $cond, 'label'), $required); } elseif ($fieldName == 'participant_role') { if (CRM_Utils_Array::value('is_multiple', $field)) { $form->addCheckBox($name, $title, CRM_Event_PseudoConstant::participantRole(), NULL, NULL, NULL, NULL, ' ', TRUE); } else { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), $required); } } elseif ($fieldName == 'scholarship_type_id') { $form->add('select', $name, $title, array('' => '-- Select -- ') + array_flip(CRM_Core_OptionGroup::values('scholarship_type', TRUE))); } elseif ($fieldName == 'applicant_status_id') { $form->add('select', $name, $title, array('' => '-- Select -- ') + array_flip(CRM_Core_OptionGroup::values('applicant_status', TRUE))); } elseif ($fieldName == 'highschool_gpa_id') { $form->add('select', $name, $title, array('' => '-- Select -- ') + CRM_Core_OptionGroup::values('highschool_gpa')); } elseif ($fieldName == 'world_region') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::worldRegion(), $required); } elseif ($fieldName == 'signature_html') { $form->addWysiwyg($name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName)); } elseif ($fieldName == 'signature_text') { $form->add('textarea', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName)); } elseif (substr($fieldName, -11) == 'campaign_id') { if (CRM_Campaign_BAO_Campaign::isCampaignEnable()) { $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(CRM_Utils_Array::value($contactId, $form->_componentCampaigns)); $campaign =& $form->add('select', $name, $title, array('' => ts('- select -')) + $campaigns, $required, 'class="big"'); } } elseif ($fieldName == 'activity_details') { $form->addWysiwyg($fieldName, $title, array('rows' => 4, 'cols' => 60), $required); } elseif ($fieldName == 'activity_duration') { $form->add('text', $fieldName, $title, $attributes, $required); $form->addRule($name, ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger'); } else { $processed = FALSE; if (CRM_Core_Permission::access('Quest', FALSE)) { $processed = CRM_Quest_BAO_Student::buildStudentForm($form, $fieldName, $title, $contactId); } if (!$processed) { if (substr($fieldName, 0, 3) === 'is_' or substr($fieldName, 0, 7) === 'do_not_') { $form->add('advcheckbox', $name, $title, $attributes, $required); } else { $form->add('text', $name, $title, $attributes, $required); } } } static $hiddenSubtype = FALSE; if (!$hiddenSubtype && CRM_Contact_BAO_ContactType::isaSubType($field['field_type'])) { // In registration mode params are submitted via POST and we don't have any clue // about profile-id or the profile-type (which could be a subtype) // To generalize the behavior and simplify the process, // lets always add the hidden //subtype value if there is any, and we won't have to // compute it while processing. if ($onBehalf) { $form->addElement('hidden', 'onbehalf[contact_sub_type]', $field['field_type']); } else { $form->addElement('hidden', 'contact_sub_type_hidden', $field['field_type']); } $hiddenSubtype = TRUE; } if ($view && $mode != CRM_Profile_Form::MODE_SEARCH || $isShared) { $form->freeze($name); } //add the rules if (in_array($fieldName, array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) { $form->addRule($name, ts('Please enter a valid amount.'), 'money'); } if ($rule) { if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) { $form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule); } } }
static function location(&$form) { // Build location criteria based on _submitValues if // available; otherwise, use $form->_formValues. $formValues = $form->_submitValues; if (empty($formValues) && !empty($form->_formValues)) { $formValues = $form->_formValues; } $form->addElement('hidden', 'hidden_location', 1); $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE); $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address'); $elements = array('street_address' => array(ts('Street Address'), $attributes['street_address'], NULL, NULL), 'city' => array(ts('City'), $attributes['city'], NULL, NULL), 'postal_code' => array(ts('Zip / Postal Code'), $attributes['postal_code'], NULL, NULL), 'county' => array(ts('County'), $attributes['county_id'], 'county', TRUE), 'state_province' => array(ts('State / Province'), $attributes['state_province_id'], 'stateProvince', TRUE), 'country' => array(ts('Country'), $attributes['country_id'], 'country', FALSE), 'address_name' => array(ts('Address Name'), $attributes['address_name'], NULL, NULL), 'street_number' => array(ts('Street Number'), $attributes['street_number'], NULL, NULL), 'street_name' => array(ts('Street Name'), $attributes['street_name'], NULL, NULL), 'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], NULL, NULL)); $parseStreetAddress = CRM_Utils_Array::value('street_address_parsing', $addressOptions, 0); $form->assign('parseStreetAddress', $parseStreetAddress); foreach ($elements as $name => $v) { list($title, $attributes, $select, $multiSelect) = $v; if (in_array($name, array('street_number', 'street_name', 'street_unit'))) { if (!$parseStreetAddress) { continue; } } elseif (!$addressOptions[$name]) { continue; } if (!$attributes) { $attributes = $attributes[$name]; } if ($select) { $config = CRM_Core_Config::singleton(); $countryDefault = $config->defaultContactCountry; $stateCountryMap[] = array('state_province' => 'state_province', 'country' => 'country', 'county' => 'county'); if ($select == 'stateProvince') { if ($countryDefault && !isset($formValues['country'])) { $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault); } elseif ($formValues['country']) { $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($formValues['country']); } else { //if not setdefault any country $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select(); } $element = $form->addElement('select', $name, $title, $selectElements); } elseif ($select == 'country') { if ($countryDefault) { //for setdefault country $defaultValues = array(); $defaultValues[$name] = $countryDefault; $form->setDefaults($defaultValues); } $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select(); $element = $form->addElement('select', $name, $title, $selectElements); } elseif ($select == 'county') { if (array_key_exists('state_province', $formValues) && !CRM_Utils_System::isNull($formValues['state_province'])) { $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::countyForState($formValues['state_province']); } else { $selectElements = array('' => ts('- select a state -')); } $element = $form->addElement('select', $name, $title, $selectElements); } else { $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select(); $element = $form->addElement('select', $name, $title, $selectElements); } if ($multiSelect) { $element->setMultiple(TRUE); } } else { $form->addElement('text', $name, $title, $attributes); } if ($addressOptions['postal_code']) { $form->addElement('text', 'postal_code_low', ts('Range-From'), CRM_Utils_Array::value('postal_code', $attributes)); $form->addElement('text', 'postal_code_high', ts('To'), CRM_Utils_Array::value('postal_code', $attributes)); } } // extend addresses with proximity search $form->addElement('text', 'prox_distance', ts('Find contacts within')); $form->addElement('select', 'prox_distance_unit', NULL, array('miles' => ts('Miles'), 'kilos' => ts('Kilometers'))); // is there another form rule that does decimals besides money ? ... $form->addRule('prox_distance', ts('Please enter positive number as a distance'), 'numeric'); CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); $worldRegions = array('' => ts('- any region -')) + CRM_Core_PseudoConstant::worldRegion(); $form->addElement('select', 'world_region', ts('World Region'), $worldRegions); // checkboxes for location type $location_type = array(); $locationType = CRM_Core_PseudoConstant::locationType(); foreach ($locationType as $locationTypeID => $locationTypeName) { $location_type[] = $form->createElement('checkbox', $locationTypeID, NULL, $locationTypeName); } $form->addGroup($location_type, 'location_type', ts('Location Types'), ' '); // custom data extending addresses - $extends = array('Address'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('addressGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $elementName = 'custom_' . $field['id']; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $field['id'], FALSE, FALSE, TRUE); } } } }
function restWhere(&$values) { list($name, $op, $value, $grouping, $wildcard) = $values; if (!CRM_Utils_Array::value($grouping, $this->_where)) { $this->_where[$grouping] = array(); } //check if the location type exits for fields $lType = ''; $locType = array(); $locType = explode('-', $name); //add phone type if exists if (isset($locType[2]) && $locType[2]) { $locType[2] = CRM_Core_DAO::escapeString($locType[2]); } $field = CRM_Utils_Array::value($name, $this->_fields); if (!$field) { $field = CRM_Utils_Array::value($locType[0], $this->_fields); if (!$field) { return; } } $setTables = true; // FIXME: the LOWER/strtolower pairs below most probably won't work // with non-US-ASCII characters, as even if MySQL does the proper // thing with LOWER-ing them (4.0 almost certainly won't, but then // we don't officially support 4.0 for non-US-ASCII data), PHP // won't do the proper thing with strtolower-ing them unless the // underlying operating system uses an UTF-8 locale for LC_CTYPE // for the user the webserver runs at (or suEXECs); we should use // mb_strtolower(), but then we'd require mb_strings support; we // could wrap this in function_exist(), though if (substr($name, 0, 14) === 'state_province') { if (isset($locType[1]) && is_numeric($locType[1])) { $setTables = false; //get the location name $locationType =& CRM_Core_PseudoConstant::locationType(); list($tName, $fldName) = self::getLocationTableName($field['where'], $locType); $this->_whereTables[$tName] = $this->_tables[$tName]; $where = "`{$tName}`.{$fldName}"; } else { $where = $field['where']; } $wc = $op != 'LIKE' ? "LOWER({$where})" : $where; if (is_numeric($value)) { $where = str_replace('.name', '.id', $where); $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive'); $states =& CRM_Core_PseudoConstant::stateProvince(); $value = $states[(int) $value]; } else { $wc = $op != 'LIKE' ? "LOWER({$where})" : $where; $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String'); } if (!$lType) { $this->_qill[$grouping][] = ts('State') . " {$op} '{$value}'"; } else { $this->_qill[$grouping][] = ts('State') . " ({$lType}) {$op} '{$value}'"; } } else { if (substr($name, 0, 7) === 'country') { if (isset($locType[1]) && is_numeric($locType[1])) { $setTables = false; //get the location name $locationType =& CRM_Core_PseudoConstant::locationType(); list($tName, $fldName) = self::getLocationTableName($field['where'], $locType); $this->_whereTables[$tName] = $this->_tables[$tName]; $where = "`{$tName}`.{$fldName}"; } else { $where = $field['where']; } if (is_numeric($value)) { $where = str_replace('.name', '.id', $where); $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive'); $countries =& CRM_Core_PseudoConstant::country(); $value = $countries[(int) $value]; } else { $wc = $op != 'LIKE' ? "LOWER({$where})" : $where; $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String'); } if (!$lType) { $this->_qill[$grouping][] = ts('Country') . " {$op} '{$value}'"; } else { $this->_qill[$grouping][] = ts('Country') . " ({$lType}) {$op} '{$value}'"; } } else { if (substr($name, 0, 6) === 'county') { if (isset($locType[1]) && is_numeric($locType[1])) { $setTables = false; //get the location name $locationType =& CRM_Core_PseudoConstant::locationType(); list($tName, $fldName) = self::getLocationTableName($field['where'], $locType); $this->_whereTables[$tName] = $this->_tables[$tName]; $where = "`{$tName}`.{$fldName}"; } else { $where = $field['where']; } if (is_numeric($value)) { $where = str_replace('.name', '.id', $where); $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive'); $counties =& CRM_Core_PseudoConstant::county(); $value = $counties[(int) $value]; } else { $wc = $op != 'LIKE' ? "LOWER({$where})" : $where; $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String'); } if (!$lType) { $this->_qill[$grouping][] = ts('County') . " {$op} '{$value}'"; } else { $this->_qill[$grouping][] = ts('County') . " ({$lType}) {$op} '{$value}'"; } } else { if ($name === 'world_region') { $worldRegions =& CRM_Core_PseudoConstant::worldRegion(); if (is_numeric($value)) { $value = $worldRegions[(int) $value]; } $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}"; $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String'); $this->_qill[$grouping][] = ts('World Region') . " {$op} '{$value}'"; } else { if ($name === 'individual_prefix') { $individualPrefixs =& CRM_Core_PseudoConstant::individualPrefix(); if (is_numeric($value)) { $value = $individualPrefixs[(int) $value]; } $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}"; $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String'); $this->_qill[$grouping][] = ts('Individual Prefix') . " {$op} '{$value}'"; } else { if ($name === 'individual_suffix') { $individualSuffixs =& CRM_Core_PseudoConstant::individualsuffix(); if (is_numeric($value)) { $value = $individualSuffixs[(int) $value]; } $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}"; $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String'); $this->_qill[$grouping][] = ts('Individual Suffix') . " {$op} '{$value}'"; } else { if ($name === 'gender') { $genders =& CRM_Core_PseudoConstant::gender(); if (is_numeric($value)) { $value = $genders[(int) $value]; } $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}"; $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String'); $this->_qill[$grouping][] = ts('Gender') . " {$op} '{$value}'"; } else { if ($name === 'birth_date') { $date = CRM_Utils_Date::format($value); $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date); if ($date) { $date = CRM_Utils_Date::customFormat($date); $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\""; } else { $this->_qill[$grouping][] = "{$field['title']} {$op}"; } } else { if ($name === 'deceased_date') { $date = CRM_Utils_Date::format($value); $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date); if ($date) { $date = CRM_Utils_Date::customFormat($date); $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\""; } else { $this->_qill[$grouping][] = "{$field['title']} {$op}"; } } else { if ($name === 'is_deceased') { $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $value); $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\""; } else { if ($name === 'contact_id') { if (is_int($value)) { $this->_where[$grouping][] = self::buildClause($field['where'], $op, $value); $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}"; } } else { if ($name === 'name') { $value = strtolower(CRM_Core_DAO::escapeString($value)); if ($wildcard) { $value = "%{$value}%"; $op = 'LIKE'; } $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}"; $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}'"); $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\""; } else { if ($name === 'current_employer') { $value = strtolower(CRM_Core_DAO::escapeString($value)); if ($wildcard) { $value = "%{$value}%"; $op = 'LIKE'; } $wc = $op != 'LIKE' ? "LOWER(contact_a.organization_name)" : "contact_a.organization_name"; $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}' AND contact_a.contact_type ='Individual'"); $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\""; } else { if ($name === 'email_greeting') { $filterCondition = array('greeting_type' => 'email_greeting'); $emailGreetings =& CRM_Core_PseudoConstant::greeting($filterCondition); if (is_numeric($value)) { $value = $emailGreetings[(int) $value]; } $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}"; $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String'); $this->_qill[$grouping][] = ts('Email Greeting') . " {$op} '{$value}'"; } else { if ($name === 'postal_greeting') { $filterCondition = array('greeting_type' => 'postal_greeting'); $postalGreetings =& CRM_Core_PseudoConstant::greeting($filterCondition); if (is_numeric($value)) { $value = $postalGreetings[(int) $value]; } $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}"; $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String'); $this->_qill[$grouping][] = ts('Postal Greeting') . " {$op} '{$value}'"; } else { if ($name === 'addressee') { $filterCondition = array('greeting_type' => 'addressee'); $addressee =& CRM_Core_PseudoConstant::greeting($filterCondition); if (is_numeric($value)) { $value = $addressee[(int) $value]; } $wc = $op != 'LIKE' ? "LOWER({$field['where']})" : "{$field['where']}"; $this->_where[$grouping][] = self::buildClause($wc, $op, $value, 'String'); $this->_qill[$grouping][] = ts('Addressee') . " {$op} '{$value}'"; } else { // sometime the value is an array, need to investigate and fix if (is_array($value)) { CRM_Core_Error::fatal(); } if (!empty($field['where'])) { if ($op != 'IN') { $value = strtolower(CRM_Core_DAO::escapeString($value)); } if ($wildcard) { $value = "%{$value}%"; $op = 'LIKE'; } if ($op != 'IN') { $value = "'{$value}'"; } if (isset($locType[1]) && is_numeric($locType[1])) { $setTables = false; //get the location name $locationType =& CRM_Core_PseudoConstant::locationType(); list($tName, $fldName) = self::getLocationTableName($field['where'], $locType); $where = "`{$tName}`.{$fldName}"; $this->_where[$grouping][] = self::buildClause("LOWER({$where})", $op, $value); $this->_whereTables[$tName] = $this->_tables[$tName]; $this->_qill[$grouping][] = "{$field['title']} {$op} '{$value}'"; } else { list($tableName, $fieldName) = explode('.', $field['where'], 2); if ($tableName == 'civicrm_contact') { $fieldName = "LOWER(contact_a.{$fieldName})"; } else { if ($op != 'IN' && !is_numeric($value)) { $fieldName = "LOWER({$field['where']})"; } else { $fieldName = "{$field['where']}"; } } $this->_where[$grouping][] = self::buildClause($fieldName, $op, $value); $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}"; } } } } } } } } } } } } } } } } } } if ($setTables) { list($tableName, $fieldName) = explode('.', $field['where'], 2); if (isset($tableName)) { $this->_tables[$tableName] = 1; $this->_whereTables[$tableName] = 1; } } }
function restWhere(&$values) { $name = CRM_Utils_Array::value(0, $values); $op = CRM_Utils_Array::value(1, $values); $value = CRM_Utils_Array::value(2, $values); $grouping = CRM_Utils_Array::value(3, $values); $wildcard = CRM_Utils_Array::value(4, $values); if (isset($grouping) && empty($this->_where[$grouping])) { $this->_where[$grouping] = array(); } $multipleFields = array('url'); //check if the location type exits for fields $lType = ''; $locType = explode('-', $name); if (!in_array($locType[0], $multipleFields)) { //add phone type if exists if (isset($locType[2]) && $locType[2]) { $locType[2] = CRM_Core_DAO::escapeString($locType[2]); } } $field = CRM_Utils_Array::value($name, $this->_fields); if (!$field) { $field = CRM_Utils_Array::value($locType[0], $this->_fields); if (!$field) { return; } } $setTables = TRUE; $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower'; $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); if (substr($name, 0, 14) === 'state_province') { if (isset($locType[1]) && is_numeric($locType[1])) { $setTables = FALSE; $aName = "{$locationType[$locType[1]]}-address"; $where = "`{$aName}`.state_province_id"; } else { $where = "civicrm_address.state_province_id"; } $states = CRM_Core_PseudoConstant::stateProvince(); if (is_numeric($value)) { $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive'); $value = $states[(int) $value]; } else { $intVal = CRM_Utils_Array::key($value, $states); $this->_where[$grouping][] = self::buildClause($where, $op, $intVal, 'Positive'); } if (!$lType) { $this->_qill[$grouping][] = ts('State') . " {$op} '{$value}'"; } else { $this->_qill[$grouping][] = ts('State') . " ({$lType}) {$op} '{$value}'"; } } elseif (!empty($field['pseudoconstant'])) { $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', $field['name']), $field, $field['title'], 'String', TRUE); if ($name == 'gender_id') { self::$_openedPanes[ts('Demographics')] = TRUE; } } elseif (substr($name, 0, 7) === 'country') { if (isset($locType[1]) && is_numeric($locType[1])) { $setTables = FALSE; $aName = "{$locationType[$locType[1]]}-address"; $where = "`{$aName}`.country_id"; } else { $where = "civicrm_address.country_id"; } $countries = CRM_Core_PseudoConstant::country(); if (is_numeric($value)) { $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive'); $value = $countries[(int) $value]; } else { $intVal = CRM_Utils_Array::key($value, $countries); $this->_where[$grouping][] = self::buildClause($where, $op, $intVal, 'Positive'); } if (!$lType) { $this->_qill[$grouping][] = ts('Country') . " {$op} '{$value}'"; } else { $this->_qill[$grouping][] = ts('Country') . " ({$lType}) {$op} '{$value}'"; } } elseif (substr($name, 0, 6) === 'county') { if (isset($locType[1]) && is_numeric($locType[1])) { $setTables = FALSE; $aName = "{$locationType[$locType[1]]}-address"; $where = "`{$aName}`.county_id"; } else { $where = "civicrm_address.county_id"; } $counties = CRM_Core_PseudoConstant::county(); if (is_numeric($value)) { $this->_where[$grouping][] = self::buildClause($where, $op, $value, 'Positive'); $value = $counties[(int) $value]; } else { $intVal = CRM_Utils_Array::key($value, $counties); $this->_where[$grouping][] = self::buildClause($where, $op, $intVal, 'Positive'); } if (!$lType) { $this->_qill[$grouping][] = ts('County') . " {$op} '{$value}'"; } else { $this->_qill[$grouping][] = ts('County') . " ({$lType}) {$op} '{$value}'"; } } elseif ($name === 'world_region') { $field['where'] = 'civicrm_worldregion.id'; $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::worldRegion(), $field, ts('World Region')); } elseif ($name === 'birth_date') { $date = CRM_Utils_Date::processDate($value); $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date); if ($date) { $date = CRM_Utils_Date::customFormat($date); $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\""; } else { $this->_qill[$grouping][] = "{$field['title']} {$op}"; } self::$_openedPanes[ts('Demographics')] = TRUE; } elseif ($name === 'deceased_date') { $date = CRM_Utils_Date::processDate($value); $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date); if ($date) { $date = CRM_Utils_Date::customFormat($date); $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$date}\""; } else { $this->_qill[$grouping][] = "{$field['title']} {$op}"; } self::$_openedPanes[ts('Demographics')] = TRUE; } elseif ($name === 'is_deceased') { $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $value); $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\""; self::$_openedPanes[ts('Demographics')] = TRUE; } elseif ($name === 'contact_id') { if (is_int($value)) { $this->_where[$grouping][] = self::buildClause($field['where'], $op, $value); $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}"; } } elseif ($name === 'name') { $value = $strtolower(CRM_Core_DAO::escapeString($value)); if ($wildcard) { $value = "%{$value}%"; $op = 'LIKE'; } $wc = self::caseImportant($op) ? "LOWER({$field['where']})" : "{$field['where']}"; $this->_where[$grouping][] = self::buildClause($wc, $op, "'{$value}'"); $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\""; } elseif ($name === 'current_employer') { $value = $strtolower(CRM_Core_DAO::escapeString($value)); if ($wildcard) { $value = "%{$value}%"; $op = 'LIKE'; } $wc = self::caseImportant($op) ? "LOWER(contact_a.organization_name)" : "contact_a.organization_name"; $ceWhereClause = self::buildClause($wc, $op, $value); $ceWhereClause .= " AND contact_a.contact_type = 'Individual'"; $this->_where[$grouping][] = $ceWhereClause; $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\""; } elseif ($name === 'email_greeting') { $filterCondition = array('greeting_type' => 'email_greeting'); $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Email Greeting')); } elseif ($name === 'postal_greeting') { $filterCondition = array('greeting_type' => 'postal_greeting'); $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Postal Greeting')); } elseif ($name === 'addressee') { $filterCondition = array('greeting_type' => 'addressee'); $this->optionValueQuery($name, $op, $value, $grouping, CRM_Core_PseudoConstant::greeting($filterCondition), $field, ts('Addressee')); } elseif (substr($name, 0, 4) === 'url-') { $tName = 'civicrm_website'; $this->_whereTables[$tName] = $this->_tables[$tName] = "\nLEFT JOIN civicrm_website ON ( civicrm_website.contact_id = contact_a.id )"; $value = $strtolower(CRM_Core_DAO::escapeString($value)); if ($wildcard) { $value = "%{$value}%"; $op = 'LIKE'; } $wc = 'civicrm_website.url'; $this->_where[$grouping][] = $d = self::buildClause($wc, $op, $value); $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\""; } elseif ($name === 'contact_is_deleted') { $this->_where[$grouping][] = self::buildClause("contact_a.is_deleted", $op, $value); $this->_qill[$grouping][] = "{$field['title']} {$op} \"{$value}\""; } else { // sometime the value is an array, need to investigate and fix if (is_array($value)) { CRM_Core_Error::fatal(); } if (!empty($field['where'])) { if ($op != 'IN') { $value = $strtolower($value); } if ($wildcard) { $value = "%{$value}%"; $op = 'LIKE'; } if (isset($locType[1]) && is_numeric($locType[1])) { $setTables = FALSE; //get the location name list($tName, $fldName) = self::getLocationTableName($field['where'], $locType); $where = "`{$tName}`.{$fldName}"; $this->_where[$grouping][] = self::buildClause("LOWER({$where})", $op, $value); $this->_whereTables[$tName] = $this->_tables[$tName]; $this->_qill[$grouping][] = "{$field['title']} {$op} '{$value}'"; } else { list($tableName, $fieldName) = explode('.', $field['where'], 2); if ($tableName == 'civicrm_contact') { $fieldName = "LOWER(contact_a.{$fieldName})"; } else { if ($op != 'IN' && !is_numeric($value)) { $fieldName = "LOWER({$field['where']})"; } else { $fieldName = "{$field['where']}"; } } $type = NULL; if (!empty($field['type'])) { $type = CRM_Utils_Type::typeToString($field['type']); } $this->_where[$grouping][] = self::buildClause($fieldName, $op, $value, $type); $this->_qill[$grouping][] = "{$field['title']} {$op} {$value}"; } } } if ($setTables && isset($field['where'])) { list($tableName, $fieldName) = explode('.', $field['where'], 2); if (isset($tableName)) { $this->_tables[$tableName] = 1; $this->_whereTables[$tableName] = 1; } } }
static function location(&$form) { $form->addElement('hidden', 'hidden_location', 1); require_once 'CRM/Core/BAO/Preferences.php'; $addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true); $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address'); $elements = array('street_address' => array(ts('Street Address'), $attributes['street_address'], null, null), 'city' => array(ts('City'), $attributes['city'], null, null), 'postal_code' => array(ts('Zip / Postal Code'), $attributes['postal_code'], null, null), 'county' => array(ts('County'), $attributes['county_id'], 'county', false), 'state_province' => array(ts('State / Province'), $attributes['state_province_id'], 'stateProvince', true), 'country' => array(ts('Country'), $attributes['country_id'], 'country', false), 'address_name' => array(ts('Address Name'), $attributes['address_name'], null, null)); foreach ($elements as $name => $v) { list($title, $attributes, $select, $multiSelect) = $v; if (!$addressOptions[$name]) { continue; } if (!$attributes) { $attributes = $attributes[$name]; } if ($select) { $config = CRM_Core_Config::singleton(); $countryDefault = $config->defaultContactCountry; $stateCountryMap[] = array('state_province' => 'state_province', 'country' => 'country'); if ($select == 'stateProvince') { if ($countryDefault && !isset($form->_submitValues['country'])) { $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault); } else { if ($form->_submitValues['country']) { $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($form->_submitValues['country']); } else { //if not setdefault any country $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select(); } } $element = $form->addElement('select', $name, $title, $selectElements); } else { if ($select == 'country') { if ($countryDefault) { //for setdefault country $defaultValues = array(); $defaultValues[$name] = $countryDefault; $form->setDefaults($defaultValues); } $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select(); $element = $form->addElement('select', $name, $title, $selectElements); } else { $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select(); $element = $form->addElement('select', $name, $title, $selectElements); } } if ($multiSelect) { $element->setMultiple(true); } } else { $form->addElement('text', $name, $title, $attributes); } if ($addressOptions['postal_code']) { $form->addElement('text', 'postal_code_low', ts('Range-From'), CRM_Utils_Array::value('postal_code', $attributes)); $form->addElement('text', 'postal_code_high', ts('To'), CRM_Utils_Array::value('postal_code', $attributes)); } } // extend addresses with proximity search $form->addElement('text', 'prox_distance', ts('Find contacts within')); $form->addElement('select', 'prox_distance_unit', null, array('miles' => ts('Miles'), 'kilos' => ts('Kilometers'))); // is there another form rule that does decimals besides money ? ... $form->addRule('prox_distance', ts('Please enter positive number as a distance'), 'numeric'); require_once 'CRM/Core/BAO/Address.php'; CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); $worldRegions = array('' => ts('- any region -')) + CRM_Core_PseudoConstant::worldRegion(); $form->addElement('select', 'world_region', ts('World Region'), $worldRegions); // checkboxes for location type $location_type = array(); $locationType = CRM_Core_PseudoConstant::locationType(); foreach ($locationType as $locationTypeID => $locationTypeName) { $location_type[] = HTML_QuickForm::createElement('checkbox', $locationTypeID, null, $locationTypeName); } $form->addGroup($location_type, 'location_type', ts('Location Types'), ' '); // custom data extending addresses - require_once 'CRM/Core/BAO/CustomGroup.php'; $extends = array('Address'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(null, true, $extends); if ($groupDetails) { require_once 'CRM/Core/BAO/CustomField.php'; $form->assign('addressGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $elementName = 'custom_' . $field['id']; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $field['id'], false, false, true); } } } }