4 +--------------------------------------------------------------------+
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2020 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2020
38 namespace Civi\Api4\Utils
;
40 use Civi\Api4\CustomGroup
;
41 use CRM_Core_DAO_AllCoreTables
as AllCoreTables
;
43 require_once 'api/v3/utils.php';
48 * todo this class should not rely on api3 code
52 * @return \CRM_Core_DAO|string
53 * The BAO name for use in static calls. Return doc block is hacked to allow
54 * auto-completion of static methods
56 public static function getBAOFromApiName($entityName) {
57 if ($entityName === 'CustomValue' ||
strpos($entityName, 'Custom_') === 0) {
58 return 'CRM_Contact_BAO_Contact';
60 return \
_civicrm_api3_get_BAO($entityName);
64 * Get table name of given Custom group
66 * @param string $customGroupName
70 public static function getCustomTableByName($customGroupName) {
71 return CustomGroup
::get()
72 ->addSelect('table_name')
73 ->addWhere('name', '=', $customGroupName)
75 ->first()['table_name'];
79 * Given a sql table name, return the name of the api entity.
84 public static function getApiNameFromTableName($tableName) {
85 return AllCoreTables
::getBriefName(AllCoreTables
::getClassForTable($tableName));