Moodle

course tags

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Not a bug
  • Affects Version/s: 1.9
  • Fix Version/s: None
  • Component/s: Course, Tags
  • Labels:
    None
  • Difficulty:
    Moderate
  • Affected Branches:
    MOODLE_19_STABLE

Description

i added course tags so we can tag courses by their content
and see them on the site's Tag pages (later on) or just search for them.
(like we search for courses by their long titles)

it seems more useful then the category hierarchy when search for courses.
since a course could be in more then one category (tag)

i used most of the code that i was already used in:
http://tracker.moodle.org/browse/MDL-19860
http://tracker.moodle.org/browse/MDL-19865

see comments for patch instruction.

Activity

Hide
Nadav Kavalerchik added a comment -

1. add a new "tags" (TEXT type) field to the mdl_course database table.

2. open course/edit.php and add (at the begining of the file after line 9 )

/// support YUI autocomplete Tags / Interests for users
    require_js(array('yui_dom-event', 'yui_connection', 'yui_animation', 'yui_autocomplete'));
    echo '<style>'."\n";
    include ($CFG->libdir.'/yui/autocomplete/assets/skins/sam/autocomplete.css');
    echo '</style>'."\n";

and at the end, just after "$editform->display();" :

/// Tag auto complete YUI addon
if (ajaxenabled()) {
?>

<script type="text/javascript">

// An XHR DataSource
var myServer = "<?php echo $CFG->wwwroot;?>/tag/tag_autocomplete.php";
var myDataSource = new YAHOO.widget.DS_XHR(myServer, ["\n", "\t"]);
myDataSource.responseType = YAHOO.widget.DS_XHR.TYPE_FLAT;
myDataSource.maxCacheEntries = 60;
myDataSource.queryMatchSubset = true;

var myAutoComp = new YAHOO.widget.AutoComplete("id_tags","tags-autocomplete", myDataSource);
myAutoComp.delimChar = ",";
myAutoComp.maxResultsDisplayed = 20;
myAutoComp.minQueryLength = 2;
myAutoComp.allowBrowserAutocomplete = false;
myAutoComp.formatResult = function(aResultItem, sQuery) {
    return aResultItem[1];
}
</script>

<?php
}

3. now, open course/edit_form.php and add the following code
after "$mform->addElement('select', 'lang', get_string('forcelanguage'), $languages);"

/// support YUI autocomplete Tags 
	$mform->addElement('html', '<br/><div id="tags-autocomplete-container">');
        $mform->addElement('textarea', 'tags', get_string('tagslist'), 'cols="50" rows="3"');
        $mform->setType('tags', PARAM_TAGLIST);
        $mform->addElement('html', '</div>');
        $mform->addElement('html', '<div id="tags-autocomplete" class="yui-skin-sam"></div>');

        $mform->setHelpButton('tags', array('tagslist', get_string('helptagslist'),
                          false, true, false));

4. add the appropriate translation string of your local language to moodle.php lang files
(the string "tagslist" !)

5. open tag/index.php and add the following code after line 135 and just before the "echo '</td>';"

// display list of courses that has the current TAG in it
$coursesbytags = get_records_sql("SELECT c.fullname,c.id,c.tags FROM mdl_course c WHERE c.tags LIKE '%$tagname%'");

if (isset($coursesbytags)) {
	print_box_start('generalbox', 'tag-courses');
	print_heading(get_string('relatedcourses', 'tag', $tagname), '', 3);

	foreach ($coursesbytags as $course) {
		echo '<a target="_new" href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->fullname.'</a><br/>';
	}

	print_box_end();
}

now you are set to go !

Show
Nadav Kavalerchik added a comment - 1. add a new "tags" (TEXT type) field to the mdl_course database table. 2. open course/edit.php and add (at the begining of the file after line 9 )
/// support YUI autocomplete Tags / Interests for users
    require_js(array('yui_dom-event', 'yui_connection', 'yui_animation', 'yui_autocomplete'));
    echo '<style>'."\n";
    include ($CFG->libdir.'/yui/autocomplete/assets/skins/sam/autocomplete.css');
    echo '</style>'."\n";
and at the end, just after "$editform->display();" :
/// Tag auto complete YUI addon
if (ajaxenabled()) {
?>

<script type="text/javascript">

// An XHR DataSource
var myServer = "<?php echo $CFG->wwwroot;?>/tag/tag_autocomplete.php";
var myDataSource = new YAHOO.widget.DS_XHR(myServer, ["\n", "\t"]);
myDataSource.responseType = YAHOO.widget.DS_XHR.TYPE_FLAT;
myDataSource.maxCacheEntries = 60;
myDataSource.queryMatchSubset = true;

var myAutoComp = new YAHOO.widget.AutoComplete("id_tags","tags-autocomplete", myDataSource);
myAutoComp.delimChar = ",";
myAutoComp.maxResultsDisplayed = 20;
myAutoComp.minQueryLength = 2;
myAutoComp.allowBrowserAutocomplete = false;
myAutoComp.formatResult = function(aResultItem, sQuery) {
    return aResultItem[1];
}
</script>

<?php
}
3. now, open course/edit_form.php and add the following code after "$mform->addElement('select', 'lang', get_string('forcelanguage'), $languages);"
/// support YUI autocomplete Tags 
	$mform->addElement('html', '<br/><div id="tags-autocomplete-container">');
        $mform->addElement('textarea', 'tags', get_string('tagslist'), 'cols="50" rows="3"');
        $mform->setType('tags', PARAM_TAGLIST);
        $mform->addElement('html', '</div>');
        $mform->addElement('html', '<div id="tags-autocomplete" class="yui-skin-sam"></div>');

        $mform->setHelpButton('tags', array('tagslist', get_string('helptagslist'),
                          false, true, false));
4. add the appropriate translation string of your local language to moodle.php lang files (the string "tagslist" !) 5. open tag/index.php and add the following code after line 135 and just before the "echo '</td>';"
// display list of courses that has the current TAG in it
$coursesbytags = get_records_sql("SELECT c.fullname,c.id,c.tags FROM mdl_course c WHERE c.tags LIKE '%$tagname%'");

if (isset($coursesbytags)) {
	print_box_start('generalbox', 'tag-courses');
	print_heading(get_string('relatedcourses', 'tag', $tagname), '', 3);

	foreach ($coursesbytags as $course) {
		echo '<a target="_new" href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->fullname.'</a><br/>';
	}

	print_box_end();
}
now you are set to go !
Hide
Rossiani Wijaya added a comment -

Thanks Nadav Kavalerchik

Closing.

Show
Rossiani Wijaya added a comment - Thanks Nadav Kavalerchik Closing.
Hide
Jonathan Cartland added a comment -

Thank you so much. Finally a clear answer to what was a surprisingly difficult question.
Now, if I could just figure out how to protect these changes from the updating process...

Show
Jonathan Cartland added a comment - Thank you so much. Finally a clear answer to what was a surprisingly difficult question. Now, if I could just figure out how to protect these changes from the updating process...

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: