Commit b3bdbdc9 authored by Robert Lyon's avatar Robert Lyon Committed by Cecilia Vela Gurovic
Browse files

Bug 1742347: Allow $versioning variable for block rendering



To allow us to restrict things being shown for block when in older
version.

behatnotneeded

Change-Id: I8d9ffe1e7b26a07fc84e3ce64e988b9d7babc396
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 4aa41f44
......@@ -54,7 +54,7 @@ class PluginBlocktypeRecentForumPosts extends MaharaCoreBlocktype {
return $groups[$block];
}
public static function render_instance(BlockInstance $instance, $editing=false) {
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
if ($group = self::get_group($instance)) {
require_once('group.php');
......
......@@ -42,7 +42,7 @@ class PluginBlocktypeText extends MaharaCoreBlocktype {
return array('text' => array('text'));
}
public static function render_instance(BlockInstance $instance, $editing=false) {
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
safe_require('artefact', 'file');
$configdata = $instance->get('configdata');
$smarty = smarty_core();
......
......@@ -38,7 +38,7 @@ class PluginBlocktypeWall extends MaharaCoreBlocktype {
return array('profile');
}
public static function render_instance(BlockInstance $instance, $editing=false) {
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
global $USER;
$owner = $instance->get_view()->get('owner');
if (!$owner) {
......
......@@ -34,7 +34,7 @@ class PluginBlocktypeWatchlist extends MaharaCoreBlocktype {
return array('dashboard');
}
public static function render_instance(BlockInstance $instance, $editing=false) {
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
$smarty = smarty_core();
$views = self::fetch_items($instance, 0, $editing);
......
......@@ -2251,13 +2251,14 @@ class View {
* Build_rows - for each row build_columms
* @param boolean $editing whether we are in the edit more or not
* @param boolean $exporting whether we are in the process of an export
* @param boolean $versioning Whether we are in the process of view version
* Returns the HTML for the rows of this view
*/
public function build_rows($editing=false, $exporting=false) {
public function build_rows($editing=false, $exporting=false, $versioning=false) {
$numrows = $this->get('numrows');
$result = '';
for ($i = 1; $i <= $numrows; $i++) {
$result .= $this->build_columns($i, $editing, $exporting);
$result .= $this->build_columns($i, $editing, $exporting, $versioning);
}
return $result;
}
......@@ -2265,14 +2266,14 @@ class View {
/**
* Returns the HTML for the columns of this view
*/
public function build_columns($row, $editing=false, $exporting=false) {
public function build_columns($row, $editing=false, $exporting=false, $versioning=false) {
global $USER;
$columnsperrow = $this->get('columnsperrow');
$currentrownumcols = $columnsperrow[$row]->columns;
$result = '';
for ($i = 1; $i <= $currentrownumcols; $i++) {
$result .= $this->build_column($row, $i, $editing, $exporting);
$result .= $this->build_column($row, $i, $editing, $exporting, $versioning);
}
$smarty = smarty_core();
......@@ -2295,8 +2296,9 @@ class View {
* @param int $column The column to build
* @param boolean $editing Whether the view is being built in edit mode
* @param boolean $exporting Whether the view is being built for export
* @param boolean $versioning Whether the view is being built for versioning
*/
public function build_column($row, $column, $editing=false, $exporting=false) {
public function build_column($row, $column, $editing=false, $exporting=false, $versioning=false) {
global $USER;
$data = $this->get_column_datastructure($row, $column);
static $installed = array();
......@@ -2318,7 +2320,7 @@ class View {
// for configuring block instances only, is not necessary
}
else {
$result = $blockinstance->render_viewing($exporting);
$result = $blockinstance->render_viewing($exporting, $versioning);
if ($exporting) {
// Blocks with toolbars will export with their info withing the block itself instead
$classname = generate_class_name('blocktype', $blockinstance->get('blocktype'));
......@@ -2341,7 +2343,6 @@ class View {
}
}
}
$blockcontent .= $result;
}
}
......@@ -7193,6 +7194,7 @@ class View {
$html = '';
if (!empty($data->blocks)) {
require_once(get_config('docroot') . 'blocktype/lib.php');
usort($data->blocks, function($a, $b) { return $a->order > $b->order; });
foreach ($data->blocks as $k => $v) {
safe_require('blocktype', $v->blocktype);
$bi = new BlockInstance(0,
......@@ -7207,10 +7209,11 @@ class View {
'configdata' => serialize((array)$v->configdata),
)
);
// Add a fake unique id to allow for pagination etc
$this->columns[$v->row][$v->column]['blockinstances'][] = $bi;
}
}
$html = $this->build_rows();
$html = $this->build_rows(false, false, true);
$data->html = $html;
return $data;
}
......
......@@ -50,7 +50,7 @@
{/if}
{/if}
{/foreach}
{if !$editing}
{if !$editing && !$versioning}
<a href="{$plan.details}" class="detail-link link-blocktype"><span class="icon icon-link" role="presentation" aria-hidden="true"></span> {str tag=detailslinkalt section=view}</a>
{/if}
{else}
......
{if !$editing}
{if !$editing && !$versioning}
<div class="comments pull-left">
{if $commentcount > 0}
<a class="commentlink link-blocktype" id="block_{$blockid}" data-toggle="modal-docked" data-target="#feedbacktable_{$blockid}" href="#">
......
......@@ -31,7 +31,7 @@
<div class="{if !$title}no-heading {/if}block{if $retractable} collapse{if $retractedonload}{else} in{/if}{/if}" id="blockinstance_{$id}_target" {if $loadbyajax}data-blocktype-ajax="{$id}"{else}data-blocktype-noajax="{$id}"{/if}>
{if !$loadbyajax}{$content|safe}{/if}
{if $link || $viewartefacturl}
{if !$versioning && ($link || $viewartefacturl)}
{if $link}
<a href="{$link}" class="detail-link link-blocktype"><span class="icon icon-link" role="presentation" aria-hidden="true"></span> {str tag=detailslinkalt section=view}</a>
......
......@@ -46,6 +46,20 @@ if ($blocks) {
$bi->row = $oldblock->get('row');
$bi->column = $oldblock->get('column');
$bi->order = $oldblock->get('order');
if (isset($bi->configdata['artefactid']) && !empty($bi->configdata['artefactid'])) {
// The block is for one artefact so lets see if it displays more than one artefact
if ($artefacts = call_static_method(generate_class_name('blocktype', $oldblock->get('blocktype')), 'get_current_artefacts', $oldblock)) {
// We need to ignore the parent artefactid
foreach ($artefacts as $key => $artefact) {
if ($bi->configdata['artefactid'] == $artefact) {
unset($artefacts[$key]);
}
}
if (!empty($artefacts)) {
$bi->configdata['existing_artefacts'] = $artefacts;
}
}
}
$version->blocks[$k] = $bi;
}
}
......
......@@ -62,7 +62,7 @@ Scenario: Creating institution tags
And I press "Save"
Then I should see "Journal entries with tag \"Institution One: One tag\""
And I follow "Display page"
And I display the page
Then I should see "Institution One: One tag"
Given I choose "Files" in "Create" from main menu
......
......@@ -23,8 +23,7 @@ Scenario: Make Text Block Retractable
And I set the field "Block content" to "Here is a new block."
Given I select "Yes" from "Retractable"
And I press "Save"
And I scroll to the top
Then I click on "Display page"
Then I display the page
Then I should see "Here is a new block"
And I collapse "Text Block 1" node
And I should not see "Here is a new block"
......@@ -86,6 +86,9 @@ Scenario: Creating a page with content in it (Bug 1426983)
# Verifying the page title and description changed
Then I should see "This is the edited page title"
And I should see "This is the edited description"
# Create a timeline version
And I press "More..."
And I follow "Save to timeline"
# Check that the image is displayed on page and ensure the link is correct
Then I should see image "Image2.png" on the page
# The "..." button should only have the option to print and delete the page
......
......@@ -43,8 +43,7 @@ Scenario: Enable/disable external resources in mahara pages
| Block title | Text block with an external image |
| Block content | <p><img title="Open source logo" src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/42/Opensource.svg/744px-Opensource.svg.png" alt="" width="300" /></p> |
And I press "Save"
And I scroll to the top
And I follow "Display page"
And I display the page
Then I should see images within the block "Text block with an internal image"
And I should see images within the block "Text block with an external image"
And I log out
......
......@@ -27,8 +27,7 @@ Scenario: Create and delete image block
Then I should see "Image - Image1.jpg"
And I enable the switch "Show description"
And I press "Save"
And I scroll to the top
And I follow "Display page"
And I display the page
And I should see "Image1.jpg"
# delete image block
And I follow "Edit"
......
......@@ -26,8 +26,7 @@ Scenario: Create and delete text block
And I set the field "Block content" to "Here is a new block."
And I press "Save"
And I should see "Text block 1" in the "div#column-container" element
And I scroll to the top
And I follow "Display page"
And I display the page
Then I should see "Here is a new block"
# delete block
And I follow "Edit"
......
......@@ -23,8 +23,7 @@ Scenario: Add blocks and create versions
And I set the field "Block title" to "Text block version 1"
And I set the field "Block content" to "Here is the first version of the block."
And I press "Save"
And I scroll to the top
And I follow "Display page"
And I display the page
And I press "More..."
And I follow "Save to timeline"
And I should see "Saved to timeline"
......@@ -33,8 +32,7 @@ Scenario: Add blocks and create versions
And I set the field "Block title" to "Text block version 2"
And I set the field "Block content" to "Here is the second version of the block."
And I press "Save"
And I scroll to the top
And I follow "Display page"
And I display the page
And I press "More..."
And I follow "Save to timeline"
And I press "More..."
......
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