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