Import from SVN (r45945, r596)
[civicrm-core.git] / CRM / Bridge / OG / Utils.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 *
34 */
35class CRM_Bridge_OG_Utils {
36 CONST aclEnabled = 1, syncFromCiviCRM = 1;
37
38 static function aclEnabled() {
39 return self::aclEnabled;
40 }
41
42 /**
43 * Switch to stop synchronization from CiviCRM
44 * This was always false before, and is always true
45 * now. Most likely, this needs to be a setting.
46 */
47 static function syncFromCiviCRM() {
48 // make sure that acls are not enabled
49 //RMT -- the following makes no f**king sense...
50 //return ! self::aclEnabled & self::syncFromCiviCRM;
51 return TRUE;
52 }
53
54 static function ogSyncName($ogID) {
55 return "OG Sync Group :{$ogID}:";
56 }
57
58 static function ogSyncACLName($ogID) {
59 return "OG Sync Group ACL :{$ogID}:";
60 }
61
62 static function ogID($groupID, $abort = TRUE) {
63 $source = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group',
64 $groupID,
65 'source'
66 );
67
68 if (strpos($source, 'OG Sync Group') !== FALSE) {
69 preg_match('/:(\d+):$/', $source, $matches);
70 if (is_numeric($matches[1])) {
71 return $matches[1];
72 }
73 }
74 if ($abort) {
75 CRM_Core_Error::fatal();
76 }
77 return NULL;
78 }
79
80 static function contactID($ufID) {
81 $contactID = CRM_Core_BAO_UFMatch::getContactId($ufID);
82 if ($contactID) {
83 return $contactID;
84 }
85 // else synchronize contact for this user
86
87 $account = user_load($ufID);
88
89 CRM_Core_BAO_UFMatch::synchronizeUFMatch($account, $ufID, $account->mail, 'Drupal');
90 $contactID = CRM_Core_BAO_UFMatch::getContactId($ufID);
91 if (!$contactID) {
92 CRM_Core_Error::fatal();
93 }
94 return $contactID;
95 }
96
97 static function groupID($source, $title = NULL, $abort = FALSE) {
98 $query = "
99SELECT id
100 FROM civicrm_group
101 WHERE source = %1";
102 $params = array(1 => array($source, 'String'));
103
104 if ($title) {
105 $query .= " OR title = %2";
106 $params[2] = array($title, 'String');
107 }
108
109 $groupID = CRM_Core_DAO::singleValueQuery($query, $params);
110 if ($abort &&
111 !$groupID
112 ) {
113 CRM_Core_Error::fatal();
114 }
115
116 return $groupID;
117 }
118}
119