### 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.3 diff -u -r1.3 block_tags.php --- blocks/tags/block_tags.php 16 Sep 2007 21:43:08 -0000 1.3 +++ blocks/tags/block_tags.php 14 Jan 2008 13:53:02 -0000 @@ -1,9 +1,18 @@ version = 2007082800; + $this->version = 2007120600; $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 +70,248 @@ require_once($CFG->dirroot.'/tag/lib.php'); - $this->content->text = print_tag_cloud(popular_tags_count($this->config->numberoftags), false, 170, 70, true); + if (!SHOWCOURSETAGS) { + + $this->content->text = print_tag_cloud(popular_tags_count($this->config->numberoftags), false, 170, 70, 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 = print_tag_cloud(coursetag_get_all_tags($sort, $this->config->numberoftags), false, 170, 70, true); + $officialtags = print_tag_cloud(coursetag_get_tags(0, 0, 'official', $numoftags, $sort), false, 170, 70, true); + $commtags = print_tag_cloud(coursetag_get_tags(0, 0, 'personal', $numoftags, $sort), false, 170, 70, true); + if ($loggedin) { + $mytags = print_tag_cloud(coursetag_get_tags(0, $USER->id, 'personal', $numoftags, $sort), false, 170, 70, true); + } + } + if ($coursepage) { + $coursetags = print_tag_cloud(coursetag_get_tags($COURSE->id, 0, '', $numoftags, $sort), false, 170, 70, true); + if (!$coursetags) $coursetags = get_string('notagsyet', $tagslang); + $courseflag = '&courseid='.$COURSE->id; + } + if ($mymoodlepage) { + $mytags = print_tag_cloud(coursetag_get_tags(0, $USER->id, 'personal', $numoftags, $sort), false, 170, 70, true); + $officialtags = print_tag_cloud(coursetag_get_tags(0, 0, 'official', $numoftags, $sort), false, 170, 70, true); + $commtags = print_tag_cloud(coursetag_get_tags(0, 0, 'personal', $numoftags, $sort), false, 170, 70, 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 +331,22 @@ 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.'/blocks/tags/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.46 diff -u -r1.46 lib.php --- tag/lib.php 1 Nov 2007 12:32:59 -0000 1.46 +++ tag/lib.php 14 Jan 2008 13:53:08 -0000 @@ -364,9 +364,13 @@ * @param string $item_id id of the item to be tagged * @param string $tag_names_or_ids_csv comma separated tag names (can be unormalized) or ids of existing tags * @param string $tag_type type of the tags that are beeing added (optional, default value is "default") + * + * coursetag addition + * the addition of userid here allows a tag to be associated with both an item and a user + * @param int $userid userid of creator of this tag instance or 0 */ -function tag_an_item($item_type, $item_id, $tag_names_or_ids_csv, $tag_type="default") { +function tag_an_item($item_type, $item_id, $tag_names_or_ids_csv, $tag_type="default", $userid=0) { global $CFG; //convert any tag ids passed to their corresponding tag names @@ -400,6 +404,7 @@ $tag_instance = new StdClass; $tag_instance->itemtype = $item_type; $tag_instance->itemid = $item_id; + $tag_instance->tiuserid = $userid; //create tag instances @@ -408,7 +413,9 @@ $tag_instance->tagid = $tag_id; $tag_instance->ordering = $ordering[$tag_normalized_name]; $tag_instance->timemodified = time(); - $tag_instance_exists = get_record('tag_instance', 'tagid', $tag_id, 'itemtype', $item_type, 'itemid', $item_id); + //$tag_instance_exists = get_record('tag_instance', 'tagid', $tag_id, 'itemtype', $item_type, 'itemid', $item_id); + $query = "tagid = $tag_id AND itemtype = '$item_type' AND itemid = $item_id AND tiuserid = $userid"; + $tag_instance_exists = get_record_select('tag_instance', $query); if (!$tag_instance_exists) { insert_record('tag_instance',$tag_instance); @@ -842,9 +849,10 @@ // query that counts how many times any tag appears together in items // with the tag passed as argument ($tag_id) - $query = "SELECT tb.tagid , COUNT(*) nr + $query = "SELECT tb.tagid , COUNT(*) as nr FROM {$CFG->prefix}tag_instance ta - INNER JOIN {$CFG->prefix}tag_instance tb ON ta.itemid = tb.itemid + INNER JOIN {$CFG->prefix}tag_instance tb + ON ta.itemid = tb.itemid WHERE ta.tagid = {$tag_id} GROUP BY tb.tagid ORDER BY nr DESC"; @@ -900,18 +908,17 @@ // then this tag_instance is an orphan and it will be removed. foreach ($items_types as $type) { - $query = " - {$CFG->prefix}tag_instance.id - IN - ( SELECT sq1.id - FROM - (SELECT sq2.* + $query = "{$CFG->prefix}tag_instance.id + IN ( + SELECT sq1.id + FROM ( + SELECT sq2.* FROM {$CFG->prefix}tag_instance sq2 - LEFT JOIN {$CFG->prefix}{$type->itemtype} item + LEFT JOIN {$CFG->prefix}tag item ON sq2.itemid = item.id WHERE item.id IS NULL - AND sq2.itemtype = '{$type->itemtype}') - sq1 + AND sq2.itemtype = '{$type->itemtype}' + ) sq1 ) "; delete_records_select('tag_instance', $query); @@ -1129,10 +1136,12 @@ function tag_cron(){ + mtrace('Start of tag cron - tag instance table cleanup'); tag_instance_table_cleanup(); if ($tags = get_all_tags('*')) { + mtrace(' Preparing to update correlated tags cache'); foreach ($tags as $tag){ cache_correlated_tags($tag->id); } @@ -1503,14 +1512,20 @@ $can_manage_tags = has_capability('moodle/tag:manage', $systemcontext); //prints the tag cloud - $output = '