Commit 4640e10a authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic
Browse files

Bug 1868657: detail block header for Image Gallery blocks that display from individually images

Adding two functions to blocktype class to define if they show artefacts
details in a modal instead of showing details links for each one
on the block

behatnotneeded

Change-Id: If1f04bd2de1a1ceef46784ef0fe2fb6faa4194c2
parent cf6603f7
......@@ -923,4 +923,49 @@ class PluginBlocktypeGallery extends MaharaCoreBlocktype {
}
return $artefacts;
}
public static function shows_details_in_modal(BlockInstance $instance) {
$configdata = $instance->get('configdata');
return isset($configdata['artefactids']);
}
public static function render_details_in_modal(BlockInstance $instance) {
$artefacts = $instance->get('configdata')['artefactids'];
$smarty = smarty_core();
if ($artefacts) {
safe_require('artefact', 'comment');
$childrecords = array();
foreach ($artefacts as $a) {
$c = artefact_instance_from_id($a);
$child = new StdClass();
$child->id = $a;
$child->description = $c->get('description');
$child->size = $c->describe_size();
$child->title = $child->hovertitle = $c->get('title');
$child->artefacttype = $c->get('artefacttype');
$child->iconsrc = call_static_method(generate_artefact_class_name($c->get('artefacttype')), 'get_icon', array('id' => $a, 'viewid' => $instance->get('view')));
$count = ArtefactTypeComment::count_comments(null, array($child->id));
if ($count) {
$child->commentcount = $count[$child->id]->comments;
}
else {
$child->commentcount = 0;
}
$childrecords[] = $child;
}
$smarty->assign('children', $childrecords);
}
$smarty->assign('blockid', $instance->get('id'));
$smarty->assign('modal', true);
$smarty->assign('viewid', $instance->get('view'));
$template = 'artefact:file:folder_render_in_modal.tpl';
return array(
'html' => $smarty->fetch($template),
'artefactids' => $instance->get('configdata')['artefactids'],
'javascript'=>'',
);
}
}
......@@ -294,6 +294,15 @@ EOF;
return false;
}
public static function shows_details_in_modal(BlockInstance $instance) {
return false;
}
public static function render_details_in_modal(BlockInstance $instance) {
return false;
}
/**
* Indicates whether this block can be loaded by Ajax after the page is done. This
* improves page-load times by allowing blocks to be rendered in parallel instead
......@@ -1375,9 +1384,9 @@ class BlockInstance {
// If this block is for just one artefact, we set the title of the
// block to be a link to view more information about that artefact
$configdata = $this->get('configdata');
$smarty->assign('blockid', $this->get('id'));
if (!empty($configdata['artefactid']) && $displayforrole) {
if (call_static_method($classname, 'has_title_link')) {
$smarty->assign('blockid', $this->get('id'));
$smarty->assign('artefactid', $configdata['artefactid']);
}
}
......@@ -1405,7 +1414,7 @@ class BlockInstance {
$blockheader = call_static_method($classname, 'single_artefact_per_block', $this->blocktype);
// Set up template for the blocks that have the comments and details header
// Check also that an artefact has been attached to ensure empty blocks don't get empty modals
if ($blockheader && !empty($configdata['artefactid'])) {
if ($blockheader && (!empty($configdata['artefactid']) || call_static_method($classname, 'shows_details_in_modal', $this))) {
$smarty->assign('blockheader', $blockheader);
if (!empty($configdata['artefactid'])) {
$smarty->assign('artefactid', $configdata['artefactid']);
......
......@@ -19,12 +19,12 @@ safe_require('artefact', 'comment');
$viewid = param_integer('viewid');
$blockid = param_variable('blockid', null);
$artefactid = param_integer('artefactid');
$artefactid = param_integer('artefactid', 0);
if (!can_view_view($viewid)) {
json_reply('local', get_string('accessdenied', 'error'));
}
if (!artefact_in_view($artefactid, $viewid)) {
if ($artefactid && !artefact_in_view($artefactid, $viewid)) {
json_reply('local', get_string('accessdenied', 'error'));
}
......@@ -35,7 +35,9 @@ if ($blockid) {
json_reply('local', get_string('accessdenied', 'error'));
}
$view = $block->get_view();
$artefact = $block->get_artefact_instance($artefactid);
if ($artefactid) {
$artefact = $block->get_artefact_instance($artefactid);
}
}
else {
$artefact = artefact_instance_from_id($artefactid);
......@@ -56,16 +58,24 @@ $options = array(
if ($blockid) {
$options['blockid'] = $blockid;
safe_require_plugin('blocktype', $block->get('blocktype'));
$classname = generate_class_name('blocktype', $block->get('blocktype'));
if (call_static_method($classname, 'shows_details_in_modal', $block)) {
$rendered = call_static_method($classname, 'render_details_in_modal', $block);
}
$title = $block->get('title');
}
if ($artefactid) {
$rendered = $artefact->render_self($options);
}
$rendered = $artefact->render_self($options);
if (!empty($rendered['javascript'])) {
$html = '<script>' . $rendered['javascript'] . '</script>';
}
$html .= $rendered['html'];
// Get any existing comments for display
if ($artefact->get('allowcomments')) {
if (isset($artefact) && $artefact->get('allowcomments')) {
$commentoptions = ArtefactTypeComment::get_comment_options();
$commentoptions->view = $view;
$commentoptions->artefact = $artefact;
......@@ -96,7 +106,7 @@ if ($artefact->get('allowcomments')) {
$html .= $smarty->fetch('blocktype:comment:comment.tpl');
}
if ($artefact->get('allowcomments') && ( $USER->is_logged_in() || (!$USER->is_logged_in() && get_config('anonymouscomments')))) {
if (isset($artefact) && $artefact->get('allowcomments') && ( $USER->is_logged_in() || (!$USER->is_logged_in() && get_config('anonymouscomments')))) {
$tmpview = new View($viewid);
$commenttype = $tmpview->user_comments_allowed($USER);
$moderate = !$USER->is_logged_in() || (isset($commenttype) && $commenttype === 'private');
......@@ -106,8 +116,10 @@ if ($artefact->get('allowcomments') && ( $USER->is_logged_in() || (!$USER->is_lo
$html .= $link;
$html .= pieform(ArtefactTypeComment::add_comment_form(false, $moderate));
}
if (isset($artefact)) {
$title = $artefact->display_title();
}
$title = $artefact->display_title();
json_reply(false, array(
'message' => '',
'title' => $title,
......
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