}
}
document.forms['coursetag'].coursetag_sug_keyword.value = sug_disp;
- if (!sug.length || input == sug_disp)
+ if (!sug.length || input == sug_disp) {
document.getElementById('coursetag_sug_btn').style.display = "none";
- else
+ } else {
document.getElementById('coursetag_sug_btn').style.display = "block";
+ }
}
function ctags_setKeywords() {
padding-top: 4px;
}
-/* Styles for edit_tags.php */
+/* Styles for coursetag_edit.php */
.coursetag_edit_centered {
position: relative;
display: none;
}
-/* Styles for more_tags.php */
+/* Styles for coursetag_more.php */
.coursetag_more_title {
margin: 30px 30px -25px 30px;
$string['tagindex_coursetitle'] = 'Courses tagged with \"$a\"';
$string['tags'] = 'Tags';
$string['tagsaredisabled'] = 'Tags are disabled';
+$string['thingtaggedwith'] = '\"$a->name\" is used once';
+$string['thingstaggedwith'] = '\"$a->name\" is used $a->count times';
$string['thistaghasnodesc'] = 'This tag currently has no description.';
$string['timemodified'] = 'Modified';
$string['typechanged'] = 'Tag type changed';
// modify index
$index = new xmldb_index('itemtype-itemid-tagid');
$index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid'));
- $dbman->drop_index($table, $index);
+ if ($dbman->index_exists($table, $index)) {
+ $dbman->drop_index($table, $index);
+ }
$index = new xmldb_index('itemtype-itemid-tagid-tiuserid');
$index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid'));
- $dbman->add_index($table, $index);
+ if (!$dbman->index_exists($table, $index)) {
+ $dbman->add_index($table, $index);
+ }
/// Main savepoint reached
upgrade_main_savepoint($result, 2008063001);
$courseid = optional_param('entryid', 0, PARAM_INT);
$userid = optional_param('userid', 0, PARAM_INT);
-$keyword = trim(strip_tags($keyword)); //better cleanup of user input is done later
+$keyword = trim(strip_tags($keyword));
if ($keyword and confirm_sesskey()) {
require_once($CFG->dirroot.'/tag/coursetagslib.php');
if (trim(strip_tags($keyword))) {
$myurl = 'tag/search.php';
$keywords = explode(',', $keyword);
- try {
- coursetag_store_keywords($keywords, $courseid, $USER->id, 'default', $myurl);
- }
- catch (Exception $e) {
- notice($e->getmessage());
- }
+ coursetag_store_keywords($keywords, $courseid, $USER->id, 'default', $myurl);
}
// delete personal tag
if ($deltag > 0) {
global $CFG;
if (is_array($tags) and !empty($tags)) {
-
- //tag_set_add('course', $courseid, $tags, $userid);
- //if ($tagtype == 'official') {
- // $tags_ids = tag_get_id($tags);
- //}
-
foreach($tags as $tag) {
$tag = trim($tag);
if (strlen($tag) > 0) {
- tag_set_add('course', $courseid, $tag, $userid);
- if ($myurl) {
- $url = $myurl.'?query='.urlencode($tag);
+ //tag_set_add('course', $courseid, $tag, $userid); //deletes official tags
+
+ //add tag if does not exist
+ if (!$tagid = tag_get_id($tag)) {
+ $tag_id_array = tag_add(array($tag), $tagtype);
+ $tagid = $tag_id_array[moodle_strtolower($tag)];
+ }
+ //ordering
+ $ordering = 0;
+ if ($current_ids = tag_get_tags_ids('course', $courseid)) {
+ end($current_ids);
+ $ordering = key($current_ids) + 1;
}
+ //set type
+ tag_type_set($tagid, $tagtype);
+
+ //tag_instance entry
+ tag_assign('course', $courseid, $tagid, $ordering, $userid);
+
+ //logging - note only for user added tags
if ($tagtype == 'default' and $myurl != '') {
- // log the tagging request - note only for user added tags
+ $url = $myurl.'?query='.urlencode($tag);
add_to_log($courseid, 'coursetags', 'add', $url, 'Course tagged');
}
- if ($tagtype == 'official') {
- tag_type_set(tag_get_id($tag), $tagtype);
- }
}
}
}
* @param int $record_id the id of the record to tag
* @param array $tags the array of tags to set on the record. If
* given an empty array, all tags will be removed.
- * @param int $userid optional only required for course tagging
* @return void
*/
-function tag_set($record_type, $record_id, $tags, $userid = 0) {
+function tag_set($record_type, $record_id, $tags) {
static $in_recursion_semaphore = false; // this is to prevent loops when tagging a tag
if ( $record_type == 'tag' && !$in_recursion_semaphore) {
$tag_current_id = $new_tag[$clean_tag];
}
- tag_assign($record_type, $record_id, $tag_current_id, $ordering, $userid);
+ tag_assign($record_type, $record_id, $tag_current_id, $ordering);
// if we are tagging a tag (adding a manually-assigned related tag), we
// need to create the opposite relationship as well.
* 'user' for users, etc.
* @param int $record_id the id of the record to tag
* @param string $tag the tag to add
- * @param int $userid optional only required for course tagging
* @return void
*/
-function tag_set_add($record_type, $record_id, $tag, $userid = 0) {
+function tag_set_add($record_type, $record_id, $tag) {
$new_tags = array();
- foreach( tag_get_tags($record_type, $record_id, NULL, $userid) as $current_tag ) {
+ foreach( tag_get_tags($record_type, $record_id) as $current_tag ) {
$new_tags[] = $current_tag->rawname;
}
$new_tags[] = $tag;
- return tag_set($record_type, $record_id, $new_tags, $userid);
+ return tag_set($record_type, $record_id, $new_tags);
}
/**
if (!$DB->record_exists_sql("SELECT * ".
"FROM {tag} tg ".
"WHERE tg.id = ? AND ( tg.tagtype = 'official' OR ".
- "EXISTS (SELECT 1
- FROM {tag_instance} ti
- WHERE ti.tagid = ?) )",
- array($tagid, $tagid))) {
+ "EXISTS (SELECT 1
+ FROM {tag_instance} ti
+ WHERE ti.tagid = ?) )",
+ array($tagid, $tagid))) {
return tag_delete($tagid);
}
} else {
return $tagname;
} else { // TAG_RETURN_HTML
return htmlspecialchars($tagname);
- }
+ }
}
/**
// query that counts how many times any tag appears together in items
// with the tag passed as argument ($tag_id)
- $query = "SELECT tb.tagid
+ $query = "SELECT tb.tagid
FROM {tag_instance} ta JOIN {tag_instance} tb ON ta.itemid = tb.itemid
WHERE ta.tagid = ? AND tb.tagid <> ?
GROUP BY tb.tagid