diff options
Diffstat (limited to 'mod/groups/lib/discussion.php')
| -rw-r--r-- | mod/groups/lib/discussion.php | 74 |
1 files changed, 43 insertions, 31 deletions
diff --git a/mod/groups/lib/discussion.php b/mod/groups/lib/discussion.php index 62b0552e0..874e21b2d 100644 --- a/mod/groups/lib/discussion.php +++ b/mod/groups/lib/discussion.php @@ -14,17 +14,15 @@ function discussion_handle_all_page() { $content = elgg_list_entities(array( 'type' => 'object', 'subtype' => 'groupforumtopic', - 'annotation_name' => 'generic_comment', 'order_by' => 'e.last_action desc', - 'limit' => 40, - 'fullview' => false, + 'limit' => 20, + 'full_view' => false, )); $params = array( 'content' => $content, 'title' => elgg_echo('discussion:latest'), 'filter' => '', - 'buttons' => '', ); $body = elgg_view_layout('content', $params); @@ -41,12 +39,13 @@ 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(); + if (!elgg_instanceof($group, 'group')) { + forward('', '404'); } elgg_push_breadcrumb($group->name); + elgg_register_title_button(); + group_gatekeeper(); $title = elgg_echo('item:object:groupforumtopic'); @@ -57,9 +56,12 @@ function discussion_handle_list_page($guid) { 'limit' => 20, 'order_by' => 'e.last_action desc', 'container_guid' => $guid, - 'fullview' => true, + 'full_view' => false, ); $content = elgg_list_entities($options); + if (!$content) { + $content = elgg_echo('discussion:none'); + } $params = array( @@ -68,10 +70,6 @@ function discussion_handle_list_page($guid) { 'filter' => '', ); - if (!$group->isMember() && !$group->canEdit()) { - $params['buttons'] = ''; - } - $body = elgg_view_layout('content', $params); echo elgg_view_page($title, $body); @@ -87,17 +85,21 @@ 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(); + + // make sure user has permissions to add a topic to container + if (!$group->canWriteToContainer(0, 'object', 'groupforumtopic')) { + register_error(elgg_echo('groups:permissions:error')); + forward($group->getURL()); + } $title = elgg_echo('groups:addtopic'); - elgg_push_breadcrumb($group->name, "pg/discussion/owner/$group->guid"); + elgg_push_breadcrumb($group->name, "discussion/owner/$group->guid"); elgg_push_breadcrumb($title); $body_vars = discussion_prepare_form_vars(); @@ -113,11 +115,10 @@ function discussion_handle_edit_page($type, $guid) { 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($group->name, "discussion/owner/$group->guid"); elgg_push_breadcrumb($topic->title, $topic->getURL()); elgg_push_breadcrumb($title); @@ -129,7 +130,6 @@ function discussion_handle_edit_page($type, $guid) { 'content' => $content, 'title' => $title, 'filter' => '', - 'buttons' => '', ); $body = elgg_view_layout('content', $params); @@ -148,8 +148,9 @@ function discussion_handle_view_page($guid) { $topic = get_entity($guid); if (!$topic) { - register_error(elgg_echo('discussion:topic:notfound')); - forward(); + register_error(elgg_echo('noaccess')); + $_SESSION['last_forward_from'] = current_page_url(); + forward(''); } $group = $topic->getContainerEntity(); @@ -162,28 +163,36 @@ function discussion_handle_view_page($guid) { group_gatekeeper(); - elgg_push_breadcrumb($group->name, "pg/discussion/owner/$group->guid"); + elgg_push_breadcrumb($group->name, "discussion/owner/$group->guid"); elgg_push_breadcrumb($topic->title); - $content = elgg_view_entity($topic, true); + $content = elgg_view_entity($topic, array('full_view' => true)); if ($topic->status == 'closed') { - $content .= elgg_view_comments($topic, false); + $content .= elgg_view('discussion/replies', array( + 'entity' => $topic, + 'show_add_form' => false, + )); $content .= elgg_view('discussion/closed'); - } elseif ($group->isMember() || elgg_is_admin_logged_in()) { - $content .= elgg_view_comments($topic); + } elseif ($group->canWriteToContainer(0, 'object', 'groupforumtopic') || elgg_is_admin_logged_in()) { + $content .= elgg_view('discussion/replies', array( + 'entity' => $topic, + 'show_add_form' => true, + )); } else { - $content .= elgg_view_comments($topic, false); + $content .= elgg_view('discussion/replies', array( + 'entity' => $topic, + 'show_add_form' => false, + )); } $params = array( 'content' => $content, 'title' => $topic->title, 'filter' => '', - 'buttons' => '', ); $body = elgg_view_layout('content', $params); - echo elgg_view_page($title, $body); + echo elgg_view_page($topic->title, $body); } /** @@ -207,13 +216,16 @@ function discussion_prepare_form_vars($topic = NULL) { if ($topic) { foreach (array_keys($values) as $field) { - $values[$field] = $topic->$field; + if (isset($topic->$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); + $sticky_values = elgg_get_sticky_values('topic'); + foreach ($sticky_values as $key => $value) { + $values[$key] = $value; } } |
