Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Bridge_OG_CiviCRM { | |
36 | ||
e0ef6999 | 37 | /** |
100fef9d | 38 | * @param int $groupID |
e0ef6999 EM |
39 | * @param $group |
40 | * @param $op | |
41 | */ | |
00be9182 | 42 | public static function group($groupID, $group, $op) { |
6a488035 TO |
43 | if ($op == 'add') { |
44 | self::groupAdd($groupID, $group); | |
45 | } | |
46 | else { | |
47 | self::groupDelete($groupID, $group); | |
48 | } | |
49 | } | |
50 | ||
e0ef6999 | 51 | /** |
100fef9d | 52 | * @param int $groupID |
e0ef6999 EM |
53 | * @param $group |
54 | */ | |
00be9182 | 55 | public static function groupAdd($groupID, $group) { |
6a488035 TO |
56 | $ogID = CRM_Bridge_OG_Utils::ogID($groupID, FALSE); |
57 | ||
58 | $node = new StdClass(); | |
59 | if ($ogID) { | |
60 | $node->nid = $ogID; | |
61 | } | |
62 | ||
63 | global $user; | |
353ffa53 TO |
64 | $node->uid = $user->uid; |
65 | $node->title = $group->title; | |
66 | $node->type = 'og'; | |
6a488035 TO |
67 | $node->status = 1; |
68 | ||
69 | // set the og values | |
70 | $node->og_description = $group->description; | |
71 | $node->og_selective = OF_OPEN; | |
72 | $node->og_register = 0; | |
73 | $node->og_directory = 1; | |
74 | ||
75 | node_save($node); | |
76 | ||
77 | // also change the source field of the group | |
78 | CRM_Core_DAO::setFieldValue('CRM_Contact_DAO_Group', | |
79 | $groupID, | |
80 | 'source', | |
81 | CRM_Bridge_OG_Utils::ogSyncName($node->nid) | |
82 | ); | |
83 | } | |
84 | ||
e0ef6999 | 85 | /** |
100fef9d | 86 | * @param int $groupID |
e0ef6999 EM |
87 | * @param $group |
88 | */ | |
00be9182 | 89 | public static function groupDelete($groupID, $group) { |
6a488035 TO |
90 | $ogID = CRM_Bridge_OG_Utils::ogID($groupID, FALSE); |
91 | if (!$ogID) { | |
92 | return; | |
93 | } | |
94 | ||
95 | node_delete($ogID); | |
96 | } | |
97 | ||
e0ef6999 | 98 | /** |
100fef9d | 99 | * @param int $groupID |
e0ef6999 EM |
100 | * @param $contactIDs |
101 | * @param $op | |
102 | */ | |
00be9182 | 103 | public static function groupContact($groupID, $contactIDs, $op) { |
6a488035 TO |
104 | $config = CRM_Core_Config::singleton(); |
105 | $ogID = CRM_Bridge_OG_Utils::ogID($groupID, FALSE); | |
8ef12e64 | 106 | |
6a488035 TO |
107 | if (!$ogID) { |
108 | return; | |
109 | } | |
110 | ||
111 | foreach ($contactIDs as $contactID) { | |
112 | $drupalID = CRM_Core_BAO_UFMatch::getUFId($contactID); | |
113 | if ($drupalID) { | |
114 | if ($op == 'add') { | |
115 | $group_membership = $config->userSystem->og_membership_create($ogID, $drupalID); | |
116 | } | |
117 | else { | |
118 | $group_membership = $config->userSystem->og_membership_delete($ogID, $drupalID); | |
119 | } | |
120 | } | |
121 | } | |
122 | } | |
96025800 | 123 | |
6a488035 | 124 | } |