Refactored out of CRM_Core_PseudoConstant: tag(), customGroup(). CRM-12464
authorAllen Shaw <allen@emphanos.com>
Thu, 2 May 2013 04:35:42 +0000 (21:35 -0700)
committerColeman Watts <coleman@civicrm.org>
Thu, 30 May 2013 05:13:21 +0000 (22:13 -0700)
----------------------------------------
* CRM-12464:
  http://issues.civicrm.org/jira/browse/CRM-12464

26 files changed:
CRM/ACL/Form/ACL.php
CRM/ACL/Page/ACL.php
CRM/Activity/BAO/Query.php
CRM/Case/BAO/Query.php
CRM/Case/Form/ActivityView.php
CRM/Contact/BAO/Query.php
CRM/Contact/Form/Search/Custom/Basic.php
CRM/Contact/Form/Search/Custom/Group.php
CRM/Contact/Form/Search/Custom/MultipleValues.php
CRM/Contact/Form/Search/Custom/Proximity.php
CRM/Contact/Form/Search/Custom/TagContributions.php
CRM/Contact/Import/Form/Preview.php
CRM/Core/BAO/File.php
CRM/Core/BAO/UFGroup.php
CRM/Core/Form/Tag.php
CRM/Core/Permission.php
CRM/Core/PseudoConstant.php
CRM/Custom/Form/MoveField.php
CRM/Event/BAO/Event.php
CRM/Report/Form.php
api/v3/EntityTag.php
tests/phpunit/CRM/Core/PseudoConstantTest.php
tools/bin/scripts/ImportTags.php
tools/extensions/org.civicrm.search.basic/Basic.php
xml/schema/Core/CustomField.xml
xml/schema/Core/EntityTag.xml

index 23d04a76d5f65e94ebb1c15b476d32e0ec84f6db..77bd2664bfd2382fbf1c085049c14ff01bcb48f6 100644 (file)
@@ -166,7 +166,7 @@ class CRM_ACL_Form_ACL extends CRM_Admin_Form {
 
     $customGroup = array('-1' => ts('- select -'),
       '0' => ts('All Custom Groups'),
-    ) + CRM_Core_PseudoConstant::customGroup();
+    ) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_CustomField', 'custom_group_id');
 
     $ufGroup = array('-1' => ts('- select -'),
       '0' => ts('All Profiles'),
index 520faba79835c0001191e9f5727dffd96ed83162..7a0cd9cbc385fc5055735c2b9cd8fdc7b2abbc63 100644 (file)
@@ -177,7 +177,7 @@ ORDER BY entity_id
     ) + CRM_Core_PseudoConstant::group();
     $customGroup = array('-1' => ts('- select -'),
       '0' => ts('All Custom Groups'),
-    ) + CRM_Core_PseudoConstant::customGroup();
+    ) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_CustomField', 'custom_group_id');
     $ufGroup = array('-1' => ts('- select -'),
       '0' => ts('All Profiles'),
     ) + CRM_Core_PseudoConstant::ufGroup();
index 32bbd846359e98e81a5c86623aa1621becdc3c40..4d7c551a28af175c97fa89b1b3ece732c0291495 100644 (file)
@@ -342,7 +342,7 @@ class CRM_Activity_BAO_Query {
 
       case 'activity_tags':
         $value = array_keys($value);
-        $activityTags = CRM_Core_PseudoConstant::tag();
+        $activityTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
 
         $names = array();
         $val = array();
index af40d21062976e2e57485f3669c86b0970d865d3..82b56c3774893ae5861f3a876c977f8b00554e79 100644 (file)
@@ -492,7 +492,7 @@ class CRM_Case_BAO_Query {
           }
         }
       case 'case_tags':
