Skip to content

Commit

Permalink
MDL-38592 Settings for courses lists on front page are made more user…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
marinaglancy committed Apr 16, 2013
1 parent b3661ab commit 0fd2635
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 59 deletions.
4 changes: 3 additions & 1 deletion admin/settings/frontpage.php
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions admin/settings/server.php
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions config-dist.php
Expand Up @@ -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.
Expand Down
9 changes: 6 additions & 3 deletions course/lib.php
Expand Up @@ -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);

Expand Down
29 changes: 24 additions & 5 deletions course/renderer.php
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down
48 changes: 14 additions & 34 deletions index.php
Expand Up @@ -205,47 +205,40 @@
}
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
echo html_writer::start_tag('div', array('id'=>'frontpage-course-list'));

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;

Expand All @@ -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');
Expand All @@ -272,28 +264,16 @@
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');

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;

}
Expand Down
6 changes: 3 additions & 3 deletions lang/en/admin.php
Expand Up @@ -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 <a href="http://www.maxmind.com/">MaxMind</a>. You can either buy a commercial version or use the free version.<br />Simply download <a href="http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz" >http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz</a> and extract it into "{$a}" directory on your server.';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -767,8 +769,6 @@
$string['notloggedinroleid'] = 'Role for visitors';
$string['numberofmissingstrings'] = 'Number of missing strings: {$a}';
$string['numberofstrings'] = 'Total number of strings: {$a->strings}<br />Missing: {$a->missing} ({$a->missingpercent}&nbsp;%)';
$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';
Expand Down
3 changes: 2 additions & 1 deletion lang/en/moodle.php
Expand Up @@ -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';
Expand Down
11 changes: 6 additions & 5 deletions lib/adminlib.php
Expand Up @@ -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);
}

Expand All @@ -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;
}
Expand Down

0 comments on commit 0fd2635

Please sign in to comment.