Skip to content

Commit

Permalink
MDL-62347 course: use standard pagination renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
Bas Brands committed Aug 13, 2018
1 parent 6e44567 commit c8d5001
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 167 deletions.
39 changes: 3 additions & 36 deletions course/classes/management_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,47 +569,14 @@ protected function listing_pagination(coursecat $category, $page, $perpage, $sho
$html .= html_writer::div($str, 'listing-pagination-totals dimmed');
}

if ($totalcourses <= $perpage) {
return $html;
}
$aside = 2;
$span = $aside * 2 + 1;
$start = max($page - $aside, 0);
$end = min($page + $aside, $totalpages - 1);
if (($end - $start) < $span) {
if ($start == 0) {
$end = min($totalpages - 1, $span - 1);
} else if ($end == ($totalpages - 1)) {
$start = max(0, $end - $span + 1);
}
}
$items = array();
if ($viewmode !== 'default') {
$baseurl = new moodle_url('/course/management.php', array('categoryid' => $category->id,
'view' => $viewmode));
} else {
$baseurl = new moodle_url('/course/management.php', array('categoryid' => $category->id));
}
if ($page > 0) {
$items[] = $this->action_button(new moodle_url($baseurl, array('page' => 0)), get_string('first'));
$items[] = $this->action_button(new moodle_url($baseurl, array('page' => $page - 1)), get_string('prev'));
$items[] = '...';
}
for ($i = $start; $i <= $end; $i++) {
$class = '';
if ($page == $i) {
$class = 'active-page';
}
$pageurl = new moodle_url($baseurl, array('page' => $i));
$items[] = $this->action_button($pageurl, $i + 1, null, $class, get_string('pagea', 'moodle', $i+1));
}
if ($page < ($totalpages - 1)) {
$items[] = '...';
$items[] = $this->action_button(new moodle_url($baseurl, array('page' => $page + 1)), get_string('next'));
$items[] = $this->action_button(new moodle_url($baseurl, array('page' => $totalpages - 1)), get_string('last'));
}

$html .= html_writer::div(join('', $items), 'listing-pagination');
$html .= $this->output->paging_bar($totalcourses, $page, $perpage, $baseurl);
return $html;
}

Expand Down Expand Up @@ -1053,7 +1020,7 @@ public function view_mode_selector(array $modes, $currentmode, moodle_url $url =
}

$menu = new action_menu;
$menu->attributes['class'] .= ' view-mode-selector vms';
$menu->attributes['class'] .= ' view-mode-selector vms ml-1';

$selected = null;
foreach ($modes as $mode => $modestr) {
Expand All @@ -1077,7 +1044,7 @@ public function view_mode_selector(array $modes, $currentmode, moodle_url $url =

$menu->set_menu_trigger($selected);

$html = html_writer::start_div('view-mode-selector vms');
$html = html_writer::start_div('view-mode-selector vms d-flex');
$html .= get_string('viewing').' '.$this->render($menu);
$html .= html_writer::end_div();

Expand Down
Loading

0 comments on commit c8d5001

Please sign in to comment.