Skip to content

Commit

Permalink
MDL-50851 core_tag: introduce tag collections
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Jan 10, 2016
1 parent e65dfd9 commit c026a28
Show file tree
Hide file tree
Showing 70 changed files with 7,442 additions and 2,645 deletions.
3 changes: 1 addition & 2 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,6 @@ function course_delete_module($cmid) {
require_once($CFG->libdir.'/questionlib.php');
require_once($CFG->dirroot.'/blog/lib.php');
require_once($CFG->dirroot.'/calendar/lib.php');
require_once($CFG->dirroot.'/tag/lib.php');

// Get the course module.
if (!$cm = $DB->get_record('course_modules', array('id' => $cmid))) {
Expand Down Expand Up @@ -1717,7 +1716,7 @@ function course_delete_module($cmid) {
'criteriatype' => COMPLETION_CRITERIA_TYPE_ACTIVITY));

// Delete all tag instances associated with the instance of this module.
tag_delete_instances('mod_' . $modulename, $modcontext->id);
core_tag::delete_instances('mod_' . $modulename, null, $modcontext->id);

// Delete the context.
context_helper::delete_instance(CONTEXT_MODULE, $cm->id);
Expand Down
1 change: 1 addition & 0 deletions lang/en/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
$string['cachedef_questiondata'] = 'Question definitions';
$string['cachedef_repositories'] = 'Repositories instances data';
$string['cachedef_string'] = 'Language string cache';
$string['cachedef_tags'] = 'Tags collections and areas';
$string['cachedef_userselections'] = 'Data used to persist user selections throughout Moodle';
$string['cachedef_yuimodules'] = 'YUI Module definitions';
$string['cachelock_file_default'] = 'Default file locking';
Expand Down
1 change: 1 addition & 0 deletions lang/en/deprecated.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ updated,core_tag
withselectedtags,core_tag
tag:create,core_role
categoriesanditems,core_grades
taggedwith,core_tag
1 change: 1 addition & 0 deletions lang/en/question.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@
$string['submit'] = 'Submit';
$string['submitandfinish'] = 'Submit and finish';
$string['submitted'] = 'Submit: {$a}';
$string['tagarea_question'] = 'Questions';
$string['technicalinfo'] = 'Technical information';
$string['technicalinfo_help'] = 'This technical information is probably only useful for developers working on new question types. It may also be helpful when trying to diagnose problems with questions.';
$string['technicalinfominfraction'] = 'Minimum fraction: {$a}';
Expand Down
41 changes: 39 additions & 2 deletions lang/en/tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,19 @@

$string['added'] = 'Official tag(s) added';
$string['addotags'] = 'Add official tags';
$string['addtagcoll'] = 'Add tag collection';
$string['addtagtomyinterests'] = 'Add "{$a}" to my interests';
$string['alltagpages'] = 'All tag pages';
$string['backtoallitems'] = 'Back to all items tagged with "{$a}"';
$string['changessaved'] = 'Changes saved';
$string['changetagcoll'] = 'Change tag collection of area {$a}';
$string['collnameexplained'] = 'Leave the field empty to use the default value: {$a}';
$string['component'] = 'Component';
$string['confirmdeletetag'] = 'Are you sure you want to delete this tag?';
$string['confirmdeletetags'] = 'Are you sure you want to delete selected tags?';
$string['count'] = 'Count';
$string['coursetags'] = 'Course tags';
$string['defautltagcoll'] = 'Default collection';
$string['delete'] = 'Delete';
$string['deleteselected'] = 'Delete selected';
$string['deleted'] = 'Tag(s) deleted';
Expand All @@ -38,33 +45,46 @@
$string['editname'] = 'Edit tag name';
$string['edittag'] = 'Edit this tag';
$string['entertags'] = 'Enter tags...';
$string['edittagcoll'] = 'Edit tag collection {$a}';
$string['errortagfrontpage'] = 'Tagging the site main page is not allowed';
$string['errorupdatingrecord'] = 'Error updating tag record';
$string['eventtagadded'] = 'Tag added to an item';
$string['eventtagcolldeleted'] = 'Tag collection deleted';
$string['eventtagcollcreated'] = 'Tag collection created';
$string['eventtagcollupdated'] = 'Tag collection updatedhp ';
$string['eventtagcreated'] = 'Tag created';
$string['eventtagdeleted'] = 'Tag deleted';
$string['eventtagflagged'] = 'Tag flagged';
$string['eventtagremoved'] = 'Tag removed from an item';
$string['eventtagunflagged'] = 'Tag unflagged';
$string['eventtagupdated'] = 'Tag updated';
$string['exclusivemode'] = 'Show only tagged {$a->tagarea}';
$string['flag'] = 'Flag';
$string['flagged'] = 'Tag flagged';
$string['flagasinappropriate'] = 'Flag as inappropriate';
$string['helprelatedtags'] = 'Comma separated related tags';
$string['changename'] = 'Change tag name';
$string['changetype'] = 'Change tag type';
$string['id'] = 'id';
$string['inalltagcoll'] = 'Everywhere';
$string['itemstaggedwith'] = '{$a->tagarea} tagged with "{$a->tag}"';
$string['lesstags'] = 'less...';
$string['manageofficialtags'] = 'Manage official tags';
$string['managetags'] = 'Manage tags';
$string['managetagcolls'] = 'Manage tag collections';
$string['moretags'] = 'more...';
$string['name'] = 'Tag name';
$string['namesalreadybeeingused'] = 'Tag names already being used';
$string['newnamefor'] = 'New name for tag {$a}';
$string['nextpage'] = 'More';
$string['notagsfound'] = 'No tags matching "{$a}" found';
$string['noresultsfor'] = 'No results for "{$a}"';
$string['nothingtoupdate'] = 'Nothing to update';
$string['officialtag'] = 'Official';
$string['otags'] = 'Official tags';
$string['othertags'] = 'Other tags';
$string['owner'] = 'Owner';
$string['prevpage'] = 'Back';
$string['ptags'] = 'User defined tags (Comma separated)';
$string['relatedblogs'] = 'Most recent blog entries';
$string['relatedtags'] = 'Related tags';
Expand All @@ -75,16 +95,29 @@
$string['rssdesc'] = 'This RSS feed was automatically generated by Moodle and contains user generated tags for courses.';
$string['rsstitle'] = 'Course tags RSS feed for user: {$a}';
$string['search'] = 'Search';
$string['searchable'] = 'Searchable';
$string['searchable_help'] = 'Tags in this tag collection can be searched for on "Search tags" page. If unchecked, tags can still be accessed by clicking on them or via different search interfaces.';
$string['searchresultsfor'] = 'Search results for "{$a}"';
$string['searchtags'] = 'Search tags';
$string['seeallblogs'] = 'See all blog entries tagged with "{$a}"...';
$string['seeallblogs'] = 'See all blog entries tagged with "{$a}"';
$string['select'] = 'Select';
$string['selectcoll'] = 'Select tag collection';
$string['selecttag'] = 'Select tag {$a}';
$string['settypedefault'] = 'Remove from official tags';
$string['settypeofficial'] = 'Make official';
$string['showingfirsttags'] = 'Showing {$a} most popular tags';
$string['suredeletecoll'] = 'Are you sure you want to delete tag collection "{$a}"?';
$string['tag'] = 'Tag';
$string['tagarea_blog_external'] = 'External blog posts';
$string['tagarea_post'] = 'Blog posts';
$string['tagarea_user'] = 'User interests';
$string['tagarea_course'] = 'Courses';
$string['tagareaenabled'] = 'Enabled';
$string['tagareaname'] = 'Name';
$string['tagareas'] = 'Tag areas';
$string['tagcollection'] = 'Tag collection';
$string['tagcollections'] = 'Tag collections';
$string['tagdescription'] = 'Tag description';
$string['taggedwith'] = 'tagged with "{$a}"';
$string['tags'] = 'Tags';
$string['tagsaredisabled'] = 'Tags are disabled';
$string['tagtype'] = 'Tag type';
Expand All @@ -107,3 +140,7 @@
$string['thistaghasnodesc'] = 'This tag currently has no description.';
$string['updated'] = 'Updated';
$string['withselectedtags'] = 'With selected tags...';

// Deprecated since 3.1 .

$string['taggedwith'] = 'tagged with "{$a}"';
5 changes: 2 additions & 3 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,8 @@ function uninstall_plugin($type, $name) {

echo $OUTPUT->heading($pluginname);

// Delete all tag instances associated with this plugin.
require_once($CFG->dirroot . '/tag/lib.php');
tag_delete_instances($component);
// Delete all tag areas, collections and instances associated with this plugin.
core_tag_area::uninstall($component);

// Custom plugin uninstall.
$plugindirectory = core_component::get_plugin_directory($type, $name);
Expand Down
2 changes: 1 addition & 1 deletion lib/amd/build/tag.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 30 additions & 2 deletions lib/amd/src/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,37 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str'
return /** @alias module:core/tag */ {

/**
* Initialises handlers for AJAX methods.
* Initialises tag index page.
*
* @method init
* @method init_tagindex_page
*/
init_tagindex_page: function() {
// Click handler for changing tag type.
$('body').delegate('.tagarea[data-ta] a[data-quickload=1]', 'click', function(e) {
e.preventDefault();
var target = $( this ),
query = target.context.search.replace(/^\?/, ''),
tagarea = target.closest('.tagarea[data-ta]'),
args = query.split('&').reduce(function(s,c){var t=c.split('=');s[t[0]]=decodeURIComponent(t[1]);return s;},{});

var promises = ajax.call([{
methodname: 'core_tag_get_tagindex',
args: { tagindex: args }
}], true);

$.when.apply($, promises)
.done( function(data) {
templates.render('core_tag/index', data).done(function(html) {
tagarea.replaceWith(html);
});
});
});
},

/**
* Initialises tag management page.
*
* @method init_manage_page
*/
init_manage_page: function() {

Expand Down
4 changes: 2 additions & 2 deletions lib/blocklib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1497,10 +1497,10 @@ public function process_url_edit() {
if ($bits[0] == 'tag' && !empty($this->page->subpage)) {
// better navbar for tag pages
$editpage->navbar->add(get_string('tags'), new moodle_url('/tag/'));
$tag = tag_get('id', $this->page->subpage, '*');
$tag = core_tag_tag::get($this->page->subpage);
// tag search page doesn't have subpageid
if ($tag) {
$editpage->navbar->add($tag->name, new moodle_url('/tag/index.php', array('id'=>$tag->id)));
$editpage->navbar->add($tag->get_display_name(), $tag->get_view_url());
}
}
$editpage->navbar->add($block->get_title());
Expand Down
28 changes: 28 additions & 0 deletions lib/classes/event/tag_added.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,34 @@ public function get_description() {
s($this->other['itemtype']) . "' with id '{$this->other['itemid']}'.";
}

/**
* Creates an event from taginstance object
*
* @since Moodle 3.1
* @param stdClass $taginstance
* @param string $tagname
* @param string $tagrawname
* @param bool $addsnapshot trust that $taginstance has all necessary fields and add it as a record snapshot
* @return tag_added
*/
public static function create_from_tag_instance($taginstance, $tagname, $tagrawname, $addsnapshot = false) {
$event = self::create(array(
'objectid' => $taginstance->id,
'contextid' => $taginstance->contextid,
'other' => array(
'tagid' => $taginstance->tagid,
'tagname' => $tagname,
'tagrawname' => $tagrawname,
'itemid' => $taginstance->itemid,
'itemtype' => $taginstance->itemtype
)
));
if ($addsnapshot) {
$event->add_record_snapshot('tag_instance', $taginstance);
}
return $event;
}

/**
* Return legacy data for add_to_log().
*
Expand Down
Loading

0 comments on commit c026a28

Please sign in to comment.