mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 00:42:54 +02:00
MDL-42261 My Home: Added link to show all courses on my home page
If not forced by admin, user can see all courses by clicking on link
This commit is contained in:
parent
4e47920f08
commit
6fb0760827
@ -30,6 +30,11 @@ require_once($CFG->dirroot.'/blocks/course_overview/locallib.php');
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class block_course_overview extends block_base {
|
||||
/**
|
||||
* If this is passed as mynumber then showallcourses, irrespective of limit by user.
|
||||
*/
|
||||
const SHOW_ALL_COURSES = -2;
|
||||
|
||||
/**
|
||||
* Block initialization
|
||||
*/
|
||||
@ -64,7 +69,9 @@ class block_course_overview extends block_base {
|
||||
}
|
||||
|
||||
profile_load_custom_fields($USER);
|
||||
list($sortedcourses, $sitecourses, $totalcourses) = block_course_overview_get_sorted_courses();
|
||||
|
||||
$showallcourses = ($updatemynumber === self::SHOW_ALL_COURSES);
|
||||
list($sortedcourses, $sitecourses, $totalcourses) = block_course_overview_get_sorted_courses($showallcourses);
|
||||
$overviews = block_course_overview_get_overviews($sitecourses);
|
||||
|
||||
$renderer = $this->page->get_renderer('block_course_overview');
|
||||
|
@ -36,6 +36,8 @@ $string['forcedefaultmaxcourses'] = 'Force maximum courses';
|
||||
$string['forcedefaultmaxcoursesdesc'] = 'If set then user will not be able to change his/her personal setting';
|
||||
$string['hiddencoursecount'] = 'You have {$a} hidden course';
|
||||
$string['hiddencoursecountplural'] = 'You have {$a} hidden courses';
|
||||
$string['hiddencoursecountwithshowall'] = 'You have {$a->coursecount} hidden course ({$a->showalllink})';
|
||||
$string['hiddencoursecountwithshowallplural'] = 'You have {$a->coursecount} hidden courses ({$a->showalllink})';
|
||||
$string['message'] = 'message';
|
||||
$string['messages'] = 'messages';
|
||||
$string['movecourse'] = 'Move course: {$a}';
|
||||
|
@ -110,16 +110,21 @@ function block_course_overview_get_child_shortnames($courseid) {
|
||||
/**
|
||||
* Returns maximum number of courses which will be displayed in course_overview block
|
||||
*
|
||||
* @param bool $showallcourses if set true all courses will be visible.
|
||||
* @return int maximum number of courses
|
||||
*/
|
||||
function block_course_overview_get_max_user_courses() {
|
||||
function block_course_overview_get_max_user_courses($showallcourses = false) {
|
||||
// Get block configuration
|
||||
$config = get_config('block_course_overview');
|
||||
$limit = $config->defaultmaxcourses;
|
||||
|
||||
// If max course is not set then try get user preference
|
||||
if (empty($config->forcedefaultmaxcourses)) {
|
||||
$limit = get_user_preferences('course_overview_number_of_courses', $limit);
|
||||
if ($showallcourses) {
|
||||
$limit = 0;
|
||||
} else {
|
||||
$limit = get_user_preferences('course_overview_number_of_courses', $limit);
|
||||
}
|
||||
}
|
||||
return $limit;
|
||||
}
|
||||
@ -127,12 +132,13 @@ function block_course_overview_get_max_user_courses() {
|
||||
/**
|
||||
* Return sorted list of user courses
|
||||
*
|
||||
* @param bool $showallcourses if set true all courses will be visible.
|
||||
* @return array list of sorted courses and count of courses.
|
||||
*/
|
||||
function block_course_overview_get_sorted_courses() {
|
||||
function block_course_overview_get_sorted_courses($showallcourses = false) {
|
||||
global $USER;
|
||||
|
||||
$limit = block_course_overview_get_max_user_courses();
|
||||
$limit = block_course_overview_get_max_user_courses($showallcourses);
|
||||
|
||||
$courses = enrol_get_my_courses();
|
||||
$site = get_site();
|
||||
|
@ -215,7 +215,18 @@ class block_course_overview_renderer extends plugin_renderer_base {
|
||||
}
|
||||
$output = $this->output->box_start('notice');
|
||||
$plural = $total > 1 ? 'plural' : '';
|
||||
$output .= get_string('hiddencoursecount'.$plural, 'block_course_overview', $total);
|
||||
$config = get_config('block_course_overview');
|
||||
// Show view all course link to user if forcedefaultmaxcourses is not empty.
|
||||
if (!empty($config->forcedefaultmaxcourses)) {
|
||||
$output .= get_string('hiddencoursecountwithshowall'.$plural, 'block_course_overview', $total);
|
||||
} else {
|
||||
$a = new stdClass();
|
||||
$a->coursecount = $total;
|
||||
$a->showalllink = html_writer::link(new moodle_url('/my/index.php', array('mynumber' => block_course_overview::SHOW_ALL_COURSES)),
|
||||
get_string('showallcourses'));
|
||||
$output .= get_string('hiddencoursecount'.$withshowall.$plural, 'block_course_overview', $a);
|
||||
}
|
||||
|
||||
$output .= $this->output->box_end();
|
||||
return $output;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user