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 | /** | |
9bafff7c CW |
16 | * Base class for DAO entities (sql tables). |
17 | * | |
18 | * This is one of 3 possible base classes for an APIv4 Entity | |
19 | * (the others are `BasicEntity` and `AbstractEntity`). | |
20 | * | |
21 | * This base class is used for entities that have an associated DAO and support CRUD operations. | |
22 | * | |
23 | * Entities that extend this class can override actions and add others on an ad-hoc basis. | |
24 | * | |
25 | * DAO entities which do not support all CRUD operations should instead extend AbstractEntity | |
26 | * in order to implement just the actions appropriate to that entity. | |
19b53e5b C |
27 | */ |
28 | abstract class DAOEntity extends AbstractEntity { | |
29 | ||
30 | /** | |
6764a9d3 | 31 | * @param bool $checkPermissions |
19b53e5b C |
32 | * @return DAOGetAction |
33 | */ | |
6764a9d3 CW |
34 | public static function get($checkPermissions = TRUE) { |
35 | return (new DAOGetAction(static::class, __FUNCTION__)) | |
36 | ->setCheckPermissions($checkPermissions); | |
19b53e5b C |
37 | } |
38 | ||
39 | /** | |
6764a9d3 | 40 | * @param bool $checkPermissions |
121ec912 | 41 | * @return DAOSaveAction |
19b53e5b | 42 | */ |
6764a9d3 CW |
43 | public static function save($checkPermissions = TRUE) { |
44 | return (new DAOSaveAction(static::class, __FUNCTION__)) | |
45 | ->setCheckPermissions($checkPermissions); | |
19b53e5b C |
46 | } |
47 | ||
48 | /** | |
6764a9d3 | 49 | * @param bool $checkPermissions |
19b53e5b C |
50 | * @return DAOGetFieldsAction |
51 | */ | |
6764a9d3 CW |
52 | public static function getFields($checkPermissions = TRUE) { |
53 | return (new DAOGetFieldsAction(static::class, __FUNCTION__)) | |
54 | ->setCheckPermissions($checkPermissions); | |
19b53e5b C |
55 | } |
56 | ||
57 | /** | |
6764a9d3 | 58 | * @param bool $checkPermissions |
19b53e5b C |
59 | * @return DAOCreateAction |
60 | */ | |
6764a9d3 CW |
61 | public static function create($checkPermissions = TRUE) { |
62 | return (new DAOCreateAction(static::class, __FUNCTION__)) | |
63 | ->setCheckPermissions($checkPermissions); | |
19b53e5b C |
64 | } |
65 | ||
66 | /** | |
6764a9d3 | 67 | * @param bool $checkPermissions |
19b53e5b C |
68 | * @return DAOUpdateAction |
69 | */ | |
6764a9d3 CW |
70 | public static function update($checkPermissions = TRUE) { |
71 | return (new DAOUpdateAction(static::class, __FUNCTION__)) | |
72 | ->setCheckPermissions($checkPermissions); | |
19b53e5b C |
73 | } |
74 | ||
75 | /** | |
6764a9d3 | 76 | * @param bool $checkPermissions |
19b53e5b C |
77 | * @return DAODeleteAction |
78 | */ | |
6764a9d3 CW |
79 | public static function delete($checkPermissions = TRUE) { |
80 | return (new DAODeleteAction(static::class, __FUNCTION__)) | |
81 | ->setCheckPermissions($checkPermissions); | |
19b53e5b C |
82 | } |
83 | ||
84 | /** | |
6764a9d3 | 85 | * @param bool $checkPermissions |
19b53e5b C |
86 | * @return BasicReplaceAction |
87 | */ | |
6764a9d3 CW |
88 | public static function replace($checkPermissions = TRUE) { |
89 | return (new BasicReplaceAction(static::class, __FUNCTION__)) | |
90 | ->setCheckPermissions($checkPermissions); | |
19b53e5b C |
91 | } |
92 | ||
449c4e6b | 93 | /** |
7b66c3b5 AH |
94 | * @param bool $plural |
95 | * Whether to return a plural title. | |
449c4e6b CW |
96 | * @return string |
97 | */ | |
7b66c3b5 | 98 | protected static function getEntityTitle($plural = FALSE) { |
449c4e6b CW |
99 | $name = static::getEntityName(); |
100 | $dao = \CRM_Core_DAO_AllCoreTables::getFullName($name); | |
7b66c3b5 | 101 | return $dao ? $dao::getEntityTitle($plural) : $name; |
449c4e6b CW |
102 | } |
103 | ||
104 | /** | |
105 | * @return array | |
106 | */ | |
107 | public static function getInfo() { | |
108 | $info = parent::getInfo(); | |
109 | $dao = \CRM_Core_DAO_AllCoreTables::getFullName($info['name']); | |
110 | if ($dao) { | |
111 | $info['icon'] = $dao::$_icon; | |
112 | $info['dao'] = $dao; | |
113 | } | |
114 | return $info; | |
115 | } | |
116 | ||
19b53e5b | 117 | } |