';
+ $coursetagdivs .= '"f_commtags", ';
+ }
+ // Tidy up the end of a javascript array and add javascript
+ $coursetagdivs = rtrim($coursetagdivs, ', ');
+ $this->content->text .= coursetag_get_jscript($coursetagdivs);
+
+ // Add the divs (containing the tags) to the block's content
+ if ($alltags) { $this->content->text .= $alltagscontent; }
+ if ($mytags) { $this->content->text .= $mytagscontent; }
+ if ($officialtags) { $this->content->text .= $officialtagscontent; }
+ if ($coursetags) { $this->content->text .= $coursetagscontent; }
+ if ($commtags) { $this->content->text .= $commtagscontent; }
+
+ // add the input form section (allowing a user to tag the current course) and navigation, or loggin message
+ if ($loggedin) {
+ // only show the input form on course pages for those allowed (or not barred)
+ if ($coursepage && $canedit) {
+ //$this->content->footer .= coursetag_get_jscript();
+ $tagthisunit = get_string('tagthisunit', $tagslang);
+ $buttonadd = get_string('add', $tagslang);
+ $arrowtitle = get_string('arrowtitle', $tagslang);
+ $coursetaghelpbutton = helpbutton('addtags', 'adding tags', $tagslang, TRUE, FALSE, '', TRUE);
+ $this->content->footer .= <<
+
+EOT;
+ // add the edit link
+ $this->content->footer .= '
+
';
+ }
+
+ // Navigation elements at the bottom of the block
+ // show the alternative displays options if available
+ if ($mytags or $officialtags or $commtags or $coursetags) {
+ $this->content->footer .= '';
+ }
+ if ($mytags) {
+ $this->content->footer .= '
+
+ '.get_string('mytags2', $tagslang).' |';
+ }
+ if ($alltags and ($mytags or $officialtags or $commtags or $coursetags)) {
+ $this->content->footer .= '
+
+ '.get_string('alltags1', $tagslang).' |';
+ }
+ if ($officialtags) {
+ $this->content->footer .= '
+
+ '.get_string('officialtags1', $tagslang).' |';
+ }
+ if ($commtags) {
+ $this->content->footer .= '
+
+ '.get_string('communitytags1', $tagslang).' |';
+ }
+ if ($coursetags) {
+ $this->content->footer .= '
+
+ '.get_string('coursetags1', $tagslang).' |';
+ }
+ $this->content->footer = rtrim($this->content->footer, '|');
+ } else {
+ //if not logged in
+ $this->content->footer = ''.get_string('please', $tagslang).'
+ '.get_string('login', $tagslang).'
+ '.get_string('tagunits', $tagslang);
+ }
+ }
+ // end of show course tags section
+
return $this->content;
}
@@ -81,6 +333,21 @@
notice(get_string('blockconfigbad'), str_replace('blockaction=', 'dummy=', qualified_me()));
}
}
+
+ /*
+ * function removed until rsslib supports dc/cc
+ */
+ /*
+ function cron() {
+ if (SHOWCOURSETAGS) {
+ global $CFG;
+ require_once($CFG->dirroot.'/tag/coursetagslib.php');
+ return coursetag_rss_feeds();
+ } else {
+ return TRUE;
}
+ }
+ */
+}
?>
Index: tag/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/tag/lib.php,v
retrieving revision 1.80
diff -u -r1.80 lib.php
--- tag/lib.php 5 Jun 2008 20:35:29 -0000 1.80
+++ tag/lib.php 13 Jun 2008 15:12:17 -0000
@@ -66,9 +66,10 @@
* @param int $record_id the id of the record to tag
* @param array $tags the array of tags to set on the record. If
* given an empty array, all tags will be removed.
+ * @param int $userid only required for course tagging
* @return void
*/
-function tag_set($record_type, $record_id, $tags) {
+function tag_set($record_type, $record_id, $tags, $userid = 0) {
static $in_recursion_semaphore = false; // this is to prevent loops when tagging a tag
if ( $record_type == 'tag' && !$in_recursion_semaphore) {
@@ -111,7 +112,7 @@
$tag_current_id = $new_tag[$clean_tag];
}
- tag_assign($record_type, $record_id, $tag_current_id, $ordering);
+ tag_assign($record_type, $record_id, $tag_current_id, $ordering, $userid);
// if we are tagging a tag (adding a manually-assigned related tag), we
// need to create the opposite relationship as well.
@@ -129,18 +130,22 @@
* @param string $record_type the type of record to tag ('post' for blogs,
* 'user' for users, etc.
* @param int $record_id the id of the record to tag
- * @param string $tag the tag to add
+ * @param mixed $tag the tag to add, or an array of tags to add
+ * @param int $userid only required for course tagging
* @return void
*/
-function tag_set_add($record_type, $record_id, $tag) {
+function tag_set_add($record_type, $record_id, $tags, $userid = 0) {
- $new_tags = array();
- foreach( tag_get_tags($record_type, $record_id) as $current_tag ) {
- $new_tags[] = $current_tag->rawname;
+ if (!is_array($tags)) {
+ $_tag = $tags;
+ $tags = array($_tag);
}
- $new_tags[] = $tag;
- return tag_set($record_type, $record_id, $new_tags);
+ foreach( tag_get_tags($record_type, $record_id, NULL, $userid) as $current_tag ) {
+ $tags[] = $current_tag->rawname;
+ }
+
+ return tag_set($record_type, $record_id, $tags, $userid);
}
/**
@@ -239,9 +244,10 @@
* @param int $record_id the record id for which we want to get the tags
* @param string $type the tag type (either 'default' or 'official'). By default,
* all tags are returned.
+ * @param int $userid only required for course tagging
* @return array the array of tags
*/
-function tag_get_tags($record_type, $record_id, $type=null) {
+function tag_get_tags($record_type, $record_id, $type=null, $userid=0) {
global $CFG, $DB;
$params = array();
@@ -253,9 +259,15 @@
$type = '';
}
+ $u = null;
+ if ($userid) {
+ $u = "AND ti.tiuserid = :userid ";
+ $params['userid'] = $userid;
+ }
+
$sql = "SELECT tg.id, tg.tagtype, tg.name, tg.rawname, tg.flag, ti.ordering
FROM {tag_instance} ti JOIN {tag} tg ON tg.id = ti.tagid
- WHERE ti.itemtype = :recordtype AND ti.itemid = :recordid $type
+ WHERE ti.itemtype = :recordtype AND ti.itemid = :recordid $u $type
ORDER BY ti.ordering ASC";
$params['recordtype'] = $record_type;
$params['recordid'] = $record_id;
@@ -667,14 +679,15 @@
* @param int $record_id the id of the record that will be tagged
* @param string $tagid the tag id to set on the record.
* @param int $ordering the order of the instance for this record
+ * @param int $userid only required for course tagging
* @return bool true on success, false otherwise
*/
-function tag_assign($record_type, $record_id, $tagid, $ordering) {
+function tag_assign($record_type, $record_id, $tagid, $ordering, $userid = 0) {
global $DB;
require_capability('moodle/tag:create', get_context_instance(CONTEXT_SYSTEM));
- if ( $tag_instance_object = $DB->get_record('tag_instance', array('tagid'=>$tagid, 'itemtype'=>$record_type, 'itemid'=>$record_id), 'id')) {
+ if ( $tag_instance_object = $DB->get_record('tag_instance', array('tagid'=>$tagid, 'itemtype'=>$record_type, 'itemid'=>$record_id, 'tiuserid'=>$userid), 'id')) {
$tag_instance_object->ordering = $ordering;
$tag_instance_object->timemodified = time();
return $DB->update_record('tag_instance', $tag_instance_object);
@@ -685,6 +698,7 @@
$tag_instance_object->itemtype = $record_type;
$tag_instance_object->ordering = $ordering;
$tag_instance_object->timemodified = time();
+ $tag_instance_object->tiuserid = $userid;
return $DB->insert_record('tag_instance', $tag_instance_object);
}
}
Index: tag/index.php
===================================================================
RCS file: /cvsroot/moodle/moodle/tag/index.php,v
retrieving revision 1.27
diff -u -r1.27 index.php
--- tag/index.php 2 Apr 2008 07:17:18 -0000 1.27
+++ tag/index.php 13 Jun 2008 15:12:16 -0000
@@ -13,7 +13,7 @@
}
$tagid = optional_param('id', 0, PARAM_INT); // tag id
-$tagname = optional_param('tag', '', PARAM_TAG); // tag
+$tagname = optional_param('tag', '', PARAM_TAG); // tag
$edit = optional_param('edit', -1, PARAM_BOOL);
$userpage = optional_param('userpage', 0, PARAM_INT); // which page to show
@@ -96,7 +96,7 @@
// Print last 10 blogs
-// I was not able to use get_items_tagged_with() because it automatically
+// I was not able to use get_items_tagged_with() because it automatically
// tries to join on 'blog' table, since the itemtype is 'blog'. However blogs
// uses the post table so this would not really work. - Yu 29/8/07
if (has_capability('moodle/blog:view', $systemcontext)) { // You have to see blogs obviously
@@ -118,7 +118,7 @@
echo '';
echo format_string($blog->subject);
echo '';
- echo ' - ';
+ echo ' - ';
echo '';
echo fullname($blog);
echo '';
@@ -133,9 +133,26 @@
}
}
+// Display courses tagged with the tag
+require_once($CFG->dirroot.'/tag/coursetagslib.php');
+if ($courses = coursetag_get_tagged_courses($tag->id)) {
-echo '';
+ $totalcount = count( $courses );
+ $coursestitle = get_string('tagindex_coursetitle', 'tag', '"'.$tagname.'": '.$totalcount);
+
+ print_box_start('generalbox', 'tag-blogs'); //could use an id separate from tag-blogs, but would have to copy the css style to make it look the same
+
+ print_heading($coursestitle, '', 3);
+
+ foreach ($courses as $course) {
+ print_course($course);
+ print_spacer(5,5);
+ }
+ print_box_end();
+}
+
+echo '';
//----------------- right column -----------------
Index: tag/edit.php
===================================================================
RCS file: /cvsroot/moodle/moodle/tag/edit.php,v
retrieving revision 1.25
diff -u -r1.25 edit.php
--- tag/edit.php 9 Jun 2008 16:53:39 -0000 1.25
+++ tag/edit.php 13 Jun 2008 15:12:16 -0000
@@ -90,7 +90,7 @@
if (has_capability('moodle/tag:manage', $systemcontext)) {
// rename tag
if(!tag_rename($tag->id, $tagnew->rawname)) {
- error('Error updating tag record');
+ print_error('errorupdatingrecord', 'tag');
}
}
Index: course/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/course/lib.php,v
retrieving revision 1.603
diff -u -r1.603 lib.php
--- course/lib.php 4 Jun 2008 23:45:31 -0000 1.603
+++ course/lib.php 13 Jun 2008 15:12:14 -0000
@@ -40,6 +40,9 @@
case 'upload':
return $url;
break;
+ case 'coursetags':
+ return '/'.$url;
+ break;
case 'library':
case '':
return '/';
Index: lang/en_utf8/tag.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/tag.php,v
retrieving revision 1.15
diff -u -r1.15 tag.php
--- lang/en_utf8/tag.php 29 Feb 2008 09:35:04 -0000 1.15
+++ lang/en_utf8/tag.php 13 Jun 2008 15:12:14 -0000
@@ -10,7 +10,11 @@
$string['description'] = 'Description';
$string['delete'] = 'Delete';
$string['deleted'] = 'Deleted';
+$string['deletedcoursetags'] = 'Deleted - course tags';
$string['edittag'] = 'Edit this tag';
+$string['errordeleting'] = 'Error deleting tag with id $a, please report to your system administrator.';
+$string['errortagfrontpage'] = 'Tagging the site main page is not allowed';
+$string['errorupdatingrecord'] = 'Error updating tag record';
$string['flag'] = 'Flag';
$string['flagasinappropriate'] = 'Flag as inappropriate';
$string['helprelatedtags'] = 'Comma separated related tags';
@@ -40,9 +44,11 @@
$string['tagtype'] = 'Tag type';
$string['tagtype_official'] = 'Official';
$string['tagtype_default'] = 'Default';
+$string['tagindex_coursetitle'] = 'Courses tagged with $a';
$string['tags'] = 'Tags';
$string['tagsaredisabled'] = 'Tags are disabled';
$string['thingstaggedwith'] = '$a->count things tagged with \"$a->name\"';
+$string['thingtaggedwith'] = '$a->count thing tagged with \"$a->name\"';
$string['thistaghasnodesc'] = 'This tag currently has no description.';
$string['timemodified'] = 'Modified';
$string['typechanged'] = 'Tag type changed';
Index: lib/db/upgrade.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/db/upgrade.php,v
retrieving revision 1.204
diff -u -r1.204 upgrade.php
--- lib/db/upgrade.php 30 May 2008 16:50:25 -0000 1.204
+++ lib/db/upgrade.php 13 Jun 2008 15:12:16 -0000
@@ -128,6 +128,28 @@
upgrade_main_savepoint($result, 2008051202);
}
+ if ($result && $oldversion < 2008061302) {
+ // table to be modified
+ $table = new xmldb_table('tag_instance');
+ // add field
+ $field = new xmldb_field('tiuserid');
+ if (!$dbman->field_exists($table, $field)) {
+ $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0, 'itemid');
+ $result = $result && $dbman->add_field($table, $field);
+ }
+ // modify index
+ $index = new xmldb_index('itemtype-itemid-tagid');
+ $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid'));
+ $dbman->drop_index($table, $index);
+ $index = new xmldb_index('itemtype-itemid-tagid-tiuserid');
+ $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid'));
+ $dbman->drop_index($table, $index); //should not be required, but better safe than sorry
+ $result = $result && $dbman->add_index($table, $index);
+
+ /// Main savepoint reached
+ upgrade_main_savepoint($result, 2008061302);
+ }
+
/*
* TODO:
* drop adodb_logsql table and create a new general sql log table
Index: lib/db/install.xml
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/db/install.xml,v
retrieving revision 1.151
diff -u -r1.151 install.xml
--- lib/db/install.xml 12 Jun 2008 02:09:26 -0000 1.151
+++ lib/db/install.xml 13 Jun 2008 15:12:16 -0000
@@ -1503,8 +1503,9 @@
-
-
+
+
+
@@ -1512,7 +1513,7 @@
-
+
Index: lib/moodlelib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/moodlelib.php,v
retrieving revision 1.1057
diff -u -r1.1057 moodlelib.php
--- lib/moodlelib.php 9 Jun 2008 16:53:36 -0000 1.1057
+++ lib/moodlelib.php 13 Jun 2008 15:12:15 -0000
@@ -154,8 +154,8 @@
define('PARAM_TAG', 0x0011);
/**
- * PARAM_TAGLIST - list of tags separated by commas (interests, blogs, etc.)
- */
+ * PARAM_TAGLIST - list of tags separated by commas (interests, blogs, etc.)
+ */
define('PARAM_TAGLIST', 0x0012);
/**
@@ -2898,7 +2898,7 @@
}
/**
- * will truncate userinfo as it comes from auth_get_userinfo (from external auth)
+ * will truncate userinfo as it comes from auth_get_userinfo (from external auth)
* which may have large fields
*/
function truncate_userinfo($info) {
@@ -3624,6 +3624,10 @@
remove_course_grades($courseid, $showfeedback);
remove_grade_letters($context, $showfeedback);
+/// Delete course tags
+ require_once($CFG->dirroot.'/tag/coursetagslib.php');
+ coursetag_delete_course_tags($course->id, $showfeedback);
+
return $result;
}
Index: lang/en_utf8/block_tags.php
===================================================================
RCS file: lang/en_utf8/block_tags.php
diff -N lang/en_utf8/block_tags.php
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lang/en_utf8/block_tags.php 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,66 @@
+
Index: lang/en_utf8/help/block_tags/deletetags.html
===================================================================
RCS file: lang/en_utf8/help/block_tags/deletetags.html
diff -N lang/en_utf8/help/block_tags/deletetags.html
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lang/en_utf8/help/block_tags/deletetags.html 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,9 @@
+
Deleting a tag for a course
+
+
You will only be able to delete a tag entry that you have previously created.
+This allows you to tidy up those mis-spelled, or out-dated tags. Please note that
+deletion will only delete the tag if no other user has tagged something else with it,
+otherwise deletion will just delete your association of that tag for the course.
+
+
Deleting is done by highlighting the tag you wish to delete under 'Select...',
+then clicking the 'Submit' button below.
Index: tag/coursetags_add.php
===================================================================
RCS file: tag/coursetags_add.php
diff -N tag/coursetags_add.php
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tag/coursetags_add.php 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,39 @@
+dirroot.'/tag/coursetagslib.php');
+
+ if ($courseid > 0 and $userid > 0) {
+ $myurl = 'tag/search.php';
+ $keywords = explode(',', $keyword);
+ try {
+ coursetag_store_keywords($keywords, $courseid, $userid, 'default', $myurl);
+ }
+ catch (Exception $e) {
+ error($e->getmessage());
+ }
+ }
+}
+
+// send back to originating page, where the new tag will be visible in the block
+if ($courseid > 0) {
+ $myurl = $CFG->wwwroot.'/course/view.php?id='.$courseid;
+} else {
+ $myurl = $CFG->wwwroot.'/';
+}
+
+redirect($myurl);
+
+?>
Index: tag/coursetagslib.php
===================================================================
RCS file: tag/coursetagslib.php
diff -N tag/coursetagslib.php
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tag/coursetagslib.php 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,592 @@
+dirroot.'/tag/lib.php';
+
+/**
+ * Returns an ordered array of tags associated with visible courses
+ * (boosted replacement of get_all_tags() allowing association with user and tagtype).
+ *
+ * @uses $CFG
+ * @param int $courseid, a 0 will return all distinct tags for visible courses
+ * @param int $userid optional the user id, a default of 0 will return all users tags for the course
+ * @param string $tagtype optional 'official' or 'default', empty returns both tag types
+ * @param int $numtags optional number of tags to display, default of 80 is set in the block, 0 returns all
+ * @param string $sort optional selected sorting, default is alpha sort (name) also timemodified or popularity
+ * @return array
+ */
+function coursetag_get_tags($courseid, $userid=0, $tagtype='', $numtags=0, $sort='name') {
+
+ global $CFG, $DB;
+
+ // get visible course ids
+ $courselist = array();
+ if ($courseid === 0) {
+ if ($courses = $DB->get_records_select('course', 'visible=1 AND category>0', null, '', 'id')) {
+ foreach ($courses as $key => $value) {
+ $courselist[] = $key;
+ }
+ }
+ }
+
+ // 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
+ FROM {$CFG->prefix}tag t,
+ (SELECT tagid, MAX(timemodified) as timemodified, COUNT(id) as count
+ FROM {$CFG->prefix}tag_instance
+ WHERE itemtype = 'course' ";
+
+ if ($courseid > 0) {
+ $sql .= " AND itemid = :courseid ";
+ $params['courseid'] = $courseid;
+ } else {
+ if (!empty($courselist)) {
+ $depends_on = array(1, 43, 553);
+ list($usql, $uparams) = $DB->get_in_or_equal($courselist, SQL_PARAMS_NAMED);
+ $sql .= "AND itemid $usql ";
+ $params = $params + $uparams;
+ }
+ }
+
+ if ($userid > 0) {
+ $sql .= " AND tiuserid = :userid ";
+ $params['userid'] = $userid;
+ }
+
+ $sql .= " GROUP BY tagid) f
+ WHERE t.id = f.tagid ";
+ if ($tagtype != '') {
+ $sql .= "AND tagtype = :tagtype ";
+ $params['tagtype'] = $tagtype;
+ }
+ $sql .= "ORDER BY count DESC, name ASC";
+
+ // limit the number of tags for output
+ if ($numtags == 0) {
+ $tags = $DB->get_records_sql($sql, $params);
+ } else {
+ $tags = $DB->get_records_sql($sql, $params, 0, $numtags);
+ }
+
+ // prepare the return
+ $return = array();
+ if ($tags) {
+ // sort the tag display order
+ if ($sort != 'popularity') {
+ $CFG->tagsort = $sort;
+ usort($tags, "coursetag_sort");
+ }
+ // avoid print_tag_cloud()'s ksort upsetting ordering by setting the key here
+ foreach ($tags as $value) {
+ $return[] = $value;
+ }
+ }
+
+ return $return;
+
+}
+
+/**
+ * Returns an ordered array of tags
+ * (replaces popular_tags_count() allowing sorting).
+ *
+ * @uses $CFG
+ * @param string $sort optional selected sorting, default is alpha sort (name) also timemodified or popularity
+ * @param int $numtags optional number of tags to display, default of 20 is set in the block, 0 returns all
+ * @return array
+ */
+function coursetag_get_all_tags($sort='name', $numtags=0) {
+
+ global $CFG, $DB;
+
+ // note that this selects all tags except for courses that are not visible
+ $sql = "SELECT id, name, id, tagtype, rawname, f.timemodified, flag, count
+ FROM {$CFG->prefix}tag t,
+ (SELECT tagid, MAX(timemodified) as timemodified, COUNT(id) as count
+ FROM {$CFG->prefix}tag_instance WHERE tagid NOT IN
+ (SELECT tagid FROM {$CFG->prefix}tag_instance ti, {$CFG->prefix}course c
+ WHERE c.visible = 0
+ AND ti.itemtype = 'course'
+ AND ti.itemid = c.id)
+ GROUP BY tagid) f
+ WHERE t.id = f.tagid
+ ORDER BY count DESC, name ASC";
+ if ($numtags == 0) {
+ $tags = $DB->get_records_sql($sql);
+ } else {
+ $tags = $DB->get_records_sql($sql, null, 0, $numtags);
+ }
+
+ $return = array();
+ if ($tags) {
+ if ($sort != 'popularity') {
+ $CFG->tagsort = $sort;
+ usort($tags, "coursetag_sort");
+ }
+ foreach ($tags as $value) {
+ $return[] = $value;
+ }
+ }
+
+ return $return;
+}
+
+/**
+ * Callback function for coursetag_get_tags() and coursetag_get_all_tags() only
+ * @uses $CFG
+ */
+function coursetag_sort($a, $b) {
+ // originally from block_blog_tags
+ global $CFG;
+
+ // set up the variable $tagsort as either 'name' or 'timemodified' only, 'popularity' does not need sorting
+ if (empty($CFG->tagsort)) {
+ $tagsort = 'name';
+ } else {
+ $tagsort = $CFG->tagsort;
+ }
+
+ if (is_numeric($a->$tagsort)) {
+ return ($a->$tagsort == $b->$tagsort) ? 0 : ($a->$tagsort < $b->$tagsort) ? 1 : -1;
+ } elseif (is_string($a->$tagsort)) {
+ return strcmp($a->$tagsort, $b->$tagsort);
+ } else {
+ return 0;
+ }
+}
+
+/**
+ * Prints a tag cloud
+ *
+ * @param array $tagcloud array of tag objects (fields: id, name, rawname, count and flag)
+ * @param int $max_size maximum text size, in percentage
+ * @param int $min_size minimum text size, in percentage
+ * @param $return if true return html string
+ */
+function coursetag_print_cloud($tagcloud, $return=false, $max_size=180, $min_size=80) {
+
+ global $CFG;
+
+ if (empty($tagcloud)) {
+ return;
+ }
+
+ ksort($tagcloud);
+
+ $count = array();
+ foreach ($tagcloud as $key => $value) {
+ if(!empty($value->count)) {
+ $count[$key] = log10($value->count);
+ } else {
+ $count[$key] = 0;
+ }
+ }
+
+ $max = max($count);
+ $min = min($count);
+
+ $spread = $max - $min;
+ if (0 == $spread) { // we don't want to divide by zero
+ $spread = 1;
+ }
+
+ $step = ($max_size - $min_size)/($spread);
+
+ $systemcontext = get_context_instance(CONTEXT_SYSTEM);
+ $can_manage_tags = has_capability('moodle/tag:manage', $systemcontext);
+
+ //prints the tag cloud
+ $output = '
';
+ foreach ($tagcloud as $key => $tag) {
+
+ $size = $min_size + ((log10($tag->count) - $min) * $step);
+ $size = ceil($size);
+
+ $style = 'style="font-size: '.$size.'%"';
+
+ if ($tag->count > 1) {
+ $title = 'title="'.s(get_string('thingstaggedwith','tag', $tag)).'"';
+ } else {
+ $title = 'title="'.s(get_string('thingtaggedwith','tag', $tag)).'"';
+ }
+
+ $href = 'href="'.$CFG->wwwroot.'/tag/index.php?id='.$tag->id.'"';
+
+ //highlight tags that have been flagged as inappropriate for those who can manage them
+ $tagname = tag_display_name($tag);
+ if ($tag->flag > 0 && $can_manage_tags) {
+ $tagname = '' . tag_display_name($tag) . '';
+ }
+
+ $tag_link = '
A tag is a shortcut or way of navigating to your favourite things.
+
+
Not only can you tag courses, but you may also tag your blogs, or even your own profile.
+
+
Clicking on a tag will take you to a page listing all the things associated with that tag.
+If the tag is a popular one you will be able to see what other things other users have associated
+with that tag.
+
+
You may add as many tags as you like. While it is recommended to only add one tag at a time,
+more tags could be entered on one occasion by seperating the tags with a comma.
+As you are adding a tag you may notice a word appearing in the background where you are typing.
+If this word is what you want as your tag then you can click on the little
+arrow next to the entry box to save typing the that word (and don't forget to click submit to save).
+
+
Tags must be more than one character and may be up to 50 characters long.
+Please note that while extended characters are allowed (e.g. French acute
+accented characters or Chinese characters), special characters will be
+stripped (e.g. "',\,_,<,-,~,?").
+Also note that tags cannot be pure integers or float number (e.g. 1 or 1.11)
+but number and letter combinations are fine (e.g. 1a).
+Finally, commas cannot be used in tag names, as these are separators between tags entered.
+
+
Don't forget to click the 'Submit' button below to save your new tag.
A note about the tag count. Hovering the mouse over a tag will reveal a tag count message
+like '2 things tagged with ...'.
+This count (number) will vary depending on where the tag is being displayed at the time.
+
+
The 'More tags' page (and the tags block) can display several different selections of tags
+- for instance 'all tags' or 'my tags'.
+The count displayed for a tag under 'all tags' may be different to the count for the same tag
+displayed under the 'my tags' or one of the other selections.
+This is because when 'all tags' is showing, all tags for courses, blogs and user profiles
+are displayed and counted.
+Where as when 'my tags' is showing, only your own tags for courses you have tagged
+are displayed and counted.
+So the count could be quite different for one tag under different sections.
+
+
Of course the size of the tag is also a clue to the count. The bigger the font size for the tag the
+more popular the tag is.
+
+
In fact it is easy to re-order the tags displayed by popularity, using the link provided.
+And the tags may be re-ordered alphabetically or in date of creation order as well. Try it.