Commit | Line | Data |
---|---|---|
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 | */ | |
35 | class CRM_Bridge_OG_CiviCRM { | |
36 | ||
37 | static function group($groupID, $group, $op) { | |
38 | if ($op == 'add') { | |
39 | self::groupAdd($groupID, $group); | |
40 | } | |
41 | else { | |
42 | self::groupDelete($groupID, $group); | |
43 | } | |
44 | } | |
45 | ||
46 | static function groupAdd($groupID, $group) { | |
47 | $ogID = CRM_Bridge_OG_Utils::ogID($groupID, FALSE); | |
48 | ||
49 | $node = new StdClass(); | |
50 | if ($ogID) { | |
51 | $node->nid = $ogID; | |
52 | } | |
53 | ||
54 | global $user; | |
55 | $node->uid = $user->uid; | |
56 | $node->title = $group->title; | |
57 | $node->type = 'og'; | |
58 | $node->status = 1; | |
59 | ||
60 | // set the og values | |
61 | $node->og_description = $group->description; | |
62 | $node->og_selective = OF_OPEN; | |
63 | $node->og_register = 0; | |
64 | $node->og_directory = 1; | |
65 | ||
66 | node_save($node); | |
67 | ||
68 | // also change the source field of the group | |
69 | CRM_Core_DAO::setFieldValue('CRM_Contact_DAO_Group', | |
70 | $groupID, | |
71 | 'source', | |
72 | CRM_Bridge_OG_Utils::ogSyncName($node->nid) | |
73 | ); | |
74 | } | |
75 | ||
76 | static function groupDelete($groupID, $group) { | |
77 | $ogID = CRM_Bridge_OG_Utils::ogID($groupID, FALSE); | |
78 | if (!$ogID) { | |
79 | return; | |
80 | } | |
81 | ||
82 | node_delete($ogID); | |
83 | } | |
84 | ||
85 | static function groupContact($groupID, $contactIDs, $op) { | |
86 | $config = CRM_Core_Config::singleton(); | |
87 | $ogID = CRM_Bridge_OG_Utils::ogID($groupID, FALSE); | |
88 | ||
89 | if (!$ogID) { | |
90 | return; | |
91 | } | |
92 | ||
93 | foreach ($contactIDs as $contactID) { | |
94 | $drupalID = CRM_Core_BAO_UFMatch::getUFId($contactID); | |
95 | if ($drupalID) { | |
96 | if ($op == 'add') { | |
97 | $group_membership = $config->userSystem->og_membership_create($ogID, $drupalID); | |
98 | } | |
99 | else { | |
100 | $group_membership = $config->userSystem->og_membership_delete($ogID, $drupalID); | |
101 | } | |
102 | } | |
103 | } | |
104 | } | |
105 | } | |
106 |