| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | +--------------------------------------------------------------------+ |
| 5 | | CiviCRM version 4.7 | |
| 6 | +--------------------------------------------------------------------+ |
| 7 | | Copyright CiviCRM LLC (c) 2004-2015 | |
| 8 | +--------------------------------------------------------------------+ |
| 9 | | This file is a part of CiviCRM. | |
| 10 | | | |
| 11 | | CiviCRM is free software; you can copy, modify, and distribute it | |
| 12 | | under the terms of the GNU Affero General Public License | |
| 13 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
| 14 | | | |
| 15 | | CiviCRM is distributed in the hope that it will be useful, but | |
| 16 | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 18 | | See the GNU Affero General Public License for more details. | |
| 19 | | | |
| 20 | | You should have received a copy of the GNU Affero General Public | |
| 21 | | License and the CiviCRM Licensing Exception along | |
| 22 | | with this program; if not, contact CiviCRM LLC | |
| 23 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
| 24 | | GNU Affero General Public License or the licensing of CiviCRM, | |
| 25 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
| 26 | +--------------------------------------------------------------------+ |
| 27 | */ |
| 28 | |
| 29 | /** |
| 30 | * |
| 31 | * @package CRM |
| 32 | * @copyright CiviCRM LLC (c) 2004-2015 |
| 33 | * $Id$ |
| 34 | * |
| 35 | */ |
| 36 | |
| 37 | class CRM_Core_DAO_AllCoreTables {ldelim} |
| 38 | |
| 39 | static private $tables = null; |
| 40 | static private $daoToClass = null; |
| 41 | static private $entityTypes = null; |
| 42 | |
| 43 | static public function init($fresh = FALSE) {ldelim} |
| 44 | static $init = FALSE; |
| 45 | if ($init && !$fresh) return; |
| 46 | |
| 47 | $entityTypes = array( |
| 48 | {foreach from=$tables key=tableName item=table} |
| 49 | '{$table.className}' => array( |
| 50 | 'name' => '{$table.objectName}', |
| 51 | 'class' => '{$table.className}', |
| 52 | 'table' => '{$tableName}', |
| 53 | ), |
| 54 | {/foreach} |
| 55 | ); |
| 56 | |
| 57 | CRM_Utils_Hook::entityTypes($entityTypes); |
| 58 | |
| 59 | self::$entityTypes = array(); |
| 60 | self::$tables = array(); |
| 61 | self::$daoToClass = array(); |
| 62 | foreach ($entityTypes as $entityType) {ldelim} |
| 63 | self::registerEntityType($entityType['name'], $entityType['class'], $entityType['table']); |
| 64 | {rdelim} |
| 65 | |
| 66 | $init = TRUE; |
| 67 | {rdelim} |
| 68 | |
| 69 | /** |
| 70 | * (Quasi-Private) Do not call externally (except for unit-testing) |
| 71 | */ |
| 72 | static public function registerEntityType($daoName, $className, $tableName) {ldelim} |
| 73 | self::$daoToClass[$daoName] = $className; |
| 74 | self::$tables[$tableName] = $className; |
| 75 | self::$entityTypes[$className] = array( |
| 76 | 'name' => $daoName, |
| 77 | 'class' => $className, |
| 78 | 'table' => $tableName, |
| 79 | ); |
| 80 | {rdelim} |
| 81 | |
| 82 | static public function get() {ldelim} |
| 83 | self::init(); |
| 84 | return self::$entityTypes; |
| 85 | {rdelim} |
| 86 | |
| 87 | static public function tables() {ldelim} |
| 88 | self::init(); |
| 89 | return self::$tables; |
| 90 | {rdelim} |
| 91 | |
| 92 | static public function daoToClass() {ldelim} |
| 93 | self::init(); |
| 94 | return self::$daoToClass; |
| 95 | {rdelim} |
| 96 | |
| 97 | static public function getCoreTables() {ldelim} |
| 98 | return self::tables(); |
| 99 | {rdelim} |
| 100 | |
| 101 | static public function isCoreTable($tableName) {ldelim} |
| 102 | return FALSE !== array_search($tableName, self::tables()); |
| 103 | {rdelim} |
| 104 | |
| 105 | static public function getCanonicalClassName($className) {ldelim} |
| 106 | return str_replace('_BAO_', '_DAO_', $className); |
| 107 | {rdelim} |
| 108 | |
| 109 | static public function getClasses() {ldelim} |
| 110 | return array_values(self::daoToClass()); |
| 111 | {rdelim} |
| 112 | |
| 113 | static public function getClassForTable($tableName) {ldelim} |
| 114 | return CRM_Utils_Array::value($tableName, self::tables()); |
| 115 | {rdelim} |
| 116 | |
| 117 | static public function getFullName($daoName) {ldelim} |
| 118 | return CRM_Utils_Array::value($daoName, self::daoToClass()); |
| 119 | {rdelim} |
| 120 | |
| 121 | static public function getBriefName($className) {ldelim} |
| 122 | return CRM_Utils_Array::value($className, array_flip(self::daoToClass())); |
| 123 | {rdelim} |
| 124 | |
| 125 | /** |
| 126 | * @param string $className DAO or BAO name |
| 127 | * @return string|FALSE SQL table name |
| 128 | */ |
| 129 | static public function getTableForClass($className) {ldelim} |
| 130 | return array_search(self::getCanonicalClassName($className), self::tables()); |
| 131 | {rdelim} |
| 132 | |
| 133 | static public function reinitializeCache($fresh = FALSE) {ldelim} |
| 134 | self::init($fresh); |
| 135 | {rdelim} |
| 136 | |
| 137 | {rdelim} |