Merge pull request #18629 from eileenmcnaughton/aipn
[civicrm-core.git] / Civi / Api4 / Action / Entity / GetLinks.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
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 +--------------------------------------------------------------------+
11 */
12
13 /**
14 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 */
18
19
20 namespace Civi\Api4\Action\Entity;
21
22 use Civi\Api4\Utils\CoreUtil;
23
24 /**
25 * Get a list of FK links between entities
26 */
27 class GetLinks extends \Civi\Api4\Generic\BasicGetAction {
28
29 public function getRecords() {
30 $result = [];
31 /** @var \Civi\Api4\Service\Schema\SchemaMap $schema */
32 $schema = \Civi::container()->get('schema_map');
33 foreach ($schema->getTables() as $table) {
34 $entity = CoreUtil::getApiNameFromTableName($table->getName());
35 // Since this is an api function, exclude tables that don't have an api
36 if (strpos($entity, 'Custom_') === 0 || class_exists('\Civi\Api4\\' . $entity)) {
37 $item = [
38 'entity' => $entity,
39 'table' => $table->getName(),
40 'links' => [],
41 ];
42 foreach ($table->getTableLinks() as $link) {
43 $item['links'][] = $link->toArray();
44 }
45 $result[] = $item;
46 }
47 }
48 return $result;
49 }
50
51 public function fields() {
52 return [
53 [
54 'name' => 'entity',
55 ],
56 [
57 'name' => 'table',
58 ],
59 [
60 'name' => 'links',
61 'data_type' => 'Array',
62 ],
63 ];
64 }
65
66 }