mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 04:22:07 +02:00
MDL-37009 Display list of tagged courses using new renderer
This commit is contained in:
parent
6004700329
commit
9e76429dad
@ -1720,6 +1720,36 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders html to print list of courses tagged with particular tag
|
||||
*
|
||||
* @param int $tagid id of the tag
|
||||
* @return string empty string if no courses are marked with this tag or rendered list of courses
|
||||
*/
|
||||
public function tagged_courses($tagid) {
|
||||
global $CFG;
|
||||
$displayoptions = array('limit' => $CFG->coursesperpage);
|
||||
$displayoptions['viewmoreurl'] = new moodle_url('/course/search.php',
|
||||
array('tagid' => $tagid, 'page' => 1, 'perpage' => $CFG->coursesperpage));
|
||||
$displayoptions['viewmoretext'] = new lang_string('findmorecourses');
|
||||
$chelper = new coursecat_helper();
|
||||
$searchcriteria = array('tagid' => $tagid);
|
||||
$chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT)->
|
||||
set_search_criteria(array('tagid' => $tagid))->
|
||||
set_courses_display_options($displayoptions)->
|
||||
set_attributes(array('class' => 'course-search-result course-search-result-tagid'));
|
||||
// (we set the same css class as in search results by tagid)
|
||||
$courses = coursecat::search_courses($searchcriteria, $chelper->get_courses_display_options());
|
||||
$totalcount = coursecat::search_courses_count($searchcriteria);
|
||||
$content = $this->coursecat_courses($chelper, $courses, $totalcount);
|
||||
if ($totalcount) {
|
||||
require_once $CFG->dirroot.'/tag/lib.php';
|
||||
$heading = get_string('courses') . ' ' . get_string('taggedwith', 'tag', tag_get_name($tagid)) .': '. $totalcount;
|
||||
return $this->heading($heading, 3). $content;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,6 +31,7 @@ $page = optional_param('page', 0, PARAM_INT); // which page to show
|
||||
$perpage = optional_param('perpage', '', PARAM_RAW); // how many per page, may be integer or 'all'
|
||||
$blocklist = optional_param('blocklist', 0, PARAM_INT);
|
||||
$modulelist= optional_param('modulelist', '', PARAM_PLUGIN);
|
||||
$tagid = optional_param('tagid', '', PARAM_INT); // searches for courses tagged with this tag id
|
||||
|
||||
// List of minimum capabilities which user need to have for editing/moving course
|
||||
$capabilities = array('moodle/course:create', 'moodle/category:manage');
|
||||
@ -43,7 +44,7 @@ $search = trim(strip_tags($search)); // trim & clean raw searched string
|
||||
$site = get_site();
|
||||
|
||||
$searchcriteria = array();
|
||||
foreach (array('search', 'blocklist', 'modulelist') as $param) {
|
||||
foreach (array('search', 'blocklist', 'modulelist', 'tagid') as $param) {
|
||||
if (!empty($$param)) {
|
||||
$searchcriteria[$param] = $$param;
|
||||
}
|
||||
|
@ -76,6 +76,7 @@ $PAGE->navbar->add($tagname);
|
||||
$PAGE->set_title($title);
|
||||
$PAGE->set_heading($COURSE->fullname);
|
||||
$PAGE->set_button($button);
|
||||
$courserenderer = $PAGE->get_renderer('core', 'course');
|
||||
echo $OUTPUT->header();
|
||||
|
||||
// Manage all tags links
|
||||
@ -94,7 +95,7 @@ tag_print_management_box($tag);
|
||||
tag_print_description_box($tag);
|
||||
// Check what type of results are avaialable
|
||||
require_once($CFG->dirroot.'/tag/coursetagslib.php');
|
||||
$courses = coursetag_get_tagged_courses($tag->id);
|
||||
$courses = $courserenderer->tagged_courses($tag->id);
|
||||
|
||||
if (!empty($CFG->enableblogs) && has_capability('moodle/blog:view', $systemcontext)) {
|
||||
require_once($CFG->dirroot.'/blog/lib.php');
|
||||
@ -138,16 +139,10 @@ if ($countanchors == 0) {
|
||||
// Display courses tagged with the tag
|
||||
if (!empty($courses)) {
|
||||
|
||||
$totalcount = count( $courses );
|
||||
echo $OUTPUT->box_start('generalbox', 'tag-blogs'); //could use an id separate from tag-blogs, but would have to copy the css style to make it look the same
|
||||
|
||||
$heading = get_string('courses') . ' ' . get_string('taggedwith', 'tag', $tagname) .': '. $totalcount;
|
||||
echo "<a name='course'></a>";
|
||||
echo $OUTPUT->heading($heading, 3);
|
||||
|
||||
foreach ($courses as $course) {
|
||||
print_course($course);
|
||||
}
|
||||
echo $courses;
|
||||
|
||||
echo $OUTPUT->box_end();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user