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
20 namespace Civi\Api4\Utils
;
22 use CRM_Core_DAO_AllCoreTables
as AllCoreTables
;
24 require_once 'api/v3/utils.php';
29 * todo this class should not rely on api3 code
33 * @return \CRM_Core_DAO|string
34 * The BAO name for use in static calls. Return doc block is hacked to allow
35 * auto-completion of static methods
37 public static function getBAOFromApiName($entityName) {
38 if ($entityName === 'CustomValue' ||
strpos($entityName, 'Custom_') === 0) {
39 return 'CRM_Core_BAO_CustomValue';
41 return \
_civicrm_api3_get_BAO($entityName);
45 * Get table name of given entity
47 * @param string $entityName
51 public static function getTableName($entityName) {
52 if (strpos($entityName, 'Custom_') === 0) {
53 $customGroup = substr($entityName, 7);
54 return \CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroup, 'table_name', 'name');
56 return AllCoreTables
::getTableForEntityName($entityName);
60 * Given a sql table name, return the name of the api entity.
65 public static function getApiNameFromTableName($tableName) {
66 $entityName = AllCoreTables
::getBriefName(AllCoreTables
::getClassForTable($tableName));
68 $customGroup = \CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomGroup', $tableName, 'name', 'table_name');
69 $entityName = $customGroup ?
"Custom_$customGroup" : NULL;
77 public static function getOperators() {
78 $operators = \CRM_Core_DAO
::acceptedSQLOperators();
79 $operators[] = 'CONTAINS';