mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-13638 Merged from stable
This commit is contained in:
parent
17eef2e89a
commit
3627b0e387
@ -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';
|
||||
|
23
tag/lib.php
23
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
|
||||
|
@ -147,26 +147,24 @@ 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[] = '<a href="'. $CFG->wwwroot .'/user/tag.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) &&
|
||||
(tag_record_tagged_with(array('type'=>'user', 'id'=>$USER->id), $tag_object->name) ||
|
||||
has_capability('moodle/tag:manage', $systemcontext)) ) {
|
||||
$links[] = '<a href="'. $CFG->wwwroot .'/tag/edit.php?tag='. rawurlencode($tag_object->name) .'">'. get_string('edittag', 'tag') .'</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>';
|
||||
}
|
||||
|
||||
// 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>';
|
||||
$links[] = '<a href="'. $CFG->wwwroot .'/tag/user.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>' ;
|
||||
// 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))) {
|
||||
$links[] = '<a href="'. $CFG->wwwroot .'/tag/edit.php?tag='. rawurlencode($tag_object->name) .'">'. get_string('edittag', 'tag') .'</a>';
|
||||
}
|
||||
|
||||
|
||||
$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 = '<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>';
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?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);
|
||||
@ -33,12 +33,26 @@ switch ($action) {
|
||||
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;
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user