Example #1
0
require dirname(dirname(dirname(__FILE__))) . '/init.php';
safe_require('blocktype', 'groupviews');
require_once get_config('libroot') . 'view.php';
require_once get_config('libroot') . 'group.php';
require_once get_config('libroot') . 'pieforms/pieform.php';
$offset = param_integer('offset', 0);
$groupid = param_integer('group');
$editing = param_boolean('editing', false);
$group_homepage_view = group_get_homepage_view($groupid);
$bi = group_get_homepage_view_groupview_block($groupid);
if (!can_view_view($group_homepage_view) || !group_user_can_assess_submitted_views($groupid, $USER->get('id'))) {
    json_reply(true, get_string('accessdenied', 'error'));
}
$configdata = $bi->get('configdata');
$limit = isset($configdata['count']) ? intval($configdata['count']) : 5;
$limit = $limit > 0 ? $limit : 5;
if (!isset($configdata['sortsubmittedby']) || $configdata['sortsubmittedby'] == PluginBlocktypeGroupViews::SORTBY_TITLE) {
    $sortsubmittedby = 'c.name, v.title';
} else {
    $sortsubmittedby = 'c.submittedtime DESC, v.submittedtime DESC';
}
list($collections, $views) = View::get_views_and_collections(null, null, null, null, false, $groupid, $sortsubmittedby);
$allsubmitted = array_merge(array_values($collections), array_values($views));
$allsubmitted = array('data' => array_slice($allsubmitted, $offset, $limit), 'count' => count($allsubmitted), 'limit' => $limit, 'offset' => $offset);
if (!empty($configdata['showsubmitted'])) {
    $baseurl = $group_homepage_view->get_url();
    $baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'group=' . $groupid . '&editing=' . $editing;
    $pagination = array('baseurl' => $baseurl, 'id' => 'allsubmitted_pagination', 'datatable' => 'allsubmissionlist', 'jsonscript' => 'blocktype/groupviews/allsubmissions.json.php', 'resultcounttextsingular' => get_string('vieworcollection', 'view'), 'resultcounttextplural' => get_string('viewsandcollections', 'view'));
    PluginBlocktypeGroupViews::render_items($allsubmitted, 'blocktype:groupviews:allsubmissions.tpl', $configdata, $pagination);
}
json_reply(false, array('data' => $allsubmitted));
Example #2
0
$configdata = $bi->get('configdata');
if (!isset($configdata['showsharedviews'])) {
    $configdata['showsharedviews'] = 1;
}
$limit = isset($configdata['count']) ? intval($configdata['count']) : 5;
$limit = $limit > 0 ? $limit : 5;
// Find out what order to sort them by (default is titles)
if (!isset($configdata['sortsharedviewsby']) || $configdata['sortsharedviewsby'] == PluginBlocktypeGroupViews::SORTBY_TITLE) {
    $sortsharedviewsby = 'v.title';
} else {
    $sortsharedviewsby = 'v.mtime DESC';
}
// For group members, display a list of views that others have
// shared to the group
if (empty($configdata['showsharedviews'])) {
    $sharedviews = array('data' => array(), 'count' => 0, 'limit' => $limit, 'offset' => 0);
} else {
    $sharedviews = (array) View::get_sharedviews_data($limit, $offset, $groupid, $configdata['showsharedviews'] == 2 ? false : true, $sortsharedviewsby);
    foreach ($sharedviews['data'] as &$view) {
        if (!$editing && isset($view['template']) && $view['template']) {
            $view['form'] = pieform(create_view_form($group, null, $view->id));
        }
    }
}
if (!empty($configdata['showsharedviews'])) {
    $baseurl = $group_homepage_view->get_url();
    $baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'group=' . $groupid . '&editing=' . $editing;
    $pagination = array('baseurl' => $baseurl, 'id' => 'sharedviews_pagination', 'datatable' => 'sharedviewlist', 'jsonscript' => 'blocktype/groupviews/sharedviews.json.php', 'resultcounttextsingular' => get_string('view', 'view'), 'resultcounttextplural' => get_string('views', 'view'));
    PluginBlocktypeGroupViews::render_items($sharedviews, 'blocktype:groupviews:sharedviews.tpl', $configdata, $pagination);
}
json_reply(false, array('data' => $sharedviews));
Example #3
0
$bi = group_get_homepage_view_groupview_block($groupid);
if (!can_view_view($group_homepage_view)) {
    json_reply(true, get_string('accessdenied', 'error'));
}
$configdata = $bi->get('configdata');
if (!isset($configdata['showgroupviews'])) {
    $configdata['showgroupviews'] = 1;
}
$limit = isset($configdata['count']) ? intval($configdata['count']) : 5;
$limit = $limit > 0 ? $limit : 5;
// Sortorder: Group homepage should be first, then sort by sortorder
$sort = array(array('column' => "type='grouphomepage'", 'desc' => true));
// Find out what order to sort them by (default is titles)
if (!isset($configdata['sortgroupviewsby']) || $configdata['sortgroupviewsby'] == PluginBlocktypeGroupViews::SORTBY_TITLE) {
    $sort[] = array('column' => 'title');
} else {
    $sort[] = array('column' => 'mtime', 'desc' => true);
}
$groupviews = (array) View::view_search(null, null, (object) array('group' => $groupid), null, $limit, $offset, true, $sort);
foreach ($groupviews['data'] as &$view) {
    if (isset($view['template']) && $view['template']) {
        $view['form'] = pieform(create_view_form(null, null, $view['id']));
    }
}
if (!empty($configdata['showgroupviews']) && isset($groupviews)) {
    $baseurl = $group_homepage_view->get_url();
    $baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'group=' . $groupid;
    $pagination = array('baseurl' => $baseurl, 'id' => 'groupviews_pagination', 'datatable' => 'groupviewlist', 'jsonscript' => 'blocktype/groupviews/groupviews.json.php', 'resultcounttextsingular' => get_string('view', 'view'), 'resultcounttextplural' => get_string('views', 'view'));
    PluginBlocktypeGroupViews::render_items($groupviews, 'blocktype:groupviews:groupviewssection.tpl', $configdata, $pagination);
}
json_reply(false, array('data' => $groupviews));