Permalink
Browse files

MDL-37009 Display list of tagged courses using new renderer

  • Loading branch information...
1 parent 6004700 commit 9e76429dadf67d2128a3071aec2439d4d6080d8c @marinaglancy marinaglancy committed Mar 19, 2013
Showing with 35 additions and 9 deletions.
  1. +30 −0 course/renderer.php
  2. +2 −1 course/search.php
  3. +3 −8 tag/index.php
View
@@ -1720,6 +1720,36 @@ public function search_courses($searchcriteria) {
}
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 '';
+ }
}
/**
View
@@ -31,6 +31,7 @@
$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 @@
$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;
}
View
@@ -76,6 +76,7 @@
$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_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 @@
// 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();
}

0 comments on commit 9e76429

Please sign in to comment.