Commit bc40a45f authored by Maria Sorica's avatar Maria Sorica Committed by Robert Lyon
Browse files

Bug 1723961: Allow plan blocktypes to display more than one plan

1. Added a details link for each plan in the blocktype as well.
2. On site update, the existing plan blocktypes will be updated
to be able to contain more than plan.
3. Made task pagination work on blocktypes with
multiple plans.

behatnotneeded

Change-Id: I4b462f447489eb16d43fd40cfa552825c5178a47
parent 94e17a4e
......@@ -32,8 +32,13 @@ class PluginBlocktypePlans extends MaharaCoreBlocktype {
public static function get_instance_title(BlockInstance $bi) {
$configdata = $bi->get('configdata');
if (!empty($configdata['artefactid'])) {
return $bi->get_artefact_instance($configdata['artefactid'])->get('title');
if (!empty($configdata['artefactids']) && is_array($configdata['artefactids'])) {
if (count($configdata['artefactids']) > 1) {
return get_string('title', 'blocktype.plans/plans');
}
else if (count($configdata['artefactids']) == 1) {
return $bi->get_artefact_instance($configdata['artefactids'][0])->get('title');
}
}
return '';
}
......@@ -58,37 +63,52 @@ class PluginBlocktypePlans extends MaharaCoreBlocktype {
$limit = (!empty($configdata['count'])) ? $configdata['count'] : 10;
$smarty = smarty_core();
if (isset($configdata['artefactid'])) {
$plan = artefact_instance_from_id($configdata['artefactid']);
$tasks = ArtefactTypeTask::get_tasks($configdata['artefactid'], 0, $limit);
$template = 'artefact:plans:taskrows.tpl';
$blockid = $instance->get('id');
if ($exporter) {
$pagination = false;
}
else {
$baseurl = $instance->get_view()->get_url();
$baseurl .= ((false === strpos($baseurl, '?')) ? '?' : '&') . 'block=' . $blockid;
$pagination = array(
'baseurl' => $baseurl,
'id' => 'block' . $blockid . '_pagination',
'datatable' => 'tasklist_' . $blockid,
'jsonscript' => 'artefact/plans/viewtasks.json.php',
);
}
$configdata['view'] = $instance->get('view');
ArtefactTypeTask::render_tasks($tasks, $template, $configdata, $pagination);
if ($exporter && $tasks['count'] > $tasks['limit']) {
$artefacturl = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $configdata['artefactid']
. '&view=' . $instance->get('view');
$tasks['pagination'] = '<a href="' . $artefacturl . '">' . get_string('alltasks', 'artefact.plans') . '</a>';
if (isset($configdata['artefactids']) && is_array($configdata['artefactids']) && count($configdata['artefactids']) > 0) {
$plans = array();
$alltasks = array();
foreach ($configdata['artefactids'] as $planid) {
$plan = artefact_instance_from_id($planid);
$tasks = ArtefactTypeTask::get_tasks($planid, 0, $limit);
$template = 'artefact:plans:taskrows.tpl';
$blockid = $instance->get('id');
if ($exporter) {
$pagination = false;
}
else {
$baseurl = $instance->get_view()->get_url();
$baseurl .= ((false === strpos($baseurl, '?')) ? '?' : '&') . 'block=' . $blockid . '&planid=' . $planid;
$pagination = array(
'baseurl' => $baseurl,
'id' => 'block' . $blockid . '_plan' . $planid . '_pagination',
'datatable' => 'tasklist_' . $blockid . '_plan' . $planid,
'jsonscript' => 'artefact/plans/viewtasks.json.php',
);
}
$configdata['view'] = $instance->get('view');
$configdata['block'] = $blockid;
ArtefactTypeTask::render_tasks($tasks, $template, $configdata, $pagination);
if ($exporter && $tasks['count'] > $tasks['limit']) {
$artefacturl = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $planid
. '&view=' . $instance->get('view');
$tasks['pagination'] = '<a href="' . $artefacturl . '">' . get_string('alltasks', 'artefact.plans') . '</a>';
}
$plans[$planid]['id'] = $planid;
$plans[$planid]['title'] = $plan->get('title');
$plans[$planid]['description'] = $plan->get('description');
$plans[$planid]['owner'] = $plan->get('owner');
$plans[$planid]['tags'] = $plan->get('tags');
$plans[$planid]['view'] = $instance->get('view');
$plans[$planid]['details'] = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $plan->get('id') . '&view=' .
$instance->get_view()->get('id') . '&block=' . $blockid;
$plans[$planid]['numtasks'] = $tasks['count'];
$tasks['planid'] = $planid;
array_push($alltasks, $tasks);
}
$smarty->assign('description', $plan->get('description'));
$smarty->assign('owner', $plan->get('owner'));
$smarty->assign('tags', $plan->get('tags'));
$smarty->assign('tasks', $tasks);
$smarty->assign('view', $instance->get('view'));
$smarty->assign('plans', $plans);
$smarty->assign('alltasks', $alltasks);
}
else {
$smarty->assign('noplans','blocktype.plans/plans');
......@@ -109,7 +129,7 @@ class PluginBlocktypePlans extends MaharaCoreBlocktype {
$form = array();
// Which resume field does the user want
$form[] = self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null);
$form[] = self::artefactchooser_element((isset($configdata['artefactids'])) ? $configdata['artefactids'] : null);
$form['count'] = array(
'type' => 'text',
'title' => get_string('taskstodisplay', 'blocktype.plans/plans'),
......@@ -123,12 +143,12 @@ class PluginBlocktypePlans extends MaharaCoreBlocktype {
public static function artefactchooser_element($default=null) {
safe_require('artefact', 'plans');
return array(
'name' => 'artefactid',
'name' => 'artefactids',
'type' => 'artefactchooser',
'title' => get_string('planstoshow', 'blocktype.plans/plans'),
'defaultvalue' => $default,
'blocktype' => 'plans',
'selectone' => true,
'selectone' => false,
'search' => false,
'artefacttypes' => array('plan'),
'template' => 'artefact:plans:artefactchooser-element.tpl',
......
......@@ -664,6 +664,7 @@ class ArtefactTypeTask extends ArtefactType {
$smarty->assign('tasks', $tasks);
$smarty->assign('options', $options);
$smarty->assign('view', (!empty($options['view']) ? $options['view'] : null));
$smarty->assign('block', (!empty($options['block']) ? $options['block'] : null));
$tasks['tablerows'] = $smarty->fetch($template);
if ($tasks['limit'] && $pagination) {
......
......@@ -19,6 +19,7 @@ require_once(get_config('docroot') . 'artefact/plans/blocktype/plans/lib.php');
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
$editing = param_variable('editing', false);
if ($blockid = param_integer('block', null)) {
$bi = new BlockInstance($blockid);
......@@ -28,15 +29,16 @@ if ($blockid = param_integer('block', null)) {
$options = $configdata = $bi->get('configdata');
// If block sets limit use that instead
$limit = !empty($configdata['count']) ? $configdata['count'] : $limit;
$tasks = ArtefactTypeTask::get_tasks($configdata['artefactid'], $offset, $limit);
$planid = param_integer('planid');
$tasks = ArtefactTypeTask::get_tasks($planid, $offset, $limit);
$template = 'artefact:plans:taskrows.tpl';
$baseurl = $bi->get_view()->get_url();
$baseurl .= ((false === strpos($baseurl, '?')) ? '?' : '&') . 'block=' . $blockid;
$baseurl .= ((false === strpos($baseurl, '?')) ? '?' : '&') . 'block=' . $blockid . '&planid=' . $planid . '&editing=' . $editing;
$pagination = array(
'baseurl' => $baseurl,
'id' => 'block' . $blockid . '_pagination',
'datatable' => 'tasklist_' . $blockid,
'baseurl' => $baseurl,
'id' => 'block' . $blockid . '_plan' . $planid . '_pagination',
'datatable' => 'tasklist_' . $blockid . '_plan' . $planid,
'jsonscript' => 'artefact/plans/viewtasks.json.php',
);
}
......
......@@ -5811,5 +5811,31 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2018040900) {
log_debug('Change the artefactid (integer) in the configdata of the existing plan blocktypes to artefactids (array). This change will allow plan blocktypes to contain more than one plan.');
require_once(get_config('docroot') . 'blocktype/lib.php');
$instances = get_records_array('block_instance', 'blocktype', 'plans');
if ($instances) {
foreach ($instances as $instance) {
$blockinstance = new BlockInstance($instance->id);
$configdata = $blockinstance->get('configdata');
if (isset($configdata['artefactid'])) {
$configdata['artefactids'] = array($configdata['artefactid']);
unset($configdata['artefactid']);
$blockinstance->set('configdata', $configdata);
$blockinstance->commit();
}
else if (is_null($configdata['artefactid'])) {
$configdata['artefactids'] = array();
unset($configdata['artefactid']);
$blockinstance->set('configdata', $configdata);
$blockinstance->commit();
}
}
}
}
return $status;
}
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2018031900;
$config->version = 2018040900;
$config->series = '18.10';
$config->release = '18.10dev';
$config->minupgradefrom = 2015030409;
......
{foreach from=$plans item=plan}
<div class="panel-body flush">
<p>{$description}</p>
<strong>{$plan.title}</strong>
<p>{$plan.description}</p>
{if $tags}
{if $plan.tags}
<div class="tags">
<strong>{str tag=tags}:</strong> {list_tags owner=$owner tags=$tags view=$view}
<strong>{str tag=tags}:</strong> {list_tags owner=$plan.owner tags=$plan.tags view=$plan.view}
</div>
{/if}
{if $tasks.data}
<div id="tasklist_{$blockid}" class="list-group list-unstyled">
{$tasks.tablerows|safe}
</div>
{if $tasks.pagination}
<div id="plans_page_container_{$blockid}" class="hidden">
{$tasks.pagination|safe}
</div>
<script>
jQuery(function($) {literal}{{/literal}
{$tasks.pagination_js|safe}
$('#plans_page_container_{$blockid}').removeClass('hidden');
{literal}}{/literal});
</script>
{/if}
{if $plan.numtasks != 0}
{foreach from=$alltasks item=tasks}
{if $tasks.planid == $plan.id}
<div id="tasklist_{$blockid}_plan{$tasks.planid}" class="list-group list-unstyled">
{$tasks.tablerows|safe}
</div>
{if $tasks.pagination}
<div id="plans_page_container_{$blockid}_plan{$tasks.planid}" class="hidden">
{$tasks.pagination|safe}
</div>
<script>
jQuery(function($) {literal}{{/literal}
{$tasks.pagination_js|safe}
$('#plans_page_container_{$blockid}_plan{$tasks.planid}').removeClass('hidden');
{literal}}{/literal});
</script>
{/if}
{/if}
{/foreach}
<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>
{else}
<div class="lead text-center content-text">{str tag='notasks' section='artefact.plans'}</div>
{/if}
</div>
\ No newline at end of file
</div>
{/foreach}
\ No newline at end of file
......@@ -2,7 +2,7 @@
{if $task->completed == -1}
<div class="task-item plan_incomplete list-group-item {if $task->description || $task->tags}list-group-item-default{/if}">
{if $task->description || $task->tags}<a class="link-block collapsed" href="#expand-task-{$task->id}" data-toggle="collapse" aria-expanded="false" aria-controls="expand-task-{$task->id}">{/if}
{if $task->description || $task->tags}<a class="link-block collapsed" href="#expand-task-{$task->id}{if $block}-{$block}{/if}" data-toggle="collapse" aria-expanded="false" aria-controls="expand-task-{$task->id}{if $block}-{$block}{/if}">{/if}
<span class="overdue-task">
<span class="icon icon-times text-danger icon-lg left" role="presentation" aria-hidden="true"></span>
......@@ -17,7 +17,7 @@
{if $task->description || $task->tags}</a>{/if}
{if $task->description || $task->tags}
<div class="collapse" id="expand-task-{$task->id}">
<div class="collapse" id="expand-task-{$task->id}{if $block}-{$block}{/if}">
<div class="panel-body">
{if $task->description}
{$task->description|clean_html|safe}
......@@ -34,7 +34,7 @@
{else}
<div class="task-item list-group-item {if $task->description || $task->tags}list-group-item-default{/if}">
{if $task->description || $task->tags}<a class="link-block collapsed" href="#expand-task-{$task->id}" data-toggle="collapse" aria-expanded="false" aria-controls="expand-task-{$task->id}">{/if}
{if $task->description || $task->tags}<a class="link-block collapsed" href="#expand-task-{$task->id}{if $block}-{$block}{/if}" data-toggle="collapse" aria-expanded="false" aria-controls="expand-task-{$task->id}{if $block}-{$block}{/if}">{/if}
<span class="complete-task">
{if $task->completed == 1}
......@@ -58,7 +58,7 @@
{if $task->description || $task->tags}</a>{/if}
{if $task->description || $task->tags}
<div class="collapse" id="expand-task-{$task->id}">
<div class="collapse" id="expand-task-{$task->id}{if $block}-{$block}{/if}">
<div class="panel-body">
{if $task->description}
{$task->description|clean_html|safe}
......
......@@ -12,7 +12,8 @@
margin: 20px 0;
}
.task-item .complete-task .icon {
.task-item .complete-task .icon,
.task-item .overdue-task .icon {
margin-left: -8px; //correct alignment
}
......
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