Commit e4747fa2 authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic

Bug #1742347: display correct block content when dislaying version

inlcudes:
- allow to display pdf in old versions of view
that are no longer part of the view
- tagged journals && recent forum posts blocks:
show the block content
- allow pagination in the block when displaying
version of the page (for example, tasks in plan block)

behatnotneeded

Change-Id: I74af39b15f5165a1ed9916329c23051897b8463a
parent a4262300
......@@ -84,12 +84,17 @@ class PluginBlocktypeTaggedposts extends MaharaCoreBlocktype {
* @param array $tagsout Optional reference variable for finding out the "extclude" tags used by this block
* @return array of blogpost records
*/
public static function get_blog_posts_in_block(BlockInstance $instance, &$tagsinreturn = null, &$tagsoutreturn = null) {
public static function get_blog_posts_in_block(BlockInstance $instance, &$tagsinreturn = null, &$tagsoutreturn = null, $versioning=false) {
$configdata = $instance->get('configdata');
$results = array();
$tagsin = $tagsout = array();
$tagrecords = get_records_array('blocktype_taggedposts_tags', 'block_instance', $instance->get('id'), 'tagtype desc, tag', 'tag, tagtype');
if ($versioning) {
$tagrecords = $configdata['tagrecords'];
}
else {
$tagrecords = get_records_array('blocktype_taggedposts_tags', 'block_instance', $instance->get('id'), 'tagtype desc, tag', 'tag, tagtype');
}
if ($tagrecords) {
$view = $instance->get('view');
......@@ -181,7 +186,7 @@ class PluginBlocktypeTaggedposts extends MaharaCoreBlocktype {
$viewownerdisplay = null;
// Display all posts, from all blogs, owned by this user
$tagsin = $tagsout = array();
$results = self::get_blog_posts_in_block($instance, $tagsin, $tagsout);
$results = self::get_blog_posts_in_block($instance, $tagsin, $tagsout, $versioning);
if ($tagsin || $tagsout) {
$smarty->assign('blockid', $instance->get('id'));
......
......@@ -74,6 +74,7 @@ class PluginBlocktypePdf extends MaharaCoreBlocktype {
$language = 'en-GB';
}
$result = '<iframe src="' . $urlbase . 'artefact/file/blocktype/pdf/viewer.php?editing=' . $editing . '&ingroup=' . !empty($group) . '&file=' . $artefactid . '&lang=' . $language . '&view=' . $instance->get('view')
. ($versioning ? '&versioning=true' : '')
. '" width="100%" height="500" frameborder="0"></iframe>';
require_once(get_config('docroot') . 'artefact/comment/lib.php');
......
......@@ -22,12 +22,13 @@ $fileid = param_integer('file');
$viewid = param_integer('view');
$editing = param_boolean('editing', false);
$ingroup = param_boolean('ingroup', false);
$versioning = param_boolean('versioning', false);
if (!artefact_in_view($fileid, $viewid)) {
throw new AccessDeniedException('');
if (!can_view_view($viewid)) {
throw new AccessDeniedException('');
}
if (!can_view_view($viewid)) {
if (!$versioning && !artefact_in_view($fileid, $viewid)) {
throw new AccessDeniedException('');
}
......
......@@ -70,7 +70,7 @@ class PluginBlocktypePlans extends MaharaCoreBlocktype {
$tasks = ArtefactTypeTask::get_tasks($planid, 0, $limit);
$template = 'artefact:plans:taskrows.tpl';
$blockid = $instance->get('id');
if ($exporter || $versioning) {
if ($exporter) {
$pagination = false;
}
else {
......
......@@ -1164,7 +1164,7 @@ class BlockInstance {
$content = '';
$smarty->assign('loadbyajax', false);
}
else if (get_config('ajaxifyblocks') && call_static_method($classname, 'should_ajaxify') && $exporting === false) {
else if (get_config('ajaxifyblocks') && call_static_method($classname, 'should_ajaxify') && $exporting === false && $versioning === false) {
$content = '';
$smarty->assign('loadbyajax', true);
}
......
......@@ -26,9 +26,15 @@ class PluginBlocktypeRecentForumPosts extends MaharaCoreBlocktype {
return array('general' => 23000);
}
private static function get_group(BlockInstance $instance) {
private static function get_group(BlockInstance $instance, $versioning=false) {
static $groups = array();
if ($versioning) {
$configdata = $instance->get('configdata');
$groupid = $configdata['groupid'];
return get_record_select('group', 'id = ? AND deleted = 0', array($groupid), '*, ' . db_format_tsfield('ctime'));
}
$block = $instance->get('id');
if (!isset($groups[$block])) {
......@@ -55,7 +61,7 @@ class PluginBlocktypeRecentForumPosts extends MaharaCoreBlocktype {
}
public static function render_instance(BlockInstance $instance, $editing=false, $versioning=false) {
if ($group = self::get_group($instance)) {
if ($group = self::get_group($instance, $versioning)) {
require_once('group.php');
$role = group_user_access($group->id);
......
......@@ -7199,14 +7199,15 @@ class View {
safe_require('blocktype', $v->blocktype);
$bi = new BlockInstance(0,
array(
'blocktype' => $v->blocktype,
'title' => $v->title,
'view' => $this->get('id'),
'view_obj' => $this,
'row' => $v->row,
'column' => $v->column,
'order' => $v->order,
'configdata' => serialize((array)$v->configdata),
'id' => $v->originalblockid,
'blocktype' => $v->blocktype,
'title' => $v->title,
'view' => $this->get('id'),
'view_obj' => $this,
'row' => $v->row,
'column' => $v->column,
'order' => $v->order,
'configdata' => serialize((array)$v->configdata),
)
);
// Add a fake unique id to allow for pagination etc
......
......@@ -40,6 +40,7 @@ if ($blocks) {
$oldblock = new BlockInstance($b->id, $b);
$bi = new stdClass();
$bi->originalblockid = $oldblock->get('id');
$bi->blocktype = $oldblock->get('blocktype');
$bi->title = $oldblock->get('title');
$bi->configdata = $oldblock->get('configdata');
......@@ -69,6 +70,10 @@ if ($blocks) {
$bi->configdata['text'] = $artefact->get('description');
}
}
if ($oldblock->get('blocktype') == 'taggedposts') {
$tagrecords = get_records_array('blocktype_taggedposts_tags', 'block_instance', $oldblock->get('id'), 'tagtype desc, tag', 'tag, tagtype');
$bi->configdata['tagrecords'] = $tagrecords;
}
$version->blocks[$k] = $bi;
}
}
......
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