Skip to content

Commit

Permalink
Merge branch 'MDL-10965-master' of git://github.com/marinaglancy/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
David Monllaó committed Apr 10, 2019
2 parents e9cbc45 + 76f2d89 commit 11bfc07
Show file tree
Hide file tree
Showing 46 changed files with 670 additions and 418 deletions.
4 changes: 0 additions & 4 deletions admin/tool/dataprivacy/classes/output/data_registry_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,6 @@ public static function get_courses_branch(\context $catcontext) {

$coursecontext = \context_course::instance($course->id);

if (!$course->visible && !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
continue;
}

$coursenode = [
'text' => shorten_text(format_string($course->shortname, true, ['context' => $coursecontext])),
'contextid' => $coursecontext->id,
Expand Down
3 changes: 1 addition & 2 deletions admin/tool/generator/classes/make_testplan_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public function definition() {
tool_generator_testplan_backend::get_size_choices());
$mform->setDefault('size', tool_generator_testplan_backend::DEFAULT_SIZE);

$mform->addElement('select', 'courseid', get_string('targetcourse', 'tool_generator'),
tool_generator_testplan_backend::get_course_options());
$mform->addElement('course', 'courseid', get_string('targetcourse', 'tool_generator'));

$mform->addElement('advcheckbox', 'updateuserspassword', get_string('updateuserspassword', 'tool_generator'));
$mform->addHelpButton('updateuserspassword', 'updateuserspassword', 'tool_generator');
Expand Down
19 changes: 0 additions & 19 deletions admin/tool/generator/classes/testplan_backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,6 @@ public static function get_size_choices() {
return $options;
}

/**
* Gets the list of courses that can be used used to generate a test.
*
* @return array The list of options as courseid => name
*/
public static function get_course_options() {
$courses = get_courses('all', 'c.sortorder ASC', 'c.id, c.shortname, c.fullname');
if (!$courses) {
print_error('error_nocourses', 'tool_generator');
}

$options = array();
unset($courses[1]);
foreach ($courses as $course) {
$options[$course->id] = $course->fullname . '(' . $course->shortname . ')';
}
return $options;
}

/**
* Getter for moodle-performance-comparison project URL.
*
Expand Down
6 changes: 6 additions & 0 deletions admin/tool/generator/upgrade.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This files describes API changes in core libraries and APIs,
information provided here is intended especially for developers.

=== 3.7 ===

* Function tool_generator_testplan_backend::get_course_options() is removed, the 'course' form element is used instead.
21 changes: 5 additions & 16 deletions badges/criteria/award_criteria_courseset.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,10 @@ public function get_courses(&$mform) {
require_once($CFG->dirroot . '/course/lib.php');
$buttonarray = array();

// Get courses with enabled completion.
$courses = $DB->get_records('course', array('enablecompletion' => COMPLETION_ENABLED));
if (!empty($courses)) {
$list = core_course_category::make_categories_list();

$select = array();
$selected = array();
foreach ($courses as $c) {
$select[$c->id] = $list[$c->category] . ' / ' . format_string($c->fullname, true, array('context' => context_course::instance($c->id)));
}

if ($this->id !== 0) {
$selected = array_keys($this->params);
}
$settings = array('multiple' => 'multiple', 'size' => 20, 'style' => 'width:300px');
$mform->addElement('select', 'courses', get_string('addcourse', 'badges'), $select, $settings);
$hasselectablecourses = core_course_category::search_courses(['onlywithcompletion' => true], ['limit' => 1]);
if ($hasselectablecourses) {
$settings = array('multiple' => 'multiple', 'onlywithcompletion' => 1);
$mform->addElement('course', 'courses', get_string('addcourse', 'badges'), $settings);
$mform->addRule('courses', get_string('requiredcourse', 'badges'), 'required');
$mform->addHelpButton('courses', 'addcourse', 'badges');

Expand All @@ -104,6 +92,7 @@ public function get_courses(&$mform) {
$mform->addElement('hidden', 'addcourse', 'addcourse');
$mform->setType('addcourse', PARAM_TEXT);
if ($this->id !== 0) {
$selected = array_keys($this->params);
$mform->setDefault('courses', $selected);
}
$mform->setType('agg', PARAM_INT);
Expand Down
22 changes: 14 additions & 8 deletions blocks/course_list/block_course_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ function get_content() {
}
}

$allcourselink =
(has_capability('moodle/course:update', context_system::instance())
|| empty($CFG->block_course_list_hideallcourseslink)) &&
core_course_category::user_top();

if (empty($CFG->disablemycourses) and isloggedin() and !isguestuser() and
!(has_capability('moodle/course:update', context_system::instance()) and $adminseesall)) { // Just print My Courses
if ($courses = enrol_get_my_courses()) {
Expand All @@ -65,7 +70,7 @@ function get_content() {
}
$this->title = get_string('mycourses');
/// If we can update any course of the view all isn't hidden, show the view all courses link
if (has_capability('moodle/course:update', context_system::instance()) || empty($CFG->block_course_list_hideallcourseslink)) {
if ($allcourselink) {
$this->content->footer = "<a href=\"$CFG->wwwroot/course/index.php\">".get_string("fulllistofcourses")."</a> ...";
}
}
Expand All @@ -75,35 +80,36 @@ function get_content() {
}
}

$categories = core_course_category::get(0)->get_children(); // Parent = 0 ie top-level categories only
if ($categories) { //Check we have categories
// User is not enrolled in any courses, show list of available categories or courses (if there is only one category).
$topcategory = core_course_category::top();
if ($topcategory->is_uservisible() && ($categories = $topcategory->get_children())) { // Check we have categories.
if (count($categories) > 1 || (count($categories) == 1 && $DB->count_records('course') > 200)) { // Just print top level category links
foreach ($categories as $category) {
$categoryname = $category->get_formatted_name();
$linkcss = $category->visible ? "" : " class=\"dimmed\" ";
$this->content->items[]="<a $linkcss href=\"$CFG->wwwroot/course/index.php?categoryid=$category->id\">".$icon . $categoryname . "</a>";
}
/// If we can update any course of the view all isn't hidden, show the view all courses link
if (has_capability('moodle/course:update', context_system::instance()) || empty($CFG->block_course_list_hideallcourseslink)) {
if ($allcourselink) {
$this->content->footer .= "<a href=\"$CFG->wwwroot/course/index.php\">".get_string('fulllistofcourses').'</a> ...';
}
$this->title = get_string('categories');
} else { // Just print course names of single category
$category = array_shift($categories);
$courses = get_courses($category->id);
$courses = $category->get_courses();

if ($courses) {
foreach ($courses as $course) {
$coursecontext = context_course::instance($course->id);
$linkcss = $course->visible ? "" : " class=\"dimmed\" ";

$this->content->items[]="<a $linkcss title=\""
. format_string($course->shortname, true, array('context' => $coursecontext))."\" ".
. s($course->get_formatted_shortname())."\" ".
"href=\"$CFG->wwwroot/course/view.php?id=$course->id\">"
.$icon. format_string(get_course_display_name_for_list($course), true, array('context' => context_course::instance($course->id))) . "</a>";
.$icon. $course->get_formatted_name() . "</a>";
}
/// If we can update any course of the view all isn't hidden, show the view all courses link
if (has_capability('moodle/course:update', context_system::instance()) || empty($CFG->block_course_list_hideallcourseslink)) {
if ($allcourselink) {
$this->content->footer .= "<a href=\"$CFG->wwwroot/course/index.php\">".get_string('fulllistofcourses').'</a> ...';
}
$this->get_remote_courses();
Expand Down
5 changes: 2 additions & 3 deletions blocks/html/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ function block_html_pluginfile($course, $birecord_or_cm, $context, $filearea, $a
$parentcontext = $context->get_parent_context();
if ($parentcontext->contextlevel === CONTEXT_COURSECAT) {
// Check if category is visible and user can view this category.
$category = $DB->get_record('course_categories', array('id' => $parentcontext->instanceid), '*', MUST_EXIST);
if (!$category->visible) {
require_capability('moodle/category:viewhiddencategories', $parentcontext);
if (!core_course_category::get($parentcontext->instanceid, IGNORE_MISSING)) {
send_file_not_found();
}
} else if ($parentcontext->contextlevel === CONTEXT_USER && $parentcontext->instanceid != $USER->id) {
// The block is in the context of a user, it is only visible to the user who it belongs to.
Expand Down
5 changes: 4 additions & 1 deletion calendar/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2352,8 +2352,11 @@ function calendar_get_default_courses($courseid = null, $fields = '*', $canmanag
$fieldlist = explode(',', $fields);

$prefixedfields = array_map(function($value) {
return 'c.' . trim($value);
return 'c.' . trim(strtolower($value));
}, $fieldlist);
if (!in_array('c.visible', $prefixedfields) && !in_array('c.*', $prefixedfields)) {
$prefixedfields[] = 'c.visible';
}
$courses = get_courses('all', 'c.shortname', implode(',', $prefixedfields));
} else {
$courses = enrol_get_users_courses($userid, true, $fields);
Expand Down
1 change: 1 addition & 0 deletions calendar/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
if ($courseid != SITEID && !empty($courseid)) {
navigation_node::override_active_url(new moodle_url('/course/view.php', array('id' => $course->id)));
} else if (!empty($categoryid)) {
core_course_category::get($categoryid); // Check that category exists and can be accessed.
$PAGE->set_category_by_id($categoryid);
navigation_node::override_active_url(new moodle_url('/course/index.php', array('categoryid' => $categoryid)));
} else {
Expand Down

0 comments on commit 11bfc07

Please sign in to comment.