Merge pull request #22664 from braders/membershipview-default-values
[civicrm-core.git] / Civi / Api4 / Generic / DAOEntity.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 namespace Civi\Api4\Generic;
14
15 /**
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.
27 */
28 abstract class DAOEntity extends AbstractEntity {
29
30 /**
31 * @param bool $checkPermissions
32 * @return DAOGetAction
33 */
34 public static function get($checkPermissions = TRUE) {
35 return (new DAOGetAction(static::getEntityName(), __FUNCTION__))
36 ->setCheckPermissions($checkPermissions);
37 }
38
39 /**
40 * @param bool $checkPermissions
41 * @return DAOSaveAction
42 */
43 public static function save($checkPermissions = TRUE) {
44 return (new DAOSaveAction(static::getEntityName(), __FUNCTION__))
45 ->setCheckPermissions($checkPermissions);
46 }
47
48 /**
49 * @param bool $checkPermissions
50 * @return DAOGetFieldsAction
51 */
52 public static function getFields($checkPermissions = TRUE) {
53 return (new DAOGetFieldsAction(static::getEntityName(), __FUNCTION__))
54 ->setCheckPermissions($checkPermissions);
55 }
56
57 /**
58 * @param bool $checkPermissions
59 * @return DAOCreateAction
60 */
61 public static function create($checkPermissions = TRUE) {
62 return (new DAOCreateAction(static::getEntityName(), __FUNCTION__))
63 ->setCheckPermissions($checkPermissions);
64 }
65
66 /**
67 * @param bool $checkPermissions
68 * @return DAOUpdateAction
69 */
70 public static function update($checkPermissions = TRUE) {
71 return (new DAOUpdateAction(static::getEntityName(), __FUNCTION__))
72 ->setCheckPermissions($checkPermissions);
73 }
74
75 /**
76 * @param bool $checkPermissions
77 * @return DAODeleteAction
78 */
79 public static function delete($checkPermissions = TRUE) {
80 return (new DAODeleteAction(static::getEntityName(), __FUNCTION__))
81 ->setCheckPermissions($checkPermissions);
82 }
83
84 /**
85 * @param bool $checkPermissions
86 * @return BasicReplaceAction
87 */
88 public static function replace($checkPermissions = TRUE) {
89 return (new BasicReplaceAction(static::getEntityName(), __FUNCTION__))
90 ->setCheckPermissions($checkPermissions);
91 }
92
93 }