Skip to content

Commit

Permalink
MDL-50851 block_tags: tag collections settings
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Jan 10, 2016
1 parent c4e868d commit b0c62e0
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 5 deletions.
24 changes: 21 additions & 3 deletions blocks/tags/block_tags.php
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
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
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
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

0 comments on commit b0c62e0

Please sign in to comment.