*/
function _civicrm_api_get_entity_name_from_dao($bao){
$daoName = str_replace("BAO", "DAO", get_class($bao));
- $dao = array();
- require ('CRM/Core/DAO/listAll.php');
- $daos = array_flip($dao);
- return _civicrm_api_get_entity_name_from_camel($daos[$daoName]);
-
+ return _civicrm_api_get_entity_name_from_camel(CRM_Core_DAO_AllCoreTables::getFullName($daoName));
}
* eg. "civicrm_api3_contact_create" or "Contact" will return "CRM_Contact_BAO_Contact"
*/
function _civicrm_api3_get_DAO($name) {
- static $dao = NULL;
- if (!$dao) {
- require ('CRM/Core/DAO/listAll.php');
- }
-
if (strpos($name, 'civicrm_api3') !== FALSE) {
$last = strrpos($name, '_');
// len ('civicrm_api3_') == 13
}
- return CRM_Utils_Array::value(_civicrm_api_get_camel_name($name, 3), $dao);
+ return CRM_Core_DAO_AllCoreTables::getFullName(_civicrm_api_get_camel_name($name, 3));
}
/**
}
function generateListAll($tables) {
- $allDAO = "<?php\n\$dao = array ();";
- $dao = array();
-
- foreach ($tables as $table) {
- $base = $table['base'] . $table['objectName'];
- if (!array_key_exists($table['objectName'], $dao)) {
- $dao[$table['objectName']] = str_replace('/', '_', $base);
- $allDAO .= "\n\$dao['" . $table['objectName'] . "'] = '" . str_replace('/', '_', $base) . "';";
- }
- else {
- $allDAO .= "\n//NAMESPACE ERROR: " . $table['objectName'] . " already used . " . str_replace('/', '_', $base) . " ignored.";
- }
- }
-
- // TODO deal with the BAO's too ?
- file_put_contents($this->CoreDAOCodePath . "listAll.php", $allDAO);
+ $this->smarty->clear_all_assign();
+ $this->smarty->assign('tables', $tables);
+ file_put_contents($this->CoreDAOCodePath . "AllCoreTables.php", $this->smarty->fetch('listAll.tpl'));
}
function generateCiviTestTruncate($tables) {
--- /dev/null
+<?php
+
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.3 |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013 |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM. |
+ | |
+ | CiviCRM is free software; you can copy, modify, and distribute it |
+ | under the terms of the GNU Affero General Public License |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
+ | |
+ | CiviCRM is distributed in the hope that it will be useful, but |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
+ | See the GNU Affero General Public License for more details. |
+ | |
+ | You should have received a copy of the GNU Affero General Public |
+ | License and the CiviCRM Licensing Exception along |
+ | with this program; if not, contact CiviCRM LLC |
+ | at info[AT]civicrm[DOT]org. If you have questions about the |
+ | GNU Affero General Public License or the licensing of CiviCRM, |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+*/
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2013
+ * $Id$
+ *
+ */
+
+class CRM_Core_DAO_AllCoreTables {ldelim}
+
+ static $tables = array(
+{foreach from=$tables key=tableName item=table}
+ '{$tableName}',
+{/foreach} {* tables *}
+ );
+
+ static $daoToClass = array(
+{foreach from=$tables item=table}
+ '{$table.objectName}' => '{$table.className}',
+{/foreach} {* tables *}
+ );
+
+ static public function getCoreTables() {ldelim}
+ return self::$tables;
+ {rdelim}
+
+ static public function isCoreTable($tableName) {ldelim}
+ return FALSE !== array_search($tableName, self::$tables);
+ {rdelim}
+
+ static public function getFullName($daoName) {ldelim}
+ return CRM_Utils_Array::value($daoName, self::$daoToClass);
+ {rdelim}
+
+{rdelim}