Skip to content

Commit

Permalink
Merge branch 'wip-MDL-50851-master' of git://github.com/marinaglancy/…
Browse files Browse the repository at this point in the history
…moodle
  • Loading branch information
danpoltawski committed Jan 12, 2016
2 parents b8ab80f + 3da0c3c commit 04a03ff
Show file tree
Hide file tree
Showing 129 changed files with 8,149 additions and 3,002 deletions.
4 changes: 4 additions & 0 deletions admin/tool/uploadcourse/classes/course.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,10 @@ public function prepare() {
$this->data = $coursedata;
$this->enrolmentdata = tool_uploadcourse_helper::get_enrolment_data($this->rawdata);

if (isset($this->rawdata['tags']) && strval($this->rawdata['tags']) !== '') {
$this->data['tags'] = preg_split('/\s*,\s*/', trim($this->rawdata['tags']), -1, PREG_SPLIT_NO_EMPTY);
}

// Restore data.
// TODO Speed up things by not really extracting the backup just yet, but checking that
// the backup file or shortname passed are valid. Extraction should happen in proceed().
Expand Down
2 changes: 2 additions & 0 deletions admin/tool/uploadcourse/tests/course_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ public function test_data_saved() {
'groupmode' => '2',
'groupmodeforce' => '1',
'enablecompletion' => '1',
'tags' => 'Cat, Dog',

'role_teacher' => 'Knight',
'role_manager' => 'Jedi',
Expand Down Expand Up @@ -297,6 +298,7 @@ public function test_data_saved() {
$this->assertEquals($data['groupmode'], $course->groupmode);
$this->assertEquals($data['groupmodeforce'], $course->groupmodeforce);
$this->assertEquals($data['enablecompletion'], $course->enablecompletion);
$this->assertEquals($data['tags'], join(', ', core_tag_tag::get_item_tags_array('core', 'course', $course->id)));

// Roles.
$roleids = array();
Expand Down
5 changes: 5 additions & 0 deletions admin/tool/uploaduser/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
'suspended', // 1 means suspend user account, 0 means activate user account, nothing means keep as is for existing users
'deleted', // 1 means delete user
'mnethostid', // Can not be used for adding, updating or deleting of users - only for enrolments, groups, cohorts and suspending.
'interests',
);
// Include all name fields.
$STD_FIELDS = array_merge($STD_FIELDS, get_all_user_name_fields());
Expand Down Expand Up @@ -836,6 +837,10 @@
}
}

// Update user interests.
if (isset($user->interests) && strval($user->interests) !== '') {
useredit_update_interests($user, preg_split('/\s*,\s*/', $user->interests, -1, PREG_SPLIT_NO_EMPTY));
}