-        $tags = CRM_Core_PseudoConstant::tag();
+        $tags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
 
         if (is_array($value)) {
           foreach ($value as $k => $v) {
index 3df941e3c921793654194783f2813daafa6b1163..5f8395ca506a0c247a6b91fd9562debefd537cf4 100644 (file)
@@ -84,7 +84,7 @@ class CRM_Case_Form_ActivityView extends CRM_Core_Form {
 
     $tags = CRM_Core_BAO_EntityTag::getTag($activityID, 'civicrm_activity');
     if (!empty($tags)) {
-      $allTag = CRM_Core_PseudoConstant::tag();
+      $allTag = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
       foreach ($tags as $tid) {
         $tags[$tid] = $allTag[$tid];
       }
index fba6b89ebadda382f38bd95f936b6811d376f96d..16f392f481108c2d59b31a81f80b3cfda41a618b 100644 (file)
@@ -2710,7 +2710,7 @@ WHERE  id IN ( $groupIDs )
   function tag(&$values) {
     list($name, $op, $value, $grouping, $wildcard) = $values;
 
-    $tagNames = CRM_Core_PseudoConstant::tag();
+    $tagNames = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
     if (is_array($value)) {
       if (count($value) > 1) {
         $this->_useDistinct = TRUE;
index ddcf2fb2d6f099ccdb2e542278f65367e0718bcd..f55c4ef055ef2768a742430ed75367c7f5c2222e 100644 (file)
@@ -113,7 +113,7 @@ class CRM_Contact_Form_Search_Custom_Basic extends CRM_Contact_Form_Search_Custo
     $form->addElement('select', 'group', ts('in'), $group);
 
     // add select for categories
-    $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::tag();
+    $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
     $form->addElement('select', 'tag', ts('Tagged'), $tag);
 
     // text for sort_name
index bfc95e9ebaba707340327e5fea8bb892ee8a3577..a9d16c2193066e8040073bde4d512c9eb6b4104c 100644 (file)
@@ -91,7 +91,7 @@ class CRM_Contact_Form_Search_Custom_Group extends CRM_Contact_Form_Search_Custo
 
     $groups = CRM_Core_PseudoConstant::group();
 
-    $tags = CRM_Core_PseudoConstant::tag();
+    $tags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
     if (count($groups) == 0 || count($tags) == 0) {
       CRM_Core_Session::setStatus(ts("At least one Group and Tag must be present for Custom Group / Tag search."), ts('Missing Group/Tag'));
       $url = CRM_Utils_System::url('civicrm/contact/search/custom/list', 'reset=1');
index fb873f3e05d5c3ba8ef291b61cc2231c5c0204e9..d7bc2c62a2c44bf6531fb2fc325fa59b0a5897ef 100644 (file)
@@ -104,7 +104,7 @@ class CRM_Contact_Form_Search_Custom_MultipleValues extends CRM_Contact_Form_Sea
     $form->addElement('select', 'group', ts('in'), $group);
 
     // add select for tags
-    $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::tag();
+    $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
     $form->addElement('select', 'tag', ts('Tagged'), $tag);
 
     if (empty($this->_groupTree)) {
index 9d17cc8415fcf1ec268d20f5615aad5794e816ca..d374ddf4ee560665f66e38bea76f8d4c0da868a1 100644 (file)
@@ -134,7 +134,7 @@ class CRM_Contact_Form_Search_Custom_Proximity extends CRM_Contact_Form_Search_C
     $group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant::group();
     $form->addElement('select', 'group', ts('Group'), $group);
 
-    $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::tag();
+    $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
     $form->addElement('select', 'tag', ts('Tag'), $tag);
 
 
index 35aa7691fa5eb3e60d9f58ff89dbae5c2fa56c3a..5b24abfc9a404bbe4f1d40012ba344ea5781e9d8 100644 (file)
@@ -64,7 +64,7 @@ class CRM_Contact_Form_Search_Custom_TagContributions implements CRM_Contact_For
 
     $form->addDate('start_date', ts('Contribution Date From'), FALSE, array('formatType' => 'custom'));
     $form->addDate('end_date', ts('...through'), FALSE, array('formatType' => 'custom'));
-    $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::tag();
+    $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
     $form->addElement('select', 'tag', ts('Tagged'), $tag);
 
     /**
index f81f354eff21737b7c1bd1dad803849cf99e0f80..f84341e2bac59a15415d2cc476ebd6435c4de64a 100644 (file)
@@ -72,7 +72,7 @@ class CRM_Contact_Import_Form_Preview extends CRM_Core_Form {
     $groups = CRM_Core_PseudoConstant::group();
     $this->set('groups', $groups);
 
-    $tag = CRM_Core_PseudoConstant::tag();
+    $tag = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
     if ($tag) {
       $this->set('tag', $tag);
     }
index 18f29a8b90b7cd81d4657b20beff0c967a6378c0..9826726a6738b91fb1f8449d45f35a135ae3495e 100644 (file)
      }
 
      //fix tag names
-     $tags = CRM_Core_PseudoConstant::tag();
+     $tags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
 
      foreach($results as &$values) {
        if (!empty($values['tag'])) {
index 6fdaa2a51616b16f8ee11e5e6850e49ebc50b752..777444d25fc50c27651efec51b63ce90c96669be 100644 (file)
@@ -1008,7 +1008,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
         }
         elseif ($name == 'tag') {
           $entityTags = CRM_Core_BAO_EntityTag::getTag($cid);
-          $allTags    = CRM_Core_PseudoConstant::tag();
+          $allTags    = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
           $title      = array();
           foreach ($entityTags as $tagId) {
             $title[] = $allTags[$tagId];
index 323599f12b91582e2cfbc055dfff585bcc94510a..f329eb627df53d9d64b7187d6226d95176904c31 100644 (file)
@@ -123,7 +123,7 @@ class CRM_Core_Form_Tag {
               if (!empty($form->_submitValues['activity_taglist']) &&
                 CRM_Utils_Array::value($parentId, $form->_submitValues['activity_taglist'])
               ) {
-                $allTags = CRM_Core_PseudoConstant::tag();
+                $allTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
                 $tagIds = explode(',', $form->_submitValues['activity_taglist'][$parentId]);
                 foreach ($tagIds as $tagId) {
                   if (is_numeric($tagId)) {
@@ -144,7 +144,7 @@ class CRM_Core_Form_Tag {
               if (!empty($form->_submitValues['case_taglist']) &&
                 CRM_Utils_Array::value($parentId, $form->_submitValues['case_taglist'])
               ) {
-                $allTags = CRM_Core_PseudoConstant::tag();
+                $allTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
                 $tagIds = explode(',', $form->_submitValues['case_taglist'][$parentId]);
                 foreach ($tagIds as $tagId) {
                   if (is_numeric($tagId)) {
@@ -169,7 +169,7 @@ class CRM_Core_Form_Tag {
                 if (!empty($form->_submitValues["attachment_taglist_$i"]) &&
                   CRM_Utils_Array::value($parentId, $form->_submitValues["attachment_taglist_$i"])
                 ) {
-                  $allTags = CRM_Core_PseudoConstant::tag();
+                  $allTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
                   $tagIds = explode(',', $form->_submitValues["attachment_taglist_$i"][$parentId]);
                   foreach ($tagIds as $tagId) {
                     if (is_numeric($tagId)) {
index 2e7facdfe7b89529bde00fdf3daf17137585a1bf..d3c318cdbca91855727e9ebbfe75b80cdb0ab6de 100644 (file)
@@ -173,7 +173,7 @@ class CRM_Core_Permission {
   }
 
   public static function customGroup($type = CRM_Core_Permission::VIEW, $reset = FALSE) {
-    $customGroups = CRM_Core_PseudoConstant::customGroup($reset);
+    $customGroups = CRM_Core_PseudoConstant::get('CRM_Core_DAO_CustomField', 'custom_group_id', array('fresh' => $reset));
     $defaultGroups = array();
 
     // check if user has all powerful permission
index a835fb33366444b5cd66dfb11763da5e2c38004b..dea911b368c8ec4ca0f7e216668443b3bcac1b76 100644 (file)
@@ -105,13 +105,6 @@ class CRM_Core_PseudoConstant {
    */
   private static $countryIsoCode;
 
-  /**
-   * tag
-   * @var array
-   * @static
-   */
-  private static $tag;
-
   /**
    * group
    * @var array
@@ -147,13 +140,6 @@ class CRM_Core_PseudoConstant {
    */
   private static $ufGroup;
 
-  /**
-   * custom groups
-   * @var array
-   * @static
-   */
-  private static $customGroup;
-
   /**
    * currency codes
    * @var array
@@ -757,28 +743,6 @@ WHERE  id = %1";
     return self::$countryIsoCode;
   }
 
-  /**
-   * Get all the categories from database.
-   *
-   * The static array tag is returned, and if it's
-   * called the first time, the <b>Tag DAO</b> is used
-   * to get all the categories.
-   *
-   * Note: any database errors will be trapped by the DAO.
-   *
-   * @access public
-   * @static
-   *
-   * @return array - array reference of all categories.
-   *
-   */
-  public static function &tag() {
-    if (!self::$tag) {
-      self::populate(self::$tag, 'CRM_Core_DAO_Tag', TRUE);
-    }
-    return self::$tag;
-  }
-
   /**
    * Get all groups from database
    *
@@ -896,21 +860,6 @@ WHERE  id = %1";
     return self::$staticGroup;
   }
 
-  /**
-   * Get all the custom groups
-   *
-   * @access public
-   *
-   * @return array - array reference of all groups.
-   * @static
-   */
-  public static function &customGroup($reset = FALSE) {
-    if (!self::$customGroup || $reset) {
-      self::populate(self::$customGroup, 'CRM_Core_DAO_CustomGroup', FALSE, 'title', 'is_active', NULL, 'title');
-    }
-    return self::$customGroup;
-  }
-
   /**
    * Get all the user framework groups
    *
index 1e4f04dd4fcd1afde7d830824f3ddb89148a5ba6..f44a86d7ad9a4e1cd68607b339245ebacd5d6df9 100644 (file)
@@ -110,7 +110,7 @@ class CRM_Custom_Form_MoveField extends CRM_Core_Form {
    */
   public function buildQuickForm() {
 
-    $customGroup = CRM_Core_PseudoConstant::customGroup();
+    $customGroup = CRM_Core_PseudoConstant::get('CRM_Core_DAO_CustomField', 'custom_group_id');
     unset($customGroup[$this->_srcGID]);
     if (empty($customGroup)) {
       CRM_Core_Error::statusBounce(ts('You need more than one custom group to move fields'));
index 46d0bdc2823685801e05cbc44f910b62c9cab20c..c3df1829900ba0e8ae54be021c6f46ec512db93b 100644 (file)
@@ -1425,7 +1425,7 @@ WHERE civicrm_event.is_active = 1
         }
         elseif ($name == 'tag') {
           $entityTags = $params[$name];
-          $allTags    = CRM_Core_PseudoConstant::tag();
+          $allTags    = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
           $title      = array();
           if (is_array($entityTags)) {
             foreach ($entityTags as $tagId => $dontCare) {
index 57e3f95989d02aa7c3d70cc3073a46f8a13b8add..49b956bca568767415b39de0ea2783a94a530404 100644 (file)
@@ -259,7 +259,7 @@ class CRM_Report_Form extends CRM_Core_Form {
     }
 
     // Get all custom groups
-    $allGroups = CRM_Core_PseudoConstant::customGroup();
+    $allGroups = CRM_Core_PseudoConstant::get('CRM_Core_DAO_CustomField', 'custom_group_id');
 
     // Get the custom groupIds for which the user have VIEW permission
     require_once 'CRM/ACL/API.php';
index ed36e5a6b7107841ae706d03ba388b8afa1f2d4e..3367acf8119eba883802ec7d19c1f728946eca02 100644 (file)
@@ -97,7 +97,7 @@ function civicrm_api3_entity_tag_display($params) {
 
   $values = CRM_Core_BAO_EntityTag::getTag($entityID, $entityTable);
   $result = array();
-  $tags   = CRM_Core_PseudoConstant::tag();
+  $tags   = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
   foreach ($values as $v) {
     $result[] = $tags[$v];
   }
index 107164f1d73f8596e203314a2aafe699a7124ff4..0b8610b3b3155d93f46cb5357230f56faf00e5df 100644 (file)
@@ -43,16 +43,41 @@ class CRM_Core_PseudoConstantTest extends CiviUnitTestCase {
     parent::setUp();
   }
 
+  /**
+   * Assure CRM_Core_PseudoConstant::get() is working properly for a range of
+   * DAO fields having a <pseudoconstant> tag in the XML schema.
+   */
   function testOptionValues() {
-    /*
+    $custom_group_name = 'Test custom group';
+    $api_params = array(
+        'version' => 3,
+        'title' => $custom_group_name,
+        'extends' => 'Individual',
+    );
+    civicrm_api('customGroup', 'create', $api_params);
+
+    /**
      * daoName/field combinations to test
-     * array[DAO Name] = properties, where properties can be:
+     * Format: array[DAO Name] = $properties, where properties is an array whose
+     * named members can be:
      * - fieldName: the SQL column name within the DAO table.
      * - sample: Any one value which is expected in the list of option values.
      * - exclude: Any one value which should not be in the list.
      * - max: integer (default = 10) maximum number of option values expected.
      */
     $fields = array(
+      'CRM_Core_DAO_CustomField' => array(
+        array(
+          'fieldName' => 'custom_group_id',
+          'sample' => $custom_group_name,
+        ),
+      ),
+      'CRM_Core_DAO_EntityTag' => array(
+        array(
+          'fieldName' => 'tag_id',
+          'sample' => 'Government Entity',
+        ),
+      ),
       'CRM_Core_DAO_OptionValue' => array(
         array(
           'fieldName' => 'component_id',
index c719561c9efc7a4b96b71d1fd2bca4a44ad8fd1f..eddc8a698667960165cd5cf495671e100ce63fd8 100644 (file)
@@ -34,7 +34,7 @@ class tagsImporter extends civicrm_cli {
       die("you need to profide a csv file (1st column parent name, 2nd tag name");
     }
     $this->file = $this->args[0];
-    $this->tags = array_flip(CRM_Core_PseudoConstant::tag());
+    $this->tags = array_flip(CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE)));
   }
 
   //format expected: parent name, tag
index 4a489a851dc34e3a4534010cce8e5403899f2d49..f1be81b19100d76662ce1cba5611e8d50b7afbfb 100644 (file)
@@ -102,7 +102,7 @@ class org_civicrm_search_basic extends CRM_Contact_Form_Search_Custom_Baseimplem
     $form->addElement('select', 'group', ts('in'), $group);
 
     // add select for categories
-    $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::tag();
+    $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
     $form->addElement('select', 'tag', ts('Tagged'), $tag);
 
     // text for sort_name
index 81b4722695b0ac12119bbad987506080d2ca2e14..d38c353a5e4582190e3ff223f14b8a8a3c7cc630 100644 (file)
       <type>int unsigned</type>
       <required>true</required>
       <comment>FK to civicrm_custom_group.</comment>
-       <add>1.1</add>
+      <add>1.1</add>
+      <pseudoconstant>
+        <table>civicrm_custom_group</table>
+        <keyColumn>id</keyColumn>
+        <labelColumn>title</labelColumn>
+      </pseudoconstant>
   </field>
   <foreignKey>
        <name>custom_group_id</name>
index 6875b2136ec436ae52f0040c53443f99fc18ab79..89ff9eb2cab6da26b9de6f99904724ab545599f3 100644 (file)
       <title>Tag ID</title>
       <required>true</required>
       <comment>FK to civicrm_tag</comment>
-       <add>1.1</add>
+      <add>1.1</add>
+      <pseudoconstant>
+        <table>civicrm_tag</table>
+        <keyColumn>id</keyColumn>
+        <labelColumn>name</labelColumn>
+      </pseudoconstant>
   </field>
   <foreignKey>
        <name>tag_id</name>