aboutsummaryrefslogtreecommitdiff
path: root/mod/autosubscribegroup/start.php
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2014-03-15 14:57:34 -0300
committerSilvio Rhatto <rhatto@riseup.net>2014-03-15 14:57:34 -0300
commit8d66daa258a58b65c3658b38e99382732c88e017 (patch)
treeec3d466553f61f099a9fd58db374c4215c3f12dd /mod/autosubscribegroup/start.php
parenta7be81c3f81c807d43ed32965ee7ac11ebe71895 (diff)
parent0be0b2d3a472b7b3a8c4a5d2ee22389acf126c3c (diff)
downloadelgg-8d66daa258a58b65c3658b38e99382732c88e017.tar.gz
elgg-8d66daa258a58b65c3658b38e99382732c88e017.tar.bz2
Merge commit '0be0b2d3a472b7b3a8c4a5d2ee22389acf126c3c' as 'mod/autosubscribegroup'
Diffstat (limited to 'mod/autosubscribegroup/start.php')
-rw-r--r--mod/autosubscribegroup/start.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/mod/autosubscribegroup/start.php b/mod/autosubscribegroup/start.php
new file mode 100644
index 000000000..69f447267
--- /dev/null
+++ b/mod/autosubscribegroup/start.php
@@ -0,0 +1,57 @@
+<?php
+
+/**
+ * Elgg autosubscribegroup plugin
+ * This plugin allows new users to get joined to groups automatically when they register.
+ *
+ * @package autosubscribegroups
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author RONNEL Jérémy
+ * @copyright (c) Elbee 2008
+ * @link /www.notredeco.com
+ *
+ * for Elgg 1.8 by iionly (iionly@gmx.de)
+ */
+
+/**
+ * Init
+ *
+ */
+function autosubscribegroup_init() {
+ //group plugin disabled : no need to go further...
+ if (!elgg_is_active_plugin("groups")) {
+ return;
+ }
+
+ //Listen to user registration
+ elgg_register_event_handler('create', 'user', 'autosubscribegroup_join', 502);
+}
+
+/**
+ * auto join group define in plugin settings
+ *
+ */
+function autosubscribegroup_join($event, $object_type, $object) {
+
+ if (($object instanceof ElggUser) && ($event == 'create') && ($object_type == 'user')) {
+ //auto submit relationships between user & groups
+ //retrieve groups ids from plugin
+ $groups = elgg_get_plugin_setting('systemgroups');
+ $groups = split(',', $groups);
+
+ //for each group ids
+ foreach($groups as $groupId) {
+ //if group exist : submit to group
+ if ($groupEnt = get_entity($groupId)) {
+ //join group succeed ?
+ if ($groupEnt->join($object)) {
+ // Remove any invite or join request flags
+ elgg_delete_metadata(array('guid' => $object->guid, 'metadata_name' => 'group_invite', 'metadata_value' => $groupEnt->guid, 'limit' => 0));
+ elgg_delete_metadata(array('guid' => $object->guid, 'metadata_name' => 'group_join_request', 'metadata_value' => $groupEnt->guid, 'limit' => 0));
+ }
+ }
+ }
+ }
+}
+
+elgg_register_event_handler('init', 'system', 'autosubscribegroup_init');