Merge pull request #18434 from agh1/titlesingular
[civicrm-core.git] / CRM / Bridge / OG / CiviCRM.php
CommitLineData
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 */
17class CRM_Bridge_OG_CiviCRM {
18
e0ef6999 19 /**
100fef9d 20 * @param int $groupID
e0ef6999
EM
21 * @param $group
22 * @param $op
23 */
00be9182 24 public static function group($groupID, $group, $op) {
6a488035
TO
25 if ($op == 'add') {
26 self::groupAdd($groupID, $group);
27 }
28 else {
29 self::groupDelete($groupID, $group);
30 }
31 }
32
e0ef6999 33 /**
100fef9d 34 * @param int $groupID
e0ef6999
EM
35 * @param $group
36 */
00be9182 37 public static function groupAdd($groupID, $group) {
ba968e38 38 $ogID = CRM_Bridge_OG_Utils::ogID($groupID);
6a488035
TO
39
40 $node = new StdClass();
41 if ($ogID) {
42 $node->nid = $ogID;
43 }
44
45 global $user;
353ffa53
TO
46 $node->uid = $user->uid;
47 $node->title = $group->title;
48 $node->type = 'og';
6a488035
TO
49 $node->status = 1;
50
51 // set the og values
52 $node->og_description = $group->description;
53 $node->og_selective = OF_OPEN;
54 $node->og_register = 0;
55 $node->og_directory = 1;
56
57 node_save($node);
58
59 // also change the source field of the group
60 CRM_Core_DAO::setFieldValue('CRM_Contact_DAO_Group',
61 $groupID,
62 'source',
63 CRM_Bridge_OG_Utils::ogSyncName($node->nid)
64 );
65 }
66
e0ef6999 67 /**
100fef9d 68 * @param int $groupID
e0ef6999
EM
69 * @param $group
70 */
00be9182 71 public static function groupDelete($groupID, $group) {
ba968e38 72 $ogID = CRM_Bridge_OG_Utils::ogID($groupID);
6a488035
TO
73 if (!$ogID) {
74 return;
75 }
76
77 node_delete($ogID);
78 }
79
e0ef6999 80 /**
100fef9d 81 * @param int $groupID
e0ef6999
EM
82 * @param $contactIDs
83 * @param $op
84 */
00be9182 85 public static function groupContact($groupID, $contactIDs, $op) {
6a488035 86 $config = CRM_Core_Config::singleton();
ba968e38 87 $ogID = CRM_Bridge_OG_Utils::ogID($groupID);
8ef12e64 88
6a488035
TO
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 }
96025800 105
6a488035 106}