From e11d7380c2cae739845fa252f2f8ead314c1b624 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Sun, 10 Jan 2016 15:28:36 +0800 Subject: [PATCH] MDL-51283 core_tag: change tagtype to isstandard Change 'official' to 'standard' in UI --- blocks/blog_tags/block_blog_tags.php | 6 +- blocks/blog_tags/tests/behat/blogtag.feature | 4 +- blocks/tags/block_tags.php | 6 +- blocks/tags/edit_form.php | 8 +- blocks/tags/lang/en/block_tags.php | 4 +- blocks/tags/tests/behat/tagcloud.feature | 4 +- blog/tests/lib_test.php | 2 +- course/tests/behat/coursetags.feature | 4 +- lang/en/deprecated.txt | 6 + lang/en/role.php | 2 - lang/en/tag.php | 21 ++-- lib/amd/build/tag.min.js | 2 +- lib/amd/src/tag.js | 10 +- lib/db/install.xml | 6 +- lib/db/upgrade.php | 41 +++++++ lib/deprecatedlib.php | 32 +++--- lib/form/tags.php | 4 +- lib/testing/generator/data_generator.php | 4 - mod/wiki/tests/behat/edit_tags.feature | 4 +- tag/classes/area.php | 4 +- tag/classes/collection.php | 19 ++-- tag/classes/external.php | 14 ++- tag/classes/manage_table.php | 14 +-- tag/classes/output/tag.php | 20 ++-- tag/classes/output/tagcloud.php | 6 +- tag/classes/output/taglist.php | 4 +- tag/classes/renderer.php | 2 +- tag/classes/tag.php | 70 +++++++----- tag/edit.php | 5 +- tag/edit_form.php | 2 +- tag/manage.php | 15 +-- tag/templates/tagcloud.mustache | 8 +- ...agtype.mustache => tagisstandard.mustache} | 22 ++-- tag/templates/taglist.mustache | 8 +- tag/tests/behat/collections.feature | 14 +-- tag/tests/behat/delete_tag.feature | 4 +- tag/tests/behat/edit_tag.feature | 10 +- tag/tests/behat/flag_tags.feature | 4 +- tag/tests/behat/official_tags.feature | 104 ------------------ tag/tests/behat/standard_tags.feature | 104 ++++++++++++++++++ tag/tests/external_test.php | 14 ++- tag/tests/taglib_test.php | 16 +-- tag/upgrade.txt | 1 + user/lib.php | 2 +- version.php | 2 +- 45 files changed, 364 insertions(+), 294 deletions(-) rename tag/templates/{tagtype.mustache => tagisstandard.mustache} (66%) delete mode 100644 tag/tests/behat/official_tags.feature create mode 100644 tag/tests/behat/standard_tags.feature diff --git a/blocks/blog_tags/block_blog_tags.php b/blocks/blog_tags/block_blog_tags.php index 6edc7b5dff4..f46bd417bf0 100644 --- a/blocks/blog_tags/block_blog_tags.php +++ b/blocks/blog_tags/block_blog_tags.php @@ -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; } diff --git a/blocks/blog_tags/tests/behat/blogtag.feature b/blocks/blog_tags/tests/behat/blogtag.feature index 192ba5e3b5e..d840c38eccc 100644 --- a/blocks/blog_tags/tests/behat/blogtag.feature +++ b/blocks/blog_tags/tests/behat/blogtag.feature @@ -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 | diff --git a/blocks/tags/block_tags.php b/blocks/tags/block_tags.php index 31ced5814a5..e483abe9040 100644 --- a/blocks/tags/block_tags.php +++ b/blocks/tags/block_tags.php @@ -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)); diff --git a/blocks/tags/edit_form.php b/blocks/tags/edit_form.php index 89742c59a55..4ea82094984 100644 --- a/blocks/tags/edit_form.php +++ b/blocks/tags/edit_form.php @@ -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); diff --git a/blocks/tags/lang/en/block_tags.php b/blocks/tags/lang/en/block_tags.php index 02dd7a1cb0a..8f1a1b7b0d0 100644 --- a/blocks/tags/lang/en/block_tags.php +++ b/blocks/tags/lang/en/block_tags.php @@ -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'; diff --git a/blocks/tags/tests/behat/tagcloud.feature b/blocks/tags/tests/behat/tagcloud.feature index 7a254906516..36e1bc06a69 100644 --- a/blocks/tags/tests/behat/tagcloud.feature +++ b/blocks/tags/tests/behat/tagcloud.feature @@ -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 | diff --git a/blog/tests/lib_test.php b/blog/tests/lib_test.php index 81eac309c7e..80c3be50e7a 100644 --- a/blog/tests/lib_test.php +++ b/blog/tests/lib_test.php @@ -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(); diff --git a/course/tests/behat/coursetags.feature b/course/tests/behat/coursetags.feature index f76f93a2b90..b330e80b8a5 100644 --- a/course/tests/behat/coursetags.feature +++ b/course/tests/behat/coursetags.feature @@ -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 | diff --git a/lang/en/deprecated.txt b/lang/en/deprecated.txt index 366e26bc5a2..4cb19ced201 100644 --- a/lang/en/deprecated.txt +++ b/lang/en/deprecated.txt @@ -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 diff --git a/lang/en/role.php b/lang/en/role.php index f429e4cb9ab..e7eb45e606d 100644 --- a/lang/en/role.php +++ b/lang/en/role.php @@ -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'; diff --git a/lang/en/tag.php b/lang/en/tag.php index e20a6031c95..302c8c5d2ad 100644 --- a/lang/en/tag.php +++ b/lang/en/tag.php @@ -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'; diff --git a/lib/amd/build/tag.min.js b/lib/amd/build/tag.min.js index 7a4328f304b..e57080102f9 100644 --- a/lib/amd/build/tag.min.js +++ b/lib/amd/build/tag.min.js @@ -1 +1 @@ -define(["jquery","core/ajax","core/templates","core/notification","core/str","core/config"],function(a,b,c,d,e,f){return{init_tagindex_page:function(){a("body").delegate(".tagarea[data-ta] a[data-quickload=1]","click",function(d){d.preventDefault();var e=a(this),f=e.context.search.replace(/^\?/,""),g=e.closest(".tagarea[data-ta]"),h=f.split("&").reduce(function(a,b){var c=b.split("=");return a[c[0]]=decodeURIComponent(c[1]),a},{}),i=b.call([{methodname:"core_tag_get_tagindex",args:{tagindex:h}}],!0);a.when.apply(a,i).done(function(a){c.render("core_tag/index",a).done(function(a){g.replaceWith(a)})})})},init_manage_page:function(){var g=function(b){var c=b.closest("tr").get(0);if(c){var d=a(c).find("td.col-timemodified").get(0);e.get_string("now").done(function(b){a(d).html(b)})}};a(".tag-management-table").delegate(".tagtype","click",function(d){d.preventDefault();var e=a(this),f=e.attr("data-id"),h=e.attr("data-value"),i="1"===h?0:1,j=b.call([{methodname:"core_tag_update_tags",args:{tags:[{id:f,official:i}]}},{methodname:"core_tag_get_tags",args:{tags:[{id:f}]}}],!0);a.when.apply(a,j).done(function(a,b){void 0===a.warnings[0]&&void 0!==b.tags[0]&&c.render("core_tag/tagtype",b.tags[0]).done(function(a){g(e);var b=e.parent();e.replaceWith(a),b.find(".tagtype").get(0).focus()})})}),a(".tag-management-table").delegate(".tagflag","click",function(d){d.preventDefault();var e=a(this),f=e.attr("data-id"),h=e.attr("data-value"),i="0"===h?1:0,j=b.call([{methodname:"core_tag_update_tags",args:{tags:[{id:f,flag:i}]}},{methodname:"core_tag_get_tags",args:{tags:[{id:f}]}}],!0);a.when.apply(a,j).done(function(b,d){if(void 0===b.warnings[0]&&void 0!==d.tags[0]){var f=e.closest("tr").get(0);f&&(d.tags[0].flag?a(f).addClass("flagged-tag"):a(f).removeClass("flagged-tag")),c.render("core_tag/tagflag",d.tags[0]).done(function(a){g(e);var b=e.parent();e.replaceWith(a),b.find(".tagflag").get(0).focus()})}})}),a(".tag-management-table").delegate("a.tagdelete","click",function(b){b.preventDefault();var c=a(this).attr("href");e.get_strings([{key:"delete"},{key:"confirmdeletetag",component:"tag"},{key:"yes"},{key:"no"}]).done(function(a){d.confirm(a[0],a[1],a[2],a[3],function(){window.location.href=c})})}),a("#tag-management-delete").click(function(b){var c=a(this).closest("form").get(0),f=a(c).find("input[type=checkbox]:checked").length;return f?(b.preventDefault(),void e.get_strings([{key:"delete"},{key:"confirmdeletetags",component:"tag"},{key:"yes"},{key:"no"}]).done(function(a){d.confirm(a[0],a[1],a[2],a[3],function(){c.submit()})})):!1}),a(".tag-management-table").delegate(".tagnameedit","click keypress",function(h){if("keypress"!==h.type||13===h.keyCode){h.stopImmediatePropagation(),h.preventDefault();var i=a(this),j=a(i.closest("td").get(0)),k=a(j.find("input").get(0)),l=i.attr("data-id"),m=function(f,h){var i=b.call([{methodname:"core_tag_update_tags",args:{tags:[{id:f,rawname:h}]}},{methodname:"core_tag_get_tags",args:{tags:[{id:f}]}}],!0);a.when.apply(a,i).done(function(b,f){void 0!==b.warnings[0]?e.get_string("error").done(function(a){d.alert(a,b.warnings[0].message)}):void 0!==f.tags[0]&&c.render("core_tag/tagname",f.tags[0]).done(function(b){g(j),j.html(b),a(j.find(".tagnameedit").get(0)).focus()})})},n=function(){a(".tag-management-table td.tageditingon").each(function(){var b=a(this),c=a(b.find("input").get(0));c.off(),b.removeClass("tageditingon"),c.val(b.attr("data-value"))})};n(),j.addClass("tageditingon"),j.attr("data-value",k.val()),k.select(),k.on("keypress focusout",function(a){f.behatsiterunning&&"focusout"===a.type||("keypress"===a.type&&13===a.keyCode&&(m(l,k.val()),n()),("keypress"===a.type&&27===a.keyCode||"focusout"===a.type)&&n())})}})}}}); \ No newline at end of file +define(["jquery","core/ajax","core/templates","core/notification","core/str","core/config"],function(a,b,c,d,e,f){return{init_tagindex_page:function(){a("body").delegate(".tagarea[data-ta] a[data-quickload=1]","click",function(d){d.preventDefault();var e=a(this),f=e.context.search.replace(/^\?/,""),g=e.closest(".tagarea[data-ta]"),h=f.split("&").reduce(function(a,b){var c=b.split("=");return a[c[0]]=decodeURIComponent(c[1]),a},{}),i=b.call([{methodname:"core_tag_get_tagindex",args:{tagindex:h}}],!0);a.when.apply(a,i).done(function(a){c.render("core_tag/index",a).done(function(a){g.replaceWith(a)})})})},init_manage_page:function(){var g=function(b){var c=b.closest("tr").get(0);if(c){var d=a(c).find("td.col-timemodified").get(0);e.get_string("now").done(function(b){a(d).html(b)})}};a(".tag-management-table").delegate(".tagisstandard","click",function(d){d.preventDefault();var e=a(this),f=e.attr("data-id"),h=e.attr("data-value"),i="1"===h?0:1,j=b.call([{methodname:"core_tag_update_tags",args:{tags:[{id:f,isstandard:i}]}},{methodname:"core_tag_get_tags",args:{tags:[{id:f}]}}],!0);a.when.apply(a,j).done(function(a,b){void 0===a.warnings[0]&&void 0!==b.tags[0]&&c.render("core_tag/tagisstandard",b.tags[0]).done(function(a){g(e);var b=e.parent();e.replaceWith(a),b.find(".tagisstandard").get(0).focus()})})}),a(".tag-management-table").delegate(".tagflag","click",function(d){d.preventDefault();var e=a(this),f=e.attr("data-id"),h=e.attr("data-value"),i="0"===h?1:0,j=b.call([{methodname:"core_tag_update_tags",args:{tags:[{id:f,flag:i}]}},{methodname:"core_tag_get_tags",args:{tags:[{id:f}]}}],!0);a.when.apply(a,j).done(function(b,d){if(void 0===b.warnings[0]&&void 0!==d.tags[0]){var f=e.closest("tr").get(0);f&&(d.tags[0].flag?a(f).addClass("flagged-tag"):a(f).removeClass("flagged-tag")),c.render("core_tag/tagflag",d.tags[0]).done(function(a){g(e);var b=e.parent();e.replaceWith(a),b.find(".tagflag").get(0).focus()})}})}),a(".tag-management-table").delegate("a.tagdelete","click",function(b){b.preventDefault();var c=a(this).attr("href");e.get_strings([{key:"delete"},{key:"confirmdeletetag",component:"tag"},{key:"yes"},{key:"no"}]).done(function(a){d.confirm(a[0],a[1],a[2],a[3],function(){window.location.href=c})})}),a("#tag-management-delete").click(function(b){var c=a(this).closest("form").get(0),f=a(c).find("input[type=checkbox]:checked").length;return f?(b.preventDefault(),void e.get_strings([{key:"delete"},{key:"confirmdeletetags",component:"tag"},{key:"yes"},{key:"no"}]).done(function(a){d.confirm(a[0],a[1],a[2],a[3],function(){c.submit()})})):!1}),a(".tag-management-table").delegate(".tagnameedit","click keypress",function(h){if("keypress"!==h.type||13===h.keyCode){h.stopImmediatePropagation(),h.preventDefault();var i=a(this),j=a(i.closest("td").get(0)),k=a(j.find("input").get(0)),l=i.attr("data-id"),m=function(f,h){var i=b.call([{methodname:"core_tag_update_tags",args:{tags:[{id:f,rawname:h}]}},{methodname:"core_tag_get_tags",args:{tags:[{id:f}]}}],!0);a.when.apply(a,i).done(function(b,f){void 0!==b.warnings[0]?e.get_string("error").done(function(a){d.alert(a,b.warnings[0].message)}):void 0!==f.tags[0]&&c.render("core_tag/tagname",f.tags[0]).done(function(b){g(j),j.html(b),a(j.find(".tagnameedit").get(0)).focus()})})},n=function(){a(".tag-management-table td.tageditingon").each(function(){var b=a(this),c=a(b.find("input").get(0));c.off(),b.removeClass("tageditingon"),c.val(b.attr("data-value"))})};n(),j.addClass("tageditingon"),j.attr("data-value",k.val()),k.select(),k.on("keypress focusout",function(a){f.behatsiterunning&&"focusout"===a.type||("keypress"===a.type&&13===a.keyCode&&(m(l,k.val()),n()),("keypress"===a.type&&27===a.keyCode||"focusout"===a.type)&&n())})}})}}}); \ No newline at end of file diff --git a/lib/amd/src/tag.js b/lib/amd/src/tag.js index 01ef814a7ac..1a0a94e5dc4 100644 --- a/lib/amd/src/tag.js +++ b/lib/amd/src/tag.js @@ -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(); }); } }); diff --git a/lib/db/install.xml b/lib/db/install.xml index 3c9e4204511..7eac93fe4ba 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -1997,7 +1997,7 @@ - + @@ -2010,7 +2010,7 @@ - + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 3975de34a7e..11523d5c27f 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -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; } diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 21c56f54dea..6222822795f 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -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; diff --git a/lib/form/tags.php b/lib/form/tags.php index 096bbd91955..ff2fe6850b7 100644 --- a/lib/form/tags.php +++ b/lib/form/tags.php @@ -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); } diff --git a/lib/testing/generator/data_generator.php b/lib/testing/generator/data_generator.php index 756b15cf398..cf191f5e846 100644 --- a/lib/testing/generator/data_generator.php +++ b/lib/testing/generator/data_generator.php @@ -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(); } diff --git a/mod/wiki/tests/behat/edit_tags.feature b/mod/wiki/tests/behat/edit_tags.feature index 5899b8c4056..87931c42a88 100644 --- a/mod/wiki/tests/behat/edit_tags.feature +++ b/mod/wiki/tests/behat/edit_tags.feature @@ -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" diff --git a/tag/classes/area.php b/tag/classes/area.php index 7debad9a381..ef80a1a4a4d 100644 --- a/tag/classes/area.php +++ b/tag/classes/area.php @@ -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 diff --git a/tag/classes/collection.php b/tag/classes/collection.php index c8be5d27501..2e503dd2bfd 100644 --- a/tag/classes/collection.php +++ b/tag/classes/collection.php @@ -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); diff --git a/tag/classes/external.php b/tag/classes/external.php index 324ecad963c..7999c383503 100644 --- a/tag/classes/external.php +++ b/tag/classes/external.php @@ -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') ), diff --git a/tag/classes/manage_table.php b/tag/classes/manage_table.php index 48af9026876..dbe15d14c3c 100644 --- a/tag/classes/manage_table.php +++ b/tag/classes/manage_table.php @@ -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)); } /** diff --git a/tag/classes/output/tag.php b/tag/classes/output/tag.php index dd8559f5723..4016a615dc4 100644 --- a/tag/classes/output/tag.php +++ b/tag/classes/output/tag.php @@ -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); diff --git a/tag/classes/output/tagcloud.php b/tag/classes/output/tagcloud.php index 85d61ce7350..bd20da42f6f 100644 --- a/tag/classes/output/tagcloud.php +++ b/tag/classes/output/tagcloud.php @@ -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)) { diff --git a/tag/classes/output/taglist.php b/tag/classes/output/taglist.php index d0ad198591d..df821f45664 100644 --- a/tag/classes/output/taglist.php +++ b/tag/classes/output/taglist.php @@ -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) { diff --git a/tag/classes/renderer.php b/tag/classes/renderer.php index 3949c5e81e3..f1eae09e8ec 100644 --- a/tag/classes/renderer.php +++ b/tag/classes/renderer.php @@ -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', diff --git a/tag/classes/tag.php b/tag/classes/tag.php index 48896c0bad7..909e236614a 100644 --- a/tag/classes/tag.php +++ b/tag/classes/tag.php @@ -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 diff --git a/tag/edit.php b/tag/edit.php index a3087577c82..cbd53134fc9 100644 --- a/tag/edit.php +++ b/tag/edit.php @@ -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. diff --git a/tag/edit_form.php b/tag/edit_form.php index ef2fc8a32f1..d381d79dd88 100644 --- a/tag/edit_form.php +++ b/tag/edit_form.php @@ -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'), diff --git a/tag/manage.php b/tag/manage.php index 3deb5c4e75c..6a00ddea369 100644 --- a/tag/manage.php +++ b/tag/manage.php @@ -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(''); print(''); -print(''); +print(''); print(''); print(''); print('