Commit d692dc7d authored by Son Nguyen's avatar Son Nguyen
Browse files

Fix pagination in group homepage. Bug 1457246

Add editing and sortoption parameters when getting the list of group pages,
shared pages and shared collections

Change-Id: Ie1ca8ca225ac179c55629b25c4402645c959fb48
parent 6df28ecf
...@@ -21,26 +21,31 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php'); ...@@ -21,26 +21,31 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('blocktype', 'groupviews'); safe_require('blocktype', 'groupviews');
require_once(get_config('libroot') . 'view.php'); require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'group.php'); require_once(get_config('libroot') . 'group.php');
require_once(get_config('libroot') . 'pieforms/pieform.php');
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
$groupid = param_integer('group'); $groupid = param_integer('group');
$editing = param_boolean('editing', false);
$group_homepage_view = group_get_homepage_view($groupid); $group_homepage_view = group_get_homepage_view($groupid);
$bi = group_get_homepage_view_groupview_block($groupid); $bi = group_get_homepage_view_groupview_block($groupid);
if (!can_view_view($group_homepage_view)) { if (!can_view_view($group_homepage_view)
|| !group_user_can_assess_submitted_views($groupid, $USER->get('id'))) {
json_reply(true, get_string('accessdenied', 'error')); json_reply(true, get_string('accessdenied', 'error'));
} }
$configdata = $bi->get('configdata'); $configdata = $bi->get('configdata');
if (!isset($configdata['showsubmitted'])) {
$configdata['showsubmitted'] = 1;
}
$limit = isset($configdata['count']) ? intval($configdata['count']) : 5; $limit = isset($configdata['count']) ? intval($configdata['count']) : 5;
$limit = ($limit > 0) ? $limit : 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); 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_merge(array_values($collections), array_values($views));
$allsubmitted = array( $allsubmitted = array(
'data' => array_slice($allsubmitted, $offset, $limit), 'data' => array_slice($allsubmitted, $offset, $limit),
...@@ -51,7 +56,7 @@ $allsubmitted = array( ...@@ -51,7 +56,7 @@ $allsubmitted = array(
if (!empty($configdata['showsubmitted'])) { if (!empty($configdata['showsubmitted'])) {
$baseurl = $group_homepage_view->get_url(); $baseurl = $group_homepage_view->get_url();
$baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'group=' . $groupid; $baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'group=' . $groupid . '&editing=' . $editing;
$pagination = array( $pagination = array(
'baseurl' => $baseurl, 'baseurl' => $baseurl,
'id' => 'allsubmitted_pagination', 'id' => 'allsubmitted_pagination',
......
...@@ -21,10 +21,11 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php'); ...@@ -21,10 +21,11 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('blocktype', 'groupviews'); safe_require('blocktype', 'groupviews');
require_once(get_config('libroot') . 'view.php'); require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'group.php'); require_once(get_config('libroot') . 'group.php');
require_once('pieforms/pieform.php'); require_once(get_config('libroot') . 'pieforms/pieform.php');
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
$groupid = param_integer('group'); $groupid = param_integer('group');
$editing = param_boolean('editing', false);
$group_homepage_view = group_get_homepage_view($groupid); $group_homepage_view = group_get_homepage_view($groupid);
$bi = group_get_homepage_view_groupview_block($groupid); $bi = group_get_homepage_view_groupview_block($groupid);
...@@ -37,15 +38,27 @@ $configdata = $bi->get('configdata'); ...@@ -37,15 +38,27 @@ $configdata = $bi->get('configdata');
if (!isset($configdata['showgroupviews'])) { if (!isset($configdata['showgroupviews'])) {
$configdata['showgroupviews'] = 1; $configdata['showgroupviews'] = 1;
} }
$limit = isset($configdata['count']) ? intval($configdata['count']) : 5; $limit = isset($configdata['count']) ? intval($configdata['count']) : 5;
$limit = ($limit > 0) ? $limit : 5; $limit = ($limit > 0) ? $limit : 5;
$sort = array(array('column' => 'type=\'grouphomepage\'', 'desc' => true)); // 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); $groupviews = (array)View::view_search(null, null, (object) array('group' => $groupid), null, $limit, $offset, true, $sort);
foreach ($groupviews['data'] as &$view) { foreach ($groupviews['data'] as &$view) {
if (isset($view['template']) && $view['template']) { if (isset($view['template']) && $view['template']) {
$view['form'] = pieform(create_view_form($group_homepage_view, null, $view->id)); $view['form'] = pieform(create_view_form(null, null, $view['id']));
} }
} }
if (!empty($configdata['showgroupviews']) && isset($groupviews)) { if (!empty($configdata['showgroupviews']) && isset($groupviews)) {
......
...@@ -103,7 +103,7 @@ class PluginBlocktypeGroupViews extends SystemBlocktype { ...@@ -103,7 +103,7 @@ class PluginBlocktypeGroupViews extends SystemBlocktype {
$dwoo->assign('group', $data['group']); $dwoo->assign('group', $data['group']);
$dwoo->assign('groupid', $data['group']->id); $dwoo->assign('groupid', $data['group']->id);
$baseurl = $instance->get_view()->get_url(); $baseurl = $instance->get_view()->get_url();
$baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'group=' . $groupid; $baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'group=' . $groupid . '&editing=' . $editing;
if (!empty($configdata['showgroupviews']) && isset($data['groupviews'])) { if (!empty($configdata['showgroupviews']) && isset($data['groupviews'])) {
$groupviews = (array)$data['groupviews']; $groupviews = (array)$data['groupviews'];
......
...@@ -21,9 +21,11 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php'); ...@@ -21,9 +21,11 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('blocktype', 'groupviews'); safe_require('blocktype', 'groupviews');
require_once(get_config('libroot') . 'view.php'); require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'group.php'); require_once(get_config('libroot') . 'group.php');
require_once(get_config('libroot') . 'pieforms/pieform.php');
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
$groupid = param_integer('group'); $groupid = param_integer('group');
$editing = param_boolean('editing', false);
$group_homepage_view = group_get_homepage_view($groupid); $group_homepage_view = group_get_homepage_view($groupid);
$bi = group_get_homepage_view_groupview_block($groupid); $bi = group_get_homepage_view_groupview_block($groupid);
...@@ -33,22 +35,45 @@ if (!can_view_view($group_homepage_view)) { ...@@ -33,22 +35,45 @@ if (!can_view_view($group_homepage_view)) {
} }
$configdata = $bi->get('configdata'); $configdata = $bi->get('configdata');
if (!isset($configdata['showsharedcollections'])) {
$configdata['showsharedcollections'] = 1;
}
$limit = isset($configdata['count']) ? intval($configdata['count']) : 5; $limit = isset($configdata['count']) ? intval($configdata['count']) : 5;
$limit = ($limit > 0) ? $limit : 5; $limit = ($limit > 0) ? $limit : 5;
$sharedcollections = (array) View::get_sharedcollections_data( // Find out what order to sort them by (default is titles)
$limit, if (!isset($configdata['sortsharedviewsby']) || $configdata['sortsharedviewsby'] == PluginBlocktypeGroupViews::SORTBY_TITLE) {
$offset, $sortsharedcollectionsby = array(array('column'=>'c.name'));
$groupid, }
($configdata['showsharedcollections'] == 2 ? true : false) else {
); $sortsharedcollectionsby = array(
array(
'column'=>'GREATEST(c.mtime, (SELECT MAX(v.mtime) FROM {view} v INNER JOIN {collection_view} cv ON v.id=cv.view WHERE cv.collection=c.id))',
'desc' => true
)
);
}
// For group members, display a list of collections that others have
// shared to the group
if (empty($configdata['showsharedcollections'])) {
$sharedcollections = array(
'data' => array(),
'count' => 0,
'limit' => $limit,
'offset' => 0
);
}
else {
$sharedcollections = (array) View::get_sharedcollections_data(
$limit,
$offset,
$groupid,
($configdata['showsharedcollections'] == 2 ? false : true),
$sortsharedcollectionsby
);
}
if (!empty($configdata['showsharedcollections']) && isset($sharedcollections)) { if (!empty($configdata['showsharedcollections']) && isset($sharedcollections)) {
$baseurl = $group_homepage_view->get_url(); $baseurl = $group_homepage_view->get_url();
$baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'group=' . $groupid; $baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'group=' . $groupid . '&editing=' . $editing;
$pagination = array( $pagination = array(
'baseurl' => $baseurl, 'baseurl' => $baseurl,
'id' => 'sharedcollections_pagination', 'id' => 'sharedcollections_pagination',
......
...@@ -21,9 +21,11 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php'); ...@@ -21,9 +21,11 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('blocktype', 'groupviews'); safe_require('blocktype', 'groupviews');
require_once(get_config('libroot') . 'view.php'); require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'group.php'); require_once(get_config('libroot') . 'group.php');
require_once(get_config('libroot') . 'pieforms/pieform.php');
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
$groupid = param_integer('group'); $groupid = param_integer('group');
$editing = param_boolean('editing', false);
$group_homepage_view = group_get_homepage_view($groupid); $group_homepage_view = group_get_homepage_view($groupid);
$bi = group_get_homepage_view_groupview_block($groupid); $bi = group_get_homepage_view_groupview_block($groupid);
...@@ -33,27 +35,44 @@ if (!can_view_view($group_homepage_view)) { ...@@ -33,27 +35,44 @@ if (!can_view_view($group_homepage_view)) {
} }
$configdata = $bi->get('configdata'); $configdata = $bi->get('configdata');
if (!isset($configdata['showsharedviews'])) {
$configdata['showsharedviews'] = 1;
}
$limit = isset($configdata['count']) ? intval($configdata['count']) : 5; $limit = isset($configdata['count']) ? intval($configdata['count']) : 5;
$limit = ($limit > 0) ? $limit : 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';
}
$sharedviews = (array) View::get_sharedviews_data( // For group members, display a list of views that others have
$limit, // shared to the group
$offset, if (empty($configdata['showsharedviews'])) {
$groupid, $sharedviews = array(
($configdata['showsharedviews'] == 2 ? false : true) 'data' => array(),
); 'count' => 0,
foreach ($sharedviews['data'] as &$view) { 'limit' => $limit,
if (isset($view['template']) && $view['template']) { 'offset' => 0
$view['form'] = pieform(create_view_form($group_homepage_view, null, $view->id)); );
}
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']) && isset($sharedviews)) { if (!empty($configdata['showsharedviews']) && isset($sharedviews)) {
$baseurl = $group_homepage_view->get_url(); $baseurl = $group_homepage_view->get_url();
$baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'group=' . $groupid; $baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'group=' . $groupid . '&editing=' . $editing;
$pagination = array( $pagination = array(
'baseurl' => $baseurl, 'baseurl' => $baseurl,
'id' => 'sharedviews_pagination', 'id' => 'sharedviews_pagination',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment