Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Bridge_OG_Utils { | |
7da04cde | 36 | const aclEnabled = 1, syncFromCiviCRM = 1; |
6a488035 | 37 | |
e0ef6999 EM |
38 | /** |
39 | * @return int | |
40 | */ | |
00be9182 | 41 | public static function aclEnabled() { |
6a488035 TO |
42 | return self::aclEnabled; |
43 | } | |
44 | ||
45 | /** | |
46 | * Switch to stop synchronization from CiviCRM | |
47 | * This was always false before, and is always true | |
48 | * now. Most likely, this needs to be a setting. | |
49 | */ | |
00be9182 | 50 | public static function syncFromCiviCRM() { |
6a488035 TO |
51 | // make sure that acls are not enabled |
52 | //RMT -- the following makes no f**king sense... | |
53 | //return ! self::aclEnabled & self::syncFromCiviCRM; | |
54 | return TRUE; | |
55 | } | |
56 | ||
e0ef6999 | 57 | /** |
100fef9d | 58 | * @param int $ogID |
e0ef6999 EM |
59 | * |
60 | * @return string | |
61 | */ | |
00be9182 | 62 | public static function ogSyncName($ogID) { |
6a488035 TO |
63 | return "OG Sync Group :{$ogID}:"; |
64 | } | |
65 | ||
e0ef6999 | 66 | /** |
100fef9d | 67 | * @param int $ogID |
e0ef6999 EM |
68 | * |
69 | * @return string | |
70 | */ | |
00be9182 | 71 | public static function ogSyncACLName($ogID) { |
6a488035 TO |
72 | return "OG Sync Group ACL :{$ogID}:"; |
73 | } | |
74 | ||
e0ef6999 | 75 | /** |
100fef9d | 76 | * @param int $groupID |
e0ef6999 EM |
77 | * @param bool $abort |
78 | * | |
79 | * @return int|null|string | |
80 | * @throws Exception | |
81 | */ | |
00be9182 | 82 | public static function ogID($groupID, $abort = TRUE) { |
6a488035 TO |
83 | $source = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', |
84 | $groupID, | |
85 | 'source' | |
86 | ); | |
87 | ||
88 | if (strpos($source, 'OG Sync Group') !== FALSE) { | |
89 | preg_match('/:(\d+):$/', $source, $matches); | |
90 | if (is_numeric($matches[1])) { | |
91 | return $matches[1]; | |
92 | } | |
93 | } | |
94 | if ($abort) { | |
95 | CRM_Core_Error::fatal(); | |
96 | } | |
97 | return NULL; | |
98 | } | |
99 | ||
e0ef6999 | 100 | /** |
100fef9d | 101 | * @param int $ufID |
e0ef6999 EM |
102 | * |
103 | * @return int | |
104 | * @throws Exception | |
105 | */ | |
00be9182 | 106 | public static function contactID($ufID) { |
6a488035 TO |
107 | $contactID = CRM_Core_BAO_UFMatch::getContactId($ufID); |
108 | if ($contactID) { | |
109 | return $contactID; | |
110 | } | |
111 | // else synchronize contact for this user | |
112 | ||
113 | $account = user_load($ufID); | |
114 | ||
115 | CRM_Core_BAO_UFMatch::synchronizeUFMatch($account, $ufID, $account->mail, 'Drupal'); | |
116 | $contactID = CRM_Core_BAO_UFMatch::getContactId($ufID); | |
117 | if (!$contactID) { | |
118 | CRM_Core_Error::fatal(); | |
119 | } | |
120 | return $contactID; | |
121 | } | |
122 | ||
e0ef6999 EM |
123 | /** |
124 | * @param $source | |
125 | * @param null $title | |
126 | * @param bool $abort | |
127 | * | |
128 | * @return null|string | |
129 | * @throws Exception | |
130 | */ | |
00be9182 | 131 | public static function groupID($source, $title = NULL, $abort = FALSE) { |
6a488035 TO |
132 | $query = " |
133 | SELECT id | |
134 | FROM civicrm_group | |
135 | WHERE source = %1"; | |
136 | $params = array(1 => array($source, 'String')); | |
137 | ||
138 | if ($title) { | |
139 | $query .= " OR title = %2"; | |
140 | $params[2] = array($title, 'String'); | |
141 | } | |
142 | ||
143 | $groupID = CRM_Core_DAO::singleValueQuery($query, $params); | |
144 | if ($abort && | |
145 | !$groupID | |
146 | ) { | |
147 | CRM_Core_Error::fatal(); | |
148 | } | |
149 | ||
150 | return $groupID; | |
151 | } | |
96025800 | 152 | |
6a488035 | 153 | } |