$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
}
$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)) {
$size = 20 - ( (int)((($currenttag - 1) / $totaltags) * 20) );
}
- $tag->class = "$tag->tagtype s$size";
+ $tag->class = ($tag->isstandard ? "standardtag " : "") . "s$size";
$etags[] = $tag;
}
| 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 |
$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)) {
// 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));
$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);
$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';
| 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 |
// 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();
| 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 |
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
$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';
* @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';
$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...';
$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)';
$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';
$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';
// 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';
};
// 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 } ] }
$.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();
});
}
});
<?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">
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;
}
// 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}
$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";
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
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;
}
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();
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);
}
/**
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));
}
}
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();
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;
$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;
}
$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);
}
$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();
}
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"
// 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.
// 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
}
/**
- * 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
*/
$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)) {
* 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
* @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;
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) {
$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);
'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),
)
)
)
}
}
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'])) {
$rv = $tagoutput->export_for_template($renderer);
if (!$canmanage) {
if (!$canedit) {
+ unset($rv->isstandard);
unset($rv->official);
}
unset($rv->flag);
'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')
),
$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);
$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);
$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";
* @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));
}
/**
use renderer_base;
use stdClass;
use moodle_url;
+use core_tag_tag;
/**
* Class to help display tag
*/
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;
}
'description' => '',
'descriptionformat' => FORMAT_HTML,
'flag' => 0,
- 'tagtype' => 'default',
+ 'isstandard' => 0,
'id' => 0,
'tagcollid' => 0,
);
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);
* @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
$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)) {
$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) {
$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',
* @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
/** @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.
*
*
* @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;
*
* @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;
}
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));
\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);
}
}
/**
- * 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.
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
* 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) {
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);
* 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;
$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.
/**
* 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)) {
}
// 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.
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
$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);
$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;
}
$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.
$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'),
$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);
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) {
$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));
// 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">' .
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,
<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>
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}}
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,
<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}}
| 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"
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"
| 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"
| 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
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 |
| 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"
| 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"
| 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 |
+++ /dev/null
-@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
--- /dev/null
+@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
$context = context_system::instance();
$originaltag = array(
- 'tagtype' => 'default',
+ 'isstandard' => 0,
'flag' => 1,
'rawname' => 'test',
'description' => 'desc'
'description' => 'Trying to change tag description',
'rawname' => 'Trying to change tag name',
'flag' => 0,
- 'official' => 1,
+ 'isstandard' => 1,
);
$gettag = array(
'id' => $tag->id,
$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);
$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));
$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(
$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));
// 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')));
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);
}
// 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',
- 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 ===
}
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);
}
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.