4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
22 namespace Civi\Api4\Utils
;
24 use CRM_Core_DAO_AllCoreTables
as AllCoreTables
;
26 require_once 'api/v3/utils.php';
31 * todo this class should not rely on api3 code
35 * @return \CRM_Core_DAO|string
36 * The BAO name for use in static calls. Return doc block is hacked to allow
37 * auto-completion of static methods
39 public static function getBAOFromApiName($entityName) {
40 if ($entityName === 'CustomValue' ||
strpos($entityName, 'Custom_') === 0) {
41 return 'CRM_Core_BAO_CustomValue';
43 return \
_civicrm_api3_get_BAO($entityName);
47 * Get table name of given entity
49 * @param string $entityName
53 public static function getTableName($entityName) {
54 if (strpos($entityName, 'Custom_') === 0) {
55 $customGroup = substr($entityName, 7);
56 return \CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroup, 'table_name', 'name');
58 return AllCoreTables
::getTableForEntityName($entityName);
62 * Given a sql table name, return the name of the api entity.
67 public static function getApiNameFromTableName($tableName) {
68 $entityName = AllCoreTables
::getBriefName(AllCoreTables
::getClassForTable($tableName));
70 $customGroup = \CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomGroup', $tableName, 'name', 'table_name');
71 $entityName = $customGroup ?
"Custom_$customGroup" : NULL;