diff --git a/backup/backuplib.php b/backup/backuplib.php index 3d6297e6988..9cf508fcece 100644 --- a/backup/backuplib.php +++ b/backup/backuplib.php @@ -1280,7 +1280,7 @@ //Check if we have user tags to backup if (!empty($CFG->usetags)) { - if ($tags = get_item_tags('user', $user->id)) { //This return them ordered by default + if ($tags = tag_get_tags(array('type'=>'user', 'id'=>$user->id))) { //This return them ordered by default //Start USER_TAGS tag fwrite ($bf,start_tag("USER_TAGS",4,true)); //Write user tags fields diff --git a/blocks/blog_tags/block_blog_tags.php b/blocks/blog_tags/block_blog_tags.php index c92a863e6b2..693b4efc5df 100644 --- a/blocks/blog_tags/block_blog_tags.php +++ b/blocks/blog_tags/block_blog_tags.php @@ -161,7 +161,7 @@ class block_blog_tags extends block_base { $this->content->text .= '
';
@@ -59,17 +59,14 @@ $tagname = tag_display_name($tag);
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
if ($tag->flag > 0 && has_capability('moodle/tag:manage', $systemcontext)) {
- $tagname = '' . $tagname . '';
+ $tagname = '' . rawurlencode($tagname) . '';
}
print_heading($tagname, '', 2, 'headingblock header tag-heading');
+tag_print_management_box($tag);
+tag_print_description_box($tag);
-print_tag_management_box($tag);
-
-print_tag_description_box($tag);
-
-
-$usercount = count_items_tagged_with($tag->id,'user');
+$usercount = tag_record_count('user', $tag->id);
if ($usercount > 0) {
@@ -82,16 +79,10 @@ if ($usercount > 0) {
$baseurl = $CFG->wwwroot.'/tag/index.php?id=' . $tag->id;
print_paging_bar($usercount, $userpage, $perpage, $baseurl.'&', 'userpage');
-
- print_tagged_users_table($tag, $userpage * $perpage, $perpage);
-
+ tag_print_tagged_users_table($tag, $userpage * $perpage, $perpage);
print_box_end();
-
}
-
-
-
// Print last 10 blogs
// I was not able to use get_items_tagged_with() because it automatically
diff --git a/tag/manage.php b/tag/manage.php
index 2d8b5caffe9..2a130e26a88 100644
--- a/tag/manage.php
+++ b/tag/manage.php
@@ -35,7 +35,7 @@ $notice = '';
// get all the possible tag types from db
$existing_tagtypes = array();
-if ($ptypes = get_records_sql("SELECT DISTINCT(tagtype), id FROM {$CFG->prefix}tag")) {
+if ($ptypes = get_records_sql("SELECT DISTINCT(tagtype) FROM {$CFG->prefix}tag")) {
foreach ($ptypes as $ptype) {
$existing_tagtypes[$ptype->tagtype] = $ptype->tagtype;
}
@@ -49,11 +49,9 @@ switch($action) {
if (!data_submitted() or !confirm_sesskey()) {
break;
}
- $str_tagschecked = tag_name_from_string(implode($tagschecked, ','));
- $str_tagschecked = str_replace(',', ', ', $str_tagschecked);
-
- tag_delete(implode($tagschecked, ','));
-
+
+ $str_tagschecked = implode(', ', tag_get_name($tagschecked));
+ tag_delete($tagschecked);
$notice = $str_tagschecked.' -- '.get_string('deleted','tag');
break;
@@ -61,12 +59,9 @@ switch($action) {
if (!data_submitted() or !confirm_sesskey()) {
break;
}
- $str_tagschecked = tag_name_from_string(implode($tagschecked, ','));
- $str_tagschecked = str_replace(',', ', ', $str_tagschecked);
-
- tag_flag_reset(implode($tagschecked, ','));
-
- $notice = $str_tagschecked.' -- '.get_string('reset','tag');
+ $str_tagschecked = implode(', ', tag_get_name($tagschecked));
+ tag_unset_flag($tagschecked);
+ $notice = $str_tagschecked .' -- '. get_string('reset', 'tag');
break;
case 'changetype':
@@ -75,7 +70,6 @@ switch($action) {
}
$changed = array();
-
foreach ($tagschecked as $tag_id) {
if (!array_key_exists($tagtypes[$tag_id], $existing_tagtypes)) {
//can not add new types here!!
@@ -83,19 +77,14 @@ switch($action) {
}
// update tag type;
- $tag = tag_by_id($tag_id);
- $tag->timemodified = time();
- $tag->tagtype = $tagtypes[$tag_id];
-
- if (update_record('tag', $tag)) {
+ if (tag_type_set($tag_id, $tagtypes[$tag_id])) {
$changed[] = $tag_id;
}
}
- if ($changed) {
- $str_changed = tag_name_from_string(implode($changed, ','));
- $str_changed = str_replace(',', ', ', $str_changed);
- $notice = $str_changed.' -- '.get_string('typechanged','tag');
+ if (!empty($changed)) {
+ $str_changed = implode(', ', tag_get_name($changed));
+ $notice = $str_changed .' -- '. get_string('typechanged','tag');
}
break;
@@ -103,12 +92,12 @@ switch($action) {
if (!data_submitted() or !confirm_sesskey()) {
break;
}
-
+
$tags_names_changed = array();
-
foreach ($tagschecked as $tag_id) {
if ($newnames[$tag_id] != '') {
- if (tag_exists($newnames[$tag_id])) {
+ if (! $tags_names_updated[] = tag_rename($tag_id, $newnames[$tag_id]) ) {
+ // if tag already exists, or is not a valid tag name, etc.
$err_notice .= $newnames[$tag_id]. '-- ' . get_string('namesalreadybeeingused','tag').' '; } else { $tags_names_changed[$tag_id] = $newnames[$tag_id]; @@ -116,14 +105,25 @@ switch($action) { } } - $tags_names_updated = tag_update_name($tags_names_changed); - //notice to inform what tags had their names effectively updated - if ($tags_names_updated){ - $notice = implode($tags_names_updated, ', '); + if ($tags_names_changed){ + $notice = implode($tags_names_changed, ', '); $notice .= ' -- ' . get_string('updated','tag'); } break; + case 'addofficialtag': + $new_otags = explode(',', optional_param('otagsadd', '', PARAM_TAG)); + $notice = ''; + foreach ( $new_otags as $new_otag ) { + if ( $new_otag_id = tag_get_id($new_otag) ) { + // tag exists, change the type + tag_set_type($new_otag_id, 'official'); + } else { + tag_add($new_otag, 'official'); + } + $notice .= get_string('addedotag', 'tag', $new_otag) .' '; + } + break; } echo ' '; @@ -132,18 +132,27 @@ if ($err_notice) { notify($err_notice, 'red'); } if ($notice) { - notify($notice , 'green'); + notify($notice, 'green'); } +// small form to add an official tag +print(''); + //setup table -$tablecolumns = array('id','name', 'fullname', 'count', 'flag', 'timemodified', 'rawname', 'tagtype', ''); -$tableheaders = array(get_string('id' , 'tag'), - get_string('name' , 'tag'), - get_string('owner','tag'), - get_string('count','tag'), - get_string('flag','tag'), - get_string('timemodified','tag'), +$tablecolumns = array('id', 'name', 'fullname', 'count', 'flag', 'timemodified', 'rawname', 'tagtype', ''); +$tableheaders = array(get_string('id', 'tag'), + get_string('name', 'tag'), + get_string('owner', 'tag'), + get_string('count', 'tag'), + get_string('flag', 'tag'), + get_string('timemodified', 'tag'), get_string('newname', 'tag'), get_string('tagtype', 'tag'), get_string('select', 'tag')); @@ -174,36 +183,29 @@ TABLE_VAR_PAGE => 'spage' $table->setup(); if ($table->get_sql_sort()) { - $sort = ' ORDER BY '.$table->get_sql_sort(); + $sort = 'ORDER BY '. $table->get_sql_sort(); } else { $sort = ''; } if ($table->get_sql_where()) { - $where = 'WHERE '.$table->get_sql_where(); + $where = 'WHERE '. $table->get_sql_where(); } else { $where = ''; } -$query = " - SELECT tg.id, tg.name, tg.rawname, tg.tagtype, COUNT(ti.id) AS count, u.id AS owner, tg.flag, tg.timemodified, u.firstname, u.lastname - FROM {$CFG->prefix}tag_instance ti - RIGHT JOIN {$CFG->prefix}tag tg ON tg.id = ti.tagid - LEFT JOIN {$CFG->prefix}user u ON tg.userid = u.id - {$where} - GROUP BY tg.id, tg.name, tg.rawname, tg.tagtype, u.id, tg.flag, tg.timemodified, u.firstname, u.lastname - {$sort}"; +$query = 'SELECT tg.id, tg.name, tg.rawname, tg.tagtype, COUNT(ti.id) AS count, u.id AS owner, tg.flag, tg.timemodified, u.firstname, u.lastname '. + 'FROM '. $CFG->prefix .'tag_instance ti RIGHT JOIN '. $CFG->prefix .'tag tg ON tg.id = ti.tagid LEFT JOIN '. $CFG->prefix .'user u ON tg.userid = u.id '. + $where .' '. + 'GROUP BY tg.id, tg.name, tg.rawname, tg.tagtype, u.id, tg.flag, tg.timemodified, u.firstname, u.lastname '. + $sort; - -$totalcount = count_records_sql("SELECT COUNT(DISTINCT(tg.id)) - FROM {$CFG->prefix}tag tg - LEFT JOIN {$CFG->prefix}user u ON u.id = tg.userid - $where"); +$totalcount = count_records_sql('SELECT COUNT(DISTINCT(tg.id)) FROM '. $CFG->prefix .'tag tg LEFT JOIN '. $CFG->prefix .'user u ON u.id = tg.userid '. $where); $table->initialbars(true); // always initial bars $table->pagesize($perpage, $totalcount); -echo ' |