APIv4 - Add shorthand for setCheckPermissions()
[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-based entities.
17 */
18 abstract class DAOEntity extends AbstractEntity {
19
20 /**
21 * @param bool $checkPermissions
22 * @return DAOGetAction
23 */
24 public static function get($checkPermissions = TRUE) {
25 return (new DAOGetAction(static::class, __FUNCTION__))
26 ->setCheckPermissions($checkPermissions);
27 }
28
29 /**
30 * @param bool $checkPermissions
31 * @return DAOSaveAction
32 */
33 public static function save($checkPermissions = TRUE) {
34 return (new DAOSaveAction(static::class, __FUNCTION__))
35 ->setCheckPermissions($checkPermissions);
36 }
37
38 /**
39 * @param bool $checkPermissions
40 * @return DAOGetFieldsAction
41 */
42 public static function getFields($checkPermissions = TRUE) {
43 return (new DAOGetFieldsAction(static::class, __FUNCTION__))
44 ->setCheckPermissions($checkPermissions);
45 }
46
47 /**
48 * @param bool $checkPermissions
49 * @return DAOCreateAction
50 */
51 public static function create($checkPermissions = TRUE) {
52 return (new DAOCreateAction(static::class, __FUNCTION__))
53 ->setCheckPermissions($checkPermissions);
54 }
55
56 /**
57 * @param bool $checkPermissions
58 * @return DAOUpdateAction
59 */
60 public static function update($checkPermissions = TRUE) {
61 return (new DAOUpdateAction(static::class, __FUNCTION__))
62 ->setCheckPermissions($checkPermissions);
63 }
64
65 /**
66 * @param bool $checkPermissions
67 * @return DAODeleteAction
68 */
69 public static function delete($checkPermissions = TRUE) {
70 return (new DAODeleteAction(static::class, __FUNCTION__))
71 ->setCheckPermissions($checkPermissions);
72 }
73
74 /**
75 * @param bool $checkPermissions
76 * @return BasicReplaceAction
77 */
78 public static function replace($checkPermissions = TRUE) {
79 return (new BasicReplaceAction(static::class, __FUNCTION__))
80 ->setCheckPermissions($checkPermissions);
81 }
82
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
105 }