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