3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
39 class CRM_Core_BAO_UFJoin
extends CRM_Core_DAO_UFJoin
{
42 * Takes an associative array and creates a uf join object.
44 * @param array $params
45 * (reference) an assoc array of name/value pairs.
47 * @return CRM_Core_DAO_UFJoin
49 public static function &create($params) {
50 // see if a record exists with the same weight
51 $id = self
::findJoinEntryId($params);
56 $dao = new CRM_Core_DAO_UFJoin();
57 $dao->copyValues($params);
58 if ($params['uf_group_id']) {
69 * @param array $params
71 public static function deleteAll(&$params) {
72 $module = CRM_Utils_Array
::value('module', $params);
73 $entityTable = CRM_Utils_Array
::value('entity_table', $params);
74 $entityID = CRM_Utils_Array
::value('entity_id', $params);
76 if (empty($entityTable) ||
83 $dao = new CRM_Core_DAO_UFJoin();
84 $dao->module
= $module;
85 $dao->entity_table
= $entityTable;
86 $dao->entity_id
= $entityID;
91 * Given an assoc list of params, find if there is a record
92 * for this set of params
94 * @param array $params
95 * (reference) an assoc array of name/value pairs.
100 public static function findJoinEntryId(&$params) {
101 if (!empty($params['id'])) {
102 return $params['id'];
105 $dao = new CRM_Core_DAO_UFJoin();
107 // CRM-4377 (ab)uses the module column
108 if (isset($params['module'])) {
109 $dao->module
= CRM_Utils_Array
::value('module', $params);
111 $dao->entity_table
= CRM_Utils_Array
::value('entity_table', $params);
112 $dao->entity_id
= CRM_Utils_Array
::value('entity_id', $params);
113 // user reg / my account can have multiple entries, so we return if thats
114 // the case. (since entity_table/id is empty in those cases
115 if (!$dao->entity_table ||
120 $dao->weight
= CRM_Utils_Array
::value('weight', $params);
121 if ($dao->find(TRUE)) {
128 * Given an assoc list of params, find if there is a record
129 * for this set of params and return the group id
131 * @param array $params
132 * (reference) an assoc array of name/value pairs.
137 public static function findUFGroupId(&$params) {
139 $dao = new CRM_Core_DAO_UFJoin();
141 $dao->entity_table
= CRM_Utils_Array
::value('entity_table', $params);
142 $dao->entity_id
= CRM_Utils_Array
::value('entity_id', $params);
143 $dao->weight
= CRM_Utils_Array
::value('weight', $params);
144 if ($dao->find(TRUE)) {
145 return $dao->uf_group_id
;
151 * @param array $params
155 public static function getUFGroupIds(&$params) {
157 $dao = new CRM_Core_DAO_UFJoin();
159 // CRM-4377 (ab)uses the module column
160 if (isset($params['module'])) {
161 $dao->module
= CRM_Utils_Array
::value('module', $params);
163 $dao->entity_table
= CRM_Utils_Array
::value('entity_table', $params);
164 $dao->entity_id
= CRM_Utils_Array
::value('entity_id', $params);
165 $dao->orderBy('weight asc');
167 $first = $firstActive = NULL;
168 $second = $secondActive = array();
170 while ($dao->fetch()) {
171 if ($dao->weight
== 1) {
172 $first = $dao->uf_group_id
;
173 $firstActive = $dao->is_active
;
176 $second[] = $dao->uf_group_id
;
177 $secondActive[] = $dao->is_active
;
180 return array($first, $second, $firstActive, $secondActive);