return tag_set($record_type, $record_id, $new_tags);
}
+/**
+ * Removes a tag from a record, without overwriting other current tags.
+ *
+ * @param string $record_type the type of record to tag ('post' for blogs,
+ * 'user' for users, etc.
+ * @param int $record_id the id of the record to tag
+ * @param string $tag the tag to delete
+ * @return void
+ */
+function tag_set_delete($record_type, $record_id, $tag) {
+
+ $record = array('type' => $record_type, 'id' => $record_id);
+
+ $new_tags = array();
+ foreach( tag_get_tags($record) as $current_tag ) {
+ if ($current_tag->name != $tag) { // Keep all tags but the one specified
+ $new_tags[] = $current_tag->name;
+ }
+ }
+
+ return tag_set($record_type, $record_id, $new_tags);
+}
+
/**
* Set the type of a tag. At this time (version 1.9) the possible values
* are 'default' or 'official'. Official tags will be displayed separately "at
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$links = array();
- // if the user is not tagged with the $tag_object tag, a link "add blahblah to my interests" will appear
- if( !tag_record_tagged_with(array('type'=>'user', 'id'=>$USER->id), $tag_object->name )) {
- $links[] = '<a href="'. $CFG->wwwroot .'/user/tag.php?action=addinterest&sesskey='. sesskey() .'&tag='. rawurlencode($tag_object->name) .'">'. get_string('addtagtomyinterests', 'tag', $tagname) .'</a>';
+ // Add a link for users to add/remove this from their interests
+ if (tag_record_tagged_with(array('type'=>'user', 'id'=>$USER->id), $tag_object->name)) {
+ $links[] = '<a href="'. $CFG->wwwroot .'/tag/user.php?action=removeinterest&sesskey='. sesskey() .'&tag='. rawurlencode($tag_object->name) .'">'. get_string('removetagfrommyinterests', 'tag', $tagname) .'</a>';
+ } else {
+ $links[] = '<a href="'. $CFG->wwwroot .'/tag/user.php?action=addinterest&sesskey='. sesskey() .'&tag='. rawurlencode($tag_object->name) .'">'. get_string('addtagtomyinterests', 'tag', $tagname) .'</a>';
}
- // only people with moodle/tag:edit capability may edit the tag description
- if ( has_capability('moodle/tag:edit', $systemcontext) &&
+ // flag as inappropriate link
+ $links[] = '<a href="'. $CFG->wwwroot .'/tag/user.php?action=flaginappropriate&sesskey='. sesskey() .'&tag='. rawurlencode($tag_object->name) .'">'. get_string('flagasinappropriate', 'tag', rawurlencode($tagname)) .'</a>';
+
+ // Edit tag: Only people with moodle/tag:edit capability who either have it as an interest or can manage tags
+ if (has_capability('moodle/tag:edit', $systemcontext) &&
(tag_record_tagged_with(array('type'=>'user', 'id'=>$USER->id), $tag_object->name) ||
- has_capability('moodle/tag:manage', $systemcontext)) ) {
+ has_capability('moodle/tag:manage', $systemcontext))) {
$links[] = '<a href="'. $CFG->wwwroot .'/tag/edit.php?tag='. rawurlencode($tag_object->name) .'">'. get_string('edittag', 'tag') .'</a>';
}
- // flag as inappropriate link
- $links[] = '<a href="'. $CFG->wwwroot .'/user/tag.php?action=flaginappropriate&sesskey='. sesskey() .'&tag='. rawurlencode($tag_object->name) .'">'. get_string('flagasinappropriate', 'tag', rawurlencode($tagname)) .'</a>';
-
- // Manage all tags links
- if ( has_capability('moodle/tag:manage', $systemcontext) ) {
- $links[] = '<a href="'. $CFG->wwwroot .'/tag/manage.php">'. get_string('managetags', 'tag') .'</a>' ;
- }
$output .= implode(' | ', $links);
$output .= print_box_end(true);
// link "Add $query to my interests"
$addtaglink = '';
if( !is_item_tagged_with('user', $USER->id, $query) ) {
- $addtaglink = '<a href="'. $CFG->wwwroot .'/user/tag.php?action=addinterest&sesskey='. sesskey() .'&tag='. rawurlencode($query) .'">';
+ $addtaglink = '<a href="'. $CFG->wwwroot .'/tag/user.php?action=addinterest&sesskey='. sesskey() .'&tag='. rawurlencode($query) .'">';
$addtaglink .= get_string('addtagtomyinterests', 'tag', rawurlencode($query)) .'</a>';
}
<?php // $Id$
require_once('../config.php');
-require_once('../tag/lib.php');
+require_once('lib.php');
$action = optional_param('action', '', PARAM_ALPHA);
$id = optional_param('id', 0, PARAM_INT);
redirect($CFG->wwwroot.'/tag/index.php?tag='. rawurlencode($tag));
break;
+ case 'removeinterest':
+ if (empty($tag) && $id) { // for backward-compatibility (people saving bookmarks, mostly..)
+ $tag = tag_get_name($id);
+ }
+
+ tag_set_delete('user', $USER->id, $tag);
+
+ redirect($CFG->wwwroot.'/tag/index.php?tag='. rawurlencode($tag));
+ break;
+
case 'flaginappropriate':
tag_set_flag(tag_get_id($tag));
redirect($CFG->wwwroot.'/tag/index.php?tag='. rawurlencode($tag), get_string('responsiblewillbenotified', 'tag'));
break;
+
+ default:
+ error('No action was specified');
+ break;
}
?>