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