First checkin of tag system from GSOC student Luiz Cruz

It's a very simple first version.

TODO for 1.9:

   - Store rawname of each tag as well as normalised version and treat accordingly
   - Add blocks to the tag interest pages
This commit is contained in:
moodler
2007-07-31 07:51:32 +00:00
parent 705789bda6
commit c933a06065
9 changed files with 1868 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
<?php
$string['addtagtomyinterests'] = 'Add \"$a\" to my interests';
$string['count'] = 'Count';
$string['description'] = 'Description';
$string['delete'] = 'Delete';
$string['deleted'] = 'Deleted';
$string['edittag'] = 'Edit this tag';
$string['flag'] = 'Flag';
$string['flagasinappropriate'] = 'Flag as inappropriate';
$string['helprelatedtags'] = 'Comma separated related tags';
$string['managetags'] = 'Manage Tags';
$string['name'] = 'Name';
$string['noresultsfor'] = 'No results for \"$a\"';
$string['owner'] = 'Owner';
$string['relatedtags'] = 'Related tags';
$string['responsiblewillbenotified'] = 'The person responsible will be notified';
$string['resetflag'] = 'Reset flag';
$string['reset'] = 'Reset';
$string['search'] = 'Search';
$string['searchresultsfor'] = 'Search results for \"$a\"';
$string['searchtags'] = 'Search tags';
$string['select'] = 'Select';
$string['tagdescription'] = 'Tag description';
$string['tag'] = 'Tag';
$string['tags'] = 'Tags';
$string['tagsaredisabled'] = 'Tags are disabled';
$string['thingstaggedwith'] = '$a->count things tagged with \"$a->name\"';
$string['thistaghasnodesc'] = 'This tag currently has no description.';
$string['timemodified'] = 'Modified';
$string['userstaggedwith'] = 'Users tagged with \"$a\"';
$string['updatetag'] = 'Update';
?>
+90
View File
@@ -0,0 +1,90 @@
<?php // $Id$
require_once('../config.php');
require_once('lib.php');
require_once('edit_form.php');
require_once($CFG->dirroot.'/lib/weblib.php');
require_login();
if( empty($CFG->usetags)) {
error(get_string('tagsaredisabled', 'tag'));
}
$tagid = required_param('id', PARAM_INT); // user id
$tag = tag_by_id($tagid);
$tagname = /*ucwords*/($tag->name);
//Editing a tag requires moodle/tag:edittags capability
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
require_capability('moodle/tag:edittags', $systemcontext);
// set the relatedtags field of the $tag object that will be passed to the form
$tag->relatedtags = tag_names_csv( get_item_tags('tag',$tagid) );
$tagform = new tag_edit_form();
$tagform->set_data($tag);
// if new data has been sent, update the tag record
if ($tagnew = $tagform->get_data()) {
$tagnew->timemodified = time();
if (!update_record('tag', $tagnew)) {
error('Error updating tag record');
}
//updated related tags
update_item_tags('tag', $tagnew->id, $tagnew->relatedtags);
redirect($CFG->wwwroot.'/tag/index.php?id='.$tagnew->id);
}
$navlinks = array();
$navlinks[] = array('name' => get_string('tags', 'tag'), 'link' => "{$CFG->wwwroot}/tag/search.php", 'type' => '');
$navlinks[] = array('name' => $tagname, 'link' => '', 'type' => '');
$navigation = build_navigation($navlinks);
print_header_simple(get_string('tag', 'tag') . ' - '. $tagname, '', $navigation);
print_heading($tagname, '', 2);
$tagform->display();
?>
<!-- Dependencies -->
<script type="text/javascript" src="http://yui.yahooapis.com/2.2.2/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<!-- OPTIONAL: Connection (required only if using XHR DataSource) -->
<script type="text/javascript" src="http://yui.yahooapis.com/2.2.2/build/connection/connection-min.js"></script>
<!-- OPTIONAL: Animation (required only if enabling animation) -->
<script type="text/javascript" src="http://yui.yahooapis.com/2.2.2/build/animation/animation-min.js"></script>
<!-- Source file -->
<script type="text/javascript" src="http://yui.yahooapis.com/2.2.2/build/autocomplete/autocomplete-min.js"></script>
<script type="text/javascript">
// An XHR DataSource
var myServer = "./tag_autocomplete.php";
var myDataSource = new YAHOO.widget.DS_XHR(myServer, ["\n", "\t"]);
myDataSource.responseType = YAHOO.widget.DS_XHR.TYPE_FLAT;
myDataSource.maxCacheEntries = 60;
myDataSource.queryMatchSubset = true;
var myAutoComp = new YAHOO.widget.AutoComplete("id_relatedtags","relatedtags-autocomplete", myDataSource);
myAutoComp.delimChar = ",";
myAutoComp.maxResultsDisplayed = 20;
myAutoComp.minQueryLength = 2;
myAutoComp.allowBrowserAutocomplete = false;
</script>
<?php
print_footer();
?>
+33
View File
@@ -0,0 +1,33 @@
<?php // $Id$
require_once($CFG->dirroot.'/lib/formslib.php');
class tag_edit_form extends moodleform {
function definition () {
$mform =& $this->_form;
$mform->addElement('header', 'tag', get_string('description','tag'));
$mform->addElement('hidden', 'id');
$mform->addElement('htmleditor', 'description', get_string('description', 'tag'), array('rows'=>20));
$mform->setType('description', PARAM_CLEANHTML);
$mform->addElement('format', 'descriptionformat', get_string('format'));
$mform->addElement('html', '<br/><div id="relatedtags-autocomplete-container">');
$mform->addElement('textarea', 'relatedtags', get_string('relatedtags','tag'), 'cols="50" rows="3"');
$mform->setType('relatedtags', PARAM_MULTILANG);
$mform->addElement('html', '</div>');
$mform->addElement('html', '<div id="relatedtags-autocomplete"></div>');
$this->add_action_buttons(false, get_string('updatetag', 'tag'));
}
}
?>
+66
View File
@@ -0,0 +1,66 @@
<?php // $Id$
require_once('../config.php');
require_once('lib.php');
require_once($CFG->dirroot.'/lib/weblib.php');
require_login();
if (empty($CFG->usetags)) {
error(get_string('tagsaredisabled', 'tag'));
}
$tagid = optional_param('id', 0, PARAM_INT); // tag id
$userpage = optional_param('userpage', 0, PARAM_INT); // which page to show
$perpage = optional_param('perpage', 16, PARAM_INT);
$tag = tag_by_id($tagid);
if (!$tag) {
redirect($CFG->wwwroot.'/tag/search.php');
}
$tagname = mb_convert_case($tag->name, MB_CASE_TITLE, "UTF-8");
$navlinks = array();
$navlinks[] = array('name' => get_string('tags', 'tag'), 'link' => "{$CFG->wwwroot}/tag/search.php", 'type' => '');
$navlinks[] = array('name' => $tagname, 'link' => '', 'type' => '');
$navigation = build_navigation($navlinks);
print_header_simple(get_string('tag', 'tag') . ' - ' . $tagname, '', $navigation);
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
if ($tag->flag > 0 && has_capability('moodle/tag:manage', $systemcontext)) {
$tagname = '<span class="flagged-tag">' . $tagname . '</span>';
}
print_heading($tagname, '', 2);
print_tag_management_box($tag);
print_tag_description_box($tag);
$usercount = count_items_tagged_with($tagid,'user');
if ($usercount > 0) {
print_heading(get_string('userstaggedwith', 'tag', $tagname) . ': ' . $usercount, '', 3);
$baseurl = $CFG->wwwroot.'/tag/index.php?id=' . $tagid;
print_paging_bar($usercount, $userpage, $perpage, $baseurl.'&amp;', 'userpage');
print_tagged_users_table($tag, 4, $userpage * $perpage, $perpage);
}
//print_box_start('generalbox', 'small-tag-cloud-box');
// print_tag_cloud(15,170,80);
//print_box_end();
print_footer();
?>
+1480
View File
File diff suppressed because it is too large Load Diff
+57
View File
@@ -0,0 +1,57 @@
<?php // $Id$
require_once('../config.php');
require_once('lib.php');
require_once($CFG->dirroot.'/lib/weblib.php');
require_login();
if( empty($CFG->usetags)) {
error(get_string('tagsaredisabled', 'tag'));
}
//managing tags requires moodle/tag:managetags capability
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
require_capability('moodle/tag:managetags', $systemcontext);
$tagschecked = optional_param('tagschecked', array());
$action = optional_param('action', '', PARAM_ALPHA);
$navlinks = array();
$navlinks[] = array('name' => get_string('tags', 'tag'), 'link' => "{$CFG->wwwroot}/tag/search.php", 'type' => '');
$navlinks[] = array('name' => get_string('managetags', 'tag'), 'link' => '', 'type' => '');
$navigation = build_navigation($navlinks);
print_header_simple(get_string('managetags', 'tag'), '', $navigation);
switch($action) {
case 'delete':
$notice = tag_name_from_string(implode($tagschecked, ', '));
$notice = str_replace(',', ', ', $notice);
$notice .= ' -- ' . get_string('deleted','tag');
notify($notice , 'green');
tag_delete(implode($tagschecked, ','));
break;
case 'reset':
$notice = tag_name_from_string(implode($tagschecked, ', '));
$notice = str_replace(',', ', ', $notice);
$notice .= ' -- ' . get_string('reset','tag');
notify($notice , 'green');
tag_flag_reset(implode($tagschecked, ','));
break;
}
echo '<br/>';
print_tag_management_list();
echo '<br/>';
print_footer();
?>
+47
View File
@@ -0,0 +1,47 @@
<?php
require_once('../config.php');
require_once('lib.php');
require_once($CFG->dirroot.'/lib/weblib.php');
global $CFG;
require_login();
if( empty($CFG->usetags)) {
error(get_string('tagsaredisabled', 'tag'));
}
$query = optional_param('query', '', PARAM_TEXT);
$page = optional_param('page', 0, PARAM_INT); // which page to show
$perpage = optional_param('perpage', 18, PARAM_INT);
$navlinks = array();
$navlinks[] = array('name' => get_string('tags', 'tag'), 'link' => "{$CFG->wwwroot}/tag/search.php", 'type' => '');
$navigation = build_navigation($navlinks);
print_header_simple(get_string('tags', 'tag'), '', $navigation);
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
if ( has_capability('moodle/tag:manage',$systemcontext) ) {
$manage_link = "<a href=\"{$CFG->wwwroot}/tag/manage.php\">" . get_string('managetags', 'tag') . "</a>" ;
print_box($manage_link, '', 'tags-management-links');
}
print_heading(get_string('searchtags', 'tag'), '', 2);
print_tag_search_box();
if(!empty($query)) {
print_tag_search_results($query, $page, $perpage);
}
echo '<br/><br/>';
print_box_start('generalbox', 'big-tag-cloud-box');
print_tag_cloud(rand_tags_count(60), true, 170,70);
print_box_end();
print_footer();
?>
+19
View File
@@ -0,0 +1,19 @@
<?php // $Id$
require_once('lib.php');
if( empty($CFG->usetags)) {
error(get_string('tagsaredisabled', 'tag'));
}
$query = optional_param('query', 0, PARAM_TEXT);
$query = tag_normalize($query);
$similar_tags = similar_tags($query);
$count = 0;
foreach ($similar_tags as $tag){
echo $tag->name . "\t" . $tag->id . "\n";
}
?>
+42
View File
@@ -0,0 +1,42 @@
<?php // $Id$
require_once('../config.php');
require_once('../tag/lib.php');
$action = optional_param('action', '', PARAM_ALPHA);
require_login();
if (empty($CFG->usetags)) {
error('Tags are disabled!');
}
switch ($action) {
case 'addinterest':
$id = optional_param('id', 0, PARAM_INT);
$name = optional_param('name', '', PARAM_TEXT);
if (empty($name) && $id) {
$name = tag_name($id);
}
tag_an_item('user',$USER->id, $name);
if (!empty($name) && !$id) {
$id = tag_id($name);
}
redirect($CFG->wwwroot.'/tag/index.php?id='.$id);
break;
case 'flaginappropriate':
$id = required_param('id', PARAM_INT);
tag_flag_inappropriate($id);
redirect($CFG->wwwroot.'/tag/index.php?id='.$id, get_string('responsiblewillbenotified','tag'));
break;
}
?>