MDL-51283 core_tag: change tagtype to isstandard
authorMarina Glancy <marina@moodle.com>
Sun, 10 Jan 2016 07:28:36 +0000 (15:28 +0800)
committerMarina Glancy <marina@moodle.com>
Tue, 2 Feb 2016 09:31:14 +0000 (17:31 +0800)
Change 'official' to 'standard' in UI

45 files changed:
blocks/blog_tags/block_blog_tags.php
blocks/blog_tags/tests/behat/blogtag.feature
blocks/tags/block_tags.php
blocks/tags/edit_form.php
blocks/tags/lang/en/block_tags.php
blocks/tags/tests/behat/tagcloud.feature
blog/tests/lib_test.php
course/tests/behat/coursetags.feature
lang/en/deprecated.txt
lang/en/role.php
lang/en/tag.php
lib/amd/build/tag.min.js
lib/amd/src/tag.js
lib/db/install.xml
lib/db/upgrade.php
lib/deprecatedlib.php
lib/form/tags.php
lib/testing/generator/data_generator.php
mod/wiki/tests/behat/edit_tags.feature
tag/classes/area.php
tag/classes/collection.php
tag/classes/external.php
tag/classes/manage_table.php
tag/classes/output/tag.php
tag/classes/output/tagcloud.php
tag/classes/output/taglist.php
tag/classes/renderer.php
tag/classes/tag.php
tag/edit.php
tag/edit_form.php
tag/manage.php
tag/templates/tagcloud.mustache
tag/templates/tagisstandard.mustache [moved from tag/templates/tagtype.mustache with 66% similarity]
tag/templates/taglist.mustache
tag/tests/behat/collections.feature
tag/tests/behat/delete_tag.feature
tag/tests/behat/edit_tag.feature
tag/tests/behat/flag_tags.feature
tag/tests/behat/official_tags.feature [deleted file]
tag/tests/behat/standard_tags.feature [new file with mode: 0644]
tag/tests/external_test.php
tag/tests/taglib_test.php
tag/upgrade.txt
user/lib.php
version.php

index 6edc7b5..f46bd41 100644 (file)
@@ -121,7 +121,7 @@ class block_blog_tags extends block_base {
             $type = " AND (p.publishstate = 'site' or p.publishstate='public')";
         }
 
-        $sql  = "SELECT t.id, t.tagtype, t.rawname, t.name, COUNT(DISTINCT ti.id) AS ct
+        $sql  = "SELECT t.id, t.isstandard, t.rawname, t.name, COUNT(DISTINCT ti.id) AS ct
                    FROM {tag} t, {tag_instance} ti, {post} p, {blog_association} ba
                   WHERE t.id = ti.tagid AND p.id = ti.itemid
                         $type
@@ -136,7 +136,7 @@ class block_blog_tags extends block_base {
         }
 
         $sql .= "
-               GROUP BY t.id, t.tagtype, t.name, t.rawname
+               GROUP BY t.id, t.isstandard, t.name, t.rawname
                ORDER BY ct DESC, t.name ASC";
 
         if ($tags = $DB->get_records_sql($sql, null, 0, $this->config->numberoftags)) {
@@ -165,7 +165,7 @@ class block_blog_tags extends block_base {
                     $size = 20 - ( (int)((($currenttag - 1) / $totaltags) * 20) );
                 }
 
-                $tag->class = "$tag->tagtype s$size";
+                $tag->class = ($tag->isstandard ? "standardtag " : "") . "s$size";
                 $etags[] = $tag;
 
             }
index 192ba5e..d840c38 100644 (file)
@@ -14,8 +14,8 @@ Feature: Adding blog tag block
       | fullname  | shortname |
       | Course 1  | c1        |
     And the following "tags" exist:
-      | name         | tagtype  |
-      | Neverusedtag | official |
+      | name         | isstandard  |
+      | Neverusedtag | 1           |
     And the following "course enrolments" exist:
       | user     | course | role           |
       | teacher1 | c1     | editingteacher |
index 31ced58..e483abe 100644 (file)
@@ -70,8 +70,8 @@ class block_tags extends block_base {
             $this->config->numberoftags = 80;
         }
 
