Skip to content

Commit

Permalink
MDL-57456 mod_glossary: Implement tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewhancox authored and marinaglancy committed Apr 7, 2017
1 parent bd99cb9 commit 694d2f8
Show file tree
Hide file tree
Showing 21 changed files with 419 additions and 9 deletions.
16 changes: 16 additions & 0 deletions mod/glossary/backup/moodle2/backup_glossary_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ protected function define_structure() {
'teacherentry', 'sourceglossaryid', 'usedynalink', 'casesensitive',
'fullmatch', 'approved'));

$tags = new backup_nested_element('tags');
$tag = new backup_nested_element('tag', array('id'), array('name', 'rawname'));

$aliases = new backup_nested_element('aliases');

$alias = new backup_nested_element('alias', array('id'), array(
Expand Down Expand Up @@ -83,6 +86,9 @@ protected function define_structure() {
$entry->add_child($ratings);
$ratings->add_child($rating);

$entry->add_child($tags);
$tags->add_child($tag);

$glossary->add_child($categories);
$categories->add_child($category);

Expand All @@ -108,6 +114,16 @@ protected function define_structure() {
$rating->set_source_alias('rating', 'value');

$categoryentry->set_source_table('glossary_entries_categories', array('categoryid' => backup::VAR_PARENTID));

$tag->set_source_sql('SELECT t.id, t.name, t.rawname
FROM {tag} t
JOIN {tag_instance} ti ON ti.tagid = t.id
WHERE ti.itemtype = ?
AND ti.component = ?
AND ti.itemid = ?', array(
backup_helper::is_sqlparam('glossary_entries'),
backup_helper::is_sqlparam('mod_glossary'),
backup::VAR_PARENTID));
}

// Define id annotations
Expand Down
15 changes: 15 additions & 0 deletions mod/glossary/backup/moodle2/restore_glossary_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ protected function define_structure() {
$paths[] = new restore_path_element('glossary_category', '/activity/glossary/categories/category');
if ($userinfo) {
$paths[] = new restore_path_element('glossary_entry', '/activity/glossary/entries/entry');
$paths[] = new restore_path_element('glossary_tag', '/activity/glossary/entries/entry/tags/tag');
$paths[] = new restore_path_element('glossary_alias', '/activity/glossary/entries/entry/aliases/alias');
$paths[] = new restore_path_element('glossary_rating', '/activity/glossary/entries/entry/ratings/rating');
$paths[] = new restore_path_element('glossary_category_entry',
Expand Down Expand Up @@ -134,6 +135,20 @@ protected function process_glossary_rating($data) {
$newitemid = $DB->insert_record('rating', $data);
}

protected function process_glossary_tag($data) {
$data = (object)$data;

if (!core_tag_tag::is_enabled('mod_glossary', 'glossary_entries')) { // Tags disabled in server, nothing to process.
return;
}

$tag = $data->rawname;
$itemid = $this->get_new_parentid('glossary_entry');

$context = context_module::instance($this->task->get_moduleid());
core_tag_tag::add_item_tag('mod_glossary', 'glossary_entries', $itemid, $context, $tag);
}

protected function process_glossary_category($data) {
global $DB;

Expand Down
35 changes: 35 additions & 0 deletions mod/glossary/db/tag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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/>.

/**
* Tag areas in component mod_glossary
*
* @package mod_glossary
* @copyright 2017 Andrew Hancox <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();


$tagareas = array(
array(
'itemtype' => 'glossary_entries',
'component' => 'mod_glossary',
'callback' => 'mod_glossary_get_tagged_entries',
'callbackfile' => '/mod/glossary/locallib.php',
),
);
2 changes: 2 additions & 0 deletions mod/glossary/deleteentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@
glossary_rss_delete_file($glossary);
}

core_tag_tag::remove_all_item_tags('mod_glossary', 'glossary_entries', $origentry->id);

$event = \mod_glossary\event\entry_deleted::create(array(
'context' => $context,
'objectid' => $origentry->id,
Expand Down
11 changes: 9 additions & 2 deletions mod/glossary/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@
redirect("view.php?id=$cm->id");
}

} else if ($entry = $mform->get_data()) {
$entry = glossary_edit_entry($entry, $course, $cm, $glossary, $context);
} else if ($data = $mform->get_data()) {
$entry = glossary_edit_entry($data, $course, $cm, $glossary, $context);
if (core_tag_tag::is_enabled('mod_glossary', 'glossary_entries') && isset($data->tags)) {
core_tag_tag::set_item_tags('mod_glossary', 'glossary_entries', $data->id, $context, $data->tags);
}
redirect("view.php?id=$cm->id&mode=entry&hook=$entry->id");
}

Expand All @@ -98,6 +101,10 @@
echo $OUTPUT->box(format_module_intro('glossary', $glossary, $cm->id), 'generalbox', 'intro');
}

$data = new StdClass();
$data->tags = core_tag_tag::get_item_tags_array('mod_glossary', 'glossary_entries', $id);
$mform->set_data($data);

$mform->display();

echo $OUTPUT->footer();
Expand Down
7 changes: 7 additions & 0 deletions mod/glossary/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ function definition() {
$mform->setDefault('fullmatch', $CFG->glossary_fullmatch);
}

if (core_tag_tag::is_enabled('mod_glossary', 'glossary_entries')) {
$mform->addElement('header', 'tagshdr', get_string('tags', 'tag'));

$mform->addElement('tags', 'tags', get_string('tags'),
array('itemtype' => 'glossary_entries', 'component' => 'mod_glossary'));
}

$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'cmid');
Expand Down
7 changes: 6 additions & 1 deletion mod/glossary/formats/continuous/continuous_format.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function glossary_show_entry_continuous($course, $cm, $glossary, $entry, $mode='', $hook='', $printicons=1, $aliases=false) {

global $USER;
global $USER, $OUTPUT;

echo '<table class="glossarypost continuous" cellspacing="0">';
echo '<tr valign="top">';
Expand All @@ -13,6 +13,11 @@ function glossary_show_entry_continuous($course, $cm, $glossary, $entry, $mode='
echo '</div> ';
glossary_print_entry_definition($entry, $glossary, $cm);
glossary_print_entry_attachment($entry, $cm, 'html');

if (core_tag_tag::is_enabled('mod_glossary', 'glossary_entries')) {
echo $OUTPUT->tag_list(core_tag_tag::get_item_tags(
'mod_glossary', 'glossary_entries', $entry->id), null, 'glossary-tags');
}
$entry->alias = '';
echo '</td></tr>';

Expand Down
5 changes: 4 additions & 1 deletion mod/glossary/formats/dictionary/dictionary_format.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function glossary_show_entry_dictionary($course, $cm, $glossary, $entry, $mode='', $hook='', $printicons=1, $aliases=true) {

global $CFG, $USER;
global $CFG, $USER, $OUTPUT;

echo '<table class="glossarypost dictionary" cellspacing="0">';
echo '<tr valign="top">';
Expand All @@ -13,6 +13,9 @@ function glossary_show_entry_dictionary($course, $cm, $glossary, $entry, $mode='
echo '</div> ';
glossary_print_entry_definition($entry, $glossary, $cm);
glossary_print_entry_attachment($entry, $cm, 'html');
if (core_tag_tag::is_enabled('mod_glossary', 'glossary_entries')) {
echo $OUTPUT->tag_list(core_tag_tag::get_item_tags('mod_glossary', 'glossary_entries', $entry->id), null, 'glossary-tags');
}
echo '</td></tr>';
echo '<tr valign="top"><td class="entrylowersection">';
glossary_print_entry_lower_section($course, $cm, $glossary, $entry, $mode, $hook, $printicons, $aliases);
Expand Down
4 changes: 4 additions & 0 deletions mod/glossary/formats/encyclopedia/encyclopedia_format.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ function glossary_show_entry_encyclopedia($course, $cm, $glossary, $entry, $mode

glossary_print_entry_definition($entry, $glossary, $cm);
glossary_print_entry_attachment($entry, $cm, null);
if (core_tag_tag::is_enabled('mod_glossary', 'glossary_entries')) {
echo $OUTPUT->tag_list(
core_tag_tag::get_item_tags('mod_glossary', 'glossary_entries', $entry->id), null, 'glossary-tags');
}

if ($printicons or $aliases) {
echo '</td></tr>';
Expand Down
7 changes: 6 additions & 1 deletion mod/glossary/formats/faq/faq_format.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

function glossary_show_entry_faq($course, $cm, $glossary, $entry, $mode="", $hook="", $printicons=1, $aliases=true) {
global $USER;
global $USER, $OUTPUT;
if ( $entry ) {

echo '<table class="glossarypost faq" cellspacing="0">';
Expand Down Expand Up @@ -31,6 +31,11 @@ function glossary_show_entry_faq($course, $cm, $glossary, $entry, $mode="", $hoo
glossary_print_entry_definition($entry, $glossary, $cm);
glossary_print_entry_attachment($entry, $cm, 'html');

if (core_tag_tag::is_enabled('mod_glossary', 'glossary_entries')) {
echo $OUTPUT->tag_list(
core_tag_tag::get_item_tags('mod_glossary', 'glossary_entries', $entry->id), null, 'glossary-tags');
}

echo '</td></tr>';
echo '<tr valign="top"><td colspan="3" class="entrylowersection">';
glossary_print_entry_lower_section($course, $cm, $glossary, $entry, $mode, $hook, $printicons, $aliases);
Expand Down
5 changes: 5 additions & 0 deletions mod/glossary/formats/fullwithauthor/fullwithauthor_format.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ function glossary_show_entry_fullwithauthor($course, $cm, $glossary, $entry, $mo
glossary_print_entry_definition($entry, $glossary, $cm);
glossary_print_entry_attachment($entry, $cm, 'html');

if (core_tag_tag::is_enabled('mod_glossary', 'glossary_entries')) {
echo $OUTPUT->tag_list(
core_tag_tag::get_item_tags('mod_glossary', 'glossary_entries', $entry->id), null, 'glossary-tags');
}

echo '</td></tr>';
echo '<tr valign="top">';
echo '<td class="left">&nbsp;</td>';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

function glossary_show_entry_fullwithoutauthor($course, $cm, $glossary, $entry, $mode="", $hook="", $printicons=1, $aliases=true) {
global $CFG, $USER;
global $CFG, $USER, $OUTPUT;


if ($entry) {
Expand Down Expand Up @@ -30,6 +30,11 @@ function glossary_show_entry_fullwithoutauthor($course, $cm, $glossary, $entry,
glossary_print_entry_definition($entry, $glossary, $cm);
glossary_print_entry_attachment($entry, $cm, 'html');

if (core_tag_tag::is_enabled('mod_glossary', 'glossary_entries')) {
echo $OUTPUT->tag_list(
core_tag_tag::get_item_tags('mod_glossary', 'glossary_entries', $entry->id), null, 'glossary-tags');
}

echo '</td></tr>';
echo '<tr valign="top"><td colspan="2" class="entrylowersection">';
glossary_print_entry_lower_section($course, $cm, $glossary, $entry, $mode, $hook, $printicons, $aliases);
Expand Down
4 changes: 4 additions & 0 deletions mod/glossary/lang/en/glossary.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@
$string['question'] = 'Question';
$string['rejectedentries'] = 'Rejected entries';
$string['rejectionrpt'] = 'Rejection report';
$string['removeallglossarytags'] = 'Remove all glossary tags';
$string['resetglossaries'] = 'Delete entries from';
$string['resetglossariesall'] = 'Delete entries from all glossaries';
$string['rssarticles'] = 'Number of RSS recent articles';
Expand All @@ -292,6 +293,9 @@
$string['special'] = 'Special';
$string['standardview'] = 'Browse by alphabet';
$string['studentcanpost'] = 'Students can add entries';
$string['tagarea_glossary_entries'] = 'Glossary entries';
$string['tagsdeleted'] = 'Glossary tags have been deleted';
$string['tagtitle'] = 'See the "{$a}" tag';
$string['totalentries'] = 'Total entries';
$string['usedynalink'] = 'Automatically link glossary entries';
$string['usedynalink_help'] = 'If site-wide glossary auto-linking has been enabled by an administrator and this setting is enabled, the "Add a new entry" form includes the option to automatically link the entry wherever the concept words and phrases appear throughout the rest of the course.';
Expand Down
2 changes: 1 addition & 1 deletion mod/glossary/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,7 @@ function glossary_print_entry_ratings($course, $entry) {
* @param int $displayformat
*/
function glossary_print_dynaentry($courseid, $entries, $displayformat = -1) {
global $USER,$CFG, $DB;
global $USER, $CFG, $DB, $OUTPUT;

echo '<div class="boxaligncenter">';
echo '<table class="glossarypopup" cellspacing="0"><tr>';
Expand Down
Loading

0 comments on commit 694d2f8

Please sign in to comment.