Merge pull request #15475 from mecachisenros/externUrl
[civicrm-core.git] / Civi / Api4 / Utils / CoreUtil.php
CommitLineData
19b53e5b
C
1<?php
2
380f3545
TO
3/*
4 +--------------------------------------------------------------------+
41498ac5 5 | Copyright CiviCRM LLC. All rights reserved. |
380f3545 6 | |
41498ac5
TO
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 |
380f3545
TO
10 +--------------------------------------------------------------------+
11 */
12
13/**
14 *
15 * @package CRM
ca5cec67 16 * @copyright CiviCRM LLC https://civicrm.org/licensing
380f3545
TO
17 * $Id$
18 *
19 */
20
21
19b53e5b
C
22namespace Civi\Api4\Utils;
23
24use Civi\Api4\CustomGroup;
25use CRM_Core_DAO_AllCoreTables as AllCoreTables;
26
27require_once 'api/v3/utils.php';
28
29class CoreUtil {
30
31 /**
32 * todo this class should not rely on api3 code
33 *
34 * @param $entityName
35 *
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
39 */
40 public static function getBAOFromApiName($entityName) {
41 if ($entityName === 'CustomValue' || strpos($entityName, 'Custom_') === 0) {
42 return 'CRM_Contact_BAO_Contact';
43 }
44 return \_civicrm_api3_get_BAO($entityName);
45 }
46
47 /**
48 * Get table name of given Custom group
49 *
50 * @param string $customGroupName
51 *
52 * @return string
53 */
54 public static function getCustomTableByName($customGroupName) {
55 return CustomGroup::get()
56 ->addSelect('table_name')
57 ->addWhere('name', '=', $customGroupName)
58 ->execute()
59 ->first()['table_name'];
60 }
61
62 /**
63 * Given a sql table name, return the name of the api entity.
64 *
65 * @param $tableName
66 * @return string
67 */
68 public static function getApiNameFromTableName($tableName) {
69 return AllCoreTables::getBriefName(AllCoreTables::getClassForTable($tableName));
70 }
71
72}