Commit 97bf0689 authored by Son Nguyen's avatar Son Nguyen Committed by Gerrit Code Review
Browse files

Merge "Bug 1027739: Adjustments to allow tagged post blocks to be copied"

parents c97bca23 e2efafbe
......@@ -318,7 +318,7 @@ class PluginBlocktypeTaggedposts extends MaharaCoreBlocktype {
public static function instance_config_form(BlockInstance $instance) {
global $USER;
safe_require('artefact', 'blog');
$configdata = $instance->get('configdata');
$tags = self::get_chooseable_tags();
......@@ -370,6 +370,7 @@ EOF;
'escapeMarkup' => 'function(textToEscape) { return textToEscape; }',
),
);
$elements[] = PluginArtefactBlog::block_advanced_options_element($configdata, 'taggedposts');
$elements['count'] = array(
'type' => 'text',
'title' => get_string('itemstoshow', 'blocktype.blog/taggedposts'),
......@@ -493,7 +494,7 @@ EOF;
}
public static function default_copy_type() {
return 'shallow';
return 'nocopy';
}
/**
......
......@@ -116,6 +116,7 @@ $string['saveasdraft'] = 'Save as draft';
$string['savepost'] = 'Save entry';
$string['savesettings'] = 'Save settings';
$string['settings'] = 'Settings';
$string['taggedposts'] = 'Tagged posts';
$string['thisisdraft'] = 'This entry is a draft';
$string['thisisdraftdesc'] = 'When your entry is a draft, no one except you can see it.';
$string['title'] = 'Title';
......@@ -145,6 +146,7 @@ $string['alt'] = 'Description';
$string['copyfull'] = 'Others will get their own copy of your %s';
$string['copyreference'] = 'Others may display your %s in their page';
$string['copynocopy'] = 'Skip this block entirely when copying the page';
$string['copytagsonly'] = 'Others will get a copy of the block configuration';
$string['viewposts'] = 'Copied entries (%s)';
$string['postscopiedfromview'] = 'Entries copied from %s';
......
......@@ -105,6 +105,16 @@ class PluginArtefactBlog extends PluginArtefact {
public static function block_advanced_options_element($configdata, $artefacttype) {
$strartefacttype = strtolower(get_string($artefacttype, 'artefact.blog'));
$options = array('nocopy' => get_string('copynocopy', 'artefact.blog'));
if ($artefacttype == 'taggedposts') {
$options['tagsonly'] = get_string('copytagsonly', 'artefact.blog', $strartefacttype);
}
else {
$options['reference'] = get_string('copyreference', 'artefact.blog', $strartefacttype);
$options['full'] = get_string('copyfull', 'artefact.blog', $strartefacttype);
}
return array(
'type' => 'fieldset',
'name' => 'advanced',
......@@ -118,11 +128,7 @@ class PluginArtefactBlog extends PluginArtefact {
'title' => get_string('blockcopypermission', 'view'),
'description' => get_string('blockcopypermissiondesc', 'view'),
'defaultvalue' => isset($configdata['copytype']) ? $configdata['copytype'] : 'nocopy',
'options' => array(
'nocopy' => get_string('copynocopy', 'artefact.blog'),
'reference' => get_string('copyreference', 'artefact.blog', $strartefacttype),
'full' => get_string('copyfull', 'artefact.blog', $strartefacttype),
),
'options' => $options,
),
),
);
......
......@@ -1537,6 +1537,9 @@ class BlockInstance {
if ($sameowner || $copytype == 'reference') {
$newblock->set('configdata', $configdata);
$newblock->commit();
if ($this->get('blocktype') == 'taggedposts' && $copytype == 'tagsonly') {
$this->copy_tags($newblock->get('id'));
}
return true;
}
$artefactids = get_column('view_artefact', 'artefact', 'block', $this->get('id'));
......@@ -1605,22 +1608,26 @@ class BlockInstance {
$newblock->set('configdata', $configdata);
$newblock->commit();
$viewid=$template->get('id');
$bid=get_record('block_instance', 'view', $viewid,'blocktype','taggedposts');
if ($bid && $this->id == $bid->id ) {
$tagrecords = get_records_array('blocktype_taggedposts_tags', 'block_instance', $bid->id, 'tagtype desc, tag', 'tag, tagtype');
$newid=$newblock->get('id');
foreach ($tagrecords as $k => $v) {
$o = new stdClass();
$o->block_instance = $newid;
$o->tag = $v->tag;
$o->tagtype = 1;
insert_record('blocktype_taggedposts_tags', $o);
}
if ($this->get('blocktype') == 'taggedposts' && $copytype == 'tagsonly') {
$this->copy_tags($newblock->get('id'));
}
return true;
}
public function copy_tags($newid) {
// Need to copy the tags to the new block
if ($tagrecords = get_records_array('blocktype_taggedposts_tags', 'block_instance', $this->get('id'), 'tagtype desc, tag', 'tag, tagtype')) {
foreach ($tagrecords as $tags) {
$tagobject = new stdClass();
$tagobject->block_instance = $newid;
$tagobject->tag = $tags->tag;
$tagobject->tagtype = $tags->tagtype;
insert_record('blocktype_taggedposts_tags', $tagobject);
}
}
}
public function get_data($key, $id) {
if (!isset($this->temp[$key][$id])) {
$blocktypeclass = generate_class_name('blocktype', $this->get('blocktype'));
......
@javascript @core @core_artefact
Feature: Mahara users can allow their tagged blogs tags to be copied
As a mahara user
I need to copy a tagged blog block
Background:
Given the following "users" exist:
| username | password | email | firstname | lastname | institution | authname | role |
| userA | Kupuhipa1 | test01@example.com | Pete | Mc | mahara | internal | member |
| userB | Kupuhipa1 | test02@example.com | Kate | Li | mahara | internal | member |
And the following "pages" exist:
| title | description | ownertype | ownername |
| Page 01 | userA's page 01 | user | userA |
Scenario: Create blogs
Given I log in as "userA" with password "Kupuhipa1"
# Create tagged blog entries
When I choose "Journals" in "Content"
And I follow "New entry"
And I set the following fields to these values:
| Title | Entry one |
| Entry | This is journal entry one |
And I scroll to the base of id "editpost_tags_container"
And I fill in select2 input "editpost_tags" with "blog" and select "blog"
And I fill in select2 input "editpost_tags" with "entry" and select "entry"
And I fill in select2 input "editpost_tags" with "one" and select "one"
And I press "Save entry"
And I follow "New entry"
And I set the following fields to these values:
| Title | Entry two |
| Entry | This is journal entry two |
And I scroll to the base of id "editpost_tags_container"
And I fill in select2 input "editpost_tags" with "blog" and select "blog"
And I fill in select2 input "editpost_tags" with "entry" and select "entry"
And I fill in select2 input "editpost_tags" with "two" and select "two"
And I press "Save entry"
# Add a taggedblogs block to a page
And I choose "Pages" in "Portfolio"
And I follow "Edit \"Page 01\""
And I expand "Journals" node in the "div#content-editor-foldable" "css_element"
And I wait "1" seconds
And I follow "Tagged journal entries" in the "div#blog" "css_element"
And I press "Add"
And I fill in select2 input "instconf_tagselect" with "blog" and select "blog"
And I wait "1" seconds
And I fill in select2 input "instconf_tagselect" with "one" and select "one"
And I wait "1" seconds
And I fill in select2 input "instconf_tagselect" with "-two" and select "two"
And I wait "1" seconds
And I select "Others will get a copy of the block configuration" from "Block copy permission"
And I press "Save"
And I scroll to the id "main-nav"
And I follow "Share page"
And I follow "Advanced options"
And I enable the switch "Allow copying"
And I select "Public" from "accesslist[0][searchtype]"
And I press "Save"
# Copy the page as same user
And I follow "Page 01"
And I follow "Copy"
And I press "Save"
Then I should see "Journal entries with tags \"blog\", \"one\" but not tag \"two\""
And I should see "Entry one"
# Copy the page as another user
And I log out
Given I log in as "userB" with password "Kupuhipa1"
And I choose "Journals" in "Content"
And I follow "New entry"
And I set the following fields to these values:
| Title | userB entry |
| Entry | This is a journal entry for userB |
And I scroll to the base of id "editpost_tags_container"
And I fill in select2 input "editpost_tags" with "blog" and select "blog"
And I fill in select2 input "editpost_tags" with "one" and select "one"
And I press "Save entry"
And I go to the homepage
And I scroll to the id "view"
# allow the ajax to load
And I wait "1" seconds
And I follow "Page 01"
And I follow "Copy"
And I press "Save"
Then I should see "Journal entries with tags \"blog\", \"one\" but not tag \"two\""
And I should see "userB entry"
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment