Merge pull request #8944 from totten/master-givi
[civicrm-core.git] / CRM / Core / DAO / Managed.php
index 5794a5b01290a07e4eee23dc38c28d4bb2aa3db4..2f003a878a1c7f2f4d9115dc12151a17a6f41025 100644 (file)
@@ -41,24 +41,6 @@ class CRM_Core_DAO_Managed extends CRM_Core_DAO {
    * @var string
    */
   static $_tableName = 'civicrm_managed';
-  /**
-   * static instance to hold the field values
-   *
-   * @var array
-   */
-  static $_fields = null;
-  /**
-   * static instance to hold the keys used in $_fields for each field.
-   *
-   * @var array
-   */
-  static $_fieldKeys = null;
-  /**
-   * static instance to hold the FK relationships
-   *
-   * @var string
-   */
-  static $_links = null;
   /**
    * static value to see if we should log any modifications to
    * this table in the civicrm_log table
@@ -117,8 +99,8 @@ class CRM_Core_DAO_Managed extends CRM_Core_DAO {
    * @return array
    */
   static function &fields() {
-    if (!(self::$_fields)) {
-      self::$_fields = array(
+    if (!isset(Civi::$statics[__CLASS__]['fields'])) {
+      Civi::$statics[__CLASS__]['fields'] = array(
         'id' => array(
           'name' => 'id',
           'type' => CRM_Utils_Type::T_INT,
@@ -174,27 +156,21 @@ class CRM_Core_DAO_Managed extends CRM_Core_DAO {
           )
         ) ,
       );
+      CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
     }
-    return self::$_fields;
+    return Civi::$statics[__CLASS__]['fields'];
   }
   /**
-   * Returns an array containing, for each field, the arary key used for that
-   * field in self::$_fields.
+   * Return a mapping from field-name to the corresponding key (as used in fields()).
    *
    * @return array
+   *   Array(string $name => string $uniqueName).
    */
   static function &fieldKeys() {
-    if (!(self::$_fieldKeys)) {
-      self::$_fieldKeys = array(
-        'id' => 'id',
-        'module' => 'module',
-        'name' => 'name',
-        'entity_type' => 'entity_type',
-        'entity_id' => 'entity_id',
-        'cleanup' => 'cleanup',
-      );
+    if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
+      Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
     }
-    return self::$_fieldKeys;
+    return Civi::$statics[__CLASS__]['fieldKeys'];
   }
   /**
    * Returns the names of this table