Commit | Line | Data |
---|---|---|
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 | */ |
18 | ||
19 | ||
19b53e5b C |
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 | |
5e327f37 | 36 | if (strpos($entity, 'Custom_') === 0 || class_exists('\Civi\Api4\\' . $entity)) { |
19b53e5b C |
37 | $item = [ |
38 | 'entity' => $entity, | |
39 | 'table' => $table->getName(), | |
40 | 'links' => [], | |
41 | ]; | |
42 | foreach ($table->getTableLinks() as $link) { | |
6fe7bdee | 43 | $item['links'][] = $link->toArray(); |
19b53e5b C |
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 | } |