Skip to content
Browse files

MDL-15471 course tagging improvements

  • Loading branch information...
1 parent a3ab18c commit 7dd764b856c4b071f7d19abb86ee68586c99eb8a @jennymgray jennymgray committed
View
332 blocks/tags/block_tags.php
@@ -1,43 +1,54 @@
<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
class block_tags extends block_base {
- function init() {
+ public function init() {
$this->title = get_string('pluginname', 'block_tags');
- // the cron function goes through all users, so only do daily
- // (this creates rss feeds for personal course tags)
- // removed until rsslib supports dc/cc
- // $this->cron = 60*60*24;
}
- function instance_allow_multiple() {
+ public function instance_allow_multiple() {
return true;
}
- function has_config() {
+ public function has_config() {
return true;
}
- function applicable_formats() {
+ public function applicable_formats() {
return array('all' => true);
}
- function instance_allow_config() {
+ public function instance_allow_config() {
return true;
}
- function specialization() {
+ public function specialization() {
- // load userdefined title and make sure it's never empty
+ // Load userdefined title and make sure it's never empty.
if (empty($this->config->title)) {
- $this->title = get_string('pluginname','block_tags');
+ $this->title = get_string('pluginname', 'block_tags');
} else {
$this->title = $this->config->title;
}
}
- function get_content() {
+ public function get_content() {
- global $CFG, $COURSE, $SITE, $USER, $SCRIPT, $OUTPUT;
+ global $CFG, $COURSE, $USER, $SCRIPT, $OUTPUT;
if (empty($CFG->usetags)) {
$this->content = new stdClass();
@@ -56,6 +67,10 @@ function get_content() {
$this->config->numberoftags = 80;
}
+ if (empty($this->config->tagtype)) {
+ $this->config->tagtype = '';
+ }
+
if ($this->content !== NULL) {
return $this->content;
}
@@ -68,260 +83,111 @@ function get_content() {
$this->content = new stdClass;
$this->content->footer = '';
- /// Get a list of tags
+ // Get a list of tags.
require_once($CFG->dirroot.'/tag/locallib.php');
if (empty($CFG->block_tags_showcoursetags) or !$CFG->block_tags_showcoursetags) {
- $this->content->text = tag_print_cloud($this->config->numberoftags, true);
+ $this->content->text = tag_print_cloud(null, $this->config->numberoftags, true);
- // start of show course tags section
} else {
-
+ // Start of show course tags section.
require_once($CFG->dirroot.'/tag/coursetagslib.php');
- // Permissions and page awareness
- $systemcontext = context_system::instance();
- $loggedin = isloggedin() && !isguestuser();
- $coursepage = $canedit = false;
- $coursepage = (isset($this->page->course->id) && $this->page->course->id != SITEID);
- $mymoodlepage = ($SCRIPT == '/my/index.php') ? true : false;
- $sitepage = (isset($this->page->course->id) && $this->page->course->id == SITEID && !$mymoodlepage);
- if ($coursepage) {
- $canedit = has_capability('moodle/tag:create', $systemcontext);
- }
-
- // 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';
- $coursetagdivs = array();
- $alltags = $officialtags = $coursetags = $commtags = $mytags = $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);
+ // Page awareness.
+ $tagtype = 'all';
+ if ($SCRIPT == '/my/index.php') {
+ $tagtype = 'my';
+ } else if (isset($this->page->course->id)) {
+ if ($this->page->course->id != SITEID) {
+ $tagtype = 'course';
}
}
- if ($coursepage) {
- $coursetags = coursetag_print_cloud(coursetag_get_tags($this->page->course->id, 0, '', $numoftags, $sort), true);
- if (!$coursetags) $coursetags = get_string('notagsyet', $tagslang);
- $courseflag = '&amp;courseid='.$this->page->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 = '
- <div id="f_alltags" '.$display.'>'.
- get_string("alltags", $tagslang).
- '<div class="coursetag_list">'.$alltags.'</div>
- <div class="coursetag_morelink">
- <a href="'.$moretags.'?show=all'.$courseflag.'" title="'.$moretagstitle.'">'.$moretagsstring.'</a>
- </div>
- </div>';
- $coursetagdivs[] = 'f_alltags';
- }
- if ($mytags) {
- if ($mymoodlepage) {
- $display = $displayblock;
- } else {
- $display = $displaynone;
- }
- $mytagscontent = '
- <div id="f_mytags" '.$display.'>';
- /*if ($rssfeed) { // - temporarily removed
- $mytagscontent .= link_to_popup_window(
- $rssfeed, $name='popup',
- '<img src="'.$CFG->wwwroot.'/pix/rss.gif" alt="User Unit Tags RSS" /> My Unit Tags RSS',
- $height=600, $width=800,
- $title='My Unit Tags RSS', $options='menubar=1,scrollbars,resizable', $return=true).'<br />';
- }*/
- $mytagscontent .=
- get_string('mytags', $tagslang).
- '<div class="coursetag_list">'.$mytags.'</div>
- <div class="coursetag_morelink">
- <a href="'.$moretags.'?show=my'.$courseflag.'" title="'.$moretagstitle.'">'.$moretagsstring.'</a>
- </div>
- </div>';
- $coursetagdivs[] = 'f_mytags';
- }
- if ($officialtags) {
- if ($mytags or $alltags) {
- $display = $displaynone;
- } else {
- $display = $displayblock;
- }
- $officialtagscontent = '
- <div id="f_officialtags" '.$display.'>'.
- get_string('officialtags', $tagslang).
- '<div class="coursetag_list">'.$officialtags.'</div>
- <div class="coursetag_morelink">
- <a href="'.$moretags.'?show=official'.$courseflag.'" title="'.$moretagstitle.'">'.$moretagsstring.'</a>
- </div>
- </div>';
- $coursetagdivs[] = 'f_officialtags';
+ // DB hits to get groups of marked up tags (if available).
+ // TODO check whether time limited personal tags are required.
+ $content = '';
+ $moretags = new moodle_url('/tag/coursetags_more.php', array('show'=>$tagtype));
+ if ($tagtype == 'all') {
+ $tags = coursetag_get_tags(0, 0, $this->config->tagtype, $this->config->numberoftags, 'name');
+ } else if ($tagtype=='course') {
+ $tags = coursetag_get_tags($this->page->course->id, 0, $this->config->tagtype, $this->config->numberoftags, 'name');
+ $moretags->param('courseid', $this->page->course->id);
+ } else if ($tagtype=='my') {
+ $tags = coursetag_get_tags(0, $USER->id, $this->config->tagtype, $this->config->numberoftags, 'name');
}
- if ($coursetags) {
- if ($coursepage) {
- $display = $displayblock;
- } else {
- $display = $displaynone;
- }
- $coursetagscontent = '
- <div id="f_coursetags" '.$display.'>'.
- get_string('coursetags', $tagslang).
- '<div class="coursetag_list">'.$coursetags.'</div>
- <div class="coursetag_morelink">
- <a href="'.$moretags.'?show=course'.$courseflag.'" title="'.$moretagstitle.'">'.$moretagsstring.'</a>
- </div>
- </div>';
- $coursetagdivs[] = 'f_coursetags';
+ $tagcloud = tag_print_cloud($tags, 150, true);
+ if (!$tagcloud) {
+ $tagcloud = get_string('notagsyet', 'block_tags');
}
- if ($commtags) {
- $commtagscontent = '
- <div id="f_commtags" '.$displaynone.'>'.
- get_string('communitytags', $tagslang).
- '<div class="coursetag_list">'.$commtags.'</div>
- <div class="coursetag_morelink">
- <a href="'.$moretags.'?show=community'.$courseflag.'" title="'.$moretagstitle.'">'.$moretagsstring.'</a>
- </div>
- </div>';
- $coursetagdivs[] .= 'f_commtags';
- }
- // Tidy up the end of a javascript array and add javascript
- 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);
+ // Prepare the divs that display the groups of tags.
+ $content = get_string($tagtype."tags", 'block_tags').
+ '<div class="coursetag_list">'.$tagcloud.'</div>
+ <div class="coursetag_morelink">
+ <a href="'.$moretags->out().'" title="'.get_string('moretags', 'block_tags').'">'
+ .get_string('more', 'block_tags').'</a>
+ </div>';
+ // Add javascript.
+ coursetag_get_jscript();
+
+ // Add the divs (containing the tags) to the block's content.
+ $this->content->text .= $content;
+
+ // Add the input form section (allowing a user to tag the current course) and navigation, or login message.
+ if (isloggedin() && !isguestuser()) {
+ // Only show the input form on course pages for those allowed (or not barred).
+ if ($tagtype == 'course' &&
+ has_capability('moodle/tag:create', context_course::instance($this->page->course->id))) {
+ $buttonadd = get_string('add', 'block_tags');
+ $arrowtitle = get_string('arrowtitle', 'block_tags');
+ $edit_tags = get_string('edittags', 'block_tags');
$sesskey = sesskey();
$arrowright = $OUTPUT->pix_url('t/arrow_left');
+ $redirect = $this->page->url->out();
$this->content->footer .= <<<EOT
<hr />
<form action="{$CFG->wwwroot}/tag/coursetags_add.php" method="post" id="coursetag"
onsubmit="return ctags_checkinput(this.coursetag_new_tag.value)">
<div style="display: none;">
- <input type="hidden" name="returnurl" value="{$this->page->url}" />
<input type="hidden" name="entryid" value="$COURSE->id" />
<input type="hidden" name="userid" value="$USER->id" />
<input type="hidden" name="sesskey" value="$sesskey" />
- </div>
- <div><label for="coursetag_new_tag">$tagthisunit</label></div>
- <div class="coursetag_form_wrapper">
- <div class="coursetag_form_positioner">
- <div class="coursetag_form_input1">
- <label class="accesshide" for="coursetag_sug_keyword">$tagthisunit</label>
- <input type="text" name="coursetag_sug_keyword" id="coursetag_sug_keyword" class="coursetag_form_input1a" disabled="disabled" />
+ <input type="hidden" name="returnurl" value="$redirect" />
</div>
- <div class="coursetag_form_input2">
- <input type="text" name="coursetag_new_tag" id="coursetag_new_tag" class="coursetag_form_input2a"
- onfocus="ctags_getKeywords()" onkeyup="ctags_getKeywords()" maxlength="50" />
+ <div class="coursetag_form_wrapper">
+ <div class="coursetag_form_positioner">
+ <div class="coursetag_form_input1">
+ <input type="text" name="coursetag_sug_keyword" class="coursetag_form_input1a" disabled="disabled" />
+ </div>
+ <div class="coursetag_form_input2">
+ <input type="text" name="coursetag_new_tag" id="coursetag_new_tag"
+ class="coursetag_form_input2a" onfocus="ctags_getKeywords()" onkeyup="ctags_getKeywords()" maxlength="50" />
+ </div>
+ <div class="coursetag_form_input3" id="coursetag_sug_btn">
+ <a title="$arrowtitle">
+ <img src="$arrowright" width="10" height="10" alt="enter" onclick="ctags_setKeywords()" />
+ </a>
+ </div>
</div>
- <div class="coursetag_form_input3" id="coursetag_sug_btn">
- <a title="$arrowtitle">
- <img src="$arrowright" width="10" height="10" alt="enter" onclick="ctags_setKeywords()" />
- </a>
+ <div style="display: inline;">
+ <button type="submit">$buttonadd</button>
+ <a href="$CFG->wwwroot/tag/coursetags_edit.php?courseid=$COURSE->id" title="$edit_tags">$edit_tags</a>
</div>
</div>
- <div style="display: inline;">
- <button type="submit">$buttonadd</button>
- </div>
- </div>
</form>
EOT;
- // add the edit link
- $this->content->footer .= '
- <div>
- <a href="'.$CFG->wwwroot.'/tag/coursetags_edit.php?courseid='.$this->page->course->id.'"
- title="'.get_string('edittags', $tagslang).'">'.get_string('edittags', $tagslang).'</a>
- </div>';
- }
-
- // Navigation elements at the bottom of the block
- // show the alternative displays options if available
- $elementid = 'coursetagslinks_'.$this->instance->id;
- if ($mytags or $officialtags or $commtags or $coursetags) {
- $this->content->footer .= '<div id="'.$elementid.'"></div>';
- }
- // This section sets the order of the links
- $coursetagslinks = array();
- if ($mytags) {
- $coursetagslinks['my'] = array('title'=>get_string('mytags2', $tagslang),
- 'onclick'=>'f_mytags',
- 'text'=>get_string('mytags1', $tagslang));
- }
- // because alltags is always present, only show link if there is something else as well
- if ($alltags and ($mytags or $officialtags or $commtags or $coursetags)) {
- $coursetagslinks['all'] = array('title'=>get_string('alltags2', $tagslang),
- 'onclick'=>'f_alltags',
- 'text'=>get_string('alltags1', $tagslang));
}
- if ($officialtags) {
- $coursetagslinks['off'] = array('title'=>get_string('officialtags2', $tagslang),
- 'onclick'=>'f_officialtags',
- 'text'=>get_string('officialtags1', $tagslang));
- }
- //if ($commtags) {
- // $coursetagslinks['com'] = array('title'=>get_string('communitytags2', $tagslang),
- // 'onclick'=>'f_commtags',
- // 'text'=>get_string('communitytags1', $tagslang));
- //}
- if ($coursetags) {
- $coursetagslinks['crs'] = array('title'=>get_string('coursetags2', $tagslang),
- 'onclick'=>'f_coursetags',
- 'text'=>get_string('coursetags1', $tagslang));
- }
- coursetag_get_jscript_links($elementid, $coursetagslinks);
-
} else {
- //if not logged in
- $this->content->footer = '<hr />'.get_string('please', $tagslang).'
- <a href="'.get_login_url().'">'.get_string('login', $tagslang).'
- </a> '.get_string('tagunits', $tagslang);
+ // If not logged in.
+ $this->content->footer = '<hr />'.get_string('please', 'block_tags').'
+ <a href="'.get_login_url().'">'.get_string('login', 'block_tags').'
+ </a> '.get_string('tagunits', 'block_tags');
}
}
- // end of show course tags section
+ // End of show course tags section.
return $this->content;
}
-}
-
+}
View
5 blocks/tags/edit_form.php
@@ -1,5 +1,4 @@
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -44,5 +43,9 @@ protected function specific_definition($mform) {
}
$mform->addElement('select', 'config_numberoftags', get_string('numberoftags', 'blog'), $numberoftags);
$mform->setDefault('config_numberoftags', 80);
+
+ $defaults = array('default'=>'default', 'official'=>'official', ''=>'both');
+ $mform->addElement('select', 'config_tagtype', get_string('defaultdisplay', 'block_tags'), $defaults);
+ $mform->setDefault('config_tagtype', '');
}
}
View
18 blocks/tags/lang/en/block_tags.php
@@ -1,5 +1,4 @@
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -25,16 +24,10 @@
$string['add'] = 'Add';
$string['alltags'] = 'All tags:';
-$string['alltags1'] = 'all tags';
-$string['alltags2'] = 'Show all tags (user profile, blogs and course tags)';
$string['arrowtitle'] = 'Click here to enter the suggested text (grey letters).';
-$string['communitytags'] = 'Community tags:';
-$string['communitytags1'] = 'community tags';
-$string['communitytags2'] = 'Show all user created course tags';
$string['coursetags'] = 'Course tags:';
-$string['coursetags1'] = 'course tags';
-$string['coursetags2'] = 'Show tags for this course';
$string['disabledtags'] = 'Tags are disabled';
+$string['defaultdisplay'] = 'Tag type to display';
$string['edit'] = 'edit...';
$string['editdeletemytag'] = 'Delete tag from this course:';
$string['editmytags'] = 'My tags - shortcuts to all your tagged courses.';
@@ -56,7 +49,7 @@
$string['moreorderpop'] = 'Popularity';
$string['moreshow'] = 'Show:';
$string['moreshowalltags'] = 'All tags';
-$string['moreshowcommtags'] = 'Community tags';
+$string['moreshowcommtags'] = 'Non-official tags';
$string['moreshowcoursetags'] = 'Tags for \'{$a}\'';
$string['moreshowmytags'] = 'My tags';
$string['moreshowofficialtags'] = 'Official tags';
@@ -68,15 +61,8 @@
Different groups of tags may be displayed with the links on the \'Show:\' line,
and may be reordered with the links on the \'Order:\' line.';
$string['mycoursetags'] = 'My course tags:';
-$string['mycoursetag1'] = 'Show my course tags';
-$string['mycoursetag2'] = 'my course tags';
$string['mytags'] = 'My tags:';
-$string['mytags1'] = 'my tags';
-$string['mytags2'] = 'Show my personal tags';
$string['notagsyet'] = 'No tags yet';
-$string['officialtags'] = 'Official course tags:';
-$string['officialtags1'] = 'official tags';
-$string['officialtags2'] = 'Show official course tags';
$string['please'] = 'Please';
$string['pluginname'] = 'Tags';
$string['select'] = 'Select...';
View
15 blocks/tags/settings.php
@@ -1,4 +1,18 @@
<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') || die;
@@ -6,4 +20,3 @@
$settings->add(new admin_setting_configcheckbox('block_tags_showcoursetags', get_string('showcoursetags', 'block_tags'),
get_string('showcoursetagsdef', 'block_tags'), 0));
}
-
View
2 blocks/tags/version.php
@@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2012061700; // The current plugin version (Date: YYYYMMDDXX)
+$plugin->version = 2012082800; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2012061700; // Requires this Moodle version
$plugin->component = 'block_tags'; // Full name of the plugin (used for diagnostics)
View
1 lang/en/role.php
@@ -353,6 +353,7 @@
$string['tag:edit'] = 'Edit existing tags';
$string['tag:editblocks'] = 'Edit blocks in tags pages';
$string['tag:manage'] = 'Manage all tags';
+$string['tag:flag'] = 'Flag tags as innappropriate';
$string['thisusersroles'] = 'This user\'s role assignments';
$string['unassignarole'] = 'Unassign role {$a}';
$string['unassignerror'] = 'Error while unassigning the role {$a->role} from user {$a->user}.';
View
11 lib/db/access.php
@@ -1669,6 +1669,17 @@
)
),
+ 'moodle/tag:flag' => array(
+ 'riskbitmask' => RISK_SPAM,
+
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_SYSTEM,
+ 'archetypes' => array(
+ 'manager' => CAP_ALLOW,
+ 'user' => CAP_ALLOW
+ )
+ ),
+
'moodle/tag:editblocks' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
View
4 lib/db/install.xml
@@ -2019,8 +2019,8 @@
<KEY NAME="userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id" PREVIOUS="primary"/>
</KEYS>
<INDEXES>
- <INDEX NAME="name" UNIQUE="true" FIELDS="name" COMMENT="tag names are unique"/>
- </INDEXES>
+ <INDEX NAME="name" UNIQUE="true" FIELDS="name" COMMENT="tag names are unique" NEXT="idname"/>
+ <INDEX NAME="idname" UNIQUE="true" FIELDS="id, name" COMMENT="Improves performance of autocomplete in tag block" PREVIOUS="name"/> </INDEXES>
</TABLE>
<TABLE NAME="tag_correlation" COMMENT="The rationale for the 'tag_correlation' table is performance. It works as a cache for a potentially heavy load query done at the 'tag_instance' table. So, the 'tag_correlation' table stores redundant information derived from the 'tag_instance' table" PREVIOUS="tag" NEXT="tag_instance">
<FIELDS>
View
16 lib/db/upgrade.php
@@ -1206,5 +1206,19 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2012090700.01);
}
+ if ($oldversion < 2012092000.00) {
+ // Define index idname (unique) to be added to tag
+ $table = new xmldb_table('tag');
+ $index = new xmldb_index('idname', XMLDB_INDEX_UNIQUE, array('id', 'name'));
+
+ // Conditionally launch add index idname
+ if (!$dbman->index_exists($table, $index)) {
+ $dbman->add_index($table, $index);
+ }
+
+ // Main savepoint reached
+ upgrade_main_savepoint(true, 2012092000.01);
+ }
+
return true;
-}
+}
View
2 tag/coursetags_edit.php
@@ -96,7 +96,7 @@
$title = get_string('edittitle', $tagslang);
echo $OUTPUT->heading($title, 2, 'mdl-align');
- $mytags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default'), true);
+ $mytags = tag_print_cloud(coursetag_get_tags(0, $USER->id, 'default'), 150, true);
$outstr = '
<div class="coursetag_edit_centered">
<div>
View
30 tag/coursetags_more.php
@@ -105,44 +105,44 @@
if ($show == 'course' and $courseid) {
if ($sort == 'popularity') {
- $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'popularity'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'popularity'), 150, true);
} else if ($sort == 'date') {
- $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'timemodified'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'timemodified'), 150, true);
} else {
- $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'name'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'name'), 150, true);
}
// 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);
+ $tags = tag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'popularity'), 150, true);
} else if ($sort == 'date') {
- $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'timemodified'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'timemodified'), 150, true);
} else {
- $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'name'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'name'), 150, true);
}
// 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);
+ $tags = tag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'popularity'), 150, true);
} else if ($sort == 'date') {
- $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'timemodified'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'timemodified'), 150, true);
} else {
- $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'name'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'name'), 150, true);
}
// 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);
+ $tags = tag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'popularity'), 150, true);
} else if ($sort == 'date') {
- $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'timemodified'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'timemodified'), 150, true);
} else {
- $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'name'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'name'), 150, true);
}
// All tags for courses and blogs and any thing else tagged - the fallback default ($show == all)
@@ -150,11 +150,11 @@
$subtitle = $showalltags;
if ($sort == 'popularity') {
- $tags = coursetag_print_cloud(coursetag_get_all_tags('popularity'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_all_tags('popularity'), 150, true);
} else if ($sort == 'date') {
- $tags = coursetag_print_cloud(coursetag_get_all_tags('timemodified'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_all_tags('timemodified'), 150, true);
} else {
- $tags = coursetag_print_cloud(coursetag_get_all_tags('name'), true, 200, 90);
+ $tags = tag_print_cloud(coursetag_get_all_tags('name'), 150, true);
}
}
View
309 tag/coursetagslib.php
@@ -24,6 +24,7 @@
*/
require_once $CFG->dirroot.'/tag/lib.php';
+require_once $CFG->dirroot.'/tag/locallib.php';
/**
* Returns an ordered array of tags associated with visible courses
@@ -186,7 +187,7 @@ function coursetag_sort($a, $b) {
if (is_numeric($a->$tagsort)) {
return ($a->$tagsort == $b->$tagsort) ? 0 : ($a->$tagsort > $b->$tagsort) ? 1 : -1;
- } elseif (is_string($a->$tagsort)) {
+ } else if (is_string($a->$tagsort)) {
return strcmp($a->$tagsort, $b->$tagsort);
} else {
return 0;
@@ -194,102 +195,18 @@ function coursetag_sort($a, $b) {
}
/**
- * Prints a tag cloud
- *
- * @package core_tag
- * @category tag
- * @param array $tagcloud array of tag objects (fields: id, name, rawname, count and flag)
- * @param mixed $return if true return html string
- * @param int $max_size maximum text size, in percentage
- * @param int $min_size minimum text size, in percentage
- */
-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 = context_system::instance();
- $can_manage_tags = has_capability('moodle/tag:manage', $systemcontext);
-
- //prints the tag cloud
- $output = '<ul class="tag-cloud inline-list">';
- 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 = '<span class="flagged-tag">' . tag_display_name($tag) . '</span>';
- }
-
- $tag_link = '<li><a '.$href.' '.$title.' '. $style .'>'.$tagname.'</a></li> ';
-
- $output .= $tag_link;
-
- }
- $output .= '</ul>'."\n";
-
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
-}
-
-/**
* Returns javascript for use in tags block and supporting pages
*
* @package core_tag
* @category tag
- * @param string $coursetagdivs comma separated divs ids
* @return null
*/
-function coursetag_get_jscript($coursetagdivs = '') {
+function coursetag_get_jscript() {
global $CFG, $DB, $PAGE;
$PAGE->requires->js('/tag/tag.js');
$PAGE->requires->strings_for_js(array('jserror1', 'jserror2'), 'block_tags');
- if ($coursetagdivs) {
- $PAGE->requires->js_function_call('set_course_tag_divs', $coursetagdivs);
- }
-
if ($coursetags = $DB->get_records('tag', null, 'name ASC', 'name, id')) {
foreach ($coursetags as $key => $value) {
$PAGE->requires->js_function_call('set_course_tag', array($key));
@@ -359,7 +276,7 @@ function coursetag_store_keywords($tags, $courseid, $userid=0, $tagtype='officia
global $CFG;
if (is_array($tags) and !empty($tags)) {
- foreach($tags as $tag) {
+ foreach ($tags as $tag) {
$tag = trim($tag);
if (strlen($tag) > 0) {
//tag_set_add('course', $courseid, $tag, $userid); //deletes official tags
@@ -494,221 +411,3 @@ function coursetag_delete_course_tags($courseid, $showfeedback=false) {
}
}
-/*
- * Function called by cron to create/update users rss feeds
- *
- * @return true
- *
- * Function removed.
- * rsslib.php needs updating to accept Dublin Core tags (dc/cc) input before this can work.
- */
-/*
-function coursetag_rss_feeds() {
-
- global $CFG, $DB;
- 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 = $DB->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 {user} u, {course} c, {tag_instance} cti, {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 = $DB->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 {course} c, {tag_instance} cti, {tag} t
- WHERE c.id = cti.itemid
- AND cti.tiuserid = :userid{$user->userid}
- AND cti.tagid = t.id
- AND t.tagtype = 'personal'
- ORDER BY courseid";
- if ($usertags = $DB->get_records_sql($sql, array('userid' => $user->userid))) {
- $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 = get_string('rsstitle', 'tag', ucwords(strtolower($user->firstname.' '.$user->lastname)));
- $desc = get_string('rssdesc', 'tag');
- // 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 into seperate lib as in next two lines
- //require_once($CFG->dirroot.'/local/ocilib.php');
- //oci_create_rss_feed( $path, $file_name, $latest_date, $items, $title, $desc, $dc=true, $cc=false);
-
- // Set path to RSS file
- $full_path = "$save_path/$file_name";
-
- mtrace(" Preparing to update RSS feed for $file_name");
-
- // First let's make sure there is work to do by checking the time the file was last modified,
- // if a course was update after the file was mofified
- if (file_exists($full_path)) {
- if ($lastmodified = filemtime($full_path)) {
- mtrace(" XML File $file_name Created on ".date( "D, j M Y G:i:s T", $lastmodified ));
- mtrace(' Lastest course modification on '.date( "D, j M Y G:i:s T", $latest_date ));
- if ($latest_date > $lastmodified) {
- mtrace(" XML File $file_name needs updating");
- $changes = true;
- } else {
- mtrace(" XML File $file_name doesn't need updating");
- $changes = false;
- }
- }
- } else {
- mtrace(" XML File $file_name needs updating");
- $changes = true;
- }
-
- if ($changes) {
- // Now we know something has changed, write the new file
-
- if (!empty($items)) {
- // First set rss feeds common headers
- $header = rss_standard_header(strip_tags(format_string($title,true)),
- $CFG->wwwroot,
- $desc,
- true, true);
- // Now all the rss items
- if (!empty($header)) {
- $articles = rss_add_items($items,$dc,$cc);
- }
- // Now all rss feeds common footers
- if (!empty($header) && !empty($articles)) {
- $footer = rss_standard_footer();
- }
- // Now, if everything is ok, concatenate it
- if (!empty($header) && !empty($articles) && !empty($footer)) {
- $result = $header.$articles.$footer;
- } else {
- $result = false;
- }
- } else {
- $result = false;
- }
-
- // Save the XML contents to file
- if (!empty($result)) {
- $rss_file = fopen($full_path, "w");
- if ($rss_file) {
- $status = fwrite ($rss_file, $result);
- fclose($rss_file);
- } else {
- $status = false;
- }
- }
-
- // Output result
- if (empty($result)) {
- // There was nothing to put into the XML file. Delete it!
- if( is_file($full_path) ) {
- mtrace(" There were no items for XML File $file_name. Deleting XML File");
- unlink($full_path);
- mtrace(" $full_path -> (deleted)");
- } else {
- mtrace(" There were no items for the XML File $file_name and no file to delete. Ignore.");
- }
- } else {
- if (!empty($status)) {
- mtrace(" $full_path -> OK");
- } else {
- mtrace(" $full_path -> FAILED");
- }
- }
- }
- //end of oci_create_rss_feed()
- }
- }
- }
- }
-
- return $status;
-}
- */
-
-/*
- * Get official keywords for the <meta name="keywords"> in header.html
- * use: echo '<meta name="keywords" content="'.coursetag_get_official_keywords($COURSE->id).'"/>';
- *
- * @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 tags (not personal tags to prevent their deletion) to all
- * courses (facility not added yet) which will be automatically added to the page header to boost
- * search engine specificity/ratings.
- */
-/*
-function coursetag_get_official_keywords($courseid, $asarray=false) {
- global $CFG;
- $returnstr = '';
- $sql = "SELECT t.id, name, rawname
- FROM {tag} t, {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 = $DB->get_records_sql($sql, array('courseid' => $courseid))) {
- if ($asarray) {
- return $tags;
- }
- foreach ($tags as $tag) {
- if( empty($CFG->keeptagnamecase) ) {
- $name = textlib::strtotitle($tag->name);
- } else {
- $name = $tag->rawname;
- }
- $returnstr .= $name.', ';
- }
- $returnstr = rtrim($returnstr, ', ');
- }
- return $returnstr;
-}
-*/
View
30 tag/locallib.php
@@ -32,21 +32,29 @@
* @package core_tag
* @access public
* @category tag
- * @param int $nr_of_tags Limit for the number of tags to return/display
+ * @param array $tagset Array of tags to display
+ * @param int $nr_of_tags Limit for the number of tags to return/display, used if $tagset is null
* @param bool $return if true the function will return the generated tag cloud instead of displaying it.
* @return string|null a HTML string or null if this function does the output
*/
-function tag_print_cloud($nr_of_tags=150, $return=false) {
+//TODO question for integrator - for contrib work would it be best to add $tagset at the end of the parameter list
+// not the beginning? I put it at the beginning because it sits better as alternative to $nr_of_tags there
+function tag_print_cloud($tagset=null, $nr_of_tags=150, $return=false) {
global $CFG, $DB;
$can_manage_tags = has_capability('moodle/tag:manage', context_system::instance());
- if ( !$tagsincloud = $DB->get_records_sql('SELECT tg.rawname, tg.id, tg.name, tg.tagtype, COUNT(ti.id) AS count, tg.flag
- FROM {tag_instance} ti JOIN {tag} tg ON tg.id = ti.tagid
- WHERE ti.itemtype <> \'tag\'
- GROUP BY tg.id, tg.rawname, tg.name, tg.flag, tg.tagtype
- ORDER BY count DESC, tg.name ASC', null, 0, $nr_of_tags) ) {
- $tagsincloud = array();
+ if (is_null($tagset)) {
+ // No tag set received, so fetch tags from database
+ if ( !$tagsincloud = $DB->get_records_sql('SELECT tg.rawname, tg.id, tg.name, tg.tagtype, COUNT(ti.id) AS count, tg.flag
+ FROM {tag_instance} ti JOIN {tag} tg ON tg.id = ti.tagid
+ WHERE ti.itemtype <> \'tag\'
+ GROUP BY tg.id, tg.rawname, tg.name, tg.flag, tg.tagtype
+ ORDER BY count DESC, tg.name ASC', null, 0, $nr_of_tags) ) {
+ $tagsincloud = array();
+ }
+ } else {
+ $tagsincloud = $tagset;
}
$tagkeys = array_keys($tagsincloud);
@@ -200,8 +208,10 @@ function tag_print_management_box($tag_object, $return=false) {
$links[] = '<a href="'. $CFG->wwwroot .'/tag/user.php?action=addinterest&amp;sesskey='. sesskey() .'&amp;tag='. rawurlencode($tag_object->name) .'">'. get_string('addtagtomyinterests', 'tag', $tagname) .'</a>';
}
- // flag as inappropriate link
- $links[] = '<a href="'. $CFG->wwwroot .'/tag/user.php?action=flaginappropriate&amp;sesskey='. sesskey() .'&amp;tag='. rawurlencode($tag_object->name) .'">'. get_string('flagasinappropriate', 'tag', rawurlencode($tagname)) .'</a>';
+ // Flag as inappropriate link. Only people with moodle/tag:flag capability.
+ if (has_capability('moodle/tag:flag', $systemcontext)) {
+ $links[] = '<a href="'. $CFG->wwwroot .'/tag/user.php?action=flaginappropriate&amp;sesskey='. sesskey() .'&amp;tag='. rawurlencode($tag_object->name) .'">'. get_string('flagasinappropriate', 'tag', rawurlencode($tagname)) .'</a>';
+ }
// Edit tag: Only people with moodle/tag:edit capability who either have it as an interest or can manage tags
if (has_capability('moodle/tag:edit', $systemcontext) ||
View
2 tag/search.php
@@ -72,7 +72,7 @@
echo '<br/><br/>';
echo $OUTPUT->box_start('generalbox', 'big-tag-cloud-box');
-tag_print_cloud(150);
+tag_print_cloud(null, 150);
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
View
4 tag/tag.js
@@ -45,10 +45,6 @@ function ctags_checkinput(val) {
}
}
-function set_course_tag_divs(ctagdivs) {
- window.coursetagdivs = ctagdivs;
-}
-
function set_course_tag(key) {
window.coursetag_tags[window.coursetag_tags.length] = key;
}
View
2 version.php
@@ -30,7 +30,7 @@
defined('MOODLE_INTERNAL') || die();
-$version = 2012092000.00; // YYYYMMDD = weekly release date of this DEV branch
+$version = 2012092000.01; // YYYYMMDD = weekly release date of this DEV branch
// RR = release increments - 00 in DEV branches
// .XX = incremental changes

0 comments on commit 7dd764b

Please sign in to comment.
Something went wrong with that request. Please try again.