3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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 (reference) an assoc array of name/value pairs
46 * @return object CRM_Core_DAO_UFJoin object
50 public static function &create($params) {
51 // see if a record exists with the same weight
52 $id = self
::findJoinEntryId($params);
57 $dao = new CRM_Core_DAO_UFJoin();
58 $dao->copyValues($params);
59 if ($params['uf_group_id']) {
72 public static function deleteAll(&$params) {
73 $module = CRM_Utils_Array
::value('module', $params);
74 $entityTable = CRM_Utils_Array
::value('entity_table', $params);
75 $entityID = CRM_Utils_Array
::value('entity_id', $params);
77 if (empty($entityTable) ||
84 $dao = new CRM_Core_DAO_UFJoin();
85 $dao->module
= $module;
86 $dao->entity_table
= $entityTable;
87 $dao->entity_id
= $entityID;
92 * Given an assoc list of params, find if there is a record
93 * for this set of params
95 * @param array $params (reference) an assoc array of name/value pairs
101 public static function findJoinEntryId(&$params) {
102 if (!empty($params['id'])) {
103 return $params['id'];
106 $dao = new CRM_Core_DAO_UFJoin();
108 // CRM-4377 (ab)uses the module column
109 if (isset($params['module'])) {
110 $dao->module
= CRM_Utils_Array
::value('module', $params);
112 $dao->entity_table
= CRM_Utils_Array
::value('entity_table', $params);
113 $dao->entity_id
= CRM_Utils_Array
::value('entity_id', $params);
114 // user reg / my account can have multiple entries, so we return if thats
115 // the case. (since entity_table/id is empty in those cases
116 if (!$dao->entity_table ||
121 $dao->weight
= CRM_Utils_Array
::value('weight', $params);
122 if ($dao->find(TRUE)) {
129 * Given an assoc list of params, find if there is a record
130 * for this set of params and return the group id
132 * @param array $params (reference) an assoc array of name/value pairs
134 * @return int or null
138 public static function findUFGroupId(&$params) {
140 $dao = new CRM_Core_DAO_UFJoin();
142 $dao->entity_table
= CRM_Utils_Array
::value('entity_table', $params);
143 $dao->entity_id
= CRM_Utils_Array
::value('entity_id', $params);
144 $dao->weight
= CRM_Utils_Array
::value('weight', $params);
145 if ($dao->find(TRUE)) {
146 return $dao->uf_group_id
;
156 public static function getUFGroupIds(&$params) {
158 $dao = new CRM_Core_DAO_UFJoin();
160 // CRM-4377 (ab)uses the module column
161 if (isset($params['module'])) {
162 $dao->module
= CRM_Utils_Array
::value('module', $params);
164 $dao->entity_table
= CRM_Utils_Array
::value('entity_table', $params);
165 $dao->entity_id
= CRM_Utils_Array
::value('entity_id', $params);
166 $dao->orderBy('weight asc');
168 $first = $firstActive = NULL;
169 $second = $secondActive = array();
171 while ($dao->fetch()) {
172 if ($dao->weight
== 1) {
173 $first = $dao->uf_group_id
;
174 $firstActive = $dao->is_active
;
177 $second[] = $dao->uf_group_id
;
178 $secondActive[] = $dao->is_active
;
181 return array($first, $second, $firstActive, $secondActive);