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 | /** | |
21 | * @return DAOGetAction | |
34527c37 | 22 | * |
23 | * @throws \API_Exception | |
19b53e5b C |
24 | */ |
25 | public static function get() { | |
26 | return new DAOGetAction(static::class, __FUNCTION__); | |
27 | } | |
28 | ||
29 | /** | |
121ec912 | 30 | * @return DAOSaveAction |
19b53e5b C |
31 | */ |
32 | public static function save() { | |
33 | return new DAOSaveAction(static::class, __FUNCTION__); | |
34 | } | |
35 | ||
36 | /** | |
37 | * @return DAOGetFieldsAction | |
38 | */ | |
39 | public static function getFields() { | |
40 | return new DAOGetFieldsAction(static::class, __FUNCTION__); | |
41 | } | |
42 | ||
43 | /** | |
44 | * @return DAOCreateAction | |
34527c37 | 45 | * |
46 | * @throws \API_Exception | |
19b53e5b C |
47 | */ |
48 | public static function create() { | |
49 | return new DAOCreateAction(static::class, __FUNCTION__); | |
50 | } | |
51 | ||
52 | /** | |
53 | * @return DAOUpdateAction | |
54 | */ | |
55 | public static function update() { | |
56 | return new DAOUpdateAction(static::class, __FUNCTION__); | |
57 | } | |
58 | ||
59 | /** | |
60 | * @return DAODeleteAction | |
61 | */ | |
62 | public static function delete() { | |
63 | return new DAODeleteAction(static::class, __FUNCTION__); | |
64 | } | |
65 | ||
66 | /** | |
67 | * @return BasicReplaceAction | |
68 | */ | |
69 | public static function replace() { | |
70 | return new BasicReplaceAction(static::class, __FUNCTION__); | |
71 | } | |
72 | ||
449c4e6b CW |
73 | /** |
74 | * @return string | |
75 | */ | |
76 | protected static function getEntityTitle() { | |
77 | $name = static::getEntityName(); | |
78 | $dao = \CRM_Core_DAO_AllCoreTables::getFullName($name); | |
79 | return $dao ? $dao::getEntityTitle() : $name; | |
80 | } | |
81 | ||
82 | /** | |
83 | * @return array | |
84 | */ | |
85 | public static function getInfo() { | |
86 | $info = parent::getInfo(); | |
87 | $dao = \CRM_Core_DAO_AllCoreTables::getFullName($info['name']); | |
88 | if ($dao) { | |
89 | $info['icon'] = $dao::$_icon; | |
90 | $info['dao'] = $dao; | |
91 | } | |
92 | return $info; | |
93 | } | |
94 | ||
19b53e5b | 95 | } |