// add to cohort first, it might trigger enrolments indirectly - do NOT create cohorts here!
foreach ($filecolumns as $column) {
Expand Down
38 changes: 8 additions & 30 deletions backup/moodle2/restore_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1778,22 +1778,8 @@ public function process_tag($data) {

$data = (object)$data;

if (!empty($CFG->usetags)) { // if enabled in server
// TODO: This is highly inneficient. Each time we add one tag
// we fetch all the existing because tag_set() deletes them
// so everything must be reinserted on each call
$tags = array();
$existingtags = tag_get_tags('course', $this->get_courseid());
// Re-add all the existitng tags
foreach ($existingtags as $existingtag) {
$tags[] = $existingtag->rawname;
}
// Add the one being restored
$tags[] = $data->rawname;
// Send all the tags back to the course
tag_set('course', $this->get_courseid(), $tags, 'core',
context_course::instance($this->get_courseid())->id);
}
core_tag_tag::add_item_tag('core', 'course', $this->get_courseid(),
context_course::instance($this->get_courseid()), $data->rawname);
}

public function process_allowed_module($data) {
Expand Down Expand Up @@ -4078,25 +4064,17 @@ protected function process_tag($data) {
return;
}

if (!empty($CFG->usetags)) { // if enabled in server
// TODO: This is highly inefficient. Each time we add one tag
// we fetch all the existing because tag_set() deletes them
// so everything must be reinserted on each call
$tags = array();
$existingtags = tag_get_tags('question', $newquestion);
// Re-add all the existitng tags
foreach ($existingtags as $existingtag) {
$tags[] = $existingtag->rawname;
}
// Add the one being restored
$tags[] = $data->rawname;
if (core_tag_tag::is_enabled('core_question', 'question')) {
$tagname = $data->rawname;
// Get the category, so we can then later get the context.
$categoryid = $this->get_new_parentid('question_category');
if (empty($this->cachedcategory) || $this->cachedcategory->id != $categoryid) {
$this->cachedcategory = $DB->get_record('question_categories', array('id' => $categoryid));
}
// Send all the tags back to the question
tag_set('question', $newquestion, $tags, 'core_question', $this->cachedcategory->contextid);
// Add the tag to the question.
core_tag_tag::add_item_tag('core_question', 'question', $newquestion,
context::instance_by_id($this->cachedcategory->contextid),
$tagname);
}
}

Expand Down
8 changes: 3 additions & 5 deletions backup/util/dbops/restore_dbops.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1209,16 +1209,14 @@ public static function create_included_users($basepath, $restoreid, $userid,
}

// Process tags
if (!empty($CFG->usetags) && isset($user->tags)) { // if enabled in server and present in backup
if (core_tag_tag::is_enabled('core', 'user') && isset($user->tags)) { // If enabled in server and present in backup.
$tags = array();
foreach($user->tags['tag'] as $usertag) {
$usertag = (object)$usertag;
$tags[] = $usertag->rawname;
}
if (empty($newuserctxid)) {
$newuserctxid = null; // Tag apis expect a null contextid not 0.
}
tag_set('user', $newuserid, $tags, 'core', $newuserctxid);
core_tag_tag::set_item_tags('core', 'user', $newuserid,
context_user::instance($newuserid), $tags);
}

// Process preferences
Expand Down
7 changes: 5 additions & 2 deletions blocks/blog_tags/block_blog_tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function get_content() {
}
return $this->content;

} else if (empty($CFG->usetags)) {
} else if (!core_tag_tag::is_enabled('core', 'post')) {
$this->content = new stdClass();
$this->content->text = '';
if ($this->page->user_is_editing()) {
Expand Down Expand Up @@ -126,6 +126,7 @@ function get_content() {
WHERE t.id = ti.tagid AND p.id = ti.itemid
$type
AND ti.itemtype = 'post'
AND ti.component = 'core'
AND ti.timemodified > $timewithin";

if ($context->contextlevel == CONTEXT_MODULE) {
Expand Down Expand Up @@ -195,7 +196,9 @@ function get_content() {
}

$blogurl->param('tagid', $tag->id);
$link = html_writer::link($blogurl, tag_display_name($tag), array('class'=>$tag->class, 'title'=>get_string('numberofentries','blog',$tag->ct)));
$link = html_writer::link($blogurl, core_tag_tag::make_display_name($tag),
array('class' => $tag->class,
'title' => get_string('numberofentries', 'blog', $tag->ct)));
$this->content->text .= '<li>' . $link . '</li> ';
}
$this->content->text .= "\n</ul>\n";
Expand Down
14 changes: 8 additions & 6 deletions blocks/tag_flickr/block_tag_flickr.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ function get_content() {
global $CFG, $USER;

//note: do NOT include files at the top of this file
require_once($CFG->dirroot.'/tag/lib.php');
require_once($CFG->libdir . '/filelib.php');

if ($this->content !== NULL) {
Expand All @@ -56,11 +55,12 @@ function get_content() {

$tagid = optional_param('id', 0, PARAM_INT); // tag id - for backware compatibility
$tag = optional_param('tag', '', PARAM_TAG); // tag
$tc = optional_param('tc', 0, PARAM_INT); // Tag collection id.

if ($tag) {
$tagobject = tag_get('name', $tag);
} else if ($tagid) {
$tagobject = tag_get('id', $tagid);
if ($tagid) {
$tagobject = core_tag_tag::get($tagid);
} else if ($tag) {
$tagobject = core_tag_tag::get_by_name($tc, $tag);
}

if (empty($tagobject)) {
Expand All @@ -73,7 +73,9 @@ function get_content() {
//include related tags in the photo query ?
$tagscsv = $tagobject->name;
if (!empty($this->config->includerelatedtags)) {
$tagscsv .= ',' . tag_get_related_tags_csv(tag_get_related_tags($tagobject->id), TAG_RETURN_TEXT);
foreach ($tagobject->get_related_tags() as $t) {
$tagscsv .= ',' . $t->get_display_name(false);
}
}
$tagscsv = urlencode($tagscsv);

Expand Down
2 changes: 1 addition & 1 deletion blocks/tag_flickr/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function specific_definition($mform) {
$mform->setType('config_title', PARAM_TEXT);

$mform->addElement('text', 'config_numberofphotos', get_string('numberofphotos', 'block_tag_flickr'), array('size' => 5));
$mform->setType('config_numberofvideos', PARAM_INT);
$mform->setType('config_numberofphotos', PARAM_INT);

$mform->addElement('selectyesno', 'config_includerelatedtags', get_string('includerelatedtags', 'block_tag_flickr'));
$mform->setDefault('config_includerelatedtags', 0);
Expand Down
19 changes: 10 additions & 9 deletions blocks/tag_youtube/block_tag_youtube.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ function get_content() {
global $CFG;

//note: do NOT include files at the top of this file
require_once($CFG->dirroot.'/tag/lib.php');
require_once($CFG->libdir . '/filelib.php');

if ($this->content !== NULL) {
Expand Down Expand Up @@ -132,11 +131,12 @@ function get_videos_by_tag(){

$tagid = optional_param('id', 0, PARAM_INT); // tag id - for backware compatibility
$tag = optional_param('tag', '', PARAM_TAG); // tag
$tc = optional_param('tc', 0, PARAM_INT); // Tag collection id.

if ($tag) {
$tagobject = tag_get('name', $tag);
} else if ($tagid) {
$tagobject = tag_get('id', $tagid);
if ($tagid) {
$tagobject = core_tag_tag::get($tagid);
} else if ($tag) {
$tagobject = core_tag_tag::get_by_name($tc, $tag);
}

if (empty($tagobject)) {
Expand Down Expand Up @@ -172,11 +172,12 @@ function get_videos_by_tag_and_category(){

$tagid = optional_param('id', 0, PARAM_INT); // tag id - for backware compatibility
$tag = optional_param('tag', '', PARAM_TAG); // tag
$tc = optional_param('tc', 0, PARAM_INT); // Tag collection id.

if ($tag) {
$tagobject = tag_get('name', $tag);
} else if ($tagid) {
$tagobject = tag_get('id', $tagid);
if ($tagid) {
$tagobject = core_tag_tag::get($tagid);
} else if ($tag) {
$tagobject = core_tag_tag::get_by_name($tc, $tag);
}

if (empty($tagobject)) {
Expand Down
24 changes: 21 additions & 3 deletions blocks/tags/block_tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ public function get_content() {
$this->config->numberoftags = 80;
}

if (empty($this->config->tagtype)) {
$this->config->tagtype = '';
}

if (empty($this->config->ctx)) {
$this->config->ctx = 0;
}

if (empty($this->config->rec)) {
$this->config->rec = 1;
}

if (empty($this->config->tagcoll)) {
$this->config->tagcoll = 0;
}

if ($this->content !== NULL) {
return $this->content;
}
Expand All @@ -85,9 +101,11 @@ public function get_content() {

// Get a list of tags.

require_once($CFG->dirroot.'/tag/locallib.php');

$this->content->text = tag_print_cloud(null, $this->config->numberoftags, true);
$tagcloud = core_tag_collection::get_tag_cloud($this->config->tagcoll,
$this->config->tagtype,
$this->config->numberoftags,
'name', '', $this->page->context->id, $this->config->ctx, $this->config->rec);
$this->content->text = $OUTPUT->render_from_template('core_tag/tagcloud', $tagcloud->export_for_template($OUTPUT));

return $this->content;
}
Expand Down
53 changes: 53 additions & 0 deletions blocks/tags/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,71 @@
*/
class block_tags_edit_form extends block_edit_form {
protected function specific_definition($mform) {
global $CFG;
// Fields for editing HTML block title and contents.
$mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));

$mform->addElement('text', 'config_title', get_string('configtitle', 'block_tags'));
$mform->setType('config_title', PARAM_TEXT);
$mform->setDefault('config_title', get_string('pluginname', 'block_tags'));

$this->add_collection_selector($mform);

$numberoftags = array();
for ($i = 1; $i <= 200; $i++) {
$numberoftags[$i] = $i;
}
$mform->addElement('select', 'config_numberoftags', get_string('numberoftags', 'blog'), $numberoftags);
$mform->setDefault('config_numberoftags', 80);

$defaults = array(
'official' => get_string('officialonly', 'block_tags'),
'' => get_string('anytype', 'block_tags'));
$mform->addElement('select', 'config_tagtype', get_string('defaultdisplay', 'block_tags'), $defaults);
$mform->setDefault('config_tagtype', '');

$defaults = array(0 => context_system::instance()->get_context_name());
$parentcontext = context::instance_by_id($this->block->instance->parentcontextid);
if ($parentcontext->contextlevel > CONTEXT_COURSE) {
$coursecontext = $parentcontext->get_course_context();
$defaults[$coursecontext->id] = $coursecontext->get_context_name();
}
if ($parentcontext->contextlevel != CONTEXT_SYSTEM) {
$defaults[$parentcontext->id] = $parentcontext->get_context_name();
}
$mform->addElement('select', 'config_ctx', get_string('taggeditemscontext', 'block_tags'), $defaults);
$mform->addHelpButton('config_ctx', 'taggeditemscontext', 'block_tags');
$mform->setDefault('config_ctx', 0);

$mform->addElement('advcheckbox', 'config_rec', get_string('recursivecontext', 'block_tags'));
$mform->addHelpButton('config_rec', 'recursivecontext', 'block_tags');
$mform->setDefault('config_rec', 1);
}

/**
* Add the tag collection selector
*
* @param object $mform the form being built.
*/
protected function add_collection_selector($mform) {
$tagcolls = core_tag_collection::get_collections_menu(false, false, get_string('anycollection', 'block_tags'));
if (count($tagcolls) <= 1) {
return;
}

$tagcollssearchable = core_tag_collection::get_collections_menu(false, true);
$hasunsearchable = false;
foreach ($tagcolls as $id => $name) {
if ($id && !array_key_exists($id, $tagcollssearchable)) {
$hasunsearchable = true;
$tagcolls[$id] = $name . '*';
}
}

$mform->addElement('select', 'config_tagcoll', get_string('tagcollection', 'block_tags'), $tagcolls);
if ($hasunsearchable) {
$mform->addHelpButton('config_tagcoll', 'tagcollection', 'block_tags');
}
$mform->setDefault('config_tagcoll', 0);
}
}
12 changes: 11 additions & 1 deletion blocks/tags/lang/en/block_tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,24 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$string['anycollection'] = 'Any';
$string['anytype'] = 'All';
$string['configtitle'] = 'Block title';
$string['disabledtags'] = 'Tags are disabled';
$string['defaultdisplay'] = 'Tag type to display';
$string['officialonly'] = 'Only official';
$string['pluginname'] = 'Tags';
$string['recursivecontext'] = 'Include child contexts';
$string['recursivecontext_help'] = 'If unchecked, tags of items in the context specified above will be displayed excluding underlying contexts, for example, you can search on course level only without searching inside course activities';
$string['tagcollection'] = 'Tag collection';
$string['tagcollection_help'] = 'Select tag collection to display tags from. If you choose "Any" '
. 'the tags from all collections except for those marked with * will be displayed';
$string['taggeditemscontext'] = 'Tagged items context';
$string['taggeditemscontext_help'] = 'You can limit the tag cloud to the tags that are present in the current course category, course or module';
$string['tags:addinstance'] = 'Add a new tags block';
$string['tags:myaddinstance'] = 'Add a new tags block to Dashboard';

// Deprecated since 3.0
// Deprecated since 3.0.

$string['add'] = 'Add';
$string['alltags'] = 'All tags:';
Expand Down
2 changes: 1 addition & 1 deletion blocks/tags/tests/behat/tagcloud.feature
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ Feature: Block tags displaying tag cloud
And I should see "Cats" in the "Tags" "block"
And I should not see "Neverusedtag" in the "Tags" "block"
And I click on "Dogs" "link" in the "Tags" "block"
And I should see "Users tagged with \"Dogs\": 1"
And I should see "User interests" in the ".tag-index-items h3" "css_element"
And I should see "Teacher 1"
And I log out
Loading

0 comments on commit 04a03ff

Please sign in to comment.