-        if (empty($this->config->tagtype)) {
-            $this->config->tagtype = '';
+        if (empty($this->config->showstandard)) {
+            $this->config->showstandard = core_tag_tag::BOTH_STANDARD_AND_NOT;
         }
 
         if (empty($this->config->ctx)) {
@@ -102,7 +102,7 @@ class block_tags extends block_base {
         // Get a list of tags.
 
         $tagcloud = core_tag_collection::get_tag_cloud($this->config->tagcoll,
-                $this->config->tagtype,
+                $this->config->showstandard == core_tag_tag::STANDARD_ONLY,
                 $this->config->numberoftags,
                 'name', '', $this->page->context->id, $this->config->ctx, $this->config->rec);
         $this->content->text = $OUTPUT->render_from_template('core_tag/tagcloud', $tagcloud->export_for_template($OUTPUT));
index 89742c5..4ea8209 100644 (file)
@@ -48,10 +48,10 @@ class block_tags_edit_form extends block_edit_form {
         $mform->setDefault('config_numberoftags', 80);
 
         $defaults = array(
-            'official' => get_string('officialonly', 'block_tags'),
-            '' => get_string('anytype', 'block_tags'));
-        $mform->addElement('select', 'config_tagtype', get_string('defaultdisplay', 'block_tags'), $defaults);
-        $mform->setDefault('config_tagtype', '');
+            core_tag_tag::STANDARD_ONLY => get_string('standardonly', 'block_tags'),
+            core_tag_tag::BOTH_STANDARD_AND_NOT => get_string('anytype', 'block_tags'));
+        $mform->addElement('select', 'config_showstandard', get_string('defaultdisplay', 'block_tags'), $defaults);
+        $mform->setDefault('config_showstandard', core_tag_tag::BOTH_STANDARD_AND_NOT);
 
         $defaults = array(0 => context_system::instance()->get_context_name());
         $parentcontext = context::instance_by_id($this->block->instance->parentcontextid);
index 02dd7a1..8f1a1b7 100644 (file)
@@ -26,11 +26,11 @@ $string['anycollection'] = 'Any';
 $string['anytype'] = 'All';
 $string['configtitle'] = 'Block title';
 $string['disabledtags'] = 'Tags are disabled';
-$string['defaultdisplay'] = 'Tag type to display';
-$string['officialonly'] = 'Only official';
+$string['defaultdisplay'] = 'Display tags';
 $string['pluginname'] = 'Tags';
 $string['recursivecontext'] = 'Include child contexts';
 $string['recursivecontext_help'] = 'If unchecked, tags of items in the context specified above will be displayed excluding underlying contexts, for example, you can search on course level only without searching inside course activities';
+$string['standardonly'] = 'Only standard';
 $string['tagcollection'] = 'Tag collection';
 $string['tagcollection_help'] = 'Select tag collection to display tags from. If you choose "Any" '
         . 'the tags from all collections except for those marked with * will be displayed';
index 7a25490..36e1bc0 100644 (file)
@@ -13,8 +13,8 @@ Feature: Block tags displaying tag cloud
       | fullname  | shortname |
       | Course 1  | c1        |
     And the following "tags" exist:
-      | name         | tagtype  |
-      | Neverusedtag | official |
+      | name         | isstandard  |
+      | Neverusedtag | 1           |
     And the following "course enrolments" exist:
       | user     | course | role           |
       | teacher1 | c1     | editingteacher |
index 81eac30..80c3be5 100644 (file)
@@ -66,7 +66,7 @@ class core_blog_lib_testcase extends advanced_testcase {
 
         // Create default tag.
         $tag = $this->getDataGenerator()->create_tag(array('userid' => $user->id,
-            'rawname' => 'Testtagname', 'tagtype' => 'official'));
+            'rawname' => 'Testtagname', 'isstandard' => 1));
 
         // Create default post.
         $post = new stdClass();
index f76f93a..b330e80 100644 (file)
@@ -15,8 +15,8 @@ Feature: Tagging courses
       | Course 1  | c1        |
       | Course 2  | c2        |
     And the following "tags" exist:
-      | name         | tagtype  |
-      | Neverusedtag | official |
+      | name         | isstandard  |
+      | Neverusedtag | 1           |
     And the following "course enrolments" exist:
       | user     | course | role           |
       | teacher1 | c1     | editingteacher |
index 366e26b..4cb19ce 100644 (file)
@@ -21,3 +21,9 @@ withselectedtags,core_tag
 tag:create,core_role
 categoriesanditems,core_grades
 taggedwith,core_tag
+officialtag,core_tag
+otags,core_tag
+othertags,core_tag
+tagtype,core_tag
+manageofficialtags,core_tag
+settypeofficial,core_tag
index f429e4c..e7eb45e 100644 (file)
@@ -86,8 +86,6 @@ $string['blog:associatemodule'] = 'This capability is deprecated and does nothin
 $string['blog:create'] = 'Create new blog entries';
 $string['blog:manageentries'] = 'Edit and manage entries';
 $string['blog:manageexternal'] = 'Edit and manage external blogs';
-$string['blog:manageofficialtags'] = 'Manage official tags';
-$string['blog:managepersonaltags'] = 'Manage personal tags';
 $string['blog:search'] = 'Search blog entries';
 $string['blog:view'] = 'View blog entries';
 $string['blog:viewdrafts'] = 'View draft blog entries';
index e20a603..302c8c5 100644 (file)
@@ -22,8 +22,8 @@
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-$string['added'] = 'Official tag(s) added';
-$string['addotags'] = 'Add official tags';
+$string['added'] = 'Standard tag(s) added';
+$string['addotags'] = 'Add standard tags';
 $string['addtagcoll'] = 'Add tag collection';
 $string['addtagtomyinterests'] = 'Add "{$a}" to my interests';
 $string['alltagpages'] = 'All tag pages';
@@ -69,7 +69,7 @@ $string['id'] = 'id';
 $string['inalltagcoll'] = 'Everywhere';
 $string['itemstaggedwith'] = '{$a->tagarea} tagged with "{$a->tag}"';
 $string['lesstags'] = 'less...';
-$string['manageofficialtags'] = 'Manage official tags';
+$string['managestandardtags'] = 'Manage standard tags';
 $string['managetags'] = 'Manage tags';
 $string['managetagcolls'] = 'Manage tag collections';
 $string['moretags'] = 'more...';
@@ -80,9 +80,6 @@ $string['nextpage'] = 'More';
 $string['notagsfound'] = 'No tags matching "{$a}" found';
 $string['noresultsfor'] = 'No results for "{$a}"';
 $string['nothingtoupdate'] = 'Nothing to update';
-$string['officialtag'] = 'Official';
-$string['otags'] = 'Official tags';
-$string['othertags'] = 'Other tags';
 $string['owner'] = 'Owner';
 $string['prevpage'] = 'Back';
 $string['ptags'] = 'User defined tags (Comma separated)';
@@ -103,9 +100,10 @@ $string['seeallblogs'] = 'See all blog entries tagged with "{$a}"';
 $string['select'] = 'Select';
 $string['selectcoll'] = 'Select tag collection';
 $string['selecttag'] = 'Select tag {$a}';
-$string['settypedefault'] = 'Remove from official tags';
-$string['settypeofficial'] = 'Make official';
+$string['settypedefault'] = 'Remove from standard tags';
+$string['settypestandard'] = 'Make standard';
 $string['showingfirsttags'] = 'Showing {$a} most popular tags';
+$string['standardtag'] = 'Standard';
 $string['suredeletecoll'] = 'Are you sure you want to delete tag collection "{$a}"?';
 $string['tag'] = 'Tag';
 $string['tagarea_blog_external'] = 'External blog posts';
@@ -120,7 +118,6 @@ $string['tagcollections'] = 'Tag collections';
 $string['tagdescription'] = 'Tag description';
 $string['tags'] = 'Tags';
 $string['tagsaredisabled'] = 'Tags are disabled';
-$string['tagtype'] = 'Tag type';
 $string['thingstaggedwith'] = '"{$a->name}" is used {$a->count} times';
 $string['thingtaggedwith'] = '"{$a->name}" is used once';
 $string['timemodified'] = 'Modified';
@@ -143,4 +140,10 @@ $string['withselectedtags'] = 'With selected tags...';
 
 // Deprecated since 3.1 .
 
+$string['manageofficialtags'] = 'Manage official tags';
+$string['officialtag'] = 'Official';
+$string['otags'] = 'Official tags';
+$string['othertags'] = 'Other tags';
+$string['settypeofficial'] = 'Make official';
 $string['taggedwith'] = 'tagged with "{$a}"';
+$string['tagtype'] = 'Tag type';
index 7a4328f..e570801 100644 (file)
Binary files a/lib/amd/build/tag.min.js and b/lib/amd/build/tag.min.js differ
index 01ef814..1a0a94e 100644 (file)
@@ -72,16 +72,16 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
             };
 
             // Click handler for changing tag type.
-            $('.tag-management-table').delegate('.tagtype', 'click', function(e) {
+            $('.tag-management-table').delegate('.tagisstandard', 'click', function(e) {
                 e.preventDefault();
                 var target = $( this ),
                     tagid = target.attr('data-id'),
                     currentvalue = target.attr('data-value'),
-                    official = (currentvalue === "1") ? 0 : 1;
+                    isstandard = (currentvalue === "1") ? 0 : 1;
 
                 var promises = ajax.call([{
                     methodname: 'core_tag_update_tags',
-                    args: { tags : [ { id : tagid , official : official } ] }
+                    args: { tags : [ { id : tagid , isstandard : isstandard } ] }
                 }, {
                     methodname: 'core_tag_get_tags',
                     args: { tags : [ { id : tagid } ] }
@@ -90,11 +90,11 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
                 $.when.apply($, promises)
                     .done( function(updateresult, data) {
                         if (updateresult.warnings[0] === undefined && data.tags[0] !== undefined) {
-                            templates.render('core_tag/tagtype', data.tags[0]).done(function(html) {
+                            templates.render('core_tag/tagisstandard', data.tags[0]).done(function(html) {
                                 update_modified(target);
                                 var parent = target.parent();
                                 target.replaceWith(html);
-                                parent.find('.tagtype').get(0).focus();
+                                parent.find('.tagisstandard').get(0).focus();
                             });
                         }
                     });
index 3c9e420..7eac93f 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20160111" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20160202" COMMENT="XMLDB file for core Moodle tables"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
 >
         <FIELD NAME="tagcollid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
         <FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
         <FIELD NAME="rawname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The raw, unnormalised name for the tag as entered by users"/>
-        <FIELD NAME="tagtype" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
+        <FIELD NAME="isstandard" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Whether this tag is standard"/>
         <FIELD NAME="description" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
         <FIELD NAME="descriptionformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
         <FIELD NAME="flag" TYPE="int" LENGTH="4" NOTNULL="false" DEFAULT="0" SEQUENCE="false" COMMENT="a tag can be 'flagged' as inappropriate"/>
       </KEYS>
       <INDEXES>
         <INDEX NAME="tagcollname" UNIQUE="true" FIELDS="tagcollid, name"/>
-        <INDEX NAME="tagcolltype" UNIQUE="false" FIELDS="tagcollid, tagtype"/>
+        <INDEX NAME="tagcolltype" UNIQUE="false" FIELDS="tagcollid, isstandard"/>
       </INDEXES>
     </TABLE>
     <TABLE NAME="tag_correlation" COMMENT="The rationale for the 'tag_correlation' table is performance.   It works as a cache for a potentially heavy load query done at the 'tag_instance' table.   So, the 'tag_correlation' table stores redundant information derived from the 'tag_instance' table">
index 3975de3..11523d5 100644 (file)
@@ -4849,5 +4849,46 @@ function xmldb_main_upgrade($oldversion) {
 
         upgrade_main_savepoint(true, 2016011901.00);
     }
+
+    if ($oldversion < 2016020200.00) {
+
+        // Define field isstandard to be added to tag.
+        $table = new xmldb_table('tag');
+        $field = new xmldb_field('isstandard', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'rawname');
+
+        // Conditionally launch add field isstandard.
+        if (!$dbman->field_exists($table, $field)) {
+            $dbman->add_field($table, $field);
+        }
+
+        // Define index tagcolltype (not unique) to be dropped form tag.
+        $index = new xmldb_index('tagcolltype', XMLDB_INDEX_NOTUNIQUE, array('tagcollid', 'tagtype'));
+
+        // Conditionally launch drop index tagcolltype.
+        if ($dbman->index_exists($table, $index)) {
+            $dbman->drop_index($table, $index);
+        }
+
+        // Define index tagcolltype (not unique) to be added to tag.
+        $index = new xmldb_index('tagcolltype', XMLDB_INDEX_NOTUNIQUE, array('tagcollid', 'isstandard'));
+
+        // Conditionally launch add index tagcolltype.
+        if (!$dbman->index_exists($table, $index)) {
+            $dbman->add_index($table, $index);
+        }
+
+        // Define field tagtype to be dropped from tag.
+        $field = new xmldb_field('tagtype');
+
+        // Conditionally launch drop field tagtype and update isstandard.
+        if ($dbman->field_exists($table, $field)) {
+            $DB->execute("UPDATE {tag} SET isstandard=(CASE WHEN (tagtype = ?) THEN 1 ELSE 0 END)", array('official'));
+            $dbman->drop_field($table, $field);
+        }
+
+        // Main savepoint reached.
+        upgrade_main_savepoint(true, 2016020200.00);
+    }
+
     return true;
 }
index 21c56f5..6222822 100644 (file)
@@ -2363,7 +2363,7 @@ function coursetag_get_tags($courseid, $userid=0, $tagtype='', $numtags=0, $unus
 
     // get tags from the db ordered by highest count first
     $params = array();
-    $sql = "SELECT id as tkey, name, id, tagtype, rawname, f.timemodified, flag, count
+    $sql = "SELECT id as tkey, name, id, isstandard, rawname, f.timemodified, flag, count
               FROM {tag} t,
                  (SELECT tagid, MAX(timemodified) as timemodified, COUNT(id) as count
                     FROM {tag_instance}
@@ -2388,8 +2388,8 @@ function coursetag_get_tags($courseid, $userid=0, $tagtype='', $numtags=0, $unus
     $sql .= "   GROUP BY tagid) f
              WHERE t.id = f.tagid ";
     if ($tagtype != '') {
-        $sql .= "AND tagtype = :tagtype ";
-        $params['tagtype'] = $tagtype;
+        $sql .= "AND isstandard = :isstandard ";
+        $params['isstandard'] = ($tagtype === 'official') ? 1 : 0;
     }
     $sql .= "ORDER BY count DESC, name ASC";
 
@@ -2430,7 +2430,7 @@ function coursetag_get_all_tags($unused='', $numtags=0) {
     global $CFG, $DB;
 
     // note that this selects all tags except for courses that are not visible
-    $sql = "SELECT id, name, tagtype, rawname, f.timemodified, flag, count
+    $sql = "SELECT id, name, isstandard, rawname, f.timemodified, flag, count
         FROM {tag} t,
         (SELECT tagid, MAX(timemodified) as timemodified, COUNT(id) as count
             FROM {tag_instance} WHERE tagid NOT IN
@@ -2628,7 +2628,7 @@ function coursetag_delete_course_tags($courseid, $showfeedback=false) {
 function tag_type_set($tagid, $type) {
     debugging('Function tag_type_set() is deprecated and can be replaced with use core_tag_tag::get($tagid)->update().', DEBUG_DEVELOPER);
     if ($tag = core_tag_tag::get($tagid, '*')) {
-        return $tag->update(array('tagtype' => $type));
+        return $tag->update(array('isstandard' => ($type === 'official') ? 1 : 0));
     }
     return false;
 }
@@ -2666,8 +2666,9 @@ function tag_description_set($tagid, $description, $descriptionformat) {
 function tag_get_tags($record_type, $record_id, $type=null, $userid=0) {
     debugging('Method tag_get_tags() is deprecated and replaced with core_tag_tag::get_item_tags(). ' .
         'Component is now required when retrieving tag instances.', DEBUG_DEVELOPER);
-    $official = ($type === 'official' ? true : (!empty($type) ? false : null));
-    $tags = core_tag_tag::get_item_tags(null, $record_type, $record_id, $official, $userid);
+    $standardonly = ($type === 'official' ? core_tag_tag::STANDARD_ONLY :
+        (!empty($type) ? core_tag_tag::NOT_STANDARD_ONLY : core_tag_tag::BOTH_STANDARD_AND_NOT));
+    $tags = core_tag_tag::get_item_tags(null, $record_type, $record_id, $standardonly, $userid);
     $rv = array();
     foreach ($tags as $id => $t) {
         $rv[$id] = $t->to_object();
@@ -2688,8 +2689,9 @@ function tag_get_tags($record_type, $record_id, $type=null, $userid=0) {
 function tag_get_tags_array($record_type, $record_id, $type=null) {
     debugging('Method tag_get_tags_array() is deprecated and replaced with core_tag_tag::get_item_tags_array(). ' .
         'Component is now required when retrieving tag instances.', DEBUG_DEVELOPER);
-    $official = ($type === 'official' ? true : (!empty($type) ? false : null));
-    return core_tag_tag::get_item_tags_array('', $record_type, $record_id, $official);
+    $standardonly = ($type === 'official' ? core_tag_tag::STANDARD_ONLY :
+        (!empty($type) ? core_tag_tag::NOT_STANDARD_ONLY : core_tag_tag::BOTH_STANDARD_AND_NOT));
+    return core_tag_tag::get_item_tags_array('', $record_type, $record_id, $standardonly);
 }
 
 /**
@@ -2710,11 +2712,12 @@ function tag_get_tags_csv($record_type, $record_id, $html=null, $type=null) {
     debugging('Method tag_get_tags_csv() is deprecated. Instead you should use either ' .
             'core_tag_tag::get_item_tags_array() or $OUTPUT->tag_list(core_tag_tag::get_item_tags()). ' .
         'Component is now required when retrieving tag instances.', DEBUG_DEVELOPER);
-    $official = ($type === 'official' ? true : (!empty($type) ? false : null));
+    $standardonly = ($type === 'official' ? core_tag_tag::STANDARD_ONLY :
+        (!empty($type) ? core_tag_tag::NOT_STANDARD_ONLY : core_tag_tag::BOTH_STANDARD_AND_NOT));
     if ($html != TAG_RETURN_TEXT) {
-        return $OUTPUT->tag_list(core_tag_tag::get_item_tags('', $record_type, $record_id, $official), '');
+        return $OUTPUT->tag_list(core_tag_tag::get_item_tags('', $record_type, $record_id, $standardonly), '');
     } else {
-        return join(', ', core_tag_tag::get_item_tags_array('', $record_type, $record_id, $official, 0, false));
+        return join(', ', core_tag_tag::get_item_tags_array('', $record_type, $record_id, $standardonly, 0, false));
     }
 }
 
@@ -2856,7 +2859,8 @@ function tag_add($tags, $type="default") {
     if (!is_array($tags)) {
         $tags = array($tags);
     }
-    $objects = core_tag_tag::create_if_missing(core_tag_collection::get_default(), $tags, $type === 'official');
+    $objects = core_tag_tag::create_if_missing(core_tag_collection::get_default(), $tags,
+            $type === 'official');
 
     // New function returns the tags in different format, for BC we keep the format that this function used to have.
     $rv = array();
@@ -3007,7 +3011,7 @@ function tag_print_cloud($tagset=null, $nr_of_tags=150, $return=false, $sort='')
     if (is_null($tagset)) {
         // No tag set received, so fetch tags from database.
         // Always add query by tagcollid even when it's not known to make use of the table index.
-        $tagcloud = core_tag_collection::get_tag_cloud(0, '', $nr_of_tags, $sort);
+        $tagcloud = core_tag_collection::get_tag_cloud(0, false, $nr_of_tags, $sort);
     } else {
         $tagsincloud = $tagset;
 
index 096bbd9..ff2fe68 100644 (file)
@@ -183,7 +183,7 @@ class MoodleQuickForm_tags extends MoodleQuickForm_autocomplete {
         $managelink = '';
         if (has_capability('moodle/tag:manage', context_system::instance()) && $this->showingofficial) {
             $url = new moodle_url('/tag/manage.php', array('tc' => $this->get_tag_collection()));
-            $managelink = ' ' . $OUTPUT->action_link($url, get_string('manageofficialtags', 'tag'));
+            $managelink = ' ' . $OUTPUT->action_link($url, get_string('managestandardtags', 'tag'));
         }
 
         return parent::toHTML() . $managelink;
@@ -214,7 +214,7 @@ class MoodleQuickForm_tags extends MoodleQuickForm_autocomplete {
         }
         $namefield = empty($CFG->keeptagnamecase) ? 'name' : 'rawname';
         $tags = $DB->get_records_menu('tag',
-            array('tagtype' => 'official', 'tagcollid' => $this->get_tag_collection()),
+            array('tagtype' => core_tag_tag::TAGTYPE_OFFICIAL, 'tagcollid' => $this->get_tag_collection()),
             $namefield, 'id,' . $namefield);
         return array_combine($tags, $tags);
     }
index 756b15c..cf191f5 100644 (file)
@@ -843,10 +843,6 @@ EOD;
             $record['name'] = core_text::strtolower($record['name']);
         }
 
-        if (!isset($record['tagtype'])) {
-            $record['tagtype'] = 'default';
-        }
-
         if (!isset($record['tagcollid'])) {
             $record['tagcollid'] = core_tag_collection::get_default();
         }
index 5899b8c..87931c4 100644 (file)
@@ -44,14 +44,14 @@ Feature: Edited wiki pages handle tags correctly
     Then I should see "Cool" in the ".form-autocomplete-selection" "css_element"
     And I press "Cancel"
 
-  Scenario: Wiki page edition of official tags works as expected
+  Scenario: Wiki page edition of standard tags works as expected
     Given I log in as "admin"
     And I expand "Site administration" node
     And I expand "Appearance" node
     And I follow "Manage tags"
     And I follow "Default collection"
     And I set the field "otagsadd" to "OT1, OT2, OT3"
-    And I press "Add official tags"
+    And I press "Add standard tags"
     And I log out
     And I log in as "student1"
     And I follow "Course 1"
index 7debad9..ef80a1a 100644 (file)
@@ -370,7 +370,7 @@ class core_tag_area {
 
         // Find all tags that are related to the tags being moved and make sure they are present in the target tagcoll.
         // This query is a little complicated because Oracle does not allow to run SELECT DISTINCT on CLOB fields.
-        $sql = "SELECT name, rawname, description, descriptionformat, userid, tagtype, flag ".
+        $sql = "SELECT name, rawname, description, descriptionformat, userid, isstandard, flag ".
                 "FROM {tag} WHERE id IN ".
                 "(SELECT r.id ".
                 "FROM {tag_instance} ti ". // Instances that need moving.
@@ -404,7 +404,7 @@ class core_tag_area {
 
         // Find all tags that are used for this itemtype/component and are not present in the target tag collection.
         // This query is a little complicated because Oracle does not allow to run SELECT DISTINCT on CLOB fields.
-        $sql = "SELECT id, name, rawname, description, descriptionformat, userid, tagtype, flag
+        $sql = "SELECT id, name, rawname, description, descriptionformat, userid, isstandard, flag
                 FROM {tag} WHERE id IN
                 (SELECT t.id
                 FROM {tag_instance} ti
index c8be5d2..2e503dd 100644 (file)
@@ -320,7 +320,7 @@ class core_tag_collection {
     }
 
     /**
-     * Permanently deletes all non-official tags that no longer have any instances pointing to them
+     * Permanently deletes all non-standard tags that no longer have any instances pointing to them
      *
      * @param array $collections optional list of tag collections ids to cleanup
      */
@@ -329,9 +329,9 @@ class core_tag_collection {
 
         $params = array();
         $sql = "SELECT tg.id FROM {tag} tg LEFT OUTER JOIN {tag_instance} ti ON ti.tagid = tg.id
-                WHERE ti.id IS NULL AND tg.tagtype = 'default'";
+                WHERE ti.id IS NULL AND tg.isstandard = 0";
         if ($collections) {
-            list($sqlcoll, $params) = $DB->get_in_or_equal($collections);
+            list($sqlcoll, $params) = $DB->get_in_or_equal($collections, SQL_PARAMS_NAMED);
             $sql .= " AND tg.tagcollid " . $sqlcoll;
         }
         if ($unusedtags = $DB->get_fieldset_sql($sql, $params)) {
@@ -343,7 +343,7 @@ class core_tag_collection {
      * Returns the list of tags with number of items tagged
      *
      * @param int $tagcollid
-     * @param string $tagtype possible values 'official', 'default' or empty for any tag type
+     * @param null|bool $isstandard return only standard tags
      * @param int $limit maximum number of tags to retrieve, tags are sorted by the instance count
      *            descending here regardless of $sort parameter
      * @param string $sort sort order for display, default 'name' - tags will be sorted after they are retrieved
@@ -353,7 +353,7 @@ class core_tag_collection {
      * @param int $rec retrieve tag instances in the $ctx context and it's children (default 1)
      * @return \core_tag\output\tagcloud
      */
-    public static function get_tag_cloud($tagcollid, $tagtype = '', $limit = 150, $sort = 'name',
+    public static function get_tag_cloud($tagcollid, $isstandard = false, $limit = 150, $sort = 'name',
             $search = '', $fromctx = 0, $ctx = 0, $rec = 1) {
         global $DB;
 
@@ -362,9 +362,8 @@ class core_tag_collection {
         list($sql, $params) = $DB->get_in_or_equal($tagcollid ? array($tagcollid) :
             array_keys(self::get_collections(true)));
         $whereclause .= ' AND tg.tagcollid ' . $sql;
-        if (!empty($tagtype)) {
-            $whereclause .= ' AND tg.tagtype = ?';
-            $params[] = $tagtype;
+        if ($isstandard) {
+            $whereclause .= ' AND tg.isstandard = 1';
         }
         $context = $ctx ? context::instance_by_id($ctx) : context_system::instance();
         if ($rec && $context->contextlevel != CONTEXT_SYSTEM) {
@@ -380,10 +379,10 @@ class core_tag_collection {
             $params[] = '%' . core_text::strtolower($search) . '%';
         }
         $tagsincloud = $DB->get_records_sql(
-                "SELECT tg.id, tg.rawname, tg.name, tg.tagtype, COUNT(ti.id) AS count, tg.flag, tg.tagcollid
+                "SELECT tg.id, tg.rawname, tg.name, tg.isstandard, COUNT(ti.id) AS count, tg.flag, tg.tagcollid
                 $fromclause
                 $whereclause
-                GROUP BY tg.id, tg.rawname, tg.name, tg.flag, tg.tagtype, tg.tagcollid
+                GROUP BY tg.id, tg.rawname, tg.name, tg.flag, tg.isstandard, tg.tagcollid
                 ORDER BY count DESC, tg.name ASC",
             $params, 0, $limit);
 
index 324ecad..7999c38 100644 (file)
@@ -51,7 +51,9 @@ class core_tag_external extends external_api {
                             'description' => new external_value(PARAM_RAW, 'tag description', VALUE_OPTIONAL),
                             'descriptionformat' => new external_value(PARAM_INT, 'tag description format', VALUE_OPTIONAL),
                             'flag' => new external_value(PARAM_INT, 'flag', VALUE_OPTIONAL),
-                            'official' => new external_value(PARAM_INT, 'whether this flag is official', VALUE_OPTIONAL),
+                            'official' => new external_value(PARAM_INT,
+                                '(deprecated, use isstandard) whether this flag is standard', VALUE_OPTIONAL),
+                            'isstandard' => new external_value(PARAM_INT, 'whether this flag is standard', VALUE_OPTIONAL),
                         )
                     )
                 )
@@ -126,7 +128,8 @@ class core_tag_external extends external_api {
                 }
             }
             if (array_key_exists('official', $tag)) {
-                $tag['tagtype'] = $tag['official'] ? 'official' : 'default';
+                // Parameter 'official' deprecated and replaced with 'isstandard'.
+                $tag['isstandard'] = $tag['official'] ? 1 : 0;
                 unset($tag['official']);
             }
             if (isset($tag['flag'])) {
@@ -217,6 +220,7 @@ class core_tag_external extends external_api {
             $rv = $tagoutput->export_for_template($renderer);
             if (!$canmanage) {
                 if (!$canedit) {
+                    unset($rv->isstandard);
                     unset($rv->official);
                 }
                 unset($rv->flag);
@@ -245,9 +249,11 @@ class core_tag_external extends external_api {
                         'description' => new external_value(PARAM_RAW, 'tag description'),
                         'descriptionformat' => new external_format_value(PARAM_INT, 'tag description format'),
                         'flag' => new external_value(PARAM_INT, 'flag', VALUE_OPTIONAL),
-                        'official' => new external_value(PARAM_INT, 'whether this flag is official', VALUE_OPTIONAL),
+                        'official' => new external_value(PARAM_INT,
+                            'whether this flag is standard (deprecated, use isstandard)', VALUE_OPTIONAL),
+                        'isstandard' => new external_value(PARAM_INT, 'whether this flag is standard', VALUE_OPTIONAL),
                         'viewurl' => new external_value(PARAM_URL, 'URL to view'),
-                        'changetypeurl' => new external_value(PARAM_URL, 'URL to change type (official or not)', VALUE_OPTIONAL),
+                        'changetypeurl' => new external_value(PARAM_URL, 'URL to change type (standard or not)', VALUE_OPTIONAL),
                         'changeflagurl' => new external_value(PARAM_URL, 'URL to set or reset flag', VALUE_OPTIONAL),
                     ), 'information about one tag')
                 ),
index 48af902..dbe15d1 100644 (file)
@@ -57,14 +57,14 @@ class core_tag_manage_table extends table_sql {
         $baseurl = new moodle_url('/tag/manage.php', array('tc' => $tagcollid,
             'perpage' => $perpage, 'page' => $page));
 
-        $tablecolumns = array('select', 'name', 'fullname', 'count', 'flag', 'timemodified', 'tagtype', 'controls');
+        $tablecolumns = array('select', 'name', 'fullname', 'count', 'flag', 'timemodified', 'isstandard', 'controls');
         $tableheaders = array(get_string('select', 'tag'),
                               get_string('name', 'tag'),
                               get_string('owner', 'tag'),
                               get_string('count', 'tag'),
                               get_string('flag', 'tag'),
                               get_string('timemodified', 'tag'),
-                              get_string('officialtag', 'tag'),
+                              get_string('standardtag', 'tag'),
                               '');
 
         $this->define_columns($tablecolumns);
@@ -77,7 +77,7 @@ class core_tag_manage_table extends table_sql {
         $this->column_class('count', 'mdl-align col-count');
         $this->column_class('flag', 'mdl-align col-flag');
         $this->column_class('timemodified', 'col-timemodified');
-        $this->column_class('tagtype', 'mdl-align col-tagtype');
+        $this->column_class('isstandard', 'mdl-align col-isstandard');
         $this->column_class('controls', 'mdl-align col-controls');
 
         $this->sortable(true, 'flag', SORT_DESC);
@@ -143,14 +143,14 @@ class core_tag_manage_table extends table_sql {
 
         $allusernames = get_all_user_name_fields(true, 'u');
         $sql = "
-            SELECT tg.id, tg.name, tg.rawname, tg.tagtype, tg.flag, tg.timemodified,
+            SELECT tg.id, tg.name, tg.rawname, tg.isstandard, tg.flag, tg.timemodified,
                        u.id AS owner, $allusernames,
                        COUNT(ti.id) AS count, tg.tagcollid
             FROM {tag} tg
             LEFT JOIN {tag_instance} ti ON ti.tagid = tg.id
             LEFT JOIN {user} u ON u.id = tg.userid
                        WHERE tagcollid = :tagcollid $where
-            GROUP BY tg.id, tg.name, tg.rawname, tg.tagtype, tg.flag, tg.timemodified,
+            GROUP BY tg.id, tg.name, tg.rawname, tg.isstandard, tg.flag, tg.timemodified,
                        u.id, $allusernames, tg.tagcollid
             ORDER BY $sort";
 
@@ -224,10 +224,10 @@ class core_tag_manage_table extends table_sql {
      * @param stdClass $tag
      * @return string
      */
-    public function col_tagtype($tag) {
+    public function col_isstandard($tag) {
         global $OUTPUT;
         $tagoutput = new core_tag\output\tag($tag);
-        return $OUTPUT->render_from_template('core_tag/tagtype', $tagoutput->export_for_template($OUTPUT));
+        return $OUTPUT->render_from_template('core_tag/tagisstandard', $tagoutput->export_for_template($OUTPUT));
     }
 
     /**
index dd8559f..4016a61 100644 (file)
@@ -29,6 +29,7 @@ use templatable;
 use renderer_base;
 use stdClass;
 use moodle_url;
+use core_tag_tag;
 
 /**
  * Class to help display tag
@@ -39,16 +40,16 @@ use moodle_url;
  */
 class tag implements renderable, templatable {
 
-    /** @var \core_tag_tag|stdClass */
+    /** @var core_tag_tag|stdClass */
     protected $record;
 
     /**
      * Constructor
      *
-     * @param \core_tag_tag|stdClass $tag
+     * @param core_tag_tag|stdClass $tag
      */
     public function __construct($tag) {
-        if ($tag instanceof \core_tag_tag) {
+        if ($tag instanceof core_tag_tag) {
             $this->record = $tag;
             return;
         }
@@ -59,7 +60,7 @@ class tag implements renderable, templatable {
                 'description' => '',
                 'descriptionformat' => FORMAT_HTML,
                 'flag' => 0,
-                'tagtype' => 'default',
+                'isstandard' => 0,
                 'id' => 0,
                 'tagcollid' => 0,
             );
@@ -85,20 +86,19 @@ class tag implements renderable, templatable {
         list($r->description, $r->descriptionformat) = external_format_text($this->record->description,
             $format, \context_system::instance()->id, 'core', 'tag', $r->id);
         $r->flag = clean_param($this->record->flag, PARAM_INT);
-        if (isset($this->record->official)) {
-            $r->official = clean_param($this->record->official, PARAM_INT);
-        } else {
-            $r->official = ($this->record->tagtype === 'official') ? 1 : 0;
+        if (isset($this->record->isstandard)) {
+            $r->isstandard = clean_param($this->record->isstandard, PARAM_INT) ? 1 : 0;
         }
+        $r->official = $r->isstandard; // For backwards compatibility.
 
-        $url = \core_tag_tag::make_url($r->tagcollid, $r->rawname);
+        $url = core_tag_tag::make_url($r->tagcollid, $r->rawname);
         $r->viewurl = $url->out(false);
 
         $manageurl = new moodle_url('/tag/manage.php', array('sesskey' => sesskey(),
             'tagid' => $this->record->id));
         $url = new moodle_url($manageurl);
         $url->param('action', 'changetype');
-        $url->param('tagtype', $r->official ? 'default' : 'official');
+        $url->param('isstandard', $r->isstandard ? 0 : 1);
         $r->changetypeurl = $url->out(false);
 
         $url = new moodle_url($manageurl);
index 85d61ce..bd20da4 100644 (file)
@@ -52,7 +52,7 @@ class tagcloud implements templatable {
      * @param array $tagset array of core_tag or stdClass elements, each of them must have attributes:
      *              name, rawname, tagcollid
      *              preferrably also have attributes:
-     *              tagtype, count, flag
+     *              isstandard, count, flag
      * @param int $totalcount total count of tags (for example to indicate that there are more tags than the count of tagset)
      *            leave 0 if count of tagset is the actual count of tags
      * @param int $fromctx context id where this tag cloud is displayed
@@ -82,8 +82,8 @@ class tagcloud implements templatable {
             $viewurl = core_tag_tag::make_url($tag->tagcollid, $tag->rawname, 0, $fromctx, $ctx, $rec);
             $this->tagset[$idx]->viewurl = $viewurl->out(false);
 
-            if (!empty($tag->tagtype)) {
-                $this->tagset[$idx]->tagtype = $tag->tagtype;
+            if (isset($tag->isstandard)) {
+                $this->tagset[$idx]->isstandard = $tag->isstandard ? 1 : 0;
             }
 
             if (!empty($tag->count)) {
index d0ad198..df821f4 100644 (file)
@@ -84,8 +84,8 @@ class taglist implements templatable {
             $viewurl = core_tag_tag::make_url($tag->tagcollid, $tag->rawname, 0, $fromctx);
             $this->tags[$idx]->viewurl = $viewurl->out(false);
 
-            if (!empty($tag->tagtype)) {
-                $this->tags[$idx]->tagtype = $tag->tagtype;
+            if (isset($tag->isstandard)) {
+                $this->tags[$idx]->isstandard = $tag->isstandard ? 1 : 0;
             }
 
             if ($limit && count($this->tags) > $limit) {
index 3949c5e..f1eae09 100644 (file)
@@ -46,7 +46,7 @@ class core_tag_renderer extends plugin_renderer_base {
         $searchbox = $this->search_form($query, $tagcollid);
         $rv .= html_writer::div($searchbox, '', array('id' => 'tag-search-box'));
 
-        $tagcloud = core_tag_collection::get_tag_cloud($tagcollid, '', 150, 'name', $query);
+        $tagcloud = core_tag_collection::get_tag_cloud($tagcollid, false, 150, 'name', $query);
         $searchresults = '';
         if ($tagcloud->get_count()) {
             $searchresults = $this->output->render_from_template('core_tag/tagcloud',
index 48896c0..909e236 100644 (file)
@@ -47,7 +47,7 @@ defined('MOODLE_INTERNAL') || die();
  * @property-read string $rawname
  * @property-read int $tagcollid
  * @property-read int $userid
- * @property-read string $tagtype "official" or "default"
+ * @property-read int $isstandard
  * @property-read string $description
  * @property-read int $descriptionformat
  * @property-read int $flag 0 if not flagged or positive integer if flagged
@@ -62,6 +62,18 @@ class core_tag_tag {
     /** @var stdClass data about the tag */
     protected $record = null;
 
+    /** @var int indicates that both standard and not standard tags can be used (or should be returned) */
+    const BOTH_STANDARD_AND_NOT = 0;
+
+    /** @var int indicates that only standard tags can be used (or must be returned) */
+    const STANDARD_ONLY = 1;
+
+    /** @var int indicates that only non-standard tags should be returned - this does not really have use cases, left for BC  */
+    const NOT_STANDARD_ONLY = -1;
+
+    /** @var int option to hide standard tags when editing item tags */
+    const HIDE_STANDARD = 2;
+
     /**
      * Constructor. Use functions get(), get_by_name(), etc.
      *
@@ -143,15 +155,15 @@ class core_tag_tag {
      *
      * @param   int      $tagcollid
      * @param   string|array $tags     one tag, or an array of tags, to be created
-     * @param   bool     $isofficial type of tag to be created. An official tag is kept even if there are no records tagged with it.
+     * @param   bool     $isstandard type of tag to be created. A standard tag is kept even if there are no records tagged with it.
      * @return  array    tag objects indexed by their lowercase normalized names. Any boolean false in the array
      *                             indicates an error while adding the tag.
      */
-    protected static function add($tagcollid, $tags, $isofficial = false) {
+    protected static function add($tagcollid, $tags, $isstandard = false) {
         global $USER, $DB;
 
         $tagobject = new stdClass();
-        $tagobject->tagtype      = $isofficial ? 'official' : 'default';
+        $tagobject->isstandard   = $isstandard ? 1 : 0;
         $tagobject->userid       = $USER->id;
         $tagobject->timemodified = time();
         $tagobject->tagcollid    = $tagcollid;
@@ -319,17 +331,17 @@ class core_tag_tag {
      *
      * @param int $tagcollid
      * @param array $tags array of raw tag names, do not have to be normalised
-     * @param bool $createasofficial
+     * @param bool $isstandard create as standard tag (default false)
      * @return core_tag_tag[] array of tag objects indexed with lowercase normalised tag name
      */
-    public static function create_if_missing($tagcollid, $tags, $createasofficial = false) {
+    public static function create_if_missing($tagcollid, $tags, $isstandard = false) {
         $cleantags = self::normalize(array_filter(self::normalize($tags, false))); // Array rawname => normalised name .
 
         $result = static::get_by_name_bulk($tagcollid, $tags, '*');
         $existing = array_filter($result);
         $missing = array_diff_key(array_flip($cleantags), $existing); // Array normalised name => rawname.
         if ($missing) {
-            $newtags = static::add($tagcollid, array_values($missing), $createasofficial);
+            $newtags = static::add($tagcollid, array_values($missing), $isstandard);
             foreach ($newtags as $tag) {
                 $result[$tag->name] = $tag;
             }
@@ -412,7 +424,7 @@ class core_tag_tag {
     protected function delete_instance_as_record($taginstance, $fullobject = false) {
         global $DB;
 
-        $this->ensure_fields_exist(array('name', 'rawname', 'tagtype'), 'delete_instance_as_record');
+        $this->ensure_fields_exist(array('name', 'rawname', 'isstandard'), 'delete_instance_as_record');
 
         $DB->delete_records('tag_instance', array('id' => $taginstance->id));
 
@@ -426,7 +438,7 @@ class core_tag_tag {
         \core\event\tag_removed::create_from_tag_instance($taginstance, $this->name, $this->rawname, $fullobject)->trigger();
 
         // If there are no other instances of the tag then consider deleting the tag as well.
-        if ($this->tagtype === 'default') {
+        if (!$this->isstandard) {
             if (!$DB->record_exists('tag_instance', array('tagid' => $this->id))) {
                 self::delete_tags($this->id);
             }
@@ -436,7 +448,7 @@ class core_tag_tag {
     }
 
     /**
-     * Delete one instance of a tag.  If the last instance was deleted, it will also delete the tag, unless its type is 'official'.
+     * Delete one instance of a tag.  If the last instance was deleted, it will also delete the tag, unless it is standard.
      *
      * @param    string $component component responsible for tagging. For BC it can be empty but in this case the
      *                  query will be slow because DB index will not be used.
@@ -472,7 +484,7 @@ class core_tag_tag {
     public static function delete_instances($component, $itemtype = null, $contextid = null) {
         global $DB;
 
-        $sql = "SELECT ti.*, t.name, t.rawname, t.tagtype
+        $sql = "SELECT ti.*, t.name, t.rawname, t.isstandard
                   FROM {tag_instance} ti
                   JOIN {tag} t
                     ON ti.tagid = t.id
@@ -564,11 +576,12 @@ class core_tag_tag {
      *               query will be slow because DB index will not be used.
      * @param string $itemtype type of the tagged item
      * @param int $itemid
-     * @param null|bool $official - true - official only, false - non official only, null - any (default)
+     * @param int $standardonly wether to return only standard tags or any
      * @param int $tiuserid tag instance user id, only needed for tag areas with user tagging
      * @return core_tag_tag[] each object contains additional fields taginstanceid, taginstancecontextid and ordering
      */
-    public static function get_item_tags($component, $itemtype, $itemid, $official = null, $tiuserid = 0) {
+    public static function get_item_tags($component, $itemtype, $itemid, $standardonly = self::BOTH_STANDARD_AND_NOT,
+            $tiuserid = 0) {
         global $DB;
 
         if (static::is_enabled($component, $itemtype) === false) {
@@ -576,23 +589,24 @@ class core_tag_tag {
             return array();
         }
 
+        $standardonly = (int)$standardonly; // In case somebody passed bool.
+
         // Note: if the fields in this query are changed, you need to do the same changes in tag_get_correlated().
-        $sql = "SELECT ti.id AS taginstanceid, tg.id, tg.tagtype, tg.name, tg.rawname, tg.flag,
+        $sql = "SELECT ti.id AS taginstanceid, tg.id, tg.isstandard, tg.name, tg.rawname, tg.flag,
                     tg.tagcollid, ti.ordering, ti.contextid AS taginstancecontextid
                   FROM {tag_instance} ti
                   JOIN {tag} tg ON tg.id = ti.tagid
                   WHERE ti.itemtype = :itemtype AND ti.itemid = :itemid ".
                 ($component ? "AND ti.component = :component " : "").
                 ($tiuserid ? "AND ti.tiuserid = :tiuserid " : "").
-                (($official === true) ? "AND tg.tagtype = :official " : "").
-                (($official === false) ? "AND tg.tagtype <> :official " : "").
+                (($standardonly == self::STANDARD_ONLY) ? "AND tg.isstandard = 1 " : "").
+                (($standardonly == self::NOT_STANDARD_ONLY) ? "AND tg.isstandard = 0 " : "").
                "ORDER BY ti.ordering ASC, ti.id";
 
         $params = array();
         $params['itemtype'] = $itemtype;
         $params['itemid'] = $itemid;
         $params['component'] = $component;
-        $params['official'] = 'official';
         $params['tiuserid'] = $tiuserid;
 
         $records = $DB->get_records_sql($sql, $params);
@@ -612,14 +626,15 @@ class core_tag_tag {
      *               query will be slow because DB index will not be used.
      * @param string $itemtype type of the tagged item
      * @param int $itemid
-     * @param null|bool $official - true - official only, false - non official only, null - any (default)
+     * @param int $standardonly wether to return only standard tags or any
      * @param int $tiuserid tag instance user id, only needed for tag areas with user tagging
      * @param bool $ashtml (default true) if true will return htmlspecialchars encoded tag names
      * @return string[] array of tags display names
      */
-    public static function get_item_tags_array($component, $itemtype, $itemid, $official = null, $tiuserid = 0, $ashtml = true) {
+    public static function get_item_tags_array($component, $itemtype, $itemid, $standardonly = self::BOTH_STANDARD_AND_NOT,
+            $tiuserid = 0, $ashtml = true) {
         $tags = array();
-        foreach (static::get_item_tags($component, $itemtype, $itemid, $official, $tiuserid) as $tag) {
+        foreach (static::get_item_tags($component, $itemtype, $itemid, $standardonly, $tiuserid) as $tag) {
             $tags[$tag->id] = $tag->get_display_name($ashtml);
         }
         return $tags;
@@ -663,7 +678,7 @@ class core_tag_tag {
             $tagobjects = array();
         }
 
-        $currenttags = static::get_item_tags($component, $itemtype, $itemid, null, $tiuserid);
+        $currenttags = static::get_item_tags($component, $itemtype, $itemid, self::BOTH_STANDARD_AND_NOT, $tiuserid);
 
         // For data coherence reasons, it's better to remove deleted tags
         // before adding new data: ordering could be duplicated.
@@ -855,14 +870,14 @@ class core_tag_tag {
     /**
      * Updates the information about the tag
      *
-     * @param array|stdClass $data data to update, may contain: tagtype, description, descriptionformat, rawname
+     * @param array|stdClass $data data to update, may contain: isstandard, description, descriptionformat, rawname
      * @return bool whether the tag was updated. False may be returned if: all new values match the existing,
-     *         or an invalid tagtype was supplied, or it was attempted to rename the tag to the name that is already used.
+     *         or it was attempted to rename the tag to the name that is already used.
      */
     public function update($data) {
         global $DB, $COURSE;
 
-        $allowedfields = array('tagtype', 'description', 'descriptionformat', 'rawname');
+        $allowedfields = array('isstandard', 'description', 'descriptionformat', 'rawname');
 
         $data = (array)$data;
         if ($extrafields = array_diff(array_keys($data), $allowedfields)) {
@@ -893,9 +908,8 @@ class core_tag_tag {
         }
 
         // Validate the tag type.
-        if (array_key_exists('tagtype', $data) && $data['tagtype'] !== 'official' && $data['tagtype'] !== 'default') {
-            debugging('Unrecognised tag type "'.$data['tagtype'].'" ignored when updating the tag', DEBUG_DEVELOPER);
-            unset($data['tagtype']);
+        if (array_key_exists('isstandard', $data)) {
+            $data['isstandard'] = $data['isstandard'] ? 1 : 0;
         }
 
         // Find only the attributes that need to be changed.
@@ -1075,7 +1089,7 @@ class core_tag_tag {
         list($query, $params) = $DB->get_in_or_equal($correlated);
 
         // This is (and has to) return the same fields as the query in core_tag_tag::get_item_tags().
-        $sql = "SELECT ti.id AS taginstanceid, tg.id, tg.tagtype, tg.name, tg.rawname, tg.flag,
+        $sql = "SELECT ti.id AS taginstanceid, tg.id, tg.isstandard, tg.name, tg.rawname, tg.flag,
                 tg.tagcollid, ti.ordering, ti.contextid AS taginstancecontextid
               FROM {tag} tg
         INNER JOIN {tag_instance} ti ON tg.id = ti.tagid
index a308757..cbd5313 100644 (file)
@@ -97,7 +97,6 @@ $editoroptions = array(
 $data = file_prepare_standard_editor($data, 'description', $editoroptions, $systemcontext, 'tag', 'description', $data->id);
 
 $tagform = new tag_edit_form(null, array('editoroptions' => $editoroptions, 'tag' => $tag));
-$data->tagtype = ($data->tagtype === 'official') ? '1' : '0';
 $data->returnurl = $returnurl;
 
 $tagform->set_data($data);
@@ -109,7 +108,7 @@ if ($tagform->is_cancelled()) {
     $updatedata = array();
 
     if (has_capability('moodle/tag:manage', $systemcontext)) {
-        $updatedata['tagtype'] = empty($tagnew->tagtype) ? 'default' : 'official';
+        $updatedata['isstandard'] = empty($tagnew->isstandard) ? 0 : 1;
         $updatedata['rawname'] = $tagnew->rawname;
     }
 
@@ -118,7 +117,7 @@ if ($tagform->is_cancelled()) {
     $updatedata['description'] = $tagnew->description;
     $updatedata['descriptionformat'] = $tagnew->descriptionformat;
 
-    // Update name, description and official type.
+    // Update name, description and whether it is a standard tag.
     $tag->update($updatedata);
 
     // Updated related tags.
index ef2fc8a..d381d79 100644 (file)
@@ -65,7 +65,7 @@ class tag_edit_form extends moodleform {
         $mform->addElement('editor', 'description_editor', get_string('description', 'tag'), null, $this->_customdata['editoroptions']);
 
         if (has_capability('moodle/tag:manage', $systemcontext)) {
-           $mform->addElement('checkbox', 'tagtype', get_string('officialtag', 'tag'));
+            $mform->addElement('checkbox', 'isstandard', get_string('standardtag', 'tag'));
         }
 
         $mform->addElement('tags', 'relatedtags', get_string('relatedtags', 'tag'),
index 3deb5c4..6a00dde 100644 (file)
@@ -32,7 +32,7 @@ define('DEFAULT_PAGE_SIZE', 30);
 
 $tagschecked = optional_param_array('tagschecked', array(), PARAM_INT);
 $tagid       = optional_param('tagid', null, PARAM_INT);
-$tagtype     = optional_param('tagtype', null, PARAM_ALPHA);
+$isstandard  = optional_param('isstandard', null, PARAM_INT);
 $action      = optional_param('action', '', PARAM_ALPHA);
 $perpage     = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT);
 $page        = optional_param('page', 0, PARAM_INT);
@@ -189,13 +189,14 @@ switch($action) {
 
     case 'changetype':
         require_sesskey();
-        if ($tagid && $tagobject->update(array('tagtype' => $tagtype))) {
+        if ($tagid && $tagobject->update(
+                array('isstandard' => $isstandard ? 1 : 0))) {
             redirect(new moodle_url($PAGE->url, array('notice' => 'typechanged')));
         }
         redirect($PAGE->url);
         break;
 
-    case 'addofficialtag':
+    case 'addstandardtag':
         require_sesskey();
         $tagobjects = null;
         if ($tagcoll) {
@@ -204,8 +205,8 @@ switch($action) {
             $tagobjects = core_tag_tag::create_if_missing($tagcoll->id, $newtags, true);
         }
         foreach ($tagobjects as $tagobject) {
-            if ($tagobject->tagtype !== 'official') {
-                $tagobject->update(array('tagtype' => 'official'));
+            if (!$tagobject->isstandard) {
+                $tagobject->update(array('isstandard' => 1));
             }
         }
         redirect(new moodle_url($PAGE->url, $tagobjects ? array('notice' => 'added') : null));
@@ -237,10 +238,10 @@ if (!$tagcoll) {
 
 // Tag collection is specified. Manage tags in this collection.
 
-// Small form to add an official tag.
+// Small form to add an standard tag.
 print('<form class="tag-addtags-form" method="post" action="'.$CFG->wwwroot.'/tag/manage.php">');
 print('<input type="hidden" name="tc" value="'.$tagcollid.'" />');
-print('<input type="hidden" name="action" value="addofficialtag" />');
+print('<input type="hidden" name="action" value="addstandardtag" />');
 print('<input type="hidden" name="perpage" value="'.$perpage.'" />');
 print('<input type="hidden" name="page" value="'.$page.'" />');
 print('<div class="tag-management-form generalbox"><label class="accesshide" for="id_otagsadd">' .
index 82b9c2f..b1e86ba 100644 (file)
@@ -31,9 +31,9 @@
     Example context (json):
     {
     "tags": [
-        {"id":1,"name":"Cats","viewurl":"http://moodle.org/tag/index.php?tag=Cats","tagtype":"official","count":12,"size":20,"flag":0},
-        {"id":1,"name":"Dogs","viewurl":"http://moodle.org/tag/index.php?tag=Dogs","tagtype":"default","size":2,"flag":1},
-        {"id":1,"name":"Mice","viewurl":"http://moodle.org/tag/index.php?tag=Mice","tagtype":"default","count":4,"size":8,"flag":0}
+        {"id":1,"name":"Cats","viewurl":"http://moodle.org/tag/index.php?tag=Cats","isstandard":"1","count":12,"size":20,"flag":0},
+        {"id":1,"name":"Dogs","viewurl":"http://moodle.org/tag/index.php?tag=Dogs","isstandard":"0","size":2,"flag":1},
+        {"id":1,"name":"Mice","viewurl":"http://moodle.org/tag/index.php?tag=Mice","isstandard":"0","count":4,"size":8,"flag":0}
     ],
         "tagscount": 3,
         "totalcount": 5,
@@ -46,7 +46,7 @@
     <ul class="inline-list">
         {{#tags}}
             <li>
-                <a href="{{viewurl}}" class="{{tagtype}} s{{size}}"
+                <a href="{{viewurl}}" class="{{#isstandard}}standardtag{{/isstandard}} s{{size}}"
                     {{#count}}title="{{#str}}numberofentries, blog, {{count}}{{/str}}{{/count}}">
                         {{#flag}}
                             <span class="flagged-tag">{{name}}</span></a>
similarity index 66%
rename from tag/templates/tagtype.mustache
rename to tag/templates/tagisstandard.mustache
index eeae6a1..4deb8f0 100644 (file)
     along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 }}
 {{!
-    @template core_tag/tagtype
+    @template core_tag/tagisstandard
 
-    Displays the tag type (official or not) in the tag management table
+    Displays the tag type (standard or not) in the tag management table
 
     Classes required for JS:
-    * tagtype
+    * tagisstandard
 
     Data attributes required for JS:
     * data-id, data-value
     Example context (json):
     {
         "id" : "1",
-        "official" : "1",
+        "isstandard" : "1",
         "changetypeurl" : "http://moodle.com/"
     }
 }}
-{{#official}}
-<a href="{{changetypeurl}}" class="tagtype" data-id="{{id}}" data-value="1" title="{{#str}}settypedefault,core_tag{{/str}}">
+{{#isstandard}}
+<a href="{{changetypeurl}}" class="tagisstandard" data-id="{{id}}" data-value="1" title="{{#str}}settypedefault,core_tag{{/str}}">
     {{#pix}}i/checked,core,{{#str}}settypedefault,core_tag{{/str}}{{/pix}}
 </a>
-{{/official}}
-{{^official}}
-<a href="{{changetypeurl}}" class="tagtype" data-id="{{id}}" data-value="0" title="{{#str}}settypeofficial,core_tag{{/str}}">
-    {{#pix}}i/unchecked,core,{{#str}}settypeofficial,core_tag{{/str}}{{/pix}}
+{{/isstandard}}
+{{^isstandard}}
+<a href="{{changetypeurl}}" class="tagisstandard" data-id="{{id}}" data-value="0" title="{{#str}}settypestandard,core_tag{{/str}}">
+    {{#pix}}i/unchecked,core,{{#str}}settypestandard,core_tag{{/str}}{{/pix}}
 </a>
-{{/official}}
+{{/isstandard}}
index 7353296..746318a 100644 (file)
@@ -33,9 +33,9 @@
     Example context (json):
     {
     "tags": [
-        {"id":1,"name":"Cats","viewurl":"http://moodle.org/tag/index.php?tag=Cats","tagtype":"official","flag":0},
-        {"id":1,"name":"Dogs","viewurl":"http://moodle.org/tag/index.php?tag=Dogs","tagtype":"default","flag":1},
-        {"id":1,"name":"Mice","viewurl":"http://moodle.org/tag/index.php?tag=Mice","tagtype":"default","flag":0}
+        {"id":1,"name":"Cats","viewurl":"http://moodle.org/tag/index.php?tag=Cats","isstandard":"1","flag":0},
+        {"id":1,"name":"Dogs","viewurl":"http://moodle.org/tag/index.php?tag=Dogs","isstandard":"0","flag":1},
+        {"id":1,"name":"Mice","viewurl":"http://moodle.org/tag/index.php?tag=Mice","isstandard":"0","flag":0}
     ],
         "label": "Tags",
         "tagscount": 3,
@@ -52,7 +52,7 @@
     <ul class="inline-list">
         {{#tags}}
             <li {{#overlimit}}class="overlimit"{{/overlimit}}>
-                <a href="{{viewurl}}" class="label label-info {{tagtype}}" >
+                <a href="{{viewurl}}" class="label label-info {{#isstandard}}standardtag{{/isstandard}}" >
                 {{#flag}}
                     <span class="flagged-tag">{{name}}</span></a>
                 {{/flag}}
index f06b778..4a4275b 100644 (file)
@@ -13,11 +13,11 @@ Feature: Managers can create and manage tag collections
       | user     | course               | role    |
       | manager1 | Acceptance test site | manager |
     And the following "tags" exist:
-      | name | tagtype  |
-      | Tag0 | official  |
-      | Tag1 | official  |
-      | Tag2 | official  |
-      | Tag3 | official |
+      | name | isstandard |
+      | Tag0 | 1          |
+      | Tag1 | 1          |
+      | Tag2 | 1          |
+      | Tag3 | 1          |
     And I log in as "manager1"
     And I navigate to "Manage tags" node in "Site administration > Appearance"
     And I follow "Add tag collection"
@@ -104,9 +104,9 @@ Feature: Managers can create and manage tag collections
     And I should not see "Tag2"
     And I follow "Manage tags"
     And I follow "Default collection"
-    # Tag "Swimming" was not official and was moved completely.
+    # Tag "Swimming" was not standard and was moved completely.
     And I should not see "Swimming"
-    # Official tag was not removed.
+    # Standard tag was not removed.
     And I should see "Tag0"
     And I should see "Tag3"
     And I should see "Tag1"
index bb8d722..bda3dc4 100644 (file)
@@ -13,8 +13,8 @@ Feature: Manager is able to delete tags
       | user     | course               | role      |
       | manager1 | Acceptance test site | manager   |
     And the following "tags" exist:
-      | name         | tagtype  |
-      | Neverusedtag | official |
+      | name         | isstandard |
+      | Neverusedtag | 1          |
 
   Scenario: Deleting a tag with javascript disabled
     When I log in as "manager1"
index ea52601..4c84dae 100644 (file)
@@ -18,8 +18,8 @@ Feature: Users can edit tags to add description or rename
       | manager1 | Acceptance test site | manager   |
       | editor1  | Acceptance test site | tageditor |
     And the following "tags" exist:
-      | name         | tagtype  |
-      | Neverusedtag | official |
+      | name         | isstandard |
+      | Neverusedtag | 1          |
 
   @javascript
   Scenario: User with tag editing capability can change tag description
@@ -36,7 +36,7 @@ Feature: Users can edit tags to add description or rename
     And I follow "Cat"
     And I follow "Edit this tag"
     And I should not see "Tag name"
-    And I should not see "Official"
+    And I should not see "Standard"
     And I set the following fields to these values:
       | Description | Description of tag 1 |
       | Related tags | Dog,  Turtle,Fish |
@@ -60,7 +60,7 @@ Feature: Users can edit tags to add description or rename
       | Tag name | Kitten |
       | Description | Description of tag 1 |
       | Related tags | Dog,  Turtle,Fish |
-      | Official | 0 |
+      | Standard | 0 |
     And I press "Update"
     Then "Kitten" "text" should exist in the ".breadcrumb-nav" "css_element"
     And "Description of tag 1" "text" should exist in the ".tag-description" "css_element"
@@ -110,7 +110,7 @@ Feature: Users can edit tags to add description or rename
       | Tag name | Kitten |
       | Description | Description of tag 1 |
       | Related tags | Dog,  Turtle,Fish |
-      | Official | 0 |
+      | Standard | 0 |
     And I press "Update"
     Then "Default collection" "link" should exist in the ".breadcrumb-nav" "css_element"
     And I follow "Kitten"
index fcd0365..966abee 100644 (file)
@@ -15,8 +15,8 @@ Feature: Users can flag tags and manager can reset flags
       | user     | course               | role    |
       | manager1 | Acceptance test site | manager |
     And the following "tags" exist:
-      | name         | tagtype  |
-      | Neverusedtag | official |
+      | name         | isstandard |
+      | Neverusedtag | 1          |
     And I log in as "admin"
     And I set the following system permissions of "Authenticated user" role:
       | capability                   | permission |
diff --git a/tag/tests/behat/official_tags.feature b/tag/tests/behat/official_tags.feature
deleted file mode 100644 (file)
index cfa9a71..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-@core @core_tag
-Feature: Manager can add official tags and change the tag type of existing tags
-  In order to use tags
-  As a manage
-  I need to be able to change tag type
-
-  Background:
-    Given the following "users" exist:
-      | username | firstname | lastname | email                |
-      | manager1 | Manager   | 1        | manager1@example.com |
-      | user1    | User      | 1        | user1@example.com    |
-    And the following "system role assigns" exist:
-      | user     | course               | role    |
-      | manager1 | Acceptance test site | manager |
-    And the following "tags" exist:
-      | name | tagtype  |
-      | Tag0 | default  |
-      | Tag1 | default  |
-      | Tag2 | default  |
-      | Tag3 | official |
-
-  Scenario: Adding official tags
-    When I log in as "manager1"
-    And I navigate to "Manage tags" node in "Site administration > Appearance"
-    And I follow "Default collection"
-    Then "Make official" "link" should exist in the "Tag0" "table_row"
-    And "Make official" "link" should exist in the "Tag1" "table_row"
-    And "Make official" "link" should exist in the "Tag2" "table_row"
-    And "Remove from official tags" "link" should exist in the "Tag3" "table_row"
-    And I set the following fields to these values:
-      | Add official tags | Tag1,TAG2,Tag3,Tag4,Tag5 |
-    And I press "Add official tags"
-    And I should see "Official tag(s) added"
-    # No changes to Tag0
-    And "Make official" "link" should exist in the "Tag0" "table_row"
-    # Tag1 was already present, now it is official
-    And "Remove from official" "link" should exist in the "Tag1" "table_row"
-    # Tag2 was already present, now it is official. It was not renamed to TAG2
-    And "Remove from official" "link" should exist in the "Tag2" "table_row"
-    And I should not see "TAG2"
-    # Tag3 was already present and it already was official
-    And "Remove from official tags" "link" should exist in the "Tag3" "table_row"
-    # Tag4 and Tag5 were added as official
-    And "Remove from official tags" "link" should exist in the "Tag4" "table_row"
-    And "Remove from official tags" "link" should exist in the "Tag5" "table_row"
-    And I log out
-
-  Scenario: Changing tag type with javascript disabled
-    When I log in as "manager1"
-    And I navigate to "Manage tags" node in "Site administration > Appearance"
-    And I follow "Default collection"
-    And I click on "Make official" "link" in the "Tag0" "table_row"
-    And I should see "Tag type changed"
-    And I click on "Make official" "link" in the "Tag1" "table_row"
-    And I should see "Tag type changed"
-    And I click on "Remove from official tags" "link" in the "Tag0" "table_row"
-    And I should see "Tag type changed"
-    And I click on "Remove from official tags" "link" in the "Tag3" "table_row"
-    And I should see "Tag type changed"
-    Then "Make official" "link" should exist in the "Tag0" "table_row"
-    And "Remove from official tags" "link" should exist in the "Tag1" "table_row"
-    And "Make official" "link" should exist in the "Tag2" "table_row"
-    And "Make official" "link" should exist in the "Tag3" "table_row"
-    And I log out
-
-  @javascript
-  Scenario: Changing tag type with javascript enabled
-    When I log in as "manager1"
-    And I navigate to "Manage tags" node in "Site administration > Appearance"
-    And I follow "Default collection"
-    And I click on "Make official" "link" in the "Tag0" "table_row"
-    And I click on "Make official" "link" in the "Tag1" "table_row"
-    And I wait until "//tr[contains(.,'Tag0')]//a[contains(@title,'Remove from official tags')]" "xpath_element" exists
-    And I wait until "//tr[contains(.,'Tag1')]//a[contains(@title,'Remove from official tags')]" "xpath_element" exists
-    And I click on "Remove from official tags" "link" in the "Tag0" "table_row"
-    And I click on "Remove from official tags" "link" in the "Tag3" "table_row"
-    And I wait until "//tr[contains(.,'Tag0')]//a[contains(@title,'Make official')]" "xpath_element" exists
-    And I wait until "//tr[contains(.,'Tag3')]//a[contains(@title,'Make official')]" "xpath_element" exists
-    Then "Make official" "link" should exist in the "Tag0" "table_row"
-    And "Remove from official tags" "link" should exist in the "Tag1" "table_row"
-    And "Make official" "link" should exist in the "Tag2" "table_row"
-    And "Make official" "link" should exist in the "Tag3" "table_row"
-    And I follow "Default collection"
-    And "Make official" "link" should exist in the "Tag0" "table_row"
-    And "Remove from official tags" "link" should exist in the "Tag1" "table_row"
-    And "Make official" "link" should exist in the "Tag2" "table_row"
-    And "Make official" "link" should exist in the "Tag3" "table_row"
-    And I log out
-
-  Scenario: Changing tag type in edit form
-    When I log in as "manager1"
-    And I navigate to "Manage tags" node in "Site administration > Appearance"
-    And I follow "Default collection"
-    And I click on "Edit this tag" "link" in the "Tag1" "table_row"
-    And I set the following fields to these values:
-      | Official | 1 |
-    And I press "Update"
-    Then "Remove from official tags" "link" should exist in the "Tag1" "table_row"
-    And I click on "Edit this tag" "link" in the "Tag1" "table_row"
-    And I set the following fields to these values:
-      | Official | 0 |
-    And I press "Update"
-    And "Make official" "link" should exist in the "Tag1" "table_row"
-    And I log out
diff --git a/tag/tests/behat/standard_tags.feature b/tag/tests/behat/standard_tags.feature
new file mode 100644 (file)
index 0000000..b5a27e6
--- /dev/null
@@ -0,0 +1,104 @@
+@core @core_tag
+Feature: Manager can add standard tags and change the tag type of existing tags
+  In order to use tags
+  As a manage
+  I need to be able to change tag type
+
+  Background:
+    Given the following "users" exist:
+      | username | firstname | lastname | email                |
+      | manager1 | Manager   | 1        | manager1@example.com |
+      | user1    | User      | 1        | user1@example.com    |
+    And the following "system role assigns" exist:
+      | user     | course               | role    |
+      | manager1 | Acceptance test site | manager |
+    And the following "tags" exist:
+      | name | isstandard |
+      | Tag0 | 0          |
+      | Tag1 | 0          |
+      | Tag2 | 0          |
+      | Tag3 | 1          |
+
+  Scenario: Adding standard tags
+    When I log in as "manager1"
+    And I navigate to "Manage tags" node in "Site administration > Appearance"
+    And I follow "Default collection"
+    Then "Make standard" "link" should exist in the "Tag0" "table_row"
+    And "Make standard" "link" should exist in the "Tag1" "table_row"
+    And "Make standard" "link" should exist in the "Tag2" "table_row"
+    And "Remove from standard tags" "link" should exist in the "Tag3" "table_row"
+    And I set the following fields to these values:
+      | Add standard tags | Tag1,TAG2,Tag3,Tag4,Tag5 |
+    And I press "Add standard tags"
+    And I should see "Standard tag(s) added"
+    # No changes to Tag0
+    And "Make standard" "link" should exist in the "Tag0" "table_row"
+    # Tag1 was already present, now it is standard
+    And "Remove from standard" "link" should exist in the "Tag1" "table_row"
+    # Tag2 was already present, now it is standard. It was not renamed to TAG2
+    And "Remove from standard" "link" should exist in the "Tag2" "table_row"
+    And I should not see "TAG2"
+    # Tag3 was already present and it already was standard
+    And "Remove from standard tags" "link" should exist in the "Tag3" "table_row"
+    # Tag4 and Tag5 were added as standard
+    And "Remove from standard tags" "link" should exist in the "Tag4" "table_row"
+    And "Remove from standard tags" "link" should exist in the "Tag5" "table_row"
+    And I log out
+
+  Scenario: Changing tag type with javascript disabled
+    When I log in as "manager1"
+    And I navigate to "Manage tags" node in "Site administration > Appearance"
+    And I follow "Default collection"
+    And I click on "Make standard" "link" in the "Tag0" "table_row"
+    And I should see "Tag type changed"
+    And I click on "Make standard" "link" in the "Tag1" "table_row"
+    And I should see "Tag type changed"
+    And I click on "Remove from standard tags" "link" in the "Tag0" "table_row"
+    And I should see "Tag type changed"
+    And I click on "Remove from standard tags" "link" in the "Tag3" "table_row"
+    And I should see "Tag type changed"
+    Then "Make standard" "link" should exist in the "Tag0" "table_row"
+    And "Remove from standard tags" "link" should exist in the "Tag1" "table_row"
+    And "Make standard" "link" should exist in the "Tag2" "table_row"
+    And "Make standard" "link" should exist in the "Tag3" "table_row"
+    And I log out
+
+  @javascript
+  Scenario: Changing tag type with javascript enabled
+    When I log in as "manager1"
+    And I navigate to "Manage tags" node in "Site administration > Appearance"
+    And I follow "Default collection"
+    And I click on "Make standard" "link" in the "Tag0" "table_row"
+    And I click on "Make standard" "link" in the "Tag1" "table_row"
+    And I wait until "//tr[contains(.,'Tag0')]//a[contains(@title,'Remove from standard tags')]" "xpath_element" exists
+    And I wait until "//tr[contains(.,'Tag1')]//a[contains(@title,'Remove from standard tags')]" "xpath_element" exists
+    And I click on "Remove from standard tags" "link" in the "Tag0" "table_row"
+    And I click on "Remove from standard tags" "link" in the "Tag3" "table_row"
+    And I wait until "//tr[contains(.,'Tag0')]//a[contains(@title,'Make standard')]" "xpath_element" exists
+    And I wait until "//tr[contains(.,'Tag3')]//a[contains(@title,'Make standard')]" "xpath_element" exists
+    Then "Make standard" "link" should exist in the "Tag0" "table_row"
+    And "Remove from standard tags" "link" should exist in the "Tag1" "table_row"
+    And "Make standard" "link" should exist in the "Tag2" "table_row"
+    And "Make standard" "link" should exist in the "Tag3" "table_row"
+    And I follow "Default collection"
+    And "Make standard" "link" should exist in the "Tag0" "table_row"
+    And "Remove from standard tags" "link" should exist in the "Tag1" "table_row"
+    And "Make standard" "link" should exist in the "Tag2" "table_row"
+    And "Make standard" "link" should exist in the "Tag3" "table_row"
+    And I log out
+
+  Scenario: Changing tag type in edit form
+    When I log in as "manager1"
+    And I navigate to "Manage tags" node in "Site administration > Appearance"
+    And I follow "Default collection"
+    And I click on "Edit this tag" "link" in the "Tag1" "table_row"
+    And I set the following fields to these values:
+      | Standard | 1 |
+    And I press "Update"
+    Then "Remove from standard tags" "link" should exist in the "Tag1" "table_row"
+    And I click on "Edit this tag" "link" in the "Tag1" "table_row"
+    And I set the following fields to these values:
+      | Standard | 0 |
+    And I press "Update"
+    And "Make standard" "link" should exist in the "Tag1" "table_row"
+    And I log out
index b24ed4b..e3a26ba 100644 (file)
@@ -40,7 +40,7 @@ class core_tag_external_testcase extends externallib_advanced_testcase {
         $context = context_system::instance();
 
         $originaltag = array(
-            'tagtype' => 'default',
+            'isstandard' => 0,
             'flag' => 1,
             'rawname' => 'test',
             'description' => 'desc'
@@ -52,7 +52,7 @@ class core_tag_external_testcase extends externallib_advanced_testcase {
             'description' => 'Trying to change tag description',
             'rawname' => 'Trying to change tag name',
             'flag' => 0,
-            'official' => 1,
+            'isstandard' => 1,
         );
         $gettag = array(
             'id' => $tag->id,
@@ -78,6 +78,7 @@ class core_tag_external_testcase extends externallib_advanced_testcase {
         $this->assertArrayNotHasKey('changeflagurl', $result['tags'][0]);
         $this->assertArrayNotHasKey('flag', $result['tags'][0]);
         $this->assertArrayNotHasKey('official', $result['tags'][0]);
+        $this->assertArrayNotHasKey('isstandard', $result['tags'][0]);
 
         // User with editing only capability can change description but not the tag name.
         $roleid = $this->assignUserCapability('moodle/tag:edit', $context->id);
@@ -92,13 +93,14 @@ class core_tag_external_testcase extends externallib_advanced_testcase {
         $this->assertEquals($originaltag['rawname'], $result['tags'][0]['rawname']);
         $this->assertArrayNotHasKey('flag', $result['tags'][0]); // 'Flag' is not available unless 'moodle/tag:manage' cap exists.
         $this->assertEquals(0, $result['tags'][0]['official']);
+        $this->assertEquals(0, $result['tags'][0]['isstandard']);
         $this->assertEquals($originaltag['rawname'], $DB->get_field('tag', 'rawname',
                 array('id' => $tag->id)));
         $this->assertEquals($updatetag['description'], $DB->get_field('tag', 'description',
                 array('id' => $tag->id)));
 
         // User with editing and manage cap can also change the tag name,
-        // make it official and reset flag.
+        // make it standard and reset flag.
         assign_capability('moodle/tag:manage', CAP_ALLOW, $roleid, $context->id);
         $context->mark_dirty();
         $this->assertTrue(has_capability('moodle/tag:manage', $context));
@@ -112,11 +114,11 @@ class core_tag_external_testcase extends externallib_advanced_testcase {
         $this->assertEquals($updatetag['rawname'], $result['tags'][0]['rawname']);
         $this->assertEquals(core_text::strtolower($updatetag['rawname']), $result['tags'][0]['name']);
         $this->assertEquals($updatetag['flag'], $result['tags'][0]['flag']);
-        $this->assertEquals($updatetag['official'], $result['tags'][0]['official']);
+        $this->assertEquals($updatetag['isstandard'], $result['tags'][0]['official']);
+        $this->assertEquals($updatetag['isstandard'], $result['tags'][0]['isstandard']);
         $this->assertEquals($updatetag['rawname'], $DB->get_field('tag', 'rawname',
                 array('id' => $tag->id)));
-        $this->assertEquals('official', $DB->get_field('tag', 'tagtype',
-                array('id' => $tag->id)));
+        $this->assertEquals(1, $DB->get_field('tag', 'isstandard', array('id' => $tag->id)));
 
         // Updating and getting non-existing tag.
         $nonexistingtag = array(
index 9eb2efb..09cea36 100644 (file)
@@ -471,17 +471,17 @@ class core_tag_taglib_testcase extends advanced_testcase {
         $user = $this->getDataGenerator()->create_user();
         $defaultcoll = core_tag_collection::get_default();
 
-        // Setting tags will create non-official tags 'cat', 'dog' and 'fish'.
+        // Setting tags will create non-standard tags 'cat', 'dog' and 'fish'.
         core_tag_tag::set_item_tags('core', 'user', $user->id, context_user::instance($user->id), array('cat', 'dog', 'fish'));
 
         $this->assertTrue($DB->record_exists('tag', array('name' => 'cat')));
         $this->assertTrue($DB->record_exists('tag', array('name' => 'dog')));
         $this->assertTrue($DB->record_exists('tag', array('name' => 'fish')));
 
-        // Make tag 'dog' official.
+        // Make tag 'dog' standard.
         $dogtag = core_tag_tag::get_by_name($defaultcoll, 'dog', '*');
         $fishtag = core_tag_tag::get_by_name($defaultcoll, 'fish');
-        $dogtag->update(array('tagtype' => 'official'));
+        $dogtag->update(array('isstandard' => 1));
 
         // Manually remove the instances pointing on tags 'dog' and 'fish'.
         $DB->execute('DELETE FROM {tag_instance} WHERE tagid in (?,?)', array($dogtag->id, $fishtag->id));
@@ -489,8 +489,8 @@ class core_tag_taglib_testcase extends advanced_testcase {
         // Call tag_cleanup().
         $task->cleanup();
 
-        // Tag 'cat' is still present because it's used. Tag 'dog' is present because it's official.
-        // Tag 'fish' was removed because it is not official and it is no longer used by anybody.
+        // Tag 'cat' is still present because it's used. Tag 'dog' is present because it's standard.
+        // Tag 'fish' was removed because it is not standard and it is no longer used by anybody.
         $this->assertTrue($DB->record_exists('tag', array('name' => 'cat')));
         $this->assertTrue($DB->record_exists('tag', array('name' => 'dog')));
         $this->assertFalse($DB->record_exists('tag', array('name' => 'fish')));
@@ -705,9 +705,9 @@ class core_tag_taglib_testcase extends advanced_testcase {
         core_tag_tag::set_item_tags('core', 'user', $user2->id, context_user::instance($user2->id),
                 array('Tag2', 'Tag3'));
         $this->getDataGenerator()->create_tag(array('rawname' => 'Tag4',
-            'tagcollid' => $collid1, 'tagtype' => 'official'));
+            'tagcollid' => $collid1, 'isstandard' => 1));
         $this->getDataGenerator()->create_tag(array('rawname' => 'Tag5',
-            'tagcollid' => $collid2, 'tagtype' => 'official'));
+            'tagcollid' => $collid2, 'isstandard' => 1));
 
         return array($collid1, $collid2, $user1, $user2, $blogpost);
     }
@@ -820,7 +820,7 @@ class core_tag_taglib_testcase extends advanced_testcase {
 
         // We already have Tag1 in coll1, now let's create it in coll3.
         $extratag1 = $this->getDataGenerator()->create_tag(array('rawname' => 'Tag1',
-            'tagcollid' => $collid3, 'tagtype' => 'official'));
+            'tagcollid' => $collid3, 'isstandard' => 1));
 
         // Artificially add 'Tag1' from coll3 to user2.
         $DB->insert_record('tag_instance', array('tagid' => $extratag1->id, 'itemtype' => 'user',
index b090f9c..b0490bf 100644 (file)
@@ -60,6 +60,7 @@ here is intended especially for developers.
   - tag_get_name
   - tag_get_correlated
   - tag_cloud_sort
+* Char field 'tagtype' in database table 'tag' is replaced with int (0 or 1) field 'isstandard'.
 
 === 3.0 ===
 
index 8365624..ee99c27 100644 (file)
@@ -464,7 +464,7 @@ function user_get_user_details($user, $course = null, array $userfields = array(
     }
 
     if (in_array('interests', $userfields)) {
-        $interests = core_tag_tag::get_item_tags_array('core', 'user', $user->id, null, 0, false);
+        $interests = core_tag_tag::get_item_tags_array('core', 'user', $user->id, core_tag_tag::BOTH_STANDARD_AND_NOT, 0, false);
         if ($interests) {
             $userdetails['interests'] = join(', ', $interests);
         }
index c60895d..a1d2e5c 100644 (file)
@@ -29,7 +29,7 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$version  = 2016012900.00;              // YYYYMMDD      = weekly release date of this DEV branch.
+$version  = 2016020200.00;              // YYYYMMDD      = weekly release date of this DEV branch.
                                         //         RR    = release increments - 00 in DEV branches.
                                         //           .XX = incremental changes.