/** * When a user joins a group * * @param string $event join * @param string $type group * @param array $params array with the user and the user * * @return void */ function group_tools_join_group_event($event, $type, $params) { global $NOTIFICATION_HANDLERS; static $auto_notification; // only load plugin setting once if (!isset($auto_notification)) { $auto_notification = array(); if (isset($NOTIFICATION_HANDLERS) && is_array($NOTIFICATION_HANDLERS)) { if (elgg_get_plugin_setting("auto_notification", "group_tools") == "yes") { // Backwards compatibility $auto_notification = array("email", "site"); } foreach ($NOTIFICATION_HANDLERS as $method => $foo) { if (elgg_get_plugin_setting("auto_notification_" . $method, "group_tools") == "1") { $auto_notification[] = $method; } } } } if (!empty($params) && is_array($params)) { $group = elgg_extract("group", $params); $user = elgg_extract("user", $params); if ($user instanceof ElggUser && $group instanceof ElggGroup) { // check for the auto notification settings if (!empty($NOTIFICATION_HANDLERS) && is_array($NOTIFICATION_HANDLERS)) { foreach ($NOTIFICATION_HANDLERS as $method => $dummy) { if (in_array($method, $auto_notification)) { add_entity_relationship($user->getGUID(), "notify" . $method, $group->getGUID()); } } } // cleanup invites remove_entity_relationship($group->getGUID(), "invited", $user->getGUID()); // and requests remove_entity_relationship($user->getGUID(), "membership_request", $group->getGUID()); // cleanup email invitations $options = array("annotation_name" => "email_invitation", "annotation_value" => group_tools_generate_email_invite_code($group->getGUID(), $user->email), "limit" => false); if (elgg_is_logged_in()) { elgg_delete_annotations($options); } elseif ($annotations = elgg_get_annotations($options)) { group_tools_delete_annotations($annotations); } // welcome message $welcome_message = $group->getPrivateSetting("group_tools:welcome_message"); $check_message = trim(strip_tags($welcome_message)); if (!empty($check_message)) { // replace the place holders $welcome_message = str_ireplace("[name]", $user->name, $welcome_message); $welcome_message = str_ireplace("[group_name]", $group->name, $welcome_message); $welcome_message = str_ireplace("[group_url]", $group->getURL(), $welcome_message); // notify the user notify_user($user->getGUID(), $group->getGUID(), elgg_echo("group_tools:welcome_message:subject", array($group->name)), $welcome_message); } } } }
function group_tools_join_group_event($event, $type, $params) { global $NOTIFICATION_HANDLERS; static $auto_notification; // only load plugin setting once if (!isset($auto_notification)) { $auto_notification = false; if (elgg_get_plugin_setting("auto_notification", "group_tools") == "yes") { $auto_notification = true; } } if (!empty($params) && is_array($params)) { $group = elgg_extract("group", $params); $user = elgg_extract("user", $params); if ($user instanceof ElggUser && $group instanceof ElggGroup) { if ($auto_notification && !empty($NOTIFICATION_HANDLERS) && is_array($NOTIFICATION_HANDLERS)) { // only auto subscribe to site and email notifications $auto_notification_handlers = array("site", "email"); foreach ($NOTIFICATION_HANDLERS as $method => $dummy) { if (in_array($method, $auto_notification_handlers)) { add_entity_relationship($user->getGUID(), "notify" . $method, $group->getGUID()); } } } // cleanup invites remove_entity_relationship($group->getGUID(), "invited", $user->getGUID()); // and requests remove_entity_relationship($user->getGUID(), "membership_request", $group->getGUID()); // cleanup email invitations $options = array("annotation_name" => "email_invitation", "annotation_value" => group_tools_generate_email_invite_code($group->getGUID(), $user->email), "limit" => false); if (elgg_is_logged_in()) { elgg_delete_annotations($options); } elseif ($annotations = elgg_get_annotations($options)) { group_tools_delete_annotations($annotations); } } } }
/** * Cleanup group invitations and membershiprequests * * @param \ElggUser $user the user to cleanup for * @param \ElggGroup $group the group to cleanup on * * @return void */ protected static function cleanupGroupInvites(\ElggUser $user, \ElggGroup $group) { if (!$user instanceof \ElggUser || !$group instanceof \ElggGroup) { return; } // cleanup invites remove_entity_relationship($group->getGUID(), 'invited', $user->getGUID()); // and requests remove_entity_relationship($user->getGUID(), 'membership_request', $group->getGUID()); // cleanup email invitations $options = ['annotation_name' => 'email_invitation', 'annotation_value' => group_tools_generate_email_invite_code($group->getGUID(), $user->email), 'limit' => false]; if (elgg_is_logged_in()) { elgg_delete_annotations($options); } elseif ($annotations = elgg_get_annotations($options)) { group_tools_delete_annotations($annotations); } // join motivation $options = ['annotation_name' => 'join_motivation', 'guid' => $group->getGUID(), 'annotation_owner_guid' => $user->getGUID(), 'limit' => false]; elgg_delete_annotations($options); }