diff options
Diffstat (limited to 'mod/groups/lib')
-rw-r--r-- | mod/groups/lib/groups.php | 248 |
1 files changed, 248 insertions, 0 deletions
diff --git a/mod/groups/lib/groups.php b/mod/groups/lib/groups.php new file mode 100644 index 000000000..faedca18e --- /dev/null +++ b/mod/groups/lib/groups.php @@ -0,0 +1,248 @@ +<?php +/** + * Groups function library + */ + +/** + * List all groups + */ +function groups_handle_all_page() { + + // all groups doesn't get link to self + elgg_pop_breadcrumb(); + elgg_push_breadcrumb(elgg_echo('groups')); + + $selected_tab = get_input('filter', 'newest'); + + switch ($selected_tab) { + case 'pop': + $content = elgg_list_entities_from_relationship_count(array( + 'type' => 'group', + 'relationship' => 'member', + 'inverse_relationship' => false, + 'full_view' => false, + )); + break; + case 'active': + $content = elgg_list_entities(array( + 'type' => 'object', + 'subtype' => 'groupforumtopic', + 'annotation_name' => 'generic_comment', + 'order_by' => 'e.last_action desc', + 'limit' => 40, + 'fullview' => false, + )); + break; + case 'newest': + default: + $content = elgg_list_entities(array( + 'type' => 'group', + 'full_view' => false, + )); + break; + } + + $filter = elgg_view('groups/group_sort_menu', array('selected' => $selected_tab)); + + $sidebar = elgg_view('groups/sidebar/find'); + $sidebar .= elgg_view('groups/sidebar/featured'); + + $params = array( + 'content' => $content, + 'sidebar' => $sidebar, + 'filter' => $filter, + ); + $body = elgg_view_layout('content', $params); + + echo elgg_view_page($title, $body); +} + +/** + * List owned groups + */ +function groups_handle_owned_page() { + + $page_owner = elgg_get_page_owner(); + + $title = elgg_echo('groups:owned'); + elgg_push_breadcrumb($title); + + $content = elgg_list_entities(array( + 'type' => 'group', + 'owner_guid' => elgg_get_page_owner_guid(), + 'full_view' => false, + )); + + $params = array( + 'content' => $content, + 'title' => $title, + 'filter' => '', + ); + $body = elgg_view_layout('content', $params); + + echo elgg_view_page($title, $body); +} + +/** + * List groups the user is memober of + */ +function groups_handle_mine_page() { + + $page_owner = elgg_get_page_owner(); + + $title = elgg_echo('groups:yours'); + elgg_push_breadcrumb($title); + + $content = elgg_list_entities_from_relationship_count(array( + 'type' => 'group', + 'relationship' => 'member', + 'relationship_guid' => elgg_get_page_owner_guid(), + 'inverse_relationship' => false, + 'full_view' => false, + )); + + $params = array( + 'content' => $content, + 'title' => $title, + 'filter' => '', + ); + $body = elgg_view_layout('content', $params); + + echo elgg_view_page($title, $body); +} + +/** + * Create or edit a group + * + * @param string $page + * @param int $guid + */ +function groups_handle_edit_page($page, $guid = 0) { + gatekeeper(); + + if ($page == 'add') { + elgg_set_page_owner_guid(get_loggedin_userid()); + $title = elgg_echo('groups:add'); + elgg_push_breadcrumb($title); + $content = elgg_view('forms/groups/edit'); + } else { + $title = elgg_echo("groups:edit"); + $group = get_entity($guid); + + if ($group && $group->canEdit()) { + elgg_set_page_owner_guid($group->getGUID()); + elgg_push_breadcrumb($group->name, $group->getURL()); + elgg_push_breadcrumb($title); + $content = elgg_view("forms/groups/edit", array('entity' => $group)); + } else { + $content = elgg_echo('groups:noaccess'); + } + } + + $params = array( + 'content' => $content, + 'title' => $title, + 'filter' => '', + 'buttons' => '', + ); + $body = elgg_view_layout('content', $params); + + echo elgg_view_page($title, $body); +} + +/** + * Group invitations for a user + */ +function groups_handle_invitations_page() { + gatekeeper(); + + $user = elgg_get_page_owner(); + + $title = elgg_echo('groups:invitations'); + elgg_push_breadcrumb($title); + + // @todo temporary workaround for exts #287. + $invitations = groups_get_invited_groups($user->getGUID()); + $content = elgg_view('groups/invitationrequests', array('invitations' => $invitations)); + + $params = array( + 'content' => $content, + 'title' => $title, + 'filter' => '', + 'buttons' => '', + ); + $body = elgg_view_layout('content', $params); + + echo elgg_view_page($title, $body); +} + +/** + * Group profile page + * + * @param int $guid Group entity GUID + */ +function groups_handle_profile_page($guid) { + elgg_set_page_owner_guid($guid); + + // turn this into a core function + global $autofeed; + $autofeed = true; + + $group = get_entity($guid); + + elgg_push_breadcrumb($group->name); + + $sidebar = ''; + $content = elgg_view('groups/profile/profile_block', array('entity' => $group)); + if (group_gatekeeper(false)) { + $content .= elgg_view('groups/profile/widgets', array('entity' => $group)); + $sidebar = elgg_view('groups/sidebar/members', array('entity' => $group)); + } else { + $content .= elgg_view('groups/profile/closed_membership'); + } + + $params = array( + 'content' => $content, + 'sidebar' => $sidebar, + 'title' => $group->name, + 'buttons' => elgg_view('groups/profile/buttons', array('entity' => $group)), + 'filter' => '', + ); + $body = elgg_view_layout('content', $params); + + echo elgg_view_page($title, $body); +} + +/** + * Group activity page + * + * @param int $guid Group entity GUID + */ +function groups_handle_activity_page($guid) { + + elgg_set_page_owner_guid($guid); + + $group = get_entity($guid); + if (!$group || !elgg_instanceof($group, 'group')) { + forward(); + } + + group_gatekeeper(); + + $title = elgg_echo('groups:activity'); + + elgg_push_breadcrumb($group->name, $group->getURL()); + elgg_push_breadcrumb($title); + + $content = "Group activity goes here"; + + $params = array( + 'content' => $content, + 'title' => $title, + 'buttons' => '', + 'filter' => '', + ); + $body = elgg_view_layout('content', $params); + + echo elgg_view_page($title, $body); +} |