From: Allen Shaw Date: Thu, 2 May 2013 23:35:01 +0000 (-0700) Subject: Added method fieldKeys() to DAOs. CRM-12464 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=66abbb6d832a983e527cbfde8662c8c8b43c991a;p=civicrm-core.git Added method fieldKeys() to DAOs. CRM-12464 ---------------------------------------- * CRM-12464: Search improvements in 4.4 http://issues.civicrm.org/jira/browse/CRM-12464 --- diff --git a/xml/templates/dao.tpl b/xml/templates/dao.tpl index 1468302a7d..b5211939b7 100644 --- a/xml/templates/dao.tpl +++ b/xml/templates/dao.tpl @@ -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 *