MDL-42779 course: Pagination in management page preserves view action
authorLuca Bösch <luca.boesch@bfh.ch>
Mon, 7 May 2018 22:59:53 +0000 (00:59 +0200)
committerLuca Bösch <luca.boesch@bfh.ch>
Thu, 24 May 2018 13:44:35 +0000 (15:44 +0200)
course/classes/management_renderer.php
course/management.php
theme/boost/classes/output/core_course/management/renderer.php

index 56e47e9..93efea0 100644 (file)
@@ -484,9 +484,11 @@ class core_course_management_renderer extends plugin_renderer_base {
      * @param course_in_list $course The currently selected course.
      * @param int $page The page being displayed.
      * @param int $perpage The number of courses to display per page.
+     * @param string|null $viewmode The view mode the page is in, one out of 'default', 'combined', 'courses' or 'categories'.
      * @return string
      */
-    public function course_listing(coursecat $category = null, course_in_list $course = null, $page = 0, $perpage = 20) {
+    public function course_listing(coursecat $category = null, course_in_list $course = null, $page = 0,
+        $perpage = 20, $viewmode = 'default') {
 
         if ($category === null) {
             $html = html_writer::start_div('select-a-category');
@@ -527,13 +529,13 @@ class core_course_management_renderer extends plugin_renderer_base {
         $html .= html_writer::tag('h3', $category->get_formatted_name(),
             array('id' => 'course-listing-title', 'tabindex' => '0'));
         $html .= $this->course_listing_actions($category, $course, $perpage);
-        $html .= $this->listing_pagination($category, $page, $perpage);
+        $html .= $this->listing_pagination($category, $page, $perpage, false, $viewmode);
         $html .= html_writer::start_tag('ul', array('class' => 'ml-1 course-list', 'role' => 'group'));
         foreach ($category->get_courses($options) as $listitem) {
             $html .= $this->course_listitem($category, $listitem, $courseid);
         }
         $html .= html_writer::end_tag('ul');
-        $html .= $this->listing_pagination($category, $page, $perpage, true);
+        $html .= $this->listing_pagination($category, $page, $perpage, true, $viewmode);
         $html .= $this->course_bulk_actions($category);
         $html .= html_writer::end_div();
         return $html;
@@ -546,9 +548,10 @@ class core_course_management_renderer extends plugin_renderer_base {
      * @param int $page The current page.
      * @param int $perpage The number of courses to display per page.
      * @param bool $showtotals Set to true to show the total number of courses and what is being displayed.
+     * @param string|null $viewmode The view mode the page is in, one out of 'default', 'combined', 'courses' or 'categories'.
      * @return string
      */
-    protected function listing_pagination(coursecat $category, $page, $perpage, $showtotals = false) {
+    protected function listing_pagination(coursecat $category, $page, $perpage, $showtotals = false, $viewmode = 'default') {
         $html = '';
         $totalcourses = $category->get_courses_count();
         $totalpages = ceil($totalcourses / $perpage);
@@ -582,7 +585,12 @@ class core_course_management_renderer extends plugin_renderer_base {
             }
         }
         $items = array();
-        $baseurl = new moodle_url('/course/management.php', array('categoryid' => $category->id));
+        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'));
index 8c4d6ff..b083e28 100644 (file)
@@ -495,7 +495,7 @@ if ($displaycategorylisting) {
 if ($displaycourselisting) {
     echo $renderer->grid_column_start($coursesize, 'course-listing');
     if (!$issearching) {
-        echo $renderer->course_listing($category, $course, $page, $perpage);
+        echo $renderer->course_listing($category, $course, $page, $perpage, $viewmode);
     } else {
         list($courses, $coursescount, $coursestotal) =
             \core_course\management\helper::search_courses($search, $blocklist, $modulelist, $page, $perpage);
index 0f00dbe..9f0d404 100644 (file)
@@ -416,9 +416,11 @@ class renderer extends \core_course_management_renderer {
      * @param course_in_list $course The currently selected course.
      * @param int $page The page being displayed.
      * @param int $perpage The number of courses to display per page.
+     * @param string|null $viewmode The view mode the page is in, one out of 'default', 'combined', 'courses' or 'categories'.
      * @return string
      */
-    public function course_listing(coursecat $category = null, course_in_list $course = null, $page = 0, $perpage = 20) {
+    public function course_listing(coursecat $category = null, course_in_list $course = null,
+            $page = 0, $perpage = 20, $viewmode = 'default') {
 
         if ($category === null) {
             $html = html_writer::start_div('select-a-category');
@@ -460,13 +462,13 @@ class renderer extends \core_course_management_renderer {
             array('id' => 'course-listing-title', 'tabindex' => '0', 'class' => 'card-header'));
         $html .= html_writer::start_div('card-body');
         $html .= $this->course_listing_actions($category, $course, $perpage);
-        $html .= $this->listing_pagination($category, $page, $perpage);
+        $html .= $this->listing_pagination($category, $page, $perpage, false, $viewmode);
         $html .= html_writer::start_tag('ul', array('class' => 'ml course-list', 'role' => 'group'));
         foreach ($category->get_courses($options) as $listitem) {
             $html .= $this->course_listitem($category, $listitem, $courseid);
         }
         $html .= html_writer::end_tag('ul');
-        $html .= $this->listing_pagination($category, $page, $perpage, true);
+        $html .= $this->listing_pagination($category, $page, $perpage, true, $viewmode);
         $html .= $this->course_bulk_actions($category);
         $html .= html_writer::end_div();
         $html .= html_writer::end_div();