### Eclipse Workspace Patch 1.0 #P core Index: blocks/tags/block_tags.php =================================================================== RCS file: /cvsroot/moodle/moodle/blocks/tags/block_tags.php,v retrieving revision 1.8 diff -u -r1.8 block_tags.php --- blocks/tags/block_tags.php 3 Mar 2008 11:43:34 -0000 1.8 +++ blocks/tags/block_tags.php 1 Apr 2008 10:53:16 -0000 @@ -1,9 +1,19 @@ showcoursetags into admin/settings.php?section=sitepolicies if coursetagging is accepted into core +// Until the set SHOWCOURSETAGS to false if you do not want course tags in the tags block +define ('SHOWCOURSETAGS', true); + class block_tags extends block_base { function init() { - $this->version = 2007101509; + $this->version = 2008031200; + //$this->version = 2007101509; $this->title = get_string('blocktagstitle', 'tag'); + // the cron function goes through all users so only do daily + // remove until rsslib supports dc/cc + // $this->cron = 60*60*24; } function instance_allow_multiple() { @@ -61,7 +71,252 @@ require_once($CFG->dirroot.'/tag/lib.php'); - $this->content->text = tag_print_cloud($this->config->numberoftags, true); + if (!SHOWCOURSETAGS) { //will be $CFG->showcoursetags + + $this->content->text = tag_print_cloud($this->config->numberoftags, true); + + } else { + + require_once($CFG->dirroot.'/tag/coursetagslib.php'); + + // Permissions and page awareness + $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID); + $isguest = has_capability('moodle/legacy:guest', $sitecontext, $USER->id, false); + $loggedin = isloggedin() && !$isguest; + $isadmin = has_capability('moodle/site:doanything', $sitecontext); + $coursepage = $canedit = false; + $coursepage = (isset($COURSE->id) && $COURSE->id != SITEID); + $mymoodlepage = strpos($_SERVER['PHP_SELF'], 'my') > 0 ? true : false; + $sitepage = (isset($COURSE->id) && $COURSE->id == SITEID && !$mymoodlepage); + $coursecontext = get_context_instance(CONTEXT_COURSE, $COURSE->id); + if ($coursepage) { + $canedit = has_capability('moodle/tag:create', $sitecontext); + } + + // Check rss feed - temporarily removed until Dublin Core tags added + // provides a feed of users course tags for each unit they have tagged + //$rssfeed = ''; + //if (file_exists($CFG->dataroot.'/'.SITEID.'/usertagsrss/'.$USER->id.'/user_unit_tags_rss.xml')) { + // $rssfeed = '/file.php/'.SITEID.'/usertagsrss/'.$USER->id.'/user_unit_tags_rss.xml'; + //} + + // Language strings + $tagslang = 'block_tags'; + + // DB hits to get groups of marked up tags (if available) + //TODO check whether time limited personal tags are required + $numoftags = $this->config->numberoftags; + $sort = 'name'; + $alltags = $officialtags = $coursetags = $commtags = $mytags = $coursetagdivs = $courseflag = ''; + if ($sitepage or $coursepage) { + $alltags = coursetag_print_cloud(coursetag_get_all_tags($sort, $this->config->numberoftags), true); + $officialtags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', $numoftags, $sort), true); + $commtags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', $numoftags, $sort), true); + if ($loggedin) { + $mytags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', $numoftags, $sort), true); + } + } + if ($coursepage) { + $coursetags = coursetag_print_cloud(coursetag_get_tags($COURSE->id, 0, '', $numoftags, $sort), true); + if (!$coursetags) $coursetags = get_string('notagsyet', $tagslang); + $courseflag = '&courseid='.$COURSE->id; + } + if ($mymoodlepage) { + $mytags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', $numoftags, $sort), true); + $officialtags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', $numoftags, $sort), true); + $commtags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', $numoftags, $sort), true); + } + + // Prepare the divs and javascript that displays the groups of tags (and which is displayed first) + $moretags = $CFG->wwwroot.'/tag/coursetags_more.php'; + $moretagstitle = get_string('moretags', $tagslang); + $moretagsstring = get_string('more', $tagslang); + $displayblock = 'style="display:block"'; + $displaynone = 'style="display:none"'; //only one div created below will be displayed at a time + if ($alltags) { + if ($sitepage) { + $display = $displayblock; + } else { + $display = $displaynone; + } + $alltagscontent = ' +
'. + get_string("alltags", $tagslang). + $alltags. + ' +
'; + $coursetagdivs .= '"f_alltags", '; + } + if ($mytags) { + if ($mymoodlepage) { + $display = $displayblock; + } else { + $display = $displaynone; + } + $mytagscontent = ' +
'; + /*if ($rssfeed) { // - temporarily removed + $mytagscontent .= link_to_popup_window( + $rssfeed, $name='popup', + 'User Unit Tags RSS My Unit Tags RSS', + $height=600, $width=800, + $title='My Unit Tags RSS', $options='menubar=1,scrollbars,resizable', $return=true).'
'; + }*/ + $mytagscontent .= get_string('mytags', $tagslang). + $mytags.' + +
'; + $coursetagdivs .= '"f_mytags", '; + } + if ($officialtags) { + if ($mytags or $alltags) { + $display = $displaynone; + } else { + $display = $displayblock; + } + $officialtagscontent = ' +
'. + get_string('officialtags', $tagslang). + $officialtags.' + +
'; + $coursetagdivs .= '"f_officialtags", '; + } + if ($coursetags) { + if ($coursepage) { + $display = $displayblock; + } else { + $display = $displaynone; + } + $coursetagscontent = ' +
+
'.get_string('coursetags', $tagslang).'
'. + $coursetags.' + +
'; + $coursetagdivs .= '"f_coursetags", '; + } + if ($commtags) { + $commtagscontent = ' +
'. + get_string('communitytags', $tagslang). + $commtags.' + +
'; + $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); + $coursetaghelpbutton = helpbutton('addtags', 'adding tags', $tagslang, TRUE, FALSE, '', TRUE); + $this->content->footer .= << +
+
+ + +
+
+
+
+
+ +
+
+ +
+
+ + + +
+
+
+ + $coursetaghelpbutton +
+
+
+EOT; + // add the edit link + $this->content->footer .= ' +
+ '.get_string('edittags', $tagslang).' +
'; + } + + // 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, '|'); + $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 SHOWCOURSETAGS section return $this->content; } @@ -81,6 +336,21 @@ notice(get_string('blockconfigbad'), str_replace('blockaction=', 'dummy=', qualified_me())); } } -} + /* + * function removed unit 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.71 diff -u -r1.71 lib.php --- tag/lib.php 18 Mar 2008 08:32:56 -0000 1.71 +++ tag/lib.php 1 Apr 2008 10:53:21 -0000 @@ -7,33 +7,33 @@ * @licence http://www.gnu.org/copyleft/gpl.html GNU Public License * @package moodlecore * - * A "tag string" is always a rawurlencode'd string. This is the same behavior + * A "tag string" is always a rawurlencode'd string. This is the same behavior * as http://del.icio.us * @see http://www.php.net/manual/en/function.urlencode.php * - * Tag strings : you can use any character in tags, except the comma (which is - * the separator) and the '\' (backslash). Note that many spaces (or other + * Tag strings : you can use any character in tags, except the comma (which is + * the separator) and the '\' (backslash). Note that many spaces (or other * blank characters) will get "compressed" into one. * - * A "record" is a php array (note that an object will work too) that contains - * the following variables : + * A "record" is a php array (note that an object will work too) that contains + * the following variables : * - type: the table containing the record that we are tagging (eg: for a * blog, this is table 'post', and for a user it is 'user') - * - id: the id of the record + * - id: the id of the record * - * TODO: turn this into a full-fledged categorization system. This could start - * by modifying (removing, probably) the 'tag type' to use another table - * describing the relationship between tags (parents, sibling, etc.), which + * TODO: turn this into a full-fledged categorization system. This could start + * by modifying (removing, probably) the 'tag type' to use another table + * describing the relationship between tags (parents, sibling, etc.), which * could then be merged with the 'course categorization' system... * - * BASIC INSTRUCTIONS : - * - to "tag a blog post" (for example): + * BASIC INSTRUCTIONS : + * - to "tag a blog post" (for example): * tag_set('post', $blog_post->id, $array_of_tags); * * - to "remove all the tags on a blog post": * tag_set('post', $blog_post->id, array()); * - * Tag set will create tags that need to be created. + * Tag set will create tags that need to be created. */ define('TAG_RETURN_ARRAY', 0); @@ -58,18 +58,19 @@ /** * Set the tags assigned to a record. This overwrites the current tags. - * - * This function is meant to be fed the string coming up from the user + * + * This function is meant to be fed the string coming up from the user * interface, which contains all tags assigned to a record. * - * @param string $record_type the type of record to tag ('post' for blogs, + * @param string $record_type the type of record to tag ('post' for blogs, * 'user' for users, 'tag' for tags, etc. * @param int $record_id the id of the record to tag - * @param array $tags the array of tags to set on the record. If + * @param array $tags the array of tags to set on the record. If * given an empty array, all tags will be removed. - * @return void + * @param int $userid only required for course tagging//jb23347 + * @return void */ -function tag_set($record_type, $record_id, $tags) { +function tag_set($record_type, $record_id, $tags, $userid = 0) {//jb23347 static $in_recursion_semaphore = false; // this is to prevent loops when tagging a tag if ( $record_type == 'tag' && !$in_recursion_semaphore) { @@ -81,7 +82,7 @@ //echo 'tags-in-tag_set'; var_dump($tags); var_dump($tags_ids); var_dump($cleaned_tags); $current_ids = tag_get_tags_ids($record_type, $record_id); - //var_dump($current_ids); + //var_dump($current_ids); // for data coherence reasons, it's better to remove deleted tags // before adding new data: ordering could be duplicated. @@ -89,7 +90,7 @@ if (!in_array($current_id, $tags_ids)) { tag_delete_instance($record_type, $record_id, $current_id); if ( $record_type == 'tag' && !$in_recursion_semaphore) { - // if we are removing a tag-on-a-tag (manually related tag), + // if we are removing a tag-on-a-tag (manually related tag), // we need to remove the opposite relationship as well. tag_delete_instance('tag', $current_id, $record_id); } @@ -104,7 +105,7 @@ $clean_tag = $cleaned_tags[$tag]; $tag_current_id = $tags_ids[$clean_tag]; - + if ( is_null($tag_current_id) ) { // create new tags //echo "call to add tag $tag\n"; @@ -112,7 +113,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);//jb23347 // if we are tagging a tag (adding a manually-assigned related tag), we // need to create the opposite relationship as well. @@ -126,28 +127,29 @@ /** * Adds a tag to a record, without overwriting the current tags. - * - * @param string $record_type the type of record to tag ('post' for blogs, + * + * @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 int $userid only required for course tagging//jb23347 * @return void */ -function tag_set_add($record_type, $record_id, $tag) { +function tag_set_add($record_type, $record_id, $tag, $userid = 0) {//jb23347 $new_tags = array(); - foreach( tag_get_tags($record_type, $record_id) as $current_tag ) { + foreach( tag_get_tags($record_type, $record_id, NULL, $userid) as $current_tag ) {//jb23347 $new_tags[] = $current_tag->rawname; } $new_tags[] = $tag; - - return tag_set($record_type, $record_id, $new_tags); + + return tag_set($record_type, $record_id, $new_tags, $userid);//jb23347 } /** * Removes a tag from a record, without overwriting other current tags. - * - * @param string $record_type the type of record to tag ('post' for blogs, + * + * @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 delete @@ -184,13 +186,13 @@ } -/** +/** * Set the description of a tag - * + * * @param int $tagid the id of the tag * @param string $description the description * @param int $descriptionformat the moodle text format of the description - * @return true on success, false otherwise + * @return true on success, false otherwise */ function tag_description_set($tagid, $description, $descriptionformat) { if ($tag = get_record('tag', 'id', $tagid, '', '', '', '', 'id')) { @@ -227,17 +229,18 @@ /** - * Get the array of db record of tags associated to a record (instances). Use + * Get the array of db record of tags associated to a record (instances). Use * tag_get_tags_csv to get the same information in a comma-separated string. * - * @param string $record_type the record type for which we want to get the tags - * @param int $record_id the record id for which we want to get the tags + * @param string $record_type the record type for which we want to get the tags + * @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//jb23347 * @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) {//jb23347 + global $CFG; if ($type) { @@ -247,18 +250,18 @@ // if the fields in this query are changed, you need to do the same changes in tag_get_correlated_tags $tags = get_records_sql("SELECT tg.id, tg.tagtype, tg.name, tg.rawname, tg.flag, ti.ordering ". "FROM {$CFG->prefix}tag_instance ti INNER JOIN {$CFG->prefix}tag tg ON tg.id = ti.tagid ". - "WHERE ti.itemtype = '{$record_type}' AND ti.itemid = '{$record_id}' {$type} ". + "WHERE ti.itemtype = '{$record_type}' AND ti.itemid = '{$record_id}' AND ti.tiuserid = '{$userid}' {$type} ".//jb23347 "ORDER BY ti.ordering ASC"); - // This version of the query, reversing the ON clause, "correctly" returns - // a row with NULL values for instances that are still in the DB even though - // the tag has been deleted. This shouldn't happen, but if it did, using + // This version of the query, reversing the ON clause, "correctly" returns + // a row with NULL values for instances that are still in the DB even though + // the tag has been deleted. This shouldn't happen, but if it did, using // this query could help "clean it up". This causes bugs at this time. //$tags = get_records_sql("SELECT ti.tagid, tg.tagtype, tg.name, tg.rawname, tg.flag, ti.ordering ". // "FROM {$CFG->prefix}tag_instance ti LEFT JOIN {$CFG->prefix}tag tg ON ti.tagid = tg.id ". // "WHERE ti.itemtype = '{$record_type}' AND ti.itemid = '{$record_id}' {$type} ". // "ORDER BY ti.ordering ASC"); - if (!$tags) { + if (!$tags) { return array(); } else { return $tags; @@ -267,7 +270,7 @@ /** * Get the array of tags display names, indexed by id. - * + * * @param string $record_type the record type for which we want to get the tags * @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, @@ -316,7 +319,7 @@ * @return array of tag ids, indexed and sorted by 'ordering' */ function tag_get_tags_ids($record_type, $record_id) { - + $tag_ids = array(); foreach (tag_get_tags($record_type, $record_id) as $tag) { if ( array_key_exists($tag->ordering, $tag_ids) ) { @@ -331,16 +334,16 @@ return $tag_ids; } -/** +/** * Returns the database ID of a set of tags. - * + * * @param mixed $tags one tag, or array of tags, to look for. - * @param bool $return_value specify the type of the returned value. Either - * TAG_RETURN_OBJECT, or TAG_RETURN_ARRAY (default). If TAG_RETURN_ARRAY - * is specified, an array will be returned even if only one tag was + * @param bool $return_value specify the type of the returned value. Either + * TAG_RETURN_OBJECT, or TAG_RETURN_ARRAY (default). If TAG_RETURN_ARRAY + * is specified, an array will be returned even if only one tag was * passed in $tags. - * @return mixed tag-indexed array of ids (or objects, if second parameter is - * TAG_RETURN_OBJECT), or only an int, if only one tag is given *and* the + * @return mixed tag-indexed array of ids (or objects, if second parameter is + * TAG_RETURN_OBJECT), or only an int, if only one tag is given *and* the * second parameter is null. No value for a key means the tag wasn't found. */ function tag_get_id($tags, $return_value=null) { @@ -350,13 +353,13 @@ $return_an_int = false; if (!is_array($tags)) { if(is_null($return_value) || $return_value == TAG_RETURN_OBJECT) { - $return_an_int = true; + $return_an_int = true; } $tags = array($tags); } - + $result = array(); - + //TODO: test this and see if it helps performance without breaking anything //foreach($tags as $key => $tag) { // $clean_tag = moodle_strtolower($tag); @@ -368,7 +371,7 @@ $tags = array_values(tag_normalize($tags)); foreach($tags as $key => $tag) { - $tags[$key] = addslashes(moodle_strtolower($tag)); + $tags[$key] = addslashes(moodle_strtolower($tag)); $result[moodle_strtolower($tag)] = null; // key must exists : no value for a key means the tag wasn't found. } $tag_string = "'". implode("', '", $tags) ."'"; @@ -398,12 +401,12 @@ * - manually added related tags, which are tag_instance entries for that tag * - correlated tags, which are a calculated * - * @param string $tag_name_or_id is a single **normalized** tag name or the id + * @param string $tag_name_or_id is a single **normalized** tag name or the id * of a tag - * @param int $type the function will return either manually - * (TAG_RELATED_MANUAL) related tags or correlated (TAG_RELATED_CORRELATED) + * @param int $type the function will return either manually + * (TAG_RELATED_MANUAL) related tags or correlated (TAG_RELATED_CORRELATED) * tags. Default is TAG_RELATED_ALL, which returns everything. - * @param int $limitnum return a subset comprising this many records (optional, + * @param int $limitnum return a subset comprising this many records (optional, * default is 10) * @return array an array of tag objects */ @@ -427,7 +430,7 @@ return array_slice(object_array_unique($related_tags), 0 , $limitnum); } -/** +/** * Get a comma-separated list of tags related to another tag. * * @param array $related_tags the array returned by tag_get_related_tags @@ -470,13 +473,13 @@ // Prevent the rename if a tag with that name already exists if ($existing = tag_get('name', $newname_clean, 'id, name, rawname')) { if ($existing->id != $tagid) { // Another tag already exists with this name - return false; + return false; } } if ($tag = tag_get('id', $tagid, 'id, name, rawname')) { - $tag->rawname = addslashes($newrawname_clean); - $tag->name = addslashes($newname_clean); + $tag->rawname = addslashes($newrawname_clean); + $tag->name = addslashes($newname_clean); $tag->timemodified = time(); return update_record('tag', $tag); } @@ -486,9 +489,9 @@ /** * Delete one or more tag, and all their instances if there are any left. - * + * * @param mixed $tagids one tagid (int), or one array of tagids to delete - * @return bool true on success, false otherwise + * @return bool true on success, false otherwise */ function tag_delete($tagids) { @@ -501,8 +504,8 @@ if (is_null($tagid)) { // can happen if tag doesn't exists continue; } - // only delete the main entry if there were no problems deleting all the - // instances - that (and the fact we won't often delete lots of tags) + // only delete the main entry if there were no problems deleting all the + // instances - that (and the fact we won't often delete lots of tags) // is the reason for not using delete_records_select() if ( delete_records('tag_instance', 'tagid', $tagid) ) { $success &= (bool) delete_records('tag', 'id', $tagid); @@ -571,7 +574,7 @@ * @return array of matching objects, indexed by record id, from the table containing the type requested */ function tag_find_records($tag, $type, $limitfrom='', $limitnum='') { - + global $CFG; if (!$tag || !$type) { @@ -583,8 +586,8 @@ $query = "SELECT it.* ". "FROM {$CFG->prefix}{$type} it INNER JOIN {$CFG->prefix}tag_instance tt ON it.id = tt.itemid ". "WHERE tt.itemtype = '{$type}' AND tt.tagid = '{$tagid}'"; - - return get_records_sql($query, $limitfrom, $limitnum); + + return get_records_sql($query, $limitfrom, $limitnum); } @@ -595,22 +598,22 @@ /** * A * @param array $record the record that will be tagged - * @param string $tags the comma-separated tags to set on the record. If + * @param string $tags the comma-separated tags to set on the record. If * given an empty array, all tags will be removed. -dds one or more tag in the database. This function should not be called +dds one or more tag in the database. This function should not be called * directly : you should use tag_set. * * @param mixed $tags one tag, or an array of tags, to be created - * @param string $tag_type type of tag to be created ("default" is the default + * @param string $tag_type type of tag to be created ("default" is the default * value and "official" is the only other supported value at this time). An * official tag is kept even if there are no records tagged with it. - * @return an array of tags ids, indexed by their lowercase normalized names. + * @return an array of tags ids, indexed by their lowercase normalized names. * Any boolean false in the array indicates an error while adding the tag. */ function tag_add($tags, $type="default") { global $USER; - require_capability('moodle/tag:create', get_context_instance(CONTEXT_SYSTEM)); + require_capability('moodle/tag:create', get_context_instance(CONTEXT_SYSTEM)); if (!is_array($tags)) { $tags = array($tags); @@ -629,9 +632,9 @@ if (!$tag) { $tags_ids[$tag] = false; } else { - // note that the difference between rawname and name is only - // capitalization : the rawname is NOT the same at the rawtag. - $tag_object->rawname = addslashes($tag); + // note that the difference between rawname and name is only + // capitalization : the rawname is NOT the same at the rawtag. + $tag_object->rawname = addslashes($tag); $tag_name_lc = moodle_strtolower($tag); $tag_object->name = addslashes($tag_name_lc); //var_dump($tag_object); @@ -645,28 +648,34 @@ /** * Assigns a tag to a record: if the record already exists, the time and * ordering will be updated. - * + * * @param string $record_type the type of the record that will be tagged * @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 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//jb23347 * @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) {//jb23347 require_capability('moodle/tag:create', get_context_instance(CONTEXT_SYSTEM)); - if ( $tag_instance_object = get_record('tag_instance', 'tagid', $tagid, 'itemtype', $record_type, 'itemid', $record_id, 'id') ) { + //jb23347 + //if ( $tag_instance_object = get_record('tag_instance', 'tagid', $tagid, 'itemtype', $record['type'], 'itemid', $record['id'], 'tagid') ) { + //if ( $tag_instance_object = get_record('tag_instance', 'tagid', $tagid, 'itemtype', $record_type, 'itemid', $record_id, 'id') ) { + $select = "tagid = {$tagid} and itemtype = '{$record_type}' and itemid = {$record_id} and tiuserid = {$userid}"; + if ( $tag_instance_object = get_record_select('tag_instance', $select, 'tagid') ) { $tag_instance_object->ordering = $ordering; $tag_instance_object->timemodified = time(); return update_record('tag_instance', $tag_instance_object); - } else { + } else { $tag_instance_object = new StdClass; $tag_instance_object->tagid = $tagid; $tag_instance_object->itemid = $record_id; $tag_instance_object->itemtype = $record_type; $tag_instance_object->ordering = $ordering; $tag_instance_object->timemodified = time(); + $tag_instance_object->tiuserid = $userid;//jb23347 return insert_record('tag_instance', $tag_instance_object); } } @@ -711,11 +720,11 @@ "WHERE ta.tagid = {$tag->id} AND tb.tagid != {$tag->id} ". "GROUP BY tb.tagid ". "HAVING nr > $min_correlation ". - "ORDER BY nr DESC"; + "ORDER BY nr DESC"; $correlated = array(); - // Correlated tags happen when they appear together in more occasions + // Correlated tags happen when they appear together in more occasions // than $min_correlation. if ($tag_correlations = get_records_sql($query)) { foreach($tag_correlations as $correlation) { @@ -781,9 +790,9 @@ return get_records_sql($query, $limitfrom , $limitnum); } -/** +/** * Get the name of a tag - * + * * @param mixed $tagids the id of the tag, or an array of ids * @return mixed string name of one tag, or id-indexed array of strings */ @@ -796,7 +805,7 @@ } $tag_names = array(); - foreach(get_records_list('tag', 'id', implode(',', $tagids)) as $tag) { + foreach(get_records_list('tag', 'id', implode(',', $tagids)) as $tag) { $tag_names[$tag->id] = $tag->name; } @@ -809,7 +818,7 @@ /** * Returns the correlated tags of a tag, retrieved from the tag_correlation - * table. Make sure cron runs, otherwise the table will be empty and this + * table. Make sure cron runs, otherwise the table will be empty and this * function won't return anything. * * @param int $tag_id is a single tag id @@ -823,14 +832,14 @@ if (!$tag_correlation || empty($tag_correlation->correlatedtags)) { return array(); } - + // this is (and has to) return the same fields as the query in tag_get_tags if ( !$result = get_records_sql("SELECT tg.id, tg.tagtype, tg.name, tg.rawname, tg.flag, ti.ordering ". "FROM {$CFG->prefix}tag tg INNER JOIN {$CFG->prefix}tag_instance ti ON tg.id = ti.tagid ". "WHERE tg.id IN ({$tag_correlation->correlatedtags})") ) { return array(); } - + return $result; } @@ -838,9 +847,9 @@ * Function that normalizes a list of tag names. * * @param mixed $tags array of tags, or a single tag. - * @param int $case case to use for returned value (default: lower case). + * @param int $case case to use for returned value (default: lower case). * Either TAG_CASE_LOWER (default) or TAG_CASE_ORIGINAL - * @return array of lowercased normalized tags, indexed by the normalized tag, + * @return array of lowercased normalized tags, indexed by the normalized tag, * in the same order as the original array. (Eg: 'Banana' => 'banana'). */ function tag_normalize($rawtags, $case = TAG_CASE_LOWER) { @@ -863,13 +872,13 @@ $cleaned_tags_lc[$rawtag] = moodle_strtolower( clean_param($rawtag, PARAM_TAG) ); $cleaned_tags_mc[$rawtag] = clean_param($rawtag, PARAM_TAG); } - if ( $case == TAG_CASE_LOWER ) { + if ( $case == TAG_CASE_LOWER ) { $result[$rawtag] = $cleaned_tags_lc[$rawtag]; } else { // TAG_CASE_ORIGINAL $result[$rawtag] = $cleaned_tags_mc[$rawtag]; } } - + return $result; } @@ -885,7 +894,7 @@ } /** - * Determine if a record is tagged with a specific tag + * Determine if a record is tagged with a specific tag * * @param string $record_type the record type to look for * @param int $record_id the record id to look for @@ -902,7 +911,7 @@ /** * Flag a tag as inapropriate - * + * * @param mixed $tagids one (int) tagid, or an array of tagids * @return void */ @@ -918,9 +927,9 @@ } } -/** +/** * Remove the inapropriate flag on a tag - * + * * @param mixed $tagids one (int) tagid, or an array of tagids * @return bool true if function succeeds, false otherwise */ Index: tag/index.php =================================================================== RCS file: /cvsroot/moodle/moodle/tag/index.php,v retrieving revision 1.26 diff -u -r1.26 index.php --- tag/index.php 18 Mar 2008 08:32:56 -0000 1.26 +++ tag/index.php 1 Apr 2008 10:53:21 -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,6 +133,24 @@ } } +// Display courses tagged with the tag +require_once($CFG->dirroot.'/tag/coursetagslib.php'); +if ($courses = coursetag_get_tagged_courses($tag->id)) { + + $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 ''; Index: course/lib.php =================================================================== RCS file: /cvsroot/moodle/moodle/course/lib.php,v retrieving revision 1.568 diff -u -r1.568 lib.php --- course/lib.php 25 Mar 2008 01:25:54 -0000 1.568 +++ course/lib.php 1 Apr 2008 10:53:17 -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 1 Apr 2008 10:53:17 -0000 @@ -40,9 +40,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/install.xml =================================================================== RCS file: /cvsroot/moodle/moodle/lib/db/install.xml,v retrieving revision 1.147 diff -u -r1.147 install.xml --- lib/db/install.xml 7 Mar 2008 13:23:38 -0000 1.147 +++ lib/db/install.xml 1 Apr 2008 10:53:20 -0000 @@ -1517,8 +1517,9 @@ - - + + + @@ -1526,7 +1527,7 @@ - + Index: lib/db/upgrade.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/db/upgrade.php,v retrieving revision 1.189 diff -u -r1.189 upgrade.php --- lib/db/upgrade.php 19 Mar 2008 23:09:00 -0000 1.189 +++ lib/db/upgrade.php 1 Apr 2008 10:53:21 -0000 @@ -2338,7 +2338,7 @@ $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); /* - * Note: mysql can not create indexes on text fields larger than 333 chars! + * Note: mysql can not create indexes on text fields larger than 333 chars! */ /// Adding indexes to table cache_flags @@ -2383,7 +2383,7 @@ if (index_exists($table, $index)) { $result = $result && drop_index($table, $index); } - + $table = new XMLDBTable('cache_flags'); $index = new XMLDBIndex('flagtype'); $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('flagtype')); @@ -2545,7 +2545,7 @@ FROM {$CFG->prefix}user_lastaccess WHERE NOT EXISTS (SELECT 'x' FROM {$CFG->prefix}course c - WHERE c.id = {$CFG->prefix}user_lastaccess.courseid)"; + WHERE c.id = {$CFG->prefix}user_lastaccess.courseid)"; execute_sql($sql); upgrade_main_savepoint($result, 2007100902); @@ -2568,16 +2568,16 @@ upgrade_main_savepoint($result, 2007100903); } - + if ($result && $oldversion < 2007101500 && !file_exists($CFG->dataroot . '/user')) { // Get list of users by browsing moodledata/user $oldusersdir = $CFG->dataroot . '/users'; $folders = get_directory_list($oldusersdir, '', false, true, false); - + foreach ($folders as $userid) { $olddir = $oldusersdir . '/' . $userid; $files = get_directory_list($olddir); - + if (empty($files)) { continue; } @@ -2604,7 +2604,7 @@ $readmefilename = $oldusersdir . '/README.txt'; if ($handle = fopen($readmefilename, 'w+b')) { if (!fwrite($handle, get_string('olduserdirectory'))) { - // Could not write to the readme file. No cause for huge concern + // Could not write to the readme file. No cause for huge concern notify("Could not write to the README.txt file in $readmefilename."); } fclose($handle); @@ -2612,22 +2612,22 @@ // Could not create the readme file. No cause for huge concern notify("Could not create the README.txt file in $readmefilename."); } - } + } if ($result && $oldversion < 2007101502) { /// try to remove duplicate entries - + $SQL = "SELECT userid, itemid, COUNT(*) FROM {$CFG->prefix}grade_grades GROUP BY userid, itemid HAVING COUNT( * ) >1"; // duplicates found - + if ($rs = get_recordset_sql($SQL)) { if ($rs && $rs->RecordCount() > 0) { while ($dup = rs_fetch_next_record($rs)) { - if ($thisdups = get_records_sql("SELECT id FROM {$CFG->prefix}grade_grades + if ($thisdups = get_records_sql("SELECT id FROM {$CFG->prefix}grade_grades WHERE itemid = $dup->itemid AND userid = $dup->userid ORDER BY timemodified DESC")) { @@ -2655,7 +2655,7 @@ /// Main savepoint reached upgrade_main_savepoint($result, 2007101502); - } + } if ($result && $oldversion < 2007101503) { ///TODO: move this to the end after we stop using 19 version @@ -2691,7 +2691,7 @@ $sql = "DELETE FROM {$CFG->prefix}context WHERE contextlevel=20"; - + execute_sql($sql); /// Main savepoint reached @@ -2853,7 +2853,7 @@ } if ($result && $oldversion < 2007101508.04) { - set_field('tag_instance', 'itemtype', 'post', 'itemtype', 'blog'); + set_field('tag_instance', 'itemtype', 'post', 'itemtype', 'blog'); upgrade_main_savepoint($result, 2007101508.04); } @@ -2930,7 +2930,7 @@ /// Launch add field name $result = $result && add_field($table, $field); - + /// Copy data from old field to new field $result = $result && execute_sql('UPDATE '.$CFG->prefix.'role_names SET name = text'); @@ -2961,7 +2961,7 @@ $result = $result && drop_index($table, $index); /// Main savepoint reached - upgrade_main_savepoint($result, 2008030700); + upgrade_main_savepoint($result, 2008030700); /// Define index contextid-lowerboundary-letter (unique) to be added to grade_letters $table = new XMLDBTable('grade_letters'); @@ -2972,8 +2972,31 @@ $result = $result && add_index($table, $index); /// Main savepoint reached - upgrade_main_savepoint($result, 2008030700); - } + upgrade_main_savepoint($result, 2008030700); + } + + if ($result && $oldversion < 2008031200) { + + // table to be modified + $table = new XMLDBTable('tag_instance'); + // add field + $field = new XMLDBField('tiuserid'); + if (!field_exists($table, $field)) { + $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0, 'itemid'); + $result = $result && add_field($table, $field); + } + // modify index + $index = new XMLDBIndex('itemtype-itemid-tagid'); + $index->setAttributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid')); + drop_index($table, $index); + $index = new XMLDBIndex('itemtype-itemid-tagid-tiuserid'); + $index->setAttributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid')); + drop_index($table, $index); //should not be required, but better safe than sorry + $result = $result && add_index($table, $index); + + /// Main savepoint reached + upgrade_main_savepoint($result, 2008031200); + } return $result; } Index: version.php =================================================================== RCS file: /cvsroot/moodle/moodle/version.php,v retrieving revision 1.600 diff -u -r1.600 version.php --- version.php 1 Apr 2008 03:24:48 -0000 1.600 +++ version.php 1 Apr 2008 10:53:16 -0000 @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2008030700; // YYYYMMDD = date of the last version bump + $version = 2008031200; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20080401)'; // Human-friendly version name Index: lib/moodlelib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/moodlelib.php,v retrieving revision 1.1026 diff -u -r1.1026 moodlelib.php --- lib/moodlelib.php 25 Mar 2008 09:36:01 -0000 1.1026 +++ lib/moodlelib.php 1 Apr 2008 10:53:19 -0000 @@ -3620,6 +3620,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,37 @@ +dirroot.'/tag/coursetagslib.php'); + + if ($courseid > 0 and $userid > 0) { + $myurl = 'tag/search.php?query='.urlencode($keyword); + $keywords = (array)$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,581 @@ +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; + + // get visible course ids + if ($courseid === 0) { + $courselist = '('; + if ($courses = get_records_select('course', 'visible=1 AND category>0', '', 'id')) { + foreach ($courses as $key => $value) { + $courselist .= "$key, "; + } + $courselist = rtrim($courselist, ', '); + $courselist .= ')'; + } else { + $courselist = ''; + } + } + + // get tags from the db ordered by highest count first + $sql = "SELECT id as key, 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 "; + } else { + if ($courselist) { + $sql .= "AND itemid IN $courselist "; + } + } + if ($userid > 0) $sql .= "AND tiuserid = $userid "; + $sql .= "GROUP BY tagid) f + WHERE t.id = f.tagid "; + if ($tagtype != '') $sql .= "AND tagtype = '$tagtype' "; + $sql .= "ORDER BY count DESC, name ASC"; + + // limit the number of tags for output + if ($numtags == 0) { + $tags = get_records_sql($sql); + } else { + $tags = get_records_sql($sql, 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; + + // note that this selects all tags except for courses that are not visible + $sql = "SELECT id as key, 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, hlearn_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 = get_records_sql($sql); + } else { + $tags = get_records_sql($sql, 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 = '
  • '.$tagname.'
  • '; + + $output .= $tag_link; + + } + $output .= '
