3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 class CRM_Core_BAO_UFJoin
extends CRM_Core_DAO_UFJoin
{
24 * Takes an associative array and creates a uf join object.
26 * @param array $params
27 * (reference) an assoc array of name/value pairs.
29 * @return CRM_Core_DAO_UFJoin
31 public static function &create($params) {
32 // see if a record exists with the same weight
33 $id = self
::findJoinEntryId($params);
38 $dao = new CRM_Core_DAO_UFJoin();
39 $dao->copyValues($params);
40 if ($params['uf_group_id']) {
51 * @param array $params
53 public static function deleteAll(&$params) {
54 $module = $params['module'] ??
NULL;
55 $entityTable = $params['entity_table'] ??
NULL;
56 $entityID = $params['entity_id'] ??
NULL;
58 if (empty($entityTable) ||
65 $dao = new CRM_Core_DAO_UFJoin();
66 $dao->module
= $module;
67 $dao->entity_table
= $entityTable;
68 $dao->entity_id
= $entityID;
73 * Given an assoc list of params, find if there is a record
74 * for this set of params
76 * @param array $params
77 * (reference) an assoc array of name/value pairs.
82 public static function findJoinEntryId(&$params) {
83 if (!empty($params['id'])) {
87 $dao = new CRM_Core_DAO_UFJoin();
89 // CRM-4377 (ab)uses the module column
90 if (isset($params['module'])) {
91 $dao->module
= $params['module'];
93 $dao->entity_table
= $params['entity_table'] ??
NULL;
94 $dao->entity_id
= $params['entity_id'] ??
NULL;
95 // user reg / my account can have multiple entries, so we return if thats
96 // the case. (since entity_table/id is empty in those cases
97 if (!$dao->entity_table ||
102 $dao->weight
= $params['weight'] ??
NULL;
103 if ($dao->find(TRUE)) {
110 * Given an assoc list of params, find if there is a record
111 * for this set of params and return the group id
113 * @param array $params
114 * (reference) an assoc array of name/value pairs.
119 public static function findUFGroupId(&$params) {
121 $dao = new CRM_Core_DAO_UFJoin();
123 $dao->entity_table
= $params['entity_table'] ??
NULL;
124 $dao->entity_id
= $params['entity_id'] ??
NULL;
125 $dao->weight
= $params['weight'] ??
NULL;
126 $dao->module
= $params['module'] ??
NULL;
127 if ($dao->find(TRUE)) {
128 return $dao->uf_group_id
;
134 * @param array $params
138 public static function getUFGroupIds(&$params) {
140 $dao = new CRM_Core_DAO_UFJoin();
142 // CRM-4377 (ab)uses the module column
143 if (isset($params['module'])) {
144 $dao->module
= $params['module'];
146 $dao->entity_table
= $params['entity_table'] ??
NULL;
147 $dao->entity_id
= $params['entity_id'] ??
NULL;
148 $dao->orderBy('weight asc');
150 $first = $firstActive = NULL;
151 $second = $secondActive = [];
153 while ($dao->fetch()) {
154 if ($dao->weight
== 1) {
155 $first = $dao->uf_group_id
;
156 $firstActive = $dao->is_active
;
159 $second[] = $dao->uf_group_id
;
160 $secondActive[] = $dao->is_active
;
163 return [$first, $second, $firstActive, $secondActive];
167 * Whitelist of possible values for the entity_table field
170 public static function entityTables() {
172 'civicrm_event' => 'Event',
173 'civicrm_contribution_page' => 'ContributionPage',
174 'civicrm_survey' => 'Survey',
179 * Override base method which assumes permissions should be based on entity_table.
183 public function addSelectWhereClause() {
185 CRM_Utils_Hook
::selectWhereClause($this, $clauses);