]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13638 Merged from stable
authormoodler <moodler>
Mon, 25 Feb 2008 04:57:48 +0000 (04:57 +0000)
committermoodler <moodler>
Mon, 25 Feb 2008 04:57:48 +0000 (04:57 +0000)
lang/en_utf8/tag.php
tag/lib.php
tag/locallib.php
tag/user.php [moved from user/tag.php with 69% similarity]

index 046e304060c7950dab790f243a651510658b10cc..dfce19a0796a1959eb4737cff808d676f39c3b46 100644 (file)
@@ -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';
index ea7844f05364e5e2172e767599898e57a21bc90c..3cfed185ae26015e844e9cb517e4d304eee0f8dc 100644 (file)
@@ -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
index 49cc7e56fad098060f882735bde283497dfb6486..83884846c02c3f4859efee5b7d1b1770d09b1303 100644 (file)
@@ -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[] = '<a href="'. $CFG->wwwroot .'/user/tag.php?action=addinterest&amp;sesskey='. sesskey() .'&amp;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&amp;sesskey='. sesskey() .'&amp;tag='. rawurlencode($tag_object->name) .'">'. get_string('removetagfrommyinterests', 'tag', $tagname) .'</a>';
+        } else {
+            $links[] = '<a href="'. $CFG->wwwroot .'/tag/user.php?action=addinterest&amp;sesskey='. sesskey() .'&amp;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&amp;sesskey='. sesskey() .'&amp;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&amp;sesskey='. sesskey() .'&amp;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);
@@ -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&amp;sesskey='. sesskey() .'&amp;tag='. rawurlencode($query) .'">';
+        $addtaglink = '<a href="'. $CFG->wwwroot .'/tag/user.php?action=addinterest&amp;sesskey='. sesskey() .'&amp;tag='. rawurlencode($query) .'">';
         $addtaglink .= get_string('addtagtomyinterests', 'tag', rawurlencode($query)) .'</a>';
     }
 
similarity index 69%
rename from user/tag.php
rename to tag/user.php
index 2382477f692493fe14291031720179d37b11b9a5..ec8273de8d735a8e5bb40be139d69e8b39ff51d1 100644 (file)
@@ -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;
 }
 
 ?>