Skip to content

Commit 3b7bfbb

Browse files
author
Frederic Massart
committed
MDL-4655 course: Number of courses with summaries to display is configurable
1 parent ecfe814 commit 3b7bfbb

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

admin/settings/appearance.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@
178178
$temp->add(new admin_setting_configcheckbox('courselistshortnames',
179179
new lang_string('courselistshortnames', 'admin'),
180180
new lang_string('courselistshortnames_desc', 'admin'), 0));
181+
$temp->add(new admin_setting_configtext('coursesperpage', new lang_string('coursesperpage', 'admin'), new lang_string('configcoursesperpage', 'admin'), 20, PARAM_INT));
182+
$temp->add(new admin_setting_configtext('courseswithsummarieslimit', new lang_string('courseswithsummarieslimit', 'admin'), new lang_string('configcourseswithsummarieslimit', 'admin'), 10, PARAM_INT));
181183
$ADMIN->add('appearance', $temp);
182184

183185
$temp = new admin_settingpage('ajax', new lang_string('ajaxuse'));

admin/settings/frontpage.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@
4949
'10' => '10')));
5050
$temp->add(new admin_setting_configtext('commentsperpage', new lang_string('commentsperpage', 'admin'), '', 15, PARAM_INT));
5151

52-
$temp->add(new admin_setting_configtext('coursesperpage', new lang_string('coursesperpage', 'admin'), new lang_string('configcoursesperpage', 'admin'), 20, PARAM_INT));
53-
5452
// front page default role
5553
$options = array(0=>new lang_string('none')); // roles to choose from
5654
$defaultfrontpageroleid = 0;

course/category.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,23 +284,28 @@
284284
echo html_writer::table($table);
285285
}
286286

287-
// Print out all the courses
287+
// Print out all the courses.
288288
$courses = get_courses_page($category->id, 'c.sortorder ASC',
289289
'c.id,c.sortorder,c.shortname,c.fullname,c.summary,c.visible',
290290
$totalcount, $page*$perpage, $perpage);
291291
$numcourses = count($courses);
292292

293+
// We can consider that we are using pagination when the total count of courses is different than the one returned.
294+
$pagingmode = $totalcount != $numcourses;
295+
293296
if (!$courses) {
297+
// There is no course to display.
294298
if (empty($subcategorieswereshown)) {
295299
echo $OUTPUT->heading(get_string("nocoursesyet"));
296300
}
297-
298-
} else if ($numcourses <= COURSE_MAX_SUMMARIES_PER_PAGE and !$page and !$editingon) {
301+
} else if ($numcourses <= $CFG->courseswithsummarieslimit and !$pagingmode and !$editingon) {
302+
// We display courses with their summaries as we have not reached the limit, also we are not
303+
// in paging mode and not allowed to edit either.
299304
echo $OUTPUT->box_start('courseboxes');
300305
print_courses($category);
301306
echo $OUTPUT->box_end();
302-
303307
} else {
308+
// The conditions above have failed, we display a basic list of courses with paging/editing options.
304309
echo $OUTPUT->paging_bar($totalcount, $page, $perpage, "/course/category.php?id=$category->id&perpage=$perpage");
305310

306311
echo '<form id="movecourses" action="category.php" method="post"><div>';

course/lib.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@
3333

3434
define('COURSE_MAX_LOGS_PER_PAGE', 1000); // records
3535
define('COURSE_MAX_RECENT_PERIOD', 172800); // Two days, in seconds
36-
define('COURSE_MAX_SUMMARIES_PER_PAGE', 10); // courses
36+
37+
/**
38+
* Number of courses to display when summaries are included.
39+
* @var int
40+
* @deprecated since 2.4, use $CFG->courseswithsummarieslimit instead.
41+
*/
42+
define('COURSE_MAX_SUMMARIES_PER_PAGE', 10);
43+
3744
define('COURSE_MAX_COURSES_PER_DROPDOWN',1000); // max courses in log dropdown before switching to optional
3845
define('COURSE_MAX_USERS_PER_DROPDOWN',1000); // max users in log dropdown before switching to optional
3946
define('FRONTPAGENEWS', '0');

lang/en/admin.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@
151151
$string['configcountry'] = 'If you set a country here, then this country will be selected by default on new user accounts. To force users to choose a country, just leave this unset.';
152152
$string['configcourserequestnotify'] = 'Type username of user to be notified when new course requested.';
153153
$string['configcourserequestnotify2'] = 'Users who will be notified when a course is requested. Only users who can approve course requests are listed here.';
154-
$string['configcoursesperpage'] = 'Enter the number of courses to be display per page in a course listing.';
154+
$string['configcoursesperpage'] = 'Enter the number of courses to be displayed per page in a course listing.';
155+
$string['configcourseswithsummarieslimit'] = 'The maximum number of courses to display in a course listing including summaries before falling back to a simpler listing.';
155156
$string['configcronclionly'] = 'If this is set, then the cron script can only be run from the command line instead of via the web. This overrides the cron password setting below.';
156157
$string['configcronremotepassword'] = 'This means that the cron.php script cannot be run from a web browser without supplying the password using the following form of URL:<pre>
157158
http://site.example.com/admin/cron.php?password=opensesame
@@ -364,6 +365,7 @@
364365
$string['courserequestspending'] = 'Pending course requests';
365366
$string['courses'] = 'Courses';
366367
$string['coursesperpage'] = 'Courses per page';
368+
$string['courseswithsummarieslimit'] = 'Courses with summaries limit';
367369
$string['creatornewroleid'] = 'Creators\' role in new courses';
368370
$string['creatornewroleid_help'] = 'If the user does not already have the permission to manage the new course, the user is automatically enrolled using this role.';
369371
$string['cron'] = 'Cron';

0 commit comments

Comments
 (0)