diff --git a/backup/backuplib.php b/backup/backuplib.php index 9cf508fcece..3d6297e6988 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 = tag_get_tags(array('type'=>'user', 'id'=>$user->id))) { //This return them ordered by default + if ($tags = get_item_tags('user', $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 693b4efc5df..c92a863e6b2 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,14 +59,17 @@ $tagname = tag_display_name($tag);
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
if ($tag->flag > 0 && has_capability('moodle/tag:manage', $systemcontext)) {
- $tagname = '' . rawurlencode($tagname) . '';
+ $tagname = '' . $tagname . '';
}
print_heading($tagname, '', 2, 'headingblock header tag-heading');
-tag_print_management_box($tag);
-tag_print_description_box($tag);
-$usercount = tag_record_count('user', $tag->id);
+print_tag_management_box($tag);
+
+print_tag_description_box($tag);
+
+
+$usercount = count_items_tagged_with($tag->id,'user');
if ($usercount > 0) {
@@ -79,10 +82,16 @@ if ($usercount > 0) {
$baseurl = $CFG->wwwroot.'/tag/index.php?id=' . $tag->id;
print_paging_bar($usercount, $userpage, $perpage, $baseurl.'&', 'userpage');
- tag_print_tagged_users_table($tag, $userpage * $perpage, $perpage);
+
+ 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/lib.php b/tag/lib.php
index d7ae3c6d028..d6a1b533239 100644
--- a/tag/lib.php
+++ b/tag/lib.php
@@ -44,6 +44,8 @@ define('TAG_RETURN_HTML', 3);
define('TAG_CASE_LOWER', 0);
define('TAG_CASE_ORIGINAL', 1);
+require_once($CFG->dirroot .'/tag/locallib.php');
+
///////////////////////////////////////////////////////
/////////////////// PUBLIC TAG API ////////////////////
diff --git a/tag/manage.php b/tag/manage.php
index 2a130e26a88..2d8b5caffe9 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) FROM {$CFG->prefix}tag")) {
+if ($ptypes = get_records_sql("SELECT DISTINCT(tagtype), id FROM {$CFG->prefix}tag")) {
foreach ($ptypes as $ptype) {
$existing_tagtypes[$ptype->tagtype] = $ptype->tagtype;
}
@@ -49,9 +49,11 @@ switch($action) {
if (!data_submitted() or !confirm_sesskey()) {
break;
}
-
- $str_tagschecked = implode(', ', tag_get_name($tagschecked));
- tag_delete($tagschecked);
+ $str_tagschecked = tag_name_from_string(implode($tagschecked, ','));
+ $str_tagschecked = str_replace(',', ', ', $str_tagschecked);
+
+ tag_delete(implode($tagschecked, ','));
+
$notice = $str_tagschecked.' -- '.get_string('deleted','tag');
break;
@@ -59,9 +61,12 @@ switch($action) {
if (!data_submitted() or !confirm_sesskey()) {
break;
}
- $str_tagschecked = implode(', ', tag_get_name($tagschecked));
- tag_unset_flag($tagschecked);
- $notice = $str_tagschecked .' -- '. get_string('reset', 'tag');
+ $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');
break;
case 'changetype':
@@ -70,6 +75,7 @@ switch($action) {
}
$changed = array();
+
foreach ($tagschecked as $tag_id) {
if (!array_key_exists($tagtypes[$tag_id], $existing_tagtypes)) {
//can not add new types here!!
@@ -77,14 +83,19 @@ switch($action) {
}
// update tag type;
- if (tag_type_set($tag_id, $tagtypes[$tag_id])) {
+ $tag = tag_by_id($tag_id);
+ $tag->timemodified = time();
+ $tag->tagtype = $tagtypes[$tag_id];
+
+ if (update_record('tag', $tag)) {
$changed[] = $tag_id;
}
}
- if (!empty($changed)) {
- $str_changed = implode(', ', tag_get_name($changed));
- $notice = $str_changed .' -- '. get_string('typechanged','tag');
+ if ($changed) {
+ $str_changed = tag_name_from_string(implode($changed, ','));
+ $str_changed = str_replace(',', ', ', $str_changed);
+ $notice = $str_changed.' -- '.get_string('typechanged','tag');
}
break;
@@ -92,12 +103,12 @@ switch($action) {
if (!data_submitted() or !confirm_sesskey()) {
break;
}
-
+
$tags_names_changed = array();
+
foreach ($tagschecked as $tag_id) {
if ($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.
+ if (tag_exists($newnames[$tag_id])) {
$err_notice .= $newnames[$tag_id]. '-- ' . get_string('namesalreadybeeingused','tag').' '; } else { $tags_names_changed[$tag_id] = $newnames[$tag_id]; @@ -105,25 +116,14 @@ switch($action) { } } + $tags_names_updated = tag_update_name($tags_names_changed); + //notice to inform what tags had their names effectively updated - if ($tags_names_changed){ - $notice = implode($tags_names_changed, ', '); + if ($tags_names_updated){ + $notice = implode($tags_names_updated, ', '); $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,27 +132,18 @@ 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')); @@ -183,29 +174,36 @@ 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 ' |