From 0fd26350387b92a6f4ec1bdba55210f7aa7ac0e1 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Tue, 26 Mar 2013 13:04:42 +1100 Subject: [PATCH] MDL-38592 Settings for courses lists on front page are made more user friendly - 'List of courses' is split into 'List of courses' (available) and 'Enrolled courses', CFG->disablemycourses is deprecated; - CFG->frontpageloggedin by default shows list of available courses; - There is separate item to display course search box - CFG->maxcoursesincombo is deprecated - CFG->maxcategorydepth changed default value to 2 since we have AJAX loading now - FRONTPAGECOURSELIMIT is transformed to CFG->frontpagecourselimit c --- admin/settings/frontpage.php | 4 ++- admin/settings/server.php | 2 -- config-dist.php | 4 --- course/lib.php | 9 ++++-- course/renderer.php | 29 ++++++++++++++--- index.php | 48 ++++++++------------------- lang/en/admin.php | 6 ++-- lang/en/moodle.php | 3 +- lib/adminlib.php | 11 ++++--- lib/db/upgrade.php | 63 ++++++++++++++++++++++++++++++++++++ version.php | 2 +- 11 files changed, 122 insertions(+), 59 deletions(-) diff --git a/admin/settings/frontpage.php b/admin/settings/frontpage.php index f4ecb5bbcfbf4..e52f6ffd6ea2c 100644 --- a/admin/settings/frontpage.php +++ b/admin/settings/frontpage.php @@ -32,7 +32,9 @@ for ($i=1; $i<100; $i++) { $options[$i] = $i; } - $temp->add(new admin_setting_configselect('maxcategorydepth', new lang_string('configsitemaxcategorydepth','admin'), new lang_string('configsitemaxcategorydepthhelp','admin'), 0, $options)); + $temp->add(new admin_setting_configselect('maxcategorydepth', new lang_string('configsitemaxcategorydepth','admin'), new lang_string('configsitemaxcategorydepthhelp','admin'), 2, $options)); + + $temp->add(new admin_setting_configtext('frontpagecourselimit', new lang_string('configfrontpagecourselimit','admin'), new lang_string('configfrontpagecourselimithelp','admin'), 200, PARAM_INT)); $temp->add(new admin_setting_sitesetcheckbox('numsections', new lang_string('sitesection'), new lang_string('sitesectionhelp','admin'), 1)); $temp->add(new admin_setting_sitesetselect('newsitems', new lang_string('newsitemsnumber'), '', 3, diff --git a/admin/settings/server.php b/admin/settings/server.php index 4a12d2a93ed2f..154b98f84b1f3 100644 --- a/admin/settings/server.php +++ b/admin/settings/server.php @@ -175,8 +175,6 @@ // "performance" settingpage $temp = new admin_settingpage('performance', new lang_string('performance', 'admin')); -$temp->add(new admin_setting_configtext('numcoursesincombo', new lang_string('numcoursesincombo', 'admin'), new lang_string('numcoursesincombo_help', 'admin'), 500)); - $temp->add(new admin_setting_configselect('extramemorylimit', new lang_string('extramemorylimit', 'admin'), new lang_string('configextramemorylimit', 'admin'), '512M', // if this option is set to 0, default 128M will be used diff --git a/config-dist.php b/config-dist.php index 7653437eb6a33..0dd7032419157 100644 --- a/config-dist.php +++ b/config-dist.php @@ -221,10 +221,6 @@ // RewriteRule (^.*/theme/yui_combo\.php)(/.*) $1?file=$2 // // -// This setting will prevent the 'My Courses' page being displayed when a student -// logs in. The site front page will always show the same (logged-out) view. -// $CFG->disablemycourses = true; -// // By default all user sessions should be using locking, uncomment // the following setting to prevent locking for guests and not-logged-in // accounts. This may improve performance significantly. diff --git a/course/lib.php b/course/lib.php index a94e38ebca805..526e1843347e5 100644 --- a/course/lib.php +++ b/course/lib.php @@ -44,11 +44,14 @@ define('COURSE_MAX_COURSES_PER_DROPDOWN',1000); // max courses in log dropdown before switching to optional define('COURSE_MAX_USERS_PER_DROPDOWN',1000); // max users in log dropdown before switching to optional define('FRONTPAGENEWS', '0'); -define('FRONTPAGECOURSELIST', '1'); +define('FRONTPAGECOURSELIST', '1'); // Not used. TODO MDL-38832 remove define('FRONTPAGECATEGORYNAMES', '2'); -define('FRONTPAGETOPICONLY', '3'); +define('FRONTPAGETOPICONLY', '3'); // Not used. TODO MDL-38832 remove define('FRONTPAGECATEGORYCOMBO', '4'); -define('FRONTPAGECOURSELIMIT', 200); // maximum number of courses displayed on the frontpage +define('FRONTPAGEENROLLEDCOURSELIST', '5'); +define('FRONTPAGEALLCOURSELIST', '6'); +define('FRONTPAGECOURSESEARCH', '7'); +define('FRONTPAGECOURSELIMIT', 200); // Important! Replaced with $CFG->frontpagecourselimit - maximum number of courses displayed on the frontpage. TODO MDL-38832 remove define('EXCELROWS', 65535); define('FIRSTUSEDEXCELROW', 3); diff --git a/course/renderer.php b/course/renderer.php index 7290aca64a73b..896facb5b4060 100644 --- a/course/renderer.php +++ b/course/renderer.php @@ -1789,13 +1789,24 @@ public function frontpage_my_courses() { if (!empty($courses) || !empty($rcourses) || !empty($rhosts)) { $chelper = new coursecat_helper(); - $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED)-> - set_courses_display_options(array( + if (count($courses) > $CFG->frontpagecourselimit) { + // There are more enrolled courses than we can display, display link to 'My courses'. + $totalcount = count($courses); + $courses = array_slice($courses, 0, $CFG->frontpagecourselimit, true); + $chelper->set_courses_display_options(array( + 'viewmoreurl' => new moodle_url('/my/'), + 'viewmoretext' => new lang_string('mycourses') + )); + } else { + // All enrolled courses are displayed, display link to 'All courses' if there are more courses in system. + $chelper->set_courses_display_options(array( 'viewmoreurl' => new moodle_url('/course/index.php'), 'viewmoretext' => new lang_string('fulllistofcourses') - ))-> + )); + $totalcount = $DB->count_records('course') - 1; + } + $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED)-> set_attributes(array('class' => 'frontpage-course-list-enrolled')); - $totalcount = $DB->count_records('course') - 1; $output .= $this->coursecat_courses($chelper, $courses, $totalcount); // MNET @@ -1831,13 +1842,21 @@ public function frontpage_available_courses() { $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED)-> set_courses_display_options(array( 'recursive' => true, - 'limit' => FRONTPAGECOURSELIMIT, + 'limit' => $CFG->frontpagecourselimit, 'viewmoreurl' => new moodle_url('/course/index.php'), 'viewmoretext' => new lang_string('fulllistofcourses'))); $chelper->set_attributes(array('class' => 'frontpage-course-list-all')); $courses = coursecat::get(0)->get_courses($chelper->get_courses_display_options()); $totalcount = coursecat::get(0)->get_courses_count($chelper->get_courses_display_options()); + if (!$totalcount && has_capability('moodle/course:create', context_system::instance())) { + // Print link to create a new course, for the 1st available category. + $output = $this->container_start('buttons'); + $url = new moodle_url('/course/edit.php', array('category' => $CFG->defaultrequestcategory, 'returnto' => 'topcat')); + $output .= $this->single_button($url, get_string('addnewcourse'), 'get'); + $output .= $this->container_end('buttons'); + return $output; + } return $this->coursecat_courses($chelper, $courses, $totalcount); } diff --git a/index.php b/index.php index 8ad377bf613c7..b216a6975a6dd 100644 --- a/index.php +++ b/index.php @@ -205,17 +205,9 @@ } break; - case FRONTPAGECOURSELIST: - $ncourses = $DB->count_records('course'); - if (isloggedin() and !$hassiteconfig and !isguestuser() and empty($CFG->disablemycourses)) { - $mycourseshtml = $courserenderer->frontpage_my_courses(); - if (empty($mycourseshtml)) { - if ($DB->count_records("course_categories") > 1) { - $mycourseshtml = $courserenderer->frontpage_categories_list(); - } else { - $mycourseshtml = $courserenderer->frontpage_available_courses(); - } - } + case FRONTPAGEENROLLEDCOURSELIST: + $mycourseshtml = $courserenderer->frontpage_my_courses(); + if (!empty($mycourseshtml)) { echo html_writer::tag('a', get_string('skipa', 'access', textlib::strtolower(get_string('mycourses'))), array('href'=>'#skipmycourses', 'class'=>'skip-block')); //wrap frontpage course list in div container @@ -223,29 +215,30 @@ echo $OUTPUT->heading(get_string('mycourses'), 2, 'headingblock header'); echo $mycourseshtml; - echo $OUTPUT->box($courserenderer->course_search_form('', 'short'), 'mdl-align'); //end frontpage course list div container echo html_writer::end_tag('div'); echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipmycourses')); - } else if ((!$hassiteconfig and !isguestuser()) or ($ncourses <= FRONTPAGECOURSELIMIT)) { - // admin should not see list of courses when there are too many of them + break; + } + // No "break" here. If there are no enrolled courses - continue to 'Available courses'. + + case FRONTPAGEALLCOURSELIST: + $availablecourseshtml = $courserenderer->frontpage_available_courses(); + if (!empty($availablecourseshtml)) { echo html_writer::tag('a', get_string('skipa', 'access', textlib::strtolower(get_string('availablecourses'))), array('href'=>'#skipavailablecourses', 'class'=>'skip-block')); //wrap frontpage course list in div container echo html_writer::start_tag('div', array('id'=>'frontpage-course-list')); echo $OUTPUT->heading(get_string('availablecourses'), 2, 'headingblock header'); - echo $courserenderer->frontpage_available_courses(); + echo $availablecourseshtml; //end frontpage course list div container echo html_writer::end_tag('div'); echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipavailablecourses')); - } else { - echo html_writer::tag('div', get_string('therearecourses', '', $ncourses), array('class' => 'notifyproblem')); - echo $OUTPUT->box($courserenderer->course_search_form('', 'short'), 'mdl-align'); } break; @@ -257,7 +250,6 @@ echo $OUTPUT->heading(get_string('categories'), 2, 'headingblock header'); echo $courserenderer->frontpage_categories_list(); - echo $OUTPUT->box($courserenderer->course_search_form('', 'short'), 'mdl-align'); //end frontpage category names div container echo html_writer::end_tag('div'); @@ -272,20 +264,7 @@ echo html_writer::start_tag('div', array('id'=>'frontpage-category-combo')); echo $OUTPUT->heading(get_string('courses'), 2, 'headingblock header'); - // if there are too many courses, building course category tree could be slow, - // users should go to course index page to see the whole list. - $coursecount = $DB->count_records('course'); - if (empty($CFG->numcoursesincombo)) { - // if $CFG->numcoursesincombo hasn't been set, use default value 500 - $CFG->numcoursesincombo = 500; - } - if ($coursecount > $CFG->numcoursesincombo) { - $link = new moodle_url('/course/'); - echo $OUTPUT->notification(get_string('maxnumcoursesincombo', 'moodle', array('link'=>$link->out(), 'maxnumofcourses'=>$CFG->numcoursesincombo, 'numberofcourses'=>$coursecount))); - } else { - echo $courserenderer->frontpage_combo_list(); - } - echo $OUTPUT->box($courserenderer->course_search_form('', 'short'), 'mdl-align'); + echo $courserenderer->frontpage_combo_list(); //end frontpage category combo div container echo html_writer::end_tag('div'); @@ -293,7 +272,8 @@ echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipcourses')); break; - case FRONTPAGETOPICONLY: // Do nothing!! :-) + case FRONTPAGECOURSESEARCH: + echo $OUTPUT->box($courserenderer->course_search_form('', 'short'), 'mdl-align'); break; } diff --git a/lang/en/admin.php b/lang/en/admin.php index c71e297213093..96a8a08b64747 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -224,6 +224,8 @@ $string['configforcelogin'] = 'Normally, the front page of the site and the course listings (but not courses) can be read by people without logging in to the site. If you want to force people to log in before they do ANYTHING on the site, then you should enable this setting.'; $string['configforceloginforprofiles'] = 'This setting forces people to login as a real (non-guest) account before viewing any user\'s profile. If you disabled this setting, you may find that some users post advertising (spam) or other inappropriate content in their profiles, which is then visible to the whole world.'; $string['configfrontpage'] = 'The items selected above will be displayed on the site\'s front page.'; +$string['configfrontpagecourselimit'] = 'Maximum number of courses'; +$string['configfrontpagecourselimithelp'] = 'Maximum number of courses to be displayed on the site\'s front page in course listings.'; $string['configfrontpageloggedin'] = 'The items selected above will be displayed on the site\'s front page when a user is logged in.'; $string['configfullnamedisplay'] = 'This defines how names are shown when they are displayed in full. For most mono-lingual sites the most efficient setting is "First name + Surname", but you may choose to hide surnames altogether, or to leave it up to the current language pack to decide (some languages have different conventions).'; $string['configgeoipfile'] = 'Location of GeoIP City binary data file. This file is not part of Moodle distribution and must be obtained separately from MaxMind. You can either buy a commercial version or use the free version.
Simply download http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz and extract it into "{$a}" directory on your server.'; @@ -318,7 +320,7 @@ $string['configsitedefaultlicense'] = 'Default site licence'; $string['configsitedefaultlicensehelp'] = 'The default licence for publishing content on this site'; $string['configsitemaxcategorydepth'] = 'Maximum category depth'; -$string['configsitemaxcategorydepthhelp'] = 'This specifies the maximum depth of child categories shown'; +$string['configsitemaxcategorydepthhelp'] = 'This specifies the maximum depth of child categories expanded when displaying categories or combo list. Deeper level categories will appear as links and user can expand them with AJAX request.'; $string['configslasharguments'] = 'Files (images, uploads etc) are provided via a script using \'slash arguments\'. This method allows files to be more easily cached in web browsers, proxy servers etc. Unfortunately, some PHP servers don\'t allow this method, so if you have trouble viewing uploaded files or images (eg user pictures), disable this setting.'; $string['configsmartpix'] = 'With this on, icons are served through a PHP script that searches the current theme, then all parent themes, then the Moodle /pix folder. This reduces the need to duplicate image files within themes, but has a slight performance cost.'; $string['configstartwday'] = 'Start of week'; @@ -767,8 +769,6 @@ $string['notloggedinroleid'] = 'Role for visitors'; $string['numberofmissingstrings'] = 'Number of missing strings: {$a}'; $string['numberofstrings'] = 'Total number of strings: {$a->strings}
Missing: {$a->missing} ({$a->missingpercent} %)'; -$string['numcoursesincombo'] = 'Maximum number of courses in combo list'; -$string['numcoursesincombo_help'] = 'The combo list doesn\'t work well with large numbers of courses. When the total number of courses in the site is higher than this setting then a link to the dedicated course listing will be shown instead of trying to display all the courses on the front page.'; $string['opensslrecommended'] = 'Installing the optional OpenSSL library is highly recommended -- it enables Moodle Networking functionality.'; $string['opentogoogle'] = 'Open to Google'; $string['optionalmaintenancemessage'] = 'Optional maintenance message'; diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 262140e88b0e7..7ad3e7fe98abb 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -721,13 +721,14 @@ $string['frontpagecategorycombo'] = 'Combo list'; $string['frontpagecategorynames'] = 'List of categories'; $string['frontpagecourselist'] = 'List of courses'; +$string['frontpagecoursesearch'] = 'Course search box'; +$string['frontpageenrolledcourselist'] = 'Enrolled courses'; $string['frontpagedescription'] = 'Front page summary'; $string['frontpagedescriptionhelp'] = 'This summary can be displayed on the front page using the course/site summary block or by including a topic section on the front page.'; $string['frontpageformat'] = 'Front page format'; $string['frontpageformatloggedin'] = 'Front page format when logged in'; $string['frontpagenews'] = 'News items'; $string['frontpagesettings'] = 'Front page settings'; -$string['frontpagetopiconly'] = 'Topic section'; $string['fulllistofcourses'] = 'All courses'; $string['fullname'] = 'Full name'; // @deprecated - use fullnamecourse or fullnameuser or some own context specific string $string['fullnamecourse'] = 'Course full name'; diff --git a/lib/adminlib.php b/lib/adminlib.php index 3156374c2dfbf..6a6facff344a0 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -3339,7 +3339,7 @@ public function __construct($loggedin) { $name = 'frontpage'.($loggedin ? 'loggedin' : ''); $visiblename = get_string('frontpage'.($loggedin ? 'loggedin' : ''),'admin'); $description = get_string('configfrontpage'.($loggedin ? 'loggedin' : ''),'admin'); - $defaults = array(FRONTPAGECOURSELIST); + $defaults = array(FRONTPAGEALLCOURSELIST); parent::__construct($name, $visiblename, $description, $defaults); } @@ -3349,17 +3349,18 @@ public function __construct($loggedin) { * @return bool always returns true */ public function load_choices() { - global $DB; if (is_array($this->choices)) { return true; } $this->choices = array(FRONTPAGENEWS => get_string('frontpagenews'), - FRONTPAGECOURSELIST => get_string('frontpagecourselist'), + FRONTPAGEALLCOURSELIST => get_string('frontpagecourselist'), + FRONTPAGEENROLLEDCOURSELIST => get_string('frontpageenrolledcourselist'), FRONTPAGECATEGORYNAMES => get_string('frontpagecategorynames'), FRONTPAGECATEGORYCOMBO => get_string('frontpagecategorycombo'), + FRONTPAGECOURSESEARCH => get_string('frontpagecoursesearch'), 'none' => get_string('none')); - if ($this->name == 'frontpage' and $DB->count_records('course') > FRONTPAGECOURSELIMIT) { - unset($this->choices[FRONTPAGECOURSELIST]); + if ($this->name === 'frontpage') { + unset($this->choices[FRONTPAGEENROLLEDCOURSELIST]); } return true; } diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index ff8f1dfcad500..2ae997d43e539 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -1990,5 +1990,68 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2013040300.01); } + if ($oldversion < 2013041600.00) { + // Copy constants from /course/lib.php instead of including the whole library: + $c = array( 'FRONTPAGENEWS' => 0, + 'FRONTPAGECOURSELIST' => 1, + 'FRONTPAGECATEGORYNAMES' => 2, + 'FRONTPAGETOPICONLY' => 3, + 'FRONTPAGECATEGORYCOMBO' => 4, + 'FRONTPAGEENROLLEDCOURSELIST' => 5, + 'FRONTPAGEALLCOURSELIST' => 6, + 'FRONTPAGECOURSESEARCH' => 7); + // Update frontpage settings $CFG->frontpage and $CFG->frontpageloggedin. In 2.4 there was too much of hidden logic about them. + // This script tries to make sure that with the new (more user-friendly) frontpage settings the frontpage looks as similar as possible to what it was before upgrade. + $ncourses = $DB->count_records('course'); + foreach (array('frontpage', 'frontpageloggedin') as $configkey) { + if ($frontpage = explode(',', $CFG->{$configkey})) { + $newfrontpage = array(); + foreach ($frontpage as $v) { + switch ($v) { + case $c['FRONTPAGENEWS']: + // Not related to course listings, leave as it is. + $newfrontpage[] = $c['FRONTPAGENEWS']; + break; + case $c['FRONTPAGECOURSELIST']: + if ($configkey === 'frontpageloggedin' && empty($CFG->disablemycourses)) { + // In 2.4 unless prohibited in config, the "list of courses" was considered "list of enrolled courses" plus course search box. + $newfrontpage[] = $c['FRONTPAGEENROLLEDCOURSELIST']; + } else if ($ncourses <= 200) { + // Still list of courses was only displayed in there were less than 200 courses in system. Otherwise - search box only. + $newfrontpage[] = $c['FRONTPAGEALLCOURSELIST']; + break; // skip adding search box + } + if (!in_array($c['FRONTPAGECOURSESEARCH'], $newfrontpage)) { + $newfrontpage[] = $c['FRONTPAGECOURSESEARCH']; + } + break; + case $c['FRONTPAGECATEGORYNAMES']: + // In 2.4 search box was displayed automatically after categories list. In 2.5 it is displayed as a separate setting. + $newfrontpage[] = $c['FRONTPAGECATEGORYNAMES']; + if (!in_array($c['FRONTPAGECOURSESEARCH'], $newfrontpage)) { + $newfrontpage[] = $c['FRONTPAGECOURSESEARCH']; + } + break; + case $c['FRONTPAGECATEGORYCOMBO']: + $maxcourses = empty($CFG->numcoursesincombo) ? 500 : $CFG->numcoursesincombo; + // In 2.4 combo list was not displayed if there are more than $CFG->numcoursesincombo courses in the system. + if ($ncourses < $maxcourses) { + $newfrontpage[] = $c['FRONTPAGECATEGORYCOMBO']; + } + if (!in_array($c['FRONTPAGECOURSESEARCH'], $newfrontpage)) { + $newfrontpage[] = $c['FRONTPAGECOURSESEARCH']; + } + break; + } + } + set_config($configkey, join(',', $newfrontpage)); + } + } + // $CFG->numcoursesincombo no longer affects whether the combo list is displayed. Setting is deprecated. + unset_config('numcoursesincombo'); + + upgrade_main_savepoint(true, 2013041600.00); + } + return true; } diff --git a/version.php b/version.php index a4c2bd068944c..96baaff629ee0 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2013041100.00; // YYYYMMDD = weekly release date of this DEV branch +$version = 2013041600.00; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes