From fed67e4dd41c47e31f13f01a74fad731bfa013b8 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 4 Jul 2013 11:47:28 -0700 Subject: [PATCH] CRM_Core_DAO_AllCoreTables - Modify list with hook_civicrm_entityTypes --- CRM/Utils/Hook.php | 17 +++++++++++ xml/templates/listAll.tpl | 60 +++++++++++++++++++++++++++++---------- 2 files changed, 62 insertions(+), 15 deletions(-) diff --git a/CRM/Utils/Hook.php b/CRM/Utils/Hook.php index c4a1137676..1235e8b8ac 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -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' + ); + } } diff --git a/xml/templates/listAll.tpl b/xml/templates/listAll.tpl index 4a670377ec..f64a058325 100644 --- a/xml/templates/listAll.tpl +++ b/xml/templates/listAll.tpl @@ -36,41 +36,71 @@ 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} -- 2.25.1