'."\n"; + + if ($return) { + return $output; + } else { + echo $output; + } + +} + +/** + * Returns javascript for use in tags block and supporting pages + * @param string $coursetagdivs comma separated divs ids + * @uses $CFG + */ +function coursetag_get_jscript($coursetagdivs = '') { + + global $CFG; + + $tabscript = ''; + if ($coursetagdivs) { + $tabscript = 'coursetagdivs = new Array('.$coursetagdivs.')'; + } + + $coursetags = get_records('tag', '', '', 'name ASC', 'name, id'); + $a = 0; + $coursetagscript = ''; + if (!empty($coursetags)) { + foreach ($coursetags as $key => $value) { + $coursetagscript .= "coursetag_tags[$a] = \"$key\"; "; + $a++; + } + } + + $jserror1 = get_string('jserror1', 'block_tags'); + $jserror2 = get_string('jserror2', 'block_tags'); + $jserror3 = get_string('jserror3', 'block_tags'); + $jserror4 = get_string('jserror4', 'block_tags'); + $jserror5 = get_string('jserror5', 'block_tags'); + + $inputscript = << 50) { + alert("$jserror1"); + return false; + } else if (val.indexOf("'") > 0) { + alert("$jserror2"); + return false; + } else if (val.indexOf("_") > 0) { + alert("$jserror3"); + return false; + } else if (val.indexOf("-") > 0) { + alert("$jserror4"); + return false; + } else if (isFinite(val)) { + alert("$jserror5"); + return false; + } else { + return true; + } + } +EOT; + + $str = ' + + '; + + return $str; + +} + +/** + * Returns all tags created by a user for a course + * + * @uses $CFG + * @param int $courseid + * @param int $userid + */ +function coursetag_get_records($courseid, $userid) { + + global $CFG; + + $sql = "SELECT t.id, name, rawname + FROM {$CFG->prefix}tag t, {$CFG->prefix}tag_instance ti + WHERE t.id = ti.tagid + AND ti.tiuserid = '$userid' + AND ti.itemid = '$courseid' + ORDER by name ASC"; + $return = get_records_sql($sql); + + return $return; + +} + +/** + * Stores a tag for a course for a user + * + * @uses $CFG + * @param array $tags simple array of keywords to be stored + * @param integer $courseid + * @param integer $userid + * @param string $tagtype official or default only + * @param string $myurl optional for logging creation of course tags + */ +function coursetag_store_keywords($tags, $courseid, $userid=0, $tagtype='official', $myurl='') { + + global $CFG; + + if (is_array($tags) and !empty($tags)) { + foreach($tags as $tag) { + if (strlen($tag) > 0) { + tag_set_add('course', $courseid, $tag, $userid); + if ($tagtype == 'default' and $myurl != '') { + // log the tagging request - note only for user added tags + add_to_log($courseid, 'coursetags', 'add', $myurl, 'Course tagged'); + } + if ($tagtype == 'official') { + tag_type_set(tag_get_id($tag), $tagtype); + } + } + } + } + +} + +/** + * Deletes a personal tag for a user for a course. + * + * @uses $CFG + * @param int $tagid + * @param int $userid + * @param int $courseid + */ +function coursetag_delete_keyword($tagid, $userid, $courseid) { + + global $CFG; + + $sql = "SELECT COUNT(*) + FROM {$CFG->prefix}tag_instance + WHERE tagid = $tagid + AND tiuserid = $userid + AND itemtype = 'course' + AND itemid = $courseid"; + if (count_records_sql($sql) == 1) { + $sql = "tagid = $tagid + AND tiuserid = $userid + AND itemtype = 'course' + AND itemid = $courseid"; + delete_records_select('tag_instance', $sql); + // if there are no other instances of the tag then consider deleting the tag as well + if (!record_exists('tag_instance', 'tagid', $tagid)) { + // if the tag is a personal tag then delete it - don't do official tags + if (record_exists('tag', 'id', $tagid, 'tagtype', 'default')) { + delete_records('tag', 'id', $tagid, 'tagtype', 'default'); + } + } + } else { + error("Error deleting tag with id $tagid, please report to your system administrator."); + } + +} + +/** + * Get courses tagged with a tag + * + * @param int $tagid + * @return array of course objects + */ +function coursetag_get_tagged_courses($tagid) { + + $courses = array(); + if ($crs = get_records_select('tag_instance', "tagid='$tagid' AND itemtype='course'")) { + foreach ($crs as $c) { + //this capability check was introduced to stop display of courses that a student could not + //view, but arguably it is best that when clicking on a tag, the tagged course summary should + //be seen and then if the student clicks on that they will be given the opportunity to join + //note courses not visible should not have their tagid sent to this function + //if (has_capability('moodle/course:view', get_context_instance(CONTEXT_COURSE, $c->itemid))) { + $course = get_record('course', 'id', $c->itemid); + $courses[$c->itemid] = $course; + //} + } + } + return $courses; + +} + +/** + * Course tagging function used only during the deletion of a + * course (called by lib/moodlelib.php) to clean up associated tags + * + * @param $courseid + * @param $showfeedback + */ +function coursetag_delete_course_tags($courseid, $showfeedback=false) { + if ($tags = get_records_select('tag_instance', "itemtype='course' AND itemid=".$courseid)) { + foreach ($tags as $tag) { + //delete the course tag instance record + delete_records('tag_instance', 'tagid', $tag->tagid, 'itemtype', 'course', 'itemid', $courseid); + // delete tag if there are no other tag_instance entries now + if (!(record_exists('tag_instance', 'tagid', $tag->tagid))) { + delete_records('tag', 'id', $tag->tagid); + } + } + } + if ($showfeedback) { + notify("$strdeleted course tags"); + } + +} + +/** + * Function called by cron to create/update users rss feeds + * + * @uses $CFG + * @return true + * + * Function removed. + * rsslib.php needs updating to accept dc/cc input before this can work (or modified). + */ +/* +function coursetag_rss_feeds() { + + global $CFG; + require_once($CFG->dirroot.'/lib/dmllib.php'); + require_once($CFG->dirroot.'/lib/rsslib.php'); + + $status = true; + mtrace(' Preparing to update all user unit tags RSS feeds'); + if (empty($CFG->enablerssfeeds)) { + mtrace(' RSS DISABLED (admin variables - enablerssfeeds)'); + } else { + + // Load all the categories for use later on + $categories = get_records('course_categories'); + + // get list of users who have tagged a unit + $sql = " + SELECT DISTINCT u.id as userid, u.username, u.firstname, u.lastname, u.email + FROM {$CFG->prefix}user u, {$CFG->prefix}course c, {$CFG->prefix}tag_instance cti, {$CFG->prefix}tag t + WHERE c.id = cti.itemid + AND u.id = cti.tiuserid + AND t.id = cti.tagid + AND t.tagtype = 'personal' + AND u.confirmed = 1 + AND u.deleted = 0 + ORDER BY userid"; + if ($users = get_records_sql($sql)) { + + $items = array(); //contains rss data items for each user + foreach ($users as $user) { + + // loop through each user, getting the data (tags for courses) + $sql = " + SELECT cti.id, c.id as courseid, c.fullname, c.shortname, c.category, t.rawname, cti.timemodified + FROM {$CFG->prefix}course c, {$CFG->prefix}tag_instance cti, {$CFG->prefix}tag t + WHERE c.id = cti.itemid + AND cti.tiuserid = {$user->userid} + AND cti.tagid = t.id + AND t.tagtype = 'personal' + ORDER BY courseid"; + if ($usertags = get_records_sql($sql)) { + $latest_date = 0; //latest date any tag was created by a user + $c = 0; //course identifier + + foreach ($usertags as $usertag) { + if ($usertag->courseid != $c) { + $c = $usertag->courseid; + $items[$c] = new stdClass(); + $items[$c]->title = $usertag->fullname . '(' . $usertag->shortname . ')'; + $items[$c]->link = $CFG->wwwroot . '/course/view.php?name=' . $usertag->shortname; + $items[$c]->description = ''; //needs to be blank + $items[$c]->category = $categories[$usertag->category]->name; + $items[$c]->subject[] = $usertag->rawname; + $items[$c]->pubdate = $usertag->timemodified; + $items[$c]->tag = true; + } else { + $items[$c]->subject[] .= $usertag->rawname; + } + // Check and set the latest modified date. + $latest_date = $usertag->timemodified > $latest_date ? $usertag->timemodified : $latest_date; + } + + // Setup some vars for use while creating the file + $path = $CFG->dataroot.'/1/usertagsrss/'.$user->userid; + $file_name = 'user_unit_tags_rss.xml'; + $title = 'The OpenLearn Unit Tags RSS Feed for user: '.ucwords(strtolower($user->firstname.' '.$user->lastname)); + $desc = 'This RSS feed was automatically generated by OpenLearn folksonomies and contains user generated tags for units.'; + // check that the path exists + if (!file_exists($path)) { + mtrace(' Creating folder '.$path); + check_dir_exists($path, TRUE, TRUE); + } + + // create or update the feed for the user + // this functionality can be copied entirely once rsslib is adjusted + require_once($CFG->dirroot.'/local/ocilib.php'); + oci_create_rss_feed( $path, $file_name, $latest_date, $items, $title, $desc, true); + } + } + } + } + + return $status; +} + */ + +/** + * Get official keywords for the in header.html + * use: echo ''; + * @uses $CFG + * @param int $courseid + * @return string + * + * Function removed but fully working + * This function is potentially useful to anyone wanting to improve search results for course pages. + * The idea is to add official (not personal ones, so users cannot delete) tags to all + * courses (facility not added yet) which wil be automatically added to the page to boost + * search engine specificity/ratings. + */ +/* +function coursetag_get_official_keywords($courseid, $asarray=false) { + global $CFG; + $returnstr = ''; + $sql = "SELECT t.id, name, rawname + FROM {$CFG->prefix}tag t, {$CFG->prefix}tag_instance ti + WHERE ti.itemid = $courseid + AND ti.itemtype = 'course' + AND t.tagtype = 'official' + AND ti.tagid = t.id + ORDER BY name ASC"; + if ($tags = get_records_sql($sql)) { + if ($asarray) { + return $tags; + } + foreach ($tags as $tag) { + if( empty($CFG->keeptagnamecase) ) { + $textlib = textlib_get_instance(); + $name = $textlib->strtotitle($tag->name); + } else { + $name = $tag->rawname; + } + $returnstr .= $name.', '; + } + $returnstr = rtrim($returnstr, ', '); + } + return $returnstr; +} +*/ + +?> Index: tag/coursetags_edit.php =================================================================== RCS file: tag/coursetags_edit.php diff -N tag/coursetags_edit.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tag/coursetags_edit.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,172 @@ +dirroot.'/tag/coursetagslib.php'); +require_once($CFG->dirroot.'/tag/lib.php'); + +$courseid = optional_param('courseid', 0, PARAM_INT); +$keyword = optional_param('coursetag_new_tag', '', PARAM_TEXT); +$deltag = optional_param('del_tag', 0, PARAM_INT); + +if ($courseid != SITEID) { + if (! ($course = get_record('course', 'id', $courseid)) ) { + error('Invalid course id'); + } +} else { + error('Tagging the site main page is not allowed'); +} + +// Permissions +$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID); +require_login($course->id); +$canedit = has_capability('moodle/tag:create', $sitecontext); + +// Language strings +$tagslang = 'block_tags'; + +// Store data +if ($data = data_submitted()) { + if (confirm_sesskey() and $courseid > 0 and $USER->id > 0 and $canedit) { + // store personal tag + if (trim($keyword)) { + $myurl = 'tag/search.php?query='.urlencode($keyword); + $keywords = (array)$keyword; + try { + coursetag_store_keywords($keywords, $courseid, $USER->id, 'default', $myurl); + } + catch (Exception $e) { + error($e->getmessage()); + } + } + // delete personal tag + if ($deltag > 0) { + coursetag_delete_keyword($deltag, $USER->id, $courseid); + } + } +} + +// The title and breadcrumb +$title = get_string('edittitle', $tagslang); +$coursefullname = format_string($course->fullname); +$courseshortname = format_string($course->shortname); +//$navigation[] = array('name' => $coursefullname, 'link' => $CFG->wwwroot.'/course/view.php?id='.$courseid, 'type' => 'misc'); +$navigation[] = array('name' => $title, 'link' => null, 'type' => 'misc'); +$nav = build_navigation($navigation); +print_header_simple($title, '', $nav, '', '', false); + + // Print personal tags for all courses + $title = get_string('edittitle', $tagslang); + print_heading($title, 'center'); + + $mytags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default'), true); + $outstr = ' +
+
+ '.get_string('editmytags', $tagslang).' +
+
'; + if ($mytags) { + $outstr .= $mytags; + } else { + $outstr .= get_string('editnopersonaltags', $tagslang); + } + $outstr .= '
+
'; + echo $outstr; + + // Personal tag editing + if ($canedit) { + $title = get_string('editmytagsfor', $tagslang, '"'.$coursefullname.' ('.$courseshortname.')"'); + print_heading($title); + + // Deletion here is open to the users own tags for this course only + $selectoptions = ''; + $coursetabs = ''; + if ($options = coursetag_get_records($courseid, $USER->id)) { + $coursetabs = '"'; + foreach ($options as $option) { + $selectoptions .= ''; + $coursetabs .= $option->rawname . ', '; + } + $coursetabs = rtrim($coursetabs, ', '); + $coursetabs .= '"'; + } + if ($coursetabs) { + $outstr = ' +
+ '.get_string('editthiscoursetags', $tagslang, $coursetabs).' +
'; + } else { + $outstr = ' +
+ '.get_string('editnopersonaltags', $tagslang).' +
'; + } + + // Print the add and delete form + $script = coursetag_get_jscript(); + $addtagshelp = helpbutton('addtags', 'adding tags', $tagslang, TRUE, FALSE, '', TRUE); + $edittagthisunit = get_string('edittagthisunit', $tagslang); + $outstr .= << +
+ + +
+
+
+
+ $addtagshelp$edittagthisunit +
+
+
+ +
+
+ +
+
+ + + +
+
+
+EOT; + if ($coursetabs) { + $deletetagshelp = helpbutton('deletetags', 'deleting tags', $tagslang, TRUE, FALSE, '', TRUE); + $editdeletemytag = get_string('editdeletemytag', $tagslang); + $outstr .= << +
+ $deletetagshelp$editdeletemytag +
+
+ +
+
+EOT1; + } + $submitstr = get_string('submit'); + $outstr .= << +
+ +
+ + +EOT2; + echo $outstr; + } + +print_footer(); +?> Index: blocks/tags/styles.php =================================================================== RCS file: blocks/tags/styles.php diff -N blocks/tags/styles.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ blocks/tags/styles.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,112 @@ +/* + * CSS for course tags + * @author j.beedell@open.ac.uk July07 + * + * Styles for block_tags.php + */ + +.coursetag_form_wrapper { + margin: auto; + width: 13em; +} + +.coursetag_form_positioner { + position: relative; + margin: 5px 0 0 0; + height: 25px; +} + +.coursetag_form_input1 { + position: absolute; + top: 0; + left: 0; + z-index: 1; +} + +.coursetag_form_input2 { + position: absolute; + top: 0; + left: 0; + z-index: 2; +} + +.coursetag_form_input3 { + position: absolute; + top: 3px; + left: 12.7em; + display: none; +} + +.coursetag_form_input1a { + background-color: transparent; + border: 1px solid #999; + width: 12em; + padding: 2px +} + +.coursetag_form_input2a { + background: transparent; + color: #669954; + border: 1px solid #999; + width: 12em; + padding: 2px +} + +.coursetag_morelink { + float: right; + font-size: 0.8em; + margin: -5px 5px 5px 0; +} + +/* Styles for edit_tags.php */ + +.coursetag_edit_centered { + position: relative; + width: 600px; + margin: 20px auto; +} + +.coursetag_edit_row { + margin: 5px 0 5px 0; + height: 30px; +} + +.coursetag_edit_left { + position: relative; + float: left; + padding: 3px 5px; +} + +.coursetag_edit_right { + position: relative; + float: left; + padding: 3px 0px; +} + +.coursetag_edit_input3 { + position: relative; + left: 10.5em; + display: none; +} + +/* Styles for more_tags.php */ + +.coursetag_more_title { + margin: 30px 30px -25px 30px; +} + +.coursetag_more_tags { + margin: 30px; +} + +.coursetag_more_large { + font-size: 120% +} + +.coursetag_more_small { + font-size: 80% +} + +.coursetag_more_link { + font-size: 80%; +} Index: blocks/tags/coursetags.js =================================================================== RCS file: blocks/tags/coursetags.js diff -N blocks/tags/coursetags.js --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ blocks/tags/coursetags.js 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,62 @@ +/** + * coursetags.js + * @author j.beedell@open.ac.uk July07 + * + * getKeywords modified from an original script (Auto Complete Textfield) + * from The JavaScript Source http://javascript.internet.com + * originally created by: Timothy Groves http://www.brandspankingnew.net/ + */ + + +function ctags_show_div(mydiv) { + for(x in coursetagdivs) { + if(mydiv == coursetagdivs[x]) { + document.getElementById(coursetagdivs[x]).style.display="block"; + } else { + document.getElementById(coursetagdivs[x]).style.display="none"; + } + } + return false; +} + +var sug = ""; +var sug_disp = ""; + +function ctags_getKeywords() { + /* + // This 'workaround' removing the xhtml strict form autocomplete="off" needs to + // be added to the body onload() script to work - but decided not to include + // (having the browser list might help with screen readers more than this script) + // document.forms['coursetag'].setAttribute("autocomplete", "off"); + */ + var input = document.forms['coursetag'].coursetag_new_tag.value; + var len = input.length; + sug_disp = ""; sug = ""; + + if (input.length) { + for (ele in coursetag_tags) + { + if (coursetag_tags[ele].substr(0,len).toLowerCase() == input.toLowerCase()) + { + sug_disp = input + coursetag_tags[ele].substr(len); + sug = coursetag_tags[ele]; + break; + } + } + } + document.forms['coursetag'].coursetag_sug_keyword.value = sug_disp; + if (!sug.length || input == sug_disp) + document.getElementById('coursetag_sug_btn').style.display = "none"; + else + document.getElementById('coursetag_sug_btn').style.display = "block"; +} + +function ctags_setKeywords() { + document.forms['coursetag'].coursetag_new_tag.value = sug; + ctags_hideSug(); +} + +function ctags_hideSug() { + document.forms['coursetag'].coursetag_sug_keyword.value = ""; + document.getElementById('coursetag_sug_btn').style.display = "none"; +} Index: lang/en_utf8/help/block_tags/addtags.html =================================================================== RCS file: lang/en_utf8/help/block_tags/addtags.html diff -N lang/en_utf8/help/block_tags/addtags.html --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lang/en_utf8/help/block_tags/addtags.html 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,27 @@ +

Adding a tag for a course

+ +

Logged on users may 'tag' courses.

+ +

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.

Index: pix/t/arrow_left.gif =================================================================== RCS file: pix/t/arrow_left.gif diff -N pix/t/arrow_left.gif --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ pix/t/arrow_left.gif 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,5 @@ +GIF89a + +¢fffÿ̰°°ÿÿÿÝÝݵµµ!ù, + +º¼M?Û$/‡KºB'Œ#„ÙãU¤Fp?; Index: tag/coursetags_more.php =================================================================== RCS file: tag/coursetags_more.php diff -N tag/coursetags_more.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tag/coursetags_more.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,187 @@ +dirroot.'/tag/coursetagslib.php'); +require_once($CFG->dirroot.'/tag/lib.php'); + +$sort = optional_param('sort', 'alpha', PARAM_TEXT); //alpha, date or popularity +$show = optional_param('show', 'all', PARAM_TEXT); //all, my, official, community or course +$courseid = optional_param('courseid', 0, PARAM_INT); + +// Some things require logging in +if ($CFG->forcelogin or $show == 'my') { + require_login(); +} + +// Permissions +$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID); +$isguest = has_capability('moodle/legacy:guest', $sitecontext, $USER->id, false); +$loggedin = isloggedin() && !$isguest; + +// Course check +if ($courseid) { + if (!($course = get_record('course', 'id', $courseid))) { + $courseid = 0; + } + if ($courseid == SITEID) $courseid = 0; +} + +// Language strings +$tagslang = 'block_tags'; +$title = get_string('moretitle', $tagslang); +$link1 = get_string('moreshow', $tagslang); +$link2 = get_string('moreorder', $tagslang); +$showalltags = get_string('moreshowalltags', $tagslang); +$showofficialtags = get_string('moreshowofficialtags', $tagslang); +$showmytags = get_string('moreshowmytags', $tagslang); +$showcommtags = get_string('moreshowcommtags', $tagslang); +$orderalpha = get_string('moreorderalpha', $tagslang); +$orderdate = get_string('moreorderdate', $tagslang); +$orderpop = get_string('moreorderpop', $tagslang); +$welcome = get_string('morewelcome', $tagslang); + +// The title and breadcrumb +if ($courseid) { + $navigation[] = array('name' => format_string($course->shortname), 'link' => $CFG->wwwroot.'/course/view.php?id='.$courseid, 'type' => 'misc'); + $navigation[] = array('name' => $title, 'link' => null, 'type' => 'misc'); +} else { + $navigation[] = array('name' => $title, 'link' => null, 'type' => 'misc'); +} +$nav = build_navigation($navigation); +print_header_simple($title, '', $nav, '', '', false); +print_heading($title, 'centre'); + +// Prepare data for tags +$courselink = ''; +if ($courseid) { $courselink = '&courseid='.$courseid; } +$myurl = $CFG->wwwroot.'/tag/coursetags_more.php'; +$myurl2 = $CFG->wwwroot.'/tag/coursetags_more.php?show='.$show; + +// Course tags +if ($show == 'course' and $courseid) { + + if ($sort == 'popularity') { + $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'popularity'), true, 200, 90); + } else if ($sort == 'date') { + $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'timemodified'), true, 200, 90); + } else { + $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'name'), true, 200, 90); + } + +// My tags +} else if ($show == 'my' and $loggedin) { + + if ($sort == 'popularity') { + $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'popularity'), true, 200, 90); + } else if ($sort == 'date') { + $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'timemodified'), true, 200, 90); + } else { + $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'name'), true, 200, 90); + } + +// Official course tags +} else if ($show == 'official') { + + if ($sort == 'popularity') { + $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'popularity'), true, 200, 90); + } else if ($sort == 'date') { + $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'timemodified'), true, 200, 90); + } else { + $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'name'), true, 200, 90); + } + +// Community (official and personal together) also called user tags +} else if ($show == 'community') { + + if ($sort == 'popularity') { + $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'popularity'), true, 200, 90); + } else if ($sort == 'date') { + $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'timemodified'), true, 200, 90); + } else { + $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'name'), true, 200, 90); + } + +// All tags for courses and blogs and any thing else tagged - the fallback default ($show == all) +} else { + + $subtitle = $showalltags; + if ($sort == 'popularity') { + $tags = coursetag_print_cloud(coursetag_get_all_tags('popularity'), true, 200, 90); + } else if ($sort == 'date') { + $tags = coursetag_print_cloud(coursetag_get_all_tags('timemodified'), true, 200, 90); + } else { + $tags = coursetag_print_cloud(coursetag_get_all_tags('name'), true, 200, 90); + } + +} + +// Prepare the links for the show and order lines +if ($show == 'all') { + $link1 .= ''.$showalltags.''; +} else { + $link1 .= ''.$showalltags.''; +} +if ($show == 'official') { + $link1 .= ' | '.$showofficialtags.''; +} else { + $link1 .= ' | '.$showofficialtags.''; +} +if ($show == 'community') { + $link1 .= ' | '.$showcommtags.''; +} else { + $link1 .= ' | '.$showcommtags.''; +} +if ($loggedin) { + if ($show == 'my') { + $link1 .= ' | '.$showmytags.''; + } else { + $link1 .= ' | '.$showmytags.''; + } +} +if ($courseid) { + if ($show == 'course') { + $link1 .= ' | '.get_string('moreshowcoursetags', $tagslang, $course->fullname).''; + } else { + $link1 .= ' | '.get_string('moreshowcoursetags', $tagslang, $course->fullname).''; + } +} +if ($sort == 'alpha') { + $link2 .= ''.$orderalpha.' | '; +} else { + $link2 .= ''.$orderalpha.' | '; +} +if ($sort == 'popularity') { + $link2 .= ''.$orderpop.' | '; +} else { + $link2 .= ''.$orderpop.' | '; +} +if ($sort == 'date') { + $link2 .= ''.$orderdate.''; +} else { + $link2 .= ''.$orderdate.''; +} + +// Prepare output +$fclass = ''; +// make the tags larger when there are not so many +if (strlen($tags) < 10000) { $fclass = 'coursetag_more_large'; } +$outstr = ' +
+
'.$welcome. + helpbutton('usingtags', 'using tags', $tagslang, TRUE, FALSE, '', TRUE).' +
+ + +
+
'. + $tags.' +
'; +echo $outstr; + +print_footer(); +?> Index: lang/en_utf8/help/block_tags/usingtags.html =================================================================== RCS file: lang/en_utf8/help/block_tags/usingtags.html diff -N lang/en_utf8/help/block_tags/usingtags.html --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lang/en_utf8/help/block_tags/usingtags.html 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,21 @@ +

Using course tagging

+ +

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.