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 )
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();" :
if (ajaxenabled()) {
?>
<script type="text/javascript">
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);"
$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>';"
$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 !
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 )
and at the end, just after "$editform->display();" :
3. now, open course/edit_form.php and add the following code
after "$mform->addElement('select', 'lang', get_string('forcelanguage'), $languages);"
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>';"
now you are set to go !