Added method fieldKeys() to DAOs. CRM-12464
authorAllen Shaw <allen@emphanos.com>
Thu, 2 May 2013 23:35:01 +0000 (16:35 -0700)
committerColeman Watts <coleman@civicrm.org>
Thu, 30 May 2013 05:13:21 +0000 (22:13 -0700)
----------------------------------------
* CRM-12464: Search improvements in 4.4
  http://issues.civicrm.org/jira/browse/CRM-12464

xml/templates/dao.tpl

index 1468302a7dc29bd8898329b224e5a23f2306a293..b5211939b7596602e54e2909e684078f8f104a5d 100644 (file)
@@ -64,6 +64,14 @@ class {$table.className} extends CRM_Core_DAO {ldelim}
       */
       static $_fields = null;
 
+     /**
+      * static instance to hold the keys used in $_fields for each field.
+      *
+      * @var array
+      * @static
+      */
+      static $_fieldKeys = null;
+
      /**
       * static instance to hold the FK relationships
       *
@@ -227,6 +235,30 @@ class {$table.className} extends CRM_Core_DAO {ldelim}
           return self::$_fields;
       {rdelim}
 
+      /**
+       * Returns an array containing, for each field, the arary key used for that
+       * field in self::$_fields.
+       *
+       * @access public
+       * @return array
+       */
+      static function &fieldKeys( ) {ldelim}
+        if ( ! ( self::$_fieldKeys ) ) {ldelim}
+               self::$_fieldKeys = array (
+{foreach from=$table.fields item=field}
+                    '{$field.name}' =>
+{if $field.uniqueName}
+                                            '{$field.uniqueName}'
+{else}
+                                            '{$field.name}'
+{/if},
+
+{/foreach} {* table.fields *}
+                                      );
+          {rdelim}
+          return self::$_fieldKeys;
+      {rdelim}
+
       /**
        * returns the names of this table
        *