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 Civi\Api4\CustomGroup
;
25 use CRM_Core_DAO_AllCoreTables
as AllCoreTables
;
27 require_once 'api/v3/utils.php';
32 * todo this class should not rely on api3 code
36 * @return \CRM_Core_DAO|string
37 * The BAO name for use in static calls. Return doc block is hacked to allow
38 * auto-completion of static methods
40 public static function getBAOFromApiName($entityName) {
41 if ($entityName === 'CustomValue' ||
strpos($entityName, 'Custom_') === 0) {
42 return 'CRM_Contact_BAO_Contact';
44 return \
_civicrm_api3_get_BAO($entityName);
48 * Get table name of given Custom group
50 * @param string $customGroupName
54 public static function getCustomTableByName($customGroupName) {
55 return CustomGroup
::get()
56 ->addSelect('table_name')
57 ->addWhere('name', '=', $customGroupName)
59 ->first()['table_name'];
63 * Given a sql table name, return the name of the api entity.
68 public static function getApiNameFromTableName($tableName) {
69 return AllCoreTables
::getBriefName(AllCoreTables
::getClassForTable($tableName));