]> git.mjollnir.org Git - moodle.git/commitdiff
Essential patch for MDL-11992 course tagging. This prevents a bug that removes offica...
authorjbeedell <jbeedell>
Fri, 5 Sep 2008 14:49:06 +0000 (14:49 +0000)
committerjbeedell <jbeedell>
Fri, 5 Sep 2008 14:49:06 +0000 (14:49 +0000)
blocks/tags/coursetags.js
blocks/tags/styles.php
lang/en_utf8/tag.php
lib/db/upgrade.php
tag/coursetags_add.php
tag/coursetags_edit.php
tag/coursetagslib.php
tag/lib.php

index de4f1780c215ff557102968c4b0100a3ca441b25..783146fc0510d4e45d9c9a16e27b43bc04d18a86 100644 (file)
@@ -45,10 +45,11 @@ function ctags_getKeywords() {
     }
   }
   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() {
index ef743369225baa2aeb26e68f3cb6282dae1dc6ba..e7344b1844516d426c8a987d21f4dff91c59fb7f 100644 (file)
@@ -62,7 +62,7 @@
     padding-top: 4px;
 }
 
-/* Styles for edit_tags.php */
+/* Styles for coursetag_edit.php */
 
 .coursetag_edit_centered {
     position: relative;
@@ -93,7 +93,7 @@
     display: none;
 }
 
-/* Styles for more_tags.php */
+/* Styles for coursetag_more.php */
 
 .coursetag_more_title {
     margin: 30px 30px -25px 30px;
index 256291ebcb42faf5370932b7bce14ae5ac0ab484..8fdd76ba09a50f11b3bfe440a09796831986f4ae 100644 (file)
@@ -49,6 +49,8 @@ $string['tagtype_default'] = 'Default';
 $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';
index a98a1845fc34161081cf60d783dfb54d0a61419c..e9c1901c53580cc8516b1293c93778d3c659db4d 100644 (file)
@@ -154,10 +154,14 @@ function xmldb_main_upgrade($oldversion) {
         // 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);
index 268f6e74685703938becbf5bd13db6f234190f2a..acdaf1d1bfb7b628051b80507ee4c7b47bdb7f1f 100644 (file)
@@ -19,7 +19,7 @@ $keyword = optional_param('coursetag_new_tag', '', PARAM_TEXT);
 $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');
index 36c8efbff75ea0b1525e758b62089ba44fecd8dc..124a1ab0def993fab15f59f5312e00574b5a3967 100644 (file)
@@ -43,12 +43,7 @@ if ($data = data_submitted()) {
         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) {
index cc898ba94bfaff396d2da916257ad0475cca594d..685e96077fcaf8b5601e7f2479aa644472f76171 100644 (file)
@@ -357,26 +357,33 @@ function coursetag_store_keywords($tags, $courseid, $userid=0, $tagtype='officia
     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);
-                }
             }
         }
     }
index 8c576b45d9173e3f8368d6692c33cb0694ba15af..5c6229d3a9fe7247e5ad6de734bc184cc75ba5ed 100644 (file)
@@ -63,10 +63,9 @@ define('TAG_RELATED_CORRELATED', 2);
  * @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) {
@@ -109,7 +108,7 @@ function tag_set($record_type, $record_id, $tags, $userid = 0) {
             $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.
@@ -128,18 +127,17 @@ function tag_set($record_type, $record_id, $tags, $userid = 0) {
  *     '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);
 }
 
 /**
@@ -550,10 +548,10 @@ function tag_delete_instance($record_type, $record_id, $tagid) {
         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 {
@@ -592,7 +590,7 @@ function tag_display_name($tagobject, $html=TAG_RETURN_HTML) {
         return $tagname;
     } else { // TAG_RETURN_HTML
         return htmlspecialchars($tagname);
-    } 
+    }
 }
 
 /**
@@ -801,7 +799,7 @@ function tag_compute_correlations($min_correlation=2) {
 
         // 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