CRM-12464
authorDonald A. Lobo <lobo@civicrm.org>
Tue, 30 Apr 2013 04:13:46 +0000 (21:13 -0700)
committerColeman Watts <coleman@civicrm.org>
Wed, 29 May 2013 21:32:22 +0000 (14:32 -0700)
----------------------------------------
* CRM-12464: Search improvements in 4.4
  http://issues.civicrm.org/jira/browse/CRM-12464

CRM/Contact/BAO/Contact.php
CRM/Contact/BAO/Query.php
CRM/Core/OptionValue.php
tests/phpunit/CRM/Contact/BAO/QueryTestDataProvider.php
tests/phpunit/CRM/Contact/BAO/queryDataset.xml

index 756cecc216e99d99ce5b1f7574692f7e481fddad..acf604d1dbb4cbf602f2c6d5aace8578040787c6 100644 (file)
@@ -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
index 5b0af2c3ee021a792564c7dfa2eb1f7bfe07a691..9e1f39650e5418dc9556c73b16528b038343a909 100644 (file)
@@ -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) {
index 27165b1a8548f62a3660e34077d9ad98b1cb8874..e326171503706b4e0ee1d6de7c3f2220ab2d8c13 100644 (file)
@@ -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;
index 9f4622ad5fe7810d150eaba21ed3a94a99f6bec4..585b665a951e77c406b4c76895037df55d6cc697 100644 (file)
@@ -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:
-
index 29406270bb2bc342b256eac3140e773f74c9665b..d3b606270933da26040ad8c49792118ac48214f5 100644 (file)
@@ -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"
     />
     <!--  Groups: none  Tags: 9  -->
     <civicrm_contact
@@ -20,6 +23,9 @@
         sort_name="Test Contact 10"
         first_name="Test"
         last_name="Contact 10"
+       gender_id="2"
+       prefix_id="2"
+        suffix_id="2"
     />
     <!--  Groups: none  Tags: 7  -->
     <civicrm_contact
@@ -30,6 +36,9 @@
         sort_name="Test Contact 11"
         first_name="Test"
         last_name="Contact 11"
+       gender_id="3"
+       prefix_id="3"
+        suffix_id="3"
     />
     <!--  Groups: none  Tags: 7, 9  -->
     <civicrm_contact
@@ -40,6 +49,9 @@
         sort_name="Test Contact 12"
         first_name="Test"
         last_name="Contact 12"
+       gender_id="3"
+       prefix_id="4"
+        suffix_id="4"
     />
     <!--  Groups: 5  Tags: none  -->
     <civicrm_contact
@@ -50,6 +62,9 @@
         sort_name="Test Contact 13"
         first_name="Test"
         last_name="Contact 13"
+       gender_id="2"
+       prefix_id="2"
+        suffix_id="2"
     />
     <!--  Groups: 5  Tags: 9  -->
     <civicrm_contact
@@ -60,6 +75,9 @@
         sort_name="Test Contact 14"
         first_name="Test"
         last_name="Contact 14"
+       gender_id="3"
+       prefix_id="4"
+        suffix_id="4"
     />
     <!--  Groups: 5  Tags: 7  -->
     <civicrm_contact
@@ -70,6 +88,9 @@
         sort_name="Test Contact 15"
         first_name="Test"
         last_name="Contact 15"
+       gender_id="3"
+       prefix_id="4"
+        suffix_id="5"
     />
     <!--  Groups: 5  Tags: 7, 9  -->
     <civicrm_contact
         sort_name="Test Contact 16"
         first_name="Test"
         last_name="Contact 16"
+       gender_id="3"
+       prefix_id="4"
+        suffix_id="6"
     />
     <!--  Groups: 3  Tags: none  -->
     <civicrm_contact
         sort_name="Test Contact 17"
         first_name="Test"
         last_name="Contact 17"
+       gender_id="2"
+       prefix_id="4"
+        suffix_id="7"
     />
     <!--  Groups: 3  Tags: 9  -->
     <civicrm_contact
         sort_name="Test Contact 18"
         first_name="Test"
         last_name="Contact 18"
+       gender_id="2"
+       prefix_id="4"
+        suffix_id="4"
     />
     <!--  Groups: 3  Tags: 7  -->
     <civicrm_contact
         sort_name="Test Contact 19"
         first_name="Test"
         last_name="Contact 19"
+       gender_id="2"
+       prefix_id="4"
+        suffix_id="6"
     />
     <!--  Groups: 3  Tags: 7, 9  -->
     <civicrm_contact
         sort_name="Test Contact 20"
         first_name="Test"
         last_name="Contact 20"
+       gender_id="1"
+       prefix_id="4"
+        suffix_id="6"
     />
     <!--  Groups: 3, 5  Tags: none  -->
     <civicrm_contact
         sort_name="Test Contact 21"
         first_name="Test"
         last_name="Contact 21"
+       gender_id="3"
+       prefix_id="1"
+        suffix_id="6"
     />
     <!--  Groups: 3, 5  Tags: 9  -->
     <civicrm_contact
         sort_name="Test Contact 22"
         first_name="Test"
         last_name="Contact 22"
+       gender_id="1"
+       prefix_id="1"
+        suffix_id="1"
     />
     <!--  Groups: 3, 5  Tags: 7  -->
     <civicrm_contact
         sort_name="Test Contact 23"
         first_name="Test"
         last_name="Contact 23"
+       gender_id="3"
+       prefix_id="1"
+        suffix_id="1"
     />
     <!--  Groups: 3, 5  Tags: 7, 9  -->
     <civicrm_contact
         sort_name="Test Contact 24"
         first_name="Test"
         last_name="Contact 24"
+       gender_id="3"
+       prefix_id="3"
+        suffix_id="2"
     />
     <civicrm_tag
         id="7"
     />
     <civicrm_entity_tag
         entity_id="14"
-        entity_table="civicrm_contact" 
+        entity_table="civicrm_contact"
         tag_id="9"
     />
     <civicrm_entity_tag
         entity_id="16"
-        entity_table="civicrm_contact" 
+        entity_table="civicrm_contact"
         tag_id="9"
     />
     <civicrm_entity_tag