-- CRM-15475, changed Cancelled mmebership status to reserved
[civicrm-core.git] / xml / templates / listAll.tpl
index 1919a0d34ef06f9b32083003ef0ed61c9090eccf..f302ac11638f43c981f571196d9f16a28c73c51f 100644 (file)
@@ -2,9 +2,9 @@
 
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
 
 class CRM_Core_DAO_AllCoreTables {ldelim}
 
-  static $tables = array(
+  static private $tables = null;
+  static private $daoToClass = null;
+
+  static private function init($fresh = FALSE) {ldelim}
+    static $init = FALSE;
+    if ($init && !$fresh) return;
+
+    $entityTypes = array(
 {foreach from=$tables key=tableName item=table}
-    '{$tableName}',
-{/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 getCanonicalClassName($className) {ldelim}
+    return str_replace('_BAO_', '_DAO_', $className);
   {rdelim}
 
   static public function getClasses() {ldelim}
-    return array_values(self::$daoToClass);
+    return array_values(self::daoToClass());
   {rdelim}
 
   static public function getClassForTable($tableName) {ldelim}
-    // The $tables structure was changed, and this function was removed, but
-    // I'm not sure why, and it's killing the test-suite. So put in a
-    // placeholder.
-    // return CRM_Utils_Array::value($tableName, self::$tables);
-    throw new Exception("Not implemented: getClassForTable()");
+    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()));
+  {rdelim}
+
+  /**
+   * @param string $className DAO or BAO name
+   * @return string|FALSE SQL table name
+   */
+  static public function getTableForClass($className) {ldelim}
+    return array_search(self::getCanonicalClassName($className), self::tables());
+  {rdelim}
+
+  static public function reinitializeCache($fresh = FALSE) {ldelim}
+    self::init($fresh);
   {rdelim}
 
 {rdelim}