Skip to content

Commit

Permalink
MDL-37009 Display list of tagged courses using new renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Apr 1, 2013
1 parent 6004700 commit 9e76429
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
30 changes: 30 additions & 0 deletions course/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion course/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
}
Expand Down
11 changes: 3 additions & 8 deletions tag/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 9e76429

Please sign in to comment.