Merge pull request #15850 from civicrm/5.20
[civicrm-core.git] / CRM / ACL / BAO / EntityRole.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * Access Control EntityRole.
20 */
21 class CRM_ACL_BAO_EntityRole extends CRM_ACL_DAO_EntityRole {
22 public static $_entityTable = NULL;
23
24 /**
25 * Get entity table.
26 *
27 * @return array|null
28 */
29 public static function entityTable() {
30 if (!self::$_entityTable) {
31 self::$_entityTable = [
32 'civicrm_contact' => ts('Contact'),
33 'civicrm_group' => ts('Group'),
34 ];
35 }
36 return self::$_entityTable;
37 }
38
39 /**
40 * @param array $params
41 *
42 * @return CRM_ACL_DAO_EntityRole
43 */
44 public static function create(&$params) {
45 $dao = new CRM_ACL_DAO_EntityRole();
46 $dao->copyValues($params);
47 $dao->save();
48 return $dao;
49 }
50
51 /**
52 * @param array $params
53 * @param $defaults
54 */
55 public static function retrieve(&$params, &$defaults) {
56 CRM_Core_DAO::commonRetrieve('CRM_ACL_DAO_EntityRole', $params, $defaults);
57 }
58
59 /**
60 * Update the is_active flag in the db.
61 *
62 * @param int $id
63 * Id of the database record.
64 * @param bool $is_active
65 * Value we want to set the is_active field.
66 *
67 * @return bool
68 * true if we found and updated the object, else false
69 */
70 public static function setIsActive($id, $is_active) {
71 return CRM_Core_DAO::setFieldValue('CRM_ACL_DAO_EntityRole', $id, 'is_active', $is_active);
72 }
73
74 /**
75 * Delete Entity Role records.
76 *
77 * @param int $entityRoleId
78 * ID of the EntityRole record to be deleted.
79 *
80 */
81 public static function del($entityRoleId) {
82 $entityDAO = new CRM_ACL_DAO_EntityRole();
83 $entityDAO->id = $entityRoleId;
84 $entityDAO->find(TRUE);
85 $entityDAO->delete();
86 }
87
88 }