CRM_Core_DAO_AllCoreTables - Modify list with hook_civicrm_entityTypes
authorTim Otten <totten@civicrm.org>
Thu, 4 Jul 2013 18:47:28 +0000 (11:47 -0700)
committerTim Otten <totten@civicrm.org>
Thu, 4 Jul 2013 18:50:01 +0000 (11:50 -0700)
CRM/Utils/Hook.php
xml/templates/listAll.tpl

index c4a113767662a6c6cc542a6b705dcd1924a387f7..1235e8b8ac3574818722ca33bc09e8d273c12053 100644 (file)
@@ -1218,4 +1218,21 @@ abstract class CRM_Utils_Hook {
       'civicrm_permission'
     );
   }
+
+
+  /**
+   * This hook is called for declaring managed entities via API
+   *
+   * @param array $entities List of entity types; each entity-type is an array with keys:
+   *   - name: string, a unique short name (e.g. "ReportInstance")
+   *   - class: string, a PHP DAO class (e.g. "CRM_Report_DAO_Instance")
+   *   - table: string, a SQL table name (e.g. "civicrm_report_instance")
+   *
+   * @return null the return value is ignored
+   * @access public
+   */
+  static function entityTypes(&$entityTypes) {
+    return self::singleton()->invoke(1, $entityTypes, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_entityTypes'
+    );
+  }
 }
index 4a670377ec6a5aa8f62c4fa3ca45a965fe97c3b9..f64a05832578e9bbba0feb817cf40eeb07bc5b90 100644 (file)
 
 class CRM_Core_DAO_AllCoreTables {ldelim}
 
-  static $tables = array(
+  static private $tables = null;
+  static private $daoToClass = null;
+
+  static private function init() {ldelim}
+    static $init = FALSE;
+    if ($init) return;
+
+    $entityTypes = array(
 {foreach from=$tables key=tableName item=table}
-    '{$tableName}' => '{$table.className}',
-{/foreach} {* tables *}
-  );
+      '{$table.className}' => array(
+        'name' => '{$table.objectName}',
+        'class' => '{$table.className}',
+        'table' => '{$tableName}',
+      ),
+{/foreach}
+    );
 
-  static $daoToClass = array(
+    CRM_Utils_Hook::entityTypes($entityTypes);
 
-{foreach from=$tables item=table}
-    '{$table.objectName}' => '{$table.className}',
-{/foreach} {* tables *}
-  );
+    self::$tables = array();
+    self::$daoToClass = array();
+    foreach ($entityTypes as $entityType) {ldelim}
+      self::registerEntityType($entityType['name'], $entityType['class'], $entityType['table']);
+    {rdelim}
 
-  static public function getCoreTables() {ldelim}
+    $init = TRUE;
+  {rdelim}
+
+  static private function registerEntityType($daoName, $className, $tableName) {ldelim}
+    self::$daoToClass[$daoName] = $className;
+    self::$tables[$tableName] = $className;
+  {rdelim}
+
+  static public function tables() {ldelim}
+    self::init();
     return self::$tables;
   {rdelim}
 
+  static public function daoToClass() {ldelim}
+    self::init();
+    return self::$daoToClass;
+  {rdelim}
+
+  static public function getCoreTables() {ldelim}
+    return self::tables();
+  {rdelim}
+
   static public function isCoreTable($tableName) {ldelim}
-    return FALSE !== array_search($tableName, self::$tables);
+    return FALSE !== array_search($tableName, self::tables());
   {rdelim}
 
   static public function getClasses() {ldelim}
-    return array_values(self::$daoToClass);
+    return array_values(self::daoToClass());
   {rdelim}
 
   static public function getClassForTable($tableName) {ldelim}
-    return CRM_Utils_Array::value($tableName, self::$tables);
+    return CRM_Utils_Array::value($tableName, self::tables());
   {rdelim}
 
   static public function getFullName($daoName) {ldelim}
-    return CRM_Utils_Array::value($daoName, self::$daoToClass);
+    return CRM_Utils_Array::value($daoName, self::daoToClass());
   {rdelim}
 
   static public function getBriefName($className) {ldelim}
-    return CRM_Utils_Array::value($className, array_flip(self::$daoToClass));
+    return CRM_Utils_Array::value($className, array_flip(self::daoToClass()));
   {rdelim}
 
 {rdelim}