function poll_get_page_list($page_type, $container_guid = null) { global $autofeed; $autofeed = true; $user = elgg_get_logged_in_user_entity(); $params = array(); $options = array('type' => 'object', 'subtype' => 'poll', 'full_view' => false, 'limit' => 15); if ($page_type == 'group') { $group = get_entity($container_guid); if (!elgg_instanceof($group, 'group') || !poll_activated_for_group($group)) { forward(); } $crumbs_title = $group->name; $params['title'] = elgg_echo('poll:group_poll:listing:title', array(htmlspecialchars($crumbs_title))); $params['filter'] = ""; // set breadcrumb elgg_push_breadcrumb($crumbs_title); elgg_push_context('groups'); elgg_set_page_owner_guid($container_guid); group_gatekeeper(); $options['container_guid'] = $container_guid; $user_guid = elgg_get_logged_in_user_guid(); if (elgg_get_page_owner_entity()->canWriteToContainer($user_guid)) { elgg_register_menu_item('title', array('name' => 'add', 'href' => "poll/add/" . $container_guid, 'text' => elgg_echo('poll:add'), 'link_class' => 'elgg-button elgg-button-action')); } } else { switch ($page_type) { case 'owner': $options['owner_guid'] = $container_guid; $container_entity = get_user($container_guid); elgg_push_breadcrumb($container_entity->name); if ($user->guid == $container_guid) { $params['title'] = elgg_echo('poll:your'); $params['filter_context'] = 'mine'; } else { $params['title'] = elgg_echo('poll:not_me', array(htmlspecialchars($container_entity->name))); $params['filter_context'] = ""; } $params['sidebar'] = elgg_view('poll/sidebar'); break; case 'friends': $container_entity = get_user($container_guid); $friends = $container_entity->getFriends(array('limit' => false)); $options['container_guids'] = array(); foreach ($friends as $friend) { $options['container_guids'][] = $friend->getGUID(); } $params['filter_context'] = 'friends'; $params['title'] = elgg_echo('poll:friends'); elgg_push_breadcrumb($container_entity->name, "poll/owner/{$container_entity->username}"); elgg_push_breadcrumb(elgg_echo('friends')); break; case 'all': $params['filter_context'] = 'all'; $params['title'] = elgg_echo('item:object:poll'); $params['sidebar'] = elgg_view('poll/sidebar'); break; } $poll_site_access = elgg_get_plugin_setting('site_access', 'poll'); if (elgg_is_logged_in() && $poll_site_access != 'admins' || elgg_is_admin_logged_in()) { elgg_register_menu_item('title', array('name' => 'add', 'href' => "poll/add", 'text' => elgg_echo('poll:add'), 'link_class' => 'elgg-button elgg-button-action')); } } if ($page_type == 'friends' && count($options['container_guids']) == 0) { // this person has no friends $params['content'] = ''; } else { $params['content'] = elgg_list_entities($options); } if (!$params['content']) { $params['content'] = elgg_echo('poll:none'); } $body = elgg_view_layout("content", $params); return elgg_view_page($params['title'], $body); }
/** * Add a menu item to an owner block */ function poll_owner_block_menu($hook, $type, $return, $params) { if (elgg_instanceof($params['entity'], 'user')) { $url = "poll/owner/{$params['entity']->username}"; $item = new ElggMenuItem('poll', elgg_echo('poll'), $url); $return[] = $item; } else { elgg_load_library('elgg:poll'); if (poll_activated_for_group($params['entity'])) { $url = "poll/group/{$params['entity']->guid}/all"; $item = new ElggMenuItem('poll', elgg_echo('poll:group_poll'), $url); $return[] = $item; } } return $return; }
<?php /** * Group poll view * * @package Elggpoll_extended * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 * @author John Mellberg <*****@*****.**> * @copyright John Mellberg - 2009 * */ elgg_load_library('elgg:poll'); elgg_require_js('elgg/poll/poll'); $group = elgg_get_page_owner_entity(); if (poll_activated_for_group($group)) { elgg_push_context('widgets'); $all_link = elgg_view('output/url', array('href' => "poll/group/{$group->guid}/all", 'text' => elgg_echo('link:view:all'), 'is_trusted' => true)); $new_link = elgg_view('output/url', array('href' => "poll/add/{$group->guid}", 'text' => elgg_echo('poll:addpost'), 'is_trusted' => true)); $options = array('type' => 'object', 'subtype' => 'poll', 'limit' => 4, 'container_guid' => elgg_get_page_owner_guid()); $content = ''; if ($poll_found = elgg_get_entities($options)) { foreach ($poll_found as $poll) { $content .= elgg_view('poll/widget', array('entity' => $poll)); } } elgg_pop_context(); if (!$content) { $content = '<p>' . elgg_echo("group:poll:empty") . '</p>'; } echo elgg_view('groups/profile/module', array('title' => elgg_echo('poll:group_poll'), 'content' => $content, 'all_link' => $all_link, 'add_link' => $new_link)); }