From 1071730cbe724aa1ef567e095a2fcb91bce9d087 Mon Sep 17 00:00:00 2001 From: "Donald A. Lobo" Date: Mon, 29 Apr 2013 21:13:46 -0700 Subject: [PATCH] CRM-12464 ---------------------------------------- * CRM-12464: Search improvements in 4.4 http://issues.civicrm.org/jira/browse/CRM-12464 --- CRM/Contact/BAO/Contact.php | 25 ++-- CRM/Contact/BAO/Query.php | 66 ++++------ CRM/Core/OptionValue.php | 16 ++- .../CRM/Contact/BAO/QueryTestDataProvider.php | 121 +++++++++--------- .../phpunit/CRM/Contact/BAO/queryDataset.xml | 52 +++++++- 5 files changed, 162 insertions(+), 118 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 756cecc216..acf604d1db 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -772,13 +772,13 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); $logDAO->entity_table = 'civicrm_contact'; $logDAO->entity_id = $id; $logDAO->delete(); - + // delete contact participants CRM-12155 CRM_Event_BAO_Participant::deleteContactParticipant($id); // delete contact contributions CRM-12155 CRM_Contribute_BAO_Contribution::deleteContactContribution($id); - + // do activity cleanup, CRM-5604 CRM_Activity_BAO_Activity::cleanupActivity($id); @@ -1073,8 +1073,7 @@ WHERE id={$id}; "; * combine all the importable fields from the lower levels object * * The ordering is important, since currently we do not have a weight - * scheme. Adding weight is super important and should be done in the - * next week or so, before this can be called complete. + * scheme. Adding weight is super important * * @param int $contactType contact Type * @param boolean $status status is used to manipulate first title @@ -1141,12 +1140,8 @@ WHERE id={$id}; "; $fields = array_merge($fields, $locationFields); - $fields = array_merge($fields, - CRM_Contact_DAO_Contact::import() - ); - $fields = array_merge($fields, - CRM_Core_DAO_Note::import() - ); + $fields = array_merge($fields, CRM_Contact_DAO_Contact::import()); + $fields = array_merge($fields, CRM_Core_DAO_Note::import()); //website fields $fields = array_merge($fields, CRM_Core_DAO_Website::import()); @@ -1268,8 +1263,12 @@ WHERE id={$id}; "; $fields = CRM_Contact_DAO_Contact::export(); // the fields are meant for contact types - if (in_array($contactType, array( - 'Individual', 'Household', 'Organization', 'All'))) { + if ( + in_array( + $contactType, + array('Individual', 'Household', 'Organization', 'All') + ) + ) { $fields = array_merge($fields, CRM_Core_OptionValue::getFields('', $contactType)); } // add current employer for individuals @@ -2982,7 +2981,7 @@ LEFT JOIN civicrm_address add2 ON ( add1.master_id = add2.id ) } } - + /** * Delete a contact-related object that has an 'is_primary' field * Ensures that is_primary gets assigned to another object if available diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 5b0af2c3ee..9e1f39650e 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -578,7 +578,8 @@ class CRM_Contact_BAO_Query { // skip component fields // there are done by the alter query below // and need not be done on every field - if ((substr($name, 0, 12) == 'participant_') || + if ( + (substr($name, 0, 12) == 'participant_') || (substr($name, 0, 7) == 'pledge_') || (substr($name, 0, 5) == 'case_') ) { @@ -598,11 +599,10 @@ class CRM_Contact_BAO_Query { } $cfID = CRM_Core_BAO_CustomField::getKeyID($name); - - if (CRM_Utils_Array::value($name, $this->_paramLookup) || + if ( + CRM_Utils_Array::value($name, $this->_paramLookup) || CRM_Utils_Array::value($name, $this->_returnProperties) ) { - if ($cfID) { // add to cfIDs array if not present if (!array_key_exists($cfID, $this->_cfIDs)) { @@ -612,21 +612,25 @@ class CRM_Contact_BAO_Query { elseif (isset($field['where'])) { list($tableName, $fieldName) = explode('.', $field['where'], 2); if (isset($tableName)) { - if (CRM_Utils_Array::value($tableName, self::$_dependencies)) { $this->_tables['civicrm_address'] = 1; $this->_select['address_id'] = 'civicrm_address.id as address_id'; $this->_element['address_id'] = 1; } - if ($tableName == 'gender' || $tableName == 'individual_prefix' - || $tableName == 'individual_suffix' || $tableName == 'im_provider' - || $tableName == 'email_greeting' || $tableName == 'postal_greeting' - || $tableName == 'addressee' + if ( + $tableName == 'gender' || $tableName == 'individual_prefix' || + $tableName == 'individual_suffix' || $tableName == 'im_provider' || + $tableName == 'email_greeting' || $tableName == 'postal_greeting' || + $tableName == 'addressee' ) { CRM_Core_OptionValue::select($this); - if (in_array($tableName, array( - 'email_greeting', 'postal_greeting', 'addressee'))) { + if ( + in_array( + $tableName, + array('email_greeting', 'postal_greeting', 'addressee') + ) + ) { //get display $greetField = "{$name}_display"; $this->_select[$greetField] = "contact_a.{$greetField} as {$greetField}"; @@ -1718,6 +1722,17 @@ class CRM_Contact_BAO_Query { $this->_qill[$grouping][] = ts('State') . " ($lType) $op '$value'"; } } + elseif ($field['pseudoconstant']) { + $this->optionValueQuery( + $name, $op, $value, $grouping, + CRM_Core_PseudoConstant::{$field['pseudoconstant']['name']}(), + $field, + $field['title'] + ); + if ($name == 'gender') { + self::$_openedPanes[ts('Demographics')] = TRUE; + } + } elseif (substr($name, 0, 7) === 'country') { if (isset($locType[1]) && is_numeric($locType[1])) { $setTables = FALSE; @@ -1784,31 +1799,6 @@ class CRM_Contact_BAO_Query { ts('World Region') ); } - elseif ($name === 'individual_prefix') { - $this->optionValueQuery( - $name, $op, $value, $grouping, - CRM_Core_PseudoConstant::individualPrefix(), - $field, - ts('Individual Prefix') - ); - } - elseif ($name === 'individual_suffix') { - $this->optionValueQuery( - $name, $op, $value, $grouping, - CRM_Core_PseudoConstant::individualSuffix(), - $field, - ts('Individual Suffix') - ); - } - elseif ($name === 'gender') { - $this->optionValueQuery( - $name, $op, $value, $grouping, - CRM_Core_PseudoConstant::gender(), - $field, - ts('Gender') - ); - self::$_openedPanes[ts('Demographics')] = TRUE; - } elseif ($name === 'birth_date') { $date = CRM_Utils_Date::processDate($value); $this->_where[$grouping][] = self::buildClause("contact_a.{$name}", $op, $date); @@ -2698,7 +2688,7 @@ WHERE id IN ( $groupIDs ) $tActTable = "`civicrm_act_tag-" . $value . "`"; $activityContacts = CRM_Core_PseudoConstant::activityContacts('name'); $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); - + $this->_tables[$etActTable] = $this->_whereTables[$etActTable] = " LEFT JOIN civicrm_activity_contact @@ -4225,7 +4215,7 @@ civicrm_relationship.start_date > {$today} return CRM_Core_DAO::singleValueQuery($query); } - //crm_core_error::debug('$query', $query); //exit; + // crm_core_error::debug('$query', $query); exit; $dao = CRM_Core_DAO::executeQuery($query); if ($groupContacts) { diff --git a/CRM/Core/OptionValue.php b/CRM/Core/OptionValue.php index 27165b1a85..e326171503 100644 --- a/CRM/Core/OptionValue.php +++ b/CRM/Core/OptionValue.php @@ -297,13 +297,15 @@ class CRM_Core_OptionValue { if (in_array($contactType, array( 'Individual', 'Household', 'Organization', 'All'))) { $nameTitle = array( - 'addressee' => array('name' => 'addressee', + 'addressee' => array( + 'name' => 'addressee', 'title' => ts('Addressee'), 'headerPattern' => '/^addressee$/i', ), ); $title = array( - 'email_greeting' => array('name' => 'email_greeting', + 'email_greeting' => array( + 'name' => 'email_greeting', 'title' => ts('Email Greeting'), 'headerPattern' => '/^email_greeting$/i', ), @@ -317,20 +319,25 @@ class CRM_Core_OptionValue { } if ($contactType == 'Individual' || $contactType == 'All') { + $contactFields = CRM_Contact_DAO_Contact::fields(); $title = array( - 'gender' => array('name' => 'gender', + 'gender' => array( + 'name' => 'gender', 'title' => ts('Gender'), 'headerPattern' => '/^gender$/i', + 'pseudoconstant' => $contactFields['gender_id']['pseudoconstant'], ), 'individual_prefix' => array( 'name' => 'individual_prefix', 'title' => ts('Individual Prefix'), 'headerPattern' => '/^(prefix|title)/i', + 'pseudoconstant' => $contactFields['prefix_id']['pseudoconstant'], ), 'individual_suffix' => array( 'name' => 'individual_suffix', 'title' => ts('Individual Suffix'), 'headerPattern' => '/^suffix$/i', + 'pseudoconstant' => $contactFields['suffix_id']['pseudoconstant'], ), ); $nameTitle = array_merge($nameTitle, $title); @@ -341,9 +348,6 @@ class CRM_Core_OptionValue { foreach ($nameTitle as $name => $attribs) { self::$_fields[$key][$name] = $optionName; list($tableName, $fieldName) = explode('.', $optionName['where']); - // not sure of this fix, so keeping it commented for now - // this is from CRM-1541 - // self::$_fields[$mode][$name]['where'] = $name . '.' . $fieldName; self::$_fields[$key][$name]['where'] = "{$name}.label"; foreach ($attribs as $k => $val) { self::$_fields[$key][$name][$k] = $val; diff --git a/tests/phpunit/CRM/Contact/BAO/QueryTestDataProvider.php b/tests/phpunit/CRM/Contact/BAO/QueryTestDataProvider.php index 9f4622ad5f..585b665a95 100644 --- a/tests/phpunit/CRM/Contact/BAO/QueryTestDataProvider.php +++ b/tests/phpunit/CRM/Contact/BAO/QueryTestDataProvider.php @@ -49,55 +49,68 @@ class CRM_Contact_BAO_QueryTestDataProvider implements Iterator { * database in dataset.xml */ private $dataset = array( - // Include static group 3 - array('fv' => array('group' => array('3' => 1)), - 'id' => array( - '17', '18', '19', '20', '21', - '22', '23', '24', - ), - ), - // Include static group 5 - array('fv' => array('group' => array('5' => 1)), - 'id' => array( - '13', '14', '15', '16', '21', - '22', '23', '24', - ), - ), - // Include static groups 3 and 5 - array( - 'fv' => array('group' => array('3' => 1, - '5' => 1, - )), - 'id' => array( - '13', '14', '15', '16', '17', '18', - '19', '20', '21', '22', '23', '24', - ), - ), - // Include tag 7 - array('fv' => array('tag' => array('7' => 1)), - 'id' => array( - '11', '12', '15', '16', - '19', '20', '23', '24', - ), - ), - // Include tag 9 - array('fv' => array('tag' => array('9' => 1)), - 'id' => array( - '10', '12', '14', '16', - '18', '20', '22', '24', - ), - ), - // Include tags 7 and 9 - array( - 'fv' => array('tag' => array('7' => 1, - '9' => 1, - )), - 'id' => array( - '10', '11', '12', '14', '15', '16', - '18', '19', '20', '22', '23', '24', - ), - ), - ); + // Include static group 3 + array('fv' => array('group' => array('3' => 1)), + 'id' => array( + '17', '18', '19', '20', '21', + '22', '23', '24', + ), + ), + // Include static group 5 + array('fv' => array('group' => array('5' => 1)), + 'id' => array( + '13', '14', '15', '16', '21', + '22', '23', '24', + ), + ), + // Include static groups 3 and 5 + array( + 'fv' => array('group' => array('3' => 1, + '5' => 1, + )), + 'id' => array( + '13', '14', '15', '16', '17', '18', + '19', '20', '21', '22', '23', '24', + ), + ), + // Include tag 7 + array('fv' => array('tag' => array('7' => 1)), + 'id' => array( + '11', '12', '15', '16', + '19', '20', '23', '24', + ), + ), + // Include tag 9 + array('fv' => array('tag' => array('9' => 1)), + 'id' => array( + '10', '12', '14', '16', + '18', '20', '22', '24', + ), + ), + // Include tags 7 and 9 + array( + 'fv' => array('tag' => array('7' => 1, + '9' => 1, + )), + 'id' => array( + '10', '11', '12', '14', '15', '16', + '18', '19', '20', '22', '23', '24', + ), + ), + + // gender_id 1 (male) + array( 'fv' => array( 'gender' => 'Female' ), + 'id' => array( '9', '20', '22' ) + ), + // prefix_id 2 (Ms.) + array( 'fv' => array( 'individual_prefix' => 'Ms.' ), + 'id' => array( '10', '13' ) + ), + // suffix_id 2 (Sr.) + array( 'fv' => array( 'individual_suffix' => 'V' ), + 'id' => array( '16', '19', '20', '21') + ), + ); public function _construct() { $this->i = 0; @@ -134,13 +147,3 @@ class CRM_Contact_BAO_QueryTestDataProvider implements Iterator { } } // class CRM_Contact_BAO_QueryTestDataProvider - -// -- set Emacs parameters -- -// Local variables: -// mode: php; -// tab-width: 4 -// c-basic-offset: 4 -// c-hanging-comment-ender-p: nil -// indent-tabs-mode: nil -// End: - diff --git a/tests/phpunit/CRM/Contact/BAO/queryDataset.xml b/tests/phpunit/CRM/Contact/BAO/queryDataset.xml index 29406270bb..d3b6062709 100644 --- a/tests/phpunit/CRM/Contact/BAO/queryDataset.xml +++ b/tests/phpunit/CRM/Contact/BAO/queryDataset.xml @@ -10,6 +10,9 @@ sort_name="Test Contact 9" first_name="Test" last_name="Contact 9" + gender_id="1" + prefix_id="1" + suffix_id="1" />