Refactor phone type CRM-12464
[civicrm-core.git] / CRM / Contact / Form / Search / Criteria.php
index 701f0614f3bfc8ad06b1079923cd20edab069162..d95e97c50cc3fbd4d1947054ee9a7c44a1dec73a 100644 (file)
@@ -53,9 +53,7 @@ class CRM_Contact_Form_Search_Criteria {
       // multiselect for groups
       if ($form->_group) {
         // Arrange groups into hierarchical listing (child groups follow their parents and have indentation spacing in title)
-        $ids = implode(',', array_keys($form->_group));
-        $ids = 'IN (' . $ids . ')';
-        $groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($ids, NULL, '  ', TRUE);
+        $groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($form->_group, NULL, '  ', TRUE);
 
         $form->add('select', 'group', ts('Groups'), $groupHierarchy, FALSE,
           array('id' => 'group', 'multiple' => 'multiple', 'title' => ts('- select -'))
@@ -80,7 +78,7 @@ class CRM_Contact_Form_Search_Criteria {
 
       $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
       CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', NULL, TRUE, FALSE, TRUE);
-      
+
       $used_for = CRM_Core_OptionGroup::values('tag_used_for');
       $tagsTypes = array();
       $showAllTagTypes = false;
@@ -91,7 +89,7 @@ class CRM_Contact_Form_Search_Criteria {
         // we will hide searching contact by attachments tags until it will be implemented in core
         if (count($tags) && $key != 'civicrm_file' && $key != 'civicrm_contact') {
           //if tags exists then add type to display in adv search form help text
-          $tagsTypes[] = ts($value); 
+          $tagsTypes[] = ts($value);
           $showAllTagTypes = true;
         }
       }
@@ -116,7 +114,7 @@ class CRM_Contact_Form_Search_Criteria {
 
 
     //added internal ID
-    $form->addElement('text', 'id', ts('Contact ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'id'));
+    $form->addElement('text', 'contact_id', ts('Contact ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'id'));
 
     //added external ID
     $form->addElement('text', 'external_identifier', ts('External ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'));
@@ -262,7 +260,7 @@ class CRM_Contact_Form_Search_Criteria {
     // Phone search
     $form->addElement('text', 'phone_numeric', ts('Phone Number'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone'));
     $locationType = CRM_Core_PseudoConstant::locationType();
-    $phoneType = CRM_Core_PseudoConstant::phoneType();
+    $phoneType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
     $form->add('select', 'phone_location_type_id', ts('Phone Location'), array('' => ts('- any -')) + $locationType);
     $form->add('select', 'phone_phone_type_id', ts('Phone Type'), array('' => ts('- any -')) + $phoneType);
   }
@@ -319,25 +317,13 @@ class CRM_Contact_Form_Search_Criteria {
       }
 
       if ($select) {
-        $config = CRM_Core_Config::singleton();
-        $countryDefault = $config->defaultContactCountry;
-        $stateProvinceDefault = $config->defaultContactStateProvince;
-        $defaultValues = array();
         $stateCountryMap[] = array(
           'state_province' => 'state_province',
           'country' => 'country',
           'county' => 'county',
         );
         if ($select == 'stateProvince') {
-          if ($stateProvinceDefault) {
-            //for setdefault state/province
-            $defaultValues[$name] = $stateProvinceDefault;
-            $form->setDefaults($defaultValues);
-          }
-          if ($countryDefault && !isset($formValues['country'])) {
-            $selectElements = array('' => ts('- any -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
-          }
-          elseif ($formValues['country']) {
+          if (CRM_Utils_Array::value('country', $formValues)) {
             $selectElements = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($formValues['country']);
           }
           else {
@@ -347,11 +333,6 @@ class CRM_Contact_Form_Search_Criteria {
           $element = $form->addElement('select', $name, $title, $selectElements);
         }
         elseif ($select == 'country') {
-          if ($countryDefault) {
-            //for setdefault country
-            $defaultValues[$name] = $countryDefault;
-            $form->setDefaults($defaultValues);
-          }
           $selectElements = array('' => ts('- any -')) + CRM_Core_PseudoConstant::$select();
           $element = $form->addElement('select', $name, $title, $selectElements);
         }
@@ -386,6 +367,8 @@ class CRM_Contact_Form_Search_Criteria {
       }
     }
 
+    CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
+
     // 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')));
@@ -393,7 +376,6 @@ class CRM_Contact_Form_Search_Criteria {
     // 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);
 
@@ -488,7 +470,7 @@ class CRM_Contact_Form_Search_Criteria {
     $form->add('hidden', 'hidden_demographics', 1);
     // radio button for gender
     $genderOptions = array();
-    $gender = CRM_Core_PseudoConstant::gender();
+    $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id');
     foreach ($gender as $key => $var) {
       $genderOptions[$key] = $form->createElement('radio', NULL,
         ts('Gender'), $var, $key,