From 5dfb9a97cd5d99479610339f1c613f1468b96687 Mon Sep 17 00:00:00 2001 From: cash Date: Thu, 13 Jan 2011 12:03:27 +0000 Subject: discussion topics using new page handler git-svn-id: http://code.elgg.org/elgg/trunk@7880 36083f99-b078-4883-b0ff-0f9b5a30f544 --- mod/groups/lib/discussion.php | 209 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100644 mod/groups/lib/discussion.php (limited to 'mod/groups/lib/discussion.php') diff --git a/mod/groups/lib/discussion.php b/mod/groups/lib/discussion.php new file mode 100644 index 000000000..92ee94013 --- /dev/null +++ b/mod/groups/lib/discussion.php @@ -0,0 +1,209 @@ + 'object', + 'subtype' => 'groupforumtopic', + 'annotation_name' => 'generic_comment', + 'order_by' => 'e.last_action desc', + 'limit' => 40, + 'fullview' => false, + )); + + $params = array( + 'content' => $content, + 'title' => elgg_echo('discussion:latest'), + 'filter' => '', + 'buttons' => '', + ); + $body = elgg_view_layout('content', $params); + + echo elgg_view_page($title, $body); +} + +/** + * List discussion topics in a group + * + * @param int $guid Group entity GUID + */ +function discussion_handle_list_page($guid) { + + elgg_set_page_owner_guid($guid); + + $group = get_entity($guid); + if (!$group) { + register_error(elgg_echo('group:notfound')); + forward(); + } + elgg_push_breadcrumb($group->name); + + group_gatekeeper(); + + $title = elgg_echo('item:object:groupforumtopic'); + + $options = array( + 'type' => 'object', + 'subtype' => 'groupforumtopic', + 'limit' => 20, + 'order_by' => 'e.last_action desc', + 'container_guid' => $guid, + 'fullview' => true, + ); + $content = elgg_list_entities($options); + + + $params = array( + 'content' => $content, + 'title' => $title, + 'filter' => '', + ); + + if (!$group->isMember() && !$group->canEdit()) { + $params['buttons'] = ''; + } + + $body = elgg_view_layout('content', $params); + + echo elgg_view_page($title, $body); +} + +/** + * Edit or add a discussion topic + * + * @param string $type 'add' or 'edit' + * @param int $guid GUID of group or topic + */ +function discussion_handle_edit_page($type, $guid) { + gatekeeper(); + + if ($type == 'add') { + elgg_set_page_owner_guid($guid); + $group = get_entity($guid); + if (!$group) { + register_error(elgg_echo('group:notfound')); + forward(); + } + group_gatekeeper(); + + $title = elgg_echo('groups:addtopic'); + + elgg_push_breadcrumb($group->name, "pg/discussion/owner/$group->guid"); + elgg_push_breadcrumb($title); + + $body_vars = discussion_prepare_form_vars(); + $content = elgg_view_form('discussion/save', array(), $body_vars); + } else { + $topic = get_entity($guid); + if (!$topic || !$topic->canEdit()) { + register_error(elgg_echo('discussion:topic:notfound')); + forward(); + } + $group = $topic->getContainerEntity(); + if (!$group) { + register_error(elgg_echo('group:notfound')); + forward(); + } + elgg_set_page_owner_guid($group->getGUID()); + + $title = elgg_echo('groups:edittopic'); + + elgg_push_breadcrumb($group->name, "pg/discussion/owner/$group->guid"); + elgg_push_breadcrumb($topic->title, $topic->getURL()); + elgg_push_breadcrumb($title); + + $body_vars = discussion_prepare_form_vars($topic); + $content = elgg_view_form('discussion/save', array(), $body_vars); + } + + $params = array( + 'content' => $content, + 'title' => $title, + 'filter' => '', + 'buttons' => '', + ); + $body = elgg_view_layout('content', $params); + + echo elgg_view_page($title, $body); +} + +/** + * View a discussion topic + * + * @param int $guid GUID of topic + */ +function discussion_handle_view_page($guid) { + // We now have RSS on topics + global $autofeed; + $autofeed = true; + + $topic = get_entity($guid); + if (!$topic) { + register_error(elgg_echo('discussion:topic:notfound')); + forward(); + } + + $group = $topic->getContainerEntity(); + if (!$group) { + register_error(elgg_echo('group:notfound')); + forward(); + } + + elgg_set_page_owner_guid($group->getGUID()); + + group_gatekeeper(); + + elgg_push_breadcrumb($group->name, "pg/discussion/owner/$group->guid"); + elgg_push_breadcrumb($topic->title); + + $content = elgg_view('forum/viewposts', array('entity' => $topic)); + + $params = array( + 'content' => $content, + 'title' => $topic->title, + 'filter' => '', + 'buttons' => '', + ); + $body = elgg_view_layout('content', $params); + + echo elgg_view_page($title, $body); +} + +function discussion_prepare_form_vars($topic = NULL) { + // input names => defaults + $values = array( + 'title' => '', + 'description' => '', + 'status' => '', + 'access_id' => ACCESS_DEFAULT, + 'tags' => '', + 'container_guid' => elgg_get_page_owner_guid(), + 'guid' => null, + 'entity' => $topic, + ); + + if ($topic) { + foreach (array_keys($values) as $field) { + $values[$field] = $topic->$field; + } + } + + if (elgg_is_sticky_form('topic')) { + foreach (array_keys($values) as $field) { + $values[$field] = elgg_get_sticky_value('topic', $field); + } + } + + elgg_clear_sticky_form('topic'); + + return $values; +} -- cgit v1.2.3