From 3627b0e387eda7e73d01f1123e4eaee1eff40f38 Mon Sep 17 00:00:00 2001 From: moodler Date: Mon, 25 Feb 2008 04:57:48 +0000 Subject: [PATCH] MDL-13638 Merged from stable --- lang/en_utf8/tag.php | 1 + tag/lib.php | 23 +++++++++++++++++++++++ tag/locallib.php | 26 ++++++++++++-------------- user/tag.php => tag/user.php | 16 +++++++++++++++- 4 files changed, 51 insertions(+), 15 deletions(-) rename user/tag.php => tag/user.php (69%) diff --git a/lang/en_utf8/tag.php b/lang/en_utf8/tag.php index 046e304060..dfce19a079 100644 --- a/lang/en_utf8/tag.php +++ b/lang/en_utf8/tag.php @@ -25,6 +25,7 @@ $string['owner'] = 'Owner'; $string['otags'] = 'Official tags'; $string['ptags'] = 'User defined tags (Comma separated)'; $string['relatedtags'] = 'Related tags'; +$string['removetagfrommyinterests'] = 'Remove \"$a\" from my interests'; $string['responsiblewillbenotified'] = 'The person responsible will be notified'; $string['resetflag'] = 'Reset flag'; $string['reset'] = 'Reset'; diff --git a/tag/lib.php b/tag/lib.php index ea7844f053..3cfed185ae 100644 --- a/tag/lib.php +++ b/tag/lib.php @@ -474,6 +474,29 @@ function tag_set_add($record_type, $record_id, $tag) { 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 diff --git a/tag/locallib.php b/tag/locallib.php index 49cc7e56fa..83884846c0 100644 --- a/tag/locallib.php +++ b/tag/locallib.php @@ -147,25 +147,23 @@ function tag_print_management_box($tag_object, $return=false) { $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[] = ''. get_string('addtagtomyinterests', 'tag', $tagname) .''; + // 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[] = ''. get_string('removetagfrommyinterests', 'tag', $tagname) .''; + } else { + $links[] = ''. get_string('addtagtomyinterests', 'tag', $tagname) .''; } - // only people with moodle/tag:edit capability may edit the tag description - if ( has_capability('moodle/tag:edit', $systemcontext) && + // flag as inappropriate link + $links[] = ''. get_string('flagasinappropriate', 'tag', rawurlencode($tagname)) .''; + + // 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[] = ''. get_string('edittag', 'tag') .''; } - // flag as inappropriate link - $links[] = ''. get_string('flagasinappropriate', 'tag', rawurlencode($tagname)) .''; - - // Manage all tags links - if ( has_capability('moodle/tag:manage', $systemcontext) ) { - $links[] = ''. get_string('managetags', 'tag') .'' ; - } $output .= implode(' | ', $links); $output .= print_box_end(true); @@ -228,7 +226,7 @@ function tag_print_search_results($query, $page, $perpage, $return=false) { // link "Add $query to my interests" $addtaglink = ''; if( !is_item_tagged_with('user', $USER->id, $query) ) { - $addtaglink = ''; + $addtaglink = ''; $addtaglink .= get_string('addtagtomyinterests', 'tag', rawurlencode($query)) .''; } diff --git a/user/tag.php b/tag/user.php similarity index 69% rename from user/tag.php rename to tag/user.php index 2382477f69..ec8273de8d 100644 --- a/user/tag.php +++ b/tag/user.php @@ -1,7 +1,7 @@ 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; } ?> -- 2.39.5