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
23 class CRM_Core_BAO_UFJoin
extends CRM_Core_DAO_UFJoin
{
26 * Takes an associative array and creates a uf join object.
28 * @param array $params
29 * (reference) an assoc array of name/value pairs.
31 * @return CRM_Core_DAO_UFJoin
33 public static function &create($params) {
34 // see if a record exists with the same weight
35 $id = self
::findJoinEntryId($params);
40 $dao = new CRM_Core_DAO_UFJoin();
41 $dao->copyValues($params);
42 if ($params['uf_group_id']) {
53 * @param array $params
55 public static function deleteAll(&$params) {
56 $module = $params['module'] ??
NULL;
57 $entityTable = $params['entity_table'] ??
NULL;
58 $entityID = $params['entity_id'] ??
NULL;
60 if (empty($entityTable) ||
67 $dao = new CRM_Core_DAO_UFJoin();
68 $dao->module
= $module;
69 $dao->entity_table
= $entityTable;
70 $dao->entity_id
= $entityID;
75 * Given an assoc list of params, find if there is a record
76 * for this set of params
78 * @param array $params
79 * (reference) an assoc array of name/value pairs.
84 public static function findJoinEntryId(&$params) {
85 if (!empty($params['id'])) {
89 $dao = new CRM_Core_DAO_UFJoin();
91 // CRM-4377 (ab)uses the module column
92 if (isset($params['module'])) {
93 $dao->module
= $params['module'];
95 $dao->entity_table
= $params['entity_table'] ??
NULL;
96 $dao->entity_id
= $params['entity_id'] ??
NULL;
97 // user reg / my account can have multiple entries, so we return if thats
98 // the case. (since entity_table/id is empty in those cases
99 if (!$dao->entity_table ||
104 $dao->weight
= $params['weight'] ??
NULL;
105 if ($dao->find(TRUE)) {
112 * Given an assoc list of params, find if there is a record
113 * for this set of params and return the group id
115 * @param array $params
116 * (reference) an assoc array of name/value pairs.
121 public static function findUFGroupId(&$params) {
123 $dao = new CRM_Core_DAO_UFJoin();
125 $dao->entity_table
= $params['entity_table'] ??
NULL;
126 $dao->entity_id
= $params['entity_id'] ??
NULL;
127 $dao->weight
= $params['weight'] ??
NULL;
128 $dao->module
= $params['module'] ??
NULL;
129 if ($dao->find(TRUE)) {
130 return $dao->uf_group_id
;
136 * @param array $params
140 public static function getUFGroupIds(&$params) {
142 $dao = new CRM_Core_DAO_UFJoin();
144 // CRM-4377 (ab)uses the module column
145 if (isset($params['module'])) {
146 $dao->module
= $params['module'];
148 $dao->entity_table
= $params['entity_table'] ??
NULL;
149 $dao->entity_id
= $params['entity_id'] ??
NULL;
150 $dao->orderBy('weight asc');
152 $first = $firstActive = NULL;
153 $second = $secondActive = [];
155 while ($dao->fetch()) {
156 if ($dao->weight
== 1) {
157 $first = $dao->uf_group_id
;
158 $firstActive = $dao->is_active
;
161 $second[] = $dao->uf_group_id
;
162 $secondActive[] = $dao->is_active
;
165 return [$first, $second, $firstActive, $secondActive];
169 * Whitelist of possible values for the entity_table field
172 public static function entityTables() {
174 'civicrm_event' => 'Event',
175 'civicrm_contribution_page' => 'ContributionPage',
176 'civicrm_survey' => 'Survey',