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 | ||
19b53e5b C |
13 | namespace Civi\Api4\Generic; |
14 | ||
15 | /** | |
16 | * Base class for DAO-based entities. | |
17 | */ | |
18 | abstract class DAOEntity extends AbstractEntity { | |
19 | ||
20 | /** | |
6764a9d3 | 21 | * @param bool $checkPermissions |
19b53e5b C |
22 | * @return DAOGetAction |
23 | */ | |
6764a9d3 CW |
24 | public static function get($checkPermissions = TRUE) { |
25 | return (new DAOGetAction(static::class, __FUNCTION__)) | |
26 | ->setCheckPermissions($checkPermissions); | |
19b53e5b C |
27 | } |
28 | ||
29 | /** | |
6764a9d3 | 30 | * @param bool $checkPermissions |
121ec912 | 31 | * @return DAOSaveAction |
19b53e5b | 32 | */ |
6764a9d3 CW |
33 | public static function save($checkPermissions = TRUE) { |
34 | return (new DAOSaveAction(static::class, __FUNCTION__)) | |
35 | ->setCheckPermissions($checkPermissions); | |
19b53e5b C |
36 | } |
37 | ||
38 | /** | |
6764a9d3 | 39 | * @param bool $checkPermissions |
19b53e5b C |
40 | * @return DAOGetFieldsAction |
41 | */ | |
6764a9d3 CW |
42 | public static function getFields($checkPermissions = TRUE) { |
43 | return (new DAOGetFieldsAction(static::class, __FUNCTION__)) | |
44 | ->setCheckPermissions($checkPermissions); | |
19b53e5b C |
45 | } |
46 | ||
47 | /** | |
6764a9d3 | 48 | * @param bool $checkPermissions |
19b53e5b C |
49 | * @return DAOCreateAction |
50 | */ | |
6764a9d3 CW |
51 | public static function create($checkPermissions = TRUE) { |
52 | return (new DAOCreateAction(static::class, __FUNCTION__)) | |
53 | ->setCheckPermissions($checkPermissions); | |
19b53e5b C |
54 | } |
55 | ||
56 | /** | |
6764a9d3 | 57 | * @param bool $checkPermissions |
19b53e5b C |
58 | * @return DAOUpdateAction |
59 | */ | |
6764a9d3 CW |
60 | public static function update($checkPermissions = TRUE) { |
61 | return (new DAOUpdateAction(static::class, __FUNCTION__)) | |
62 | ->setCheckPermissions($checkPermissions); | |
19b53e5b C |
63 | } |
64 | ||
65 | /** | |
6764a9d3 | 66 | * @param bool $checkPermissions |
19b53e5b C |
67 | * @return DAODeleteAction |
68 | */ | |
6764a9d3 CW |
69 | public static function delete($checkPermissions = TRUE) { |
70 | return (new DAODeleteAction(static::class, __FUNCTION__)) | |
71 | ->setCheckPermissions($checkPermissions); | |
19b53e5b C |
72 | } |
73 | ||
74 | /** | |
6764a9d3 | 75 | * @param bool $checkPermissions |
19b53e5b C |
76 | * @return BasicReplaceAction |
77 | */ | |
6764a9d3 CW |
78 | public static function replace($checkPermissions = TRUE) { |
79 | return (new BasicReplaceAction(static::class, __FUNCTION__)) | |
80 | ->setCheckPermissions($checkPermissions); | |
19b53e5b C |
81 | } |
82 | ||
449c4e6b CW |
83 | /** |
84 | * @return string | |
85 | */ | |
86 | protected static function getEntityTitle() { | |
87 | $name = static::getEntityName(); | |
88 | $dao = \CRM_Core_DAO_AllCoreTables::getFullName($name); | |
89 | return $dao ? $dao::getEntityTitle() : $name; | |
90 | } | |
91 | ||
92 | /** | |
93 | * @return array | |
94 | */ | |
95 | public static function getInfo() { | |
96 | $info = parent::getInfo(); | |
97 | $dao = \CRM_Core_DAO_AllCoreTables::getFullName($info['name']); | |
98 | if ($dao) { | |
99 | $info['icon'] = $dao::$_icon; | |
100 | $info['dao'] = $dao; | |
101 | } | |
102 | return $info; | |
103 | } | |
104 | ||
19b53e5b | 105 | } |