Commit b829af50 authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic Committed by Robert Lyon

Bug 1804243: timeline: show correct version of a plan block

saves in version

for plans:
 title
 description
 tags

for tasks:
 task title
 description
 completion date
 completed status(yes/no)
 tags

behatnotneeded
Change-Id: Ib09cf4b8718f1180cb5f021bc532659db7f39647
parent 3a3cc5e2
......@@ -60,61 +60,90 @@ class PluginBlocktypePlans extends MaharaCoreBlocktype {
$configdata = $instance->get('configdata');
$limit = (!empty($configdata['count'])) ? $configdata['count'] : 10;
$smarty = smarty_core();
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';
$plans = array();
$alltasks = array();
$template = 'artefact:plans:taskrows.tpl';
if (($versioning && isset($configdata['existing_artefacts']) && !empty($configdata['existing_artefacts'])) ||
(isset($configdata['artefactids']) && is_array($configdata['artefactids']) && count($configdata['artefactids']) > 0)) {
if ($versioning) {
// recover the configdata from the version
$blockid = $instance->get('id');
if ($exporter) {
$pagination = false;
$blocks = $versioning->blocks;
foreach ($blocks as $key => $value) {
if ($value->originalblockid == $blockid) {
$versionblock = $value;
break;
}
}
else {
$baseurl = $instance->get_view()->get_url();
$baseurl .= ((false === strpos($baseurl, '?')) ? '?' : '&') . 'block=' . $blockid . '&planid=' . $planid . '&editing=' . $editing;
$pagination = array(
'baseurl' => $baseurl,
'id' => 'block' . $blockid . '_plan' . $planid . '_pagination',
'datatable' => 'tasklist_' . $blockid . '_plan' . $planid,
'jsonscript' => 'artefact/plans/viewtasks.json.php',
);
$configdata = (array)$versionblock->configdata;
$savedplans = $configdata['existing_artefacts'];
}
else {
$savedplans = array_flip($configdata['artefactids']);
}
foreach ($savedplans as $planid => $plancontent) {
try {
$tasks = isset($plancontent->tasks) ? (array)$plancontent->tasks : ArtefactTypeTask::get_tasks($planid, 0, $limit);
$blockid = $instance->get('id');
if ($exporter || $versioning) {
$pagination = false;
}
else {
$baseurl = $instance->get_view()->get_url();
$baseurl .= ((false === strpos($baseurl, '?')) ? '?' : '&') . 'block=' . $blockid . '&planid=' . $planid . '&editing=' . $editing;
$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;
$configdata['versioning'] = $versioning;
ArtefactTypeTask::render_tasks($tasks, $template, $configdata, $pagination, $editing, $versioning);
if (($exporter || $versioning) && $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>';
}
if ($versioning) {
$plans[$planid]['title'] = $plancontent->title;
$plans[$planid]['description'] = $plancontent->description;
$plans[$planid]['owner'] = $plancontent->owner;
$plans[$planid]['tags'] = $plancontent->tags;
}
else {
$plan = artefact_instance_from_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]['id'] = $planid;
$plans[$planid]['view'] = $instance->get('view');
$plans[$planid]['details'] = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $planid . '&view=' .
$instance->get_view()->get('id') . '&block=' . $blockid;
$plans[$planid]['numtasks'] = $tasks['count'];
$tasks['planid'] = $planid;
array_push($alltasks, $tasks);
}
$configdata['view'] = $instance->get('view');
$configdata['block'] = $blockid;
$configdata['versioning'] = $versioning;
ArtefactTypeTask::render_tasks($tasks, $template, $configdata, $pagination, $editing);
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>';
catch (ArtefactNotFoundException $e) {
// do nothing, the plan doesnt exists anymore
}
$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('plans', $plans);
$smarty->assign('alltasks', $alltasks);
}
$smarty->assign('editing', $editing);
$smarty->assign('plans', $plans);
$smarty->assign('alltasks', $alltasks);
}
else {
$smarty->assign('editing', $editing);
$smarty->assign('noplans', get_string('noplansselectone', 'blocktype.plans/plans'));
$smarty->assign('noplans', get_string('noplansselectone', 'blocktype.plans/plans'));
}
$smarty->assign('editing', $editing);
$smarty->assign('blockid', $instance->get('id'));
$smarty->assign('versioning', $versioning);
return $smarty->fetch('blocktype:plans:content.tpl');
......@@ -189,4 +218,21 @@ class PluginBlocktypePlans extends MaharaCoreBlocktype {
}
return $configdata;
}
public static function get_current_artefacts(BlockInstance $instance) {
safe_require('artefact', 'plans');
$configdata = $instance->get('configdata');
$artefacts = array();
foreach ($configdata['artefactids'] as $planid) {
$plan = artefact_instance_from_id($planid);
$tasks = ArtefactTypeTask::get_tasks($planid, 0, 0);
$artefacts[$planid]['tasks'] = $tasks;
$artefacts[$planid]['title'] = $plan->get('title');
$artefacts[$planid]['description'] = $plan->get('description');
$artefacts[$planid]['tags'] = $plan->get('tags');
$artefacts[$planid]['owner'] = $plan->get('owner');
}
return $artefacts;
}
}
......@@ -611,16 +611,22 @@ class ArtefactTypeTask extends ArtefactType {
* @param offset current page to display
* @return array (count: integer, data: array)
*/
public static function get_tasks($plan, $offset=0, $limit=10) {
public static function get_tasks($plan, $offset=0, $limit=10, $tasks=null) {
$datenow = time(); // time now to use for formatting tasks by completion
($results = get_records_sql_array("
$sql = "
SELECT a.id, at.artefact AS task, at.completed, ".db_format_tsfield('completiondate').",
a.title, a.description, a.parent, a.owner
FROM {artefact} a
JOIN {artefact_plans_task} at ON at.artefact = a.id
WHERE a.artefacttype = 'task' AND a.parent = ?
ORDER BY at.completed, at.completiondate ASC, a.id", array($plan), $offset, $limit))
WHERE a.artefacttype = 'task' AND a.parent = ?";
$values = array($plan);
if ($tasks) {
$sql .= " AND a.id IN ( " . join(',', array_fill(0, count($tasks), '?')) . ")";
$values = array_merge($values, $tasks);
}
$sql .= " ORDER BY at.completed, at.completiondate ASC, a.id";
($results = get_records_sql_array($sql, $values, $offset, $limit))
|| ($results = array());
// format the date and setup completed for display if task is incomplete
......@@ -689,7 +695,7 @@ class ArtefactTypeTask extends ArtefactType {
*
* @return array $tasks The tasks array updated with rendered table html
*/
public function render_tasks(&$tasks, $template, $options, $pagination, $editing=false) {
public function render_tasks(&$tasks, $template, $options, $pagination, $editing=false, $versioning=false) {
global $USER;
$smarty = smarty_core();
......@@ -698,6 +704,7 @@ class ArtefactTypeTask extends ArtefactType {
$smarty->assign('view', (!empty($options['view']) ? $options['view'] : null));
$smarty->assign('block', (!empty($options['block']) ? $options['block'] : null));
$smarty->assign('editing', $editing);
$smarty->assign('versioning', $versioning);
if (!empty($options['view'])) {
require_once('view.php');
$view = new View($options['view']);
......
......@@ -37,7 +37,7 @@
<div id="tasklist_{$blockid}_plan{$tasks.planid}" class="list-group list-unstyled">
{$tasks.tablerows|safe}
</div>
{if $tasks.pagination}
{if $tasks.pagination && !$versioning}
<div id="plans_page_container_{$blockid}_plan{$tasks.planid}" class="d-none">
{$tasks.pagination|safe}
</div>
......
......@@ -7,7 +7,7 @@
<a class="btn btn-secondary btn-sm" href="{$WWWROOT}artefact/plans/delete/task.php?id={$task->id}{if $view}&view={$view}{/if}" title="{str tag='deletethistask' section='artefact.plans' arg1=$task->title}"><span class="icon icon-trash text-danger"></span></a>
</div>
{/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}
{if $task->description || $task->tags} <a class="link-block collapsed" href="#expand-task-{$task->id}{if $block}-{$block}{/if}{if $versioning}-{$versioning->version}{/if}" data-toggle="collapse" aria-expanded="false" aria-controls="expand-task-{$task->id}{if $block}-{$block}{/if}{if $versioning}-{$versioning->version}{/if}">{/if}
<span class="overdue-task">
<div class="collapse-inline">
<span class="icon icon-times text-danger icon-lg left task{$task->id}{if $editing || $canedit} plan-task-icon{/if}" role="presentation" aria-hidden="true" data-task="{$task->id}"></span>
......@@ -24,7 +24,7 @@
{if $task->description || $task->tags}</a>{/if}
{if $task->description || $task->tags}
<div class="collapse" id="expand-task-{$task->id}{if $block}-{$block}{/if}">
<div class="collapse" id="expand-task-{$task->id}{if $block}-{$block}{/if}{if $versioning}-{$versioning->version}{/if}">
<div class="card-body">
{if $task->description}
{$task->description|clean_html|safe}
......@@ -46,7 +46,7 @@
<a class="btn btn-secondary btn-sm" href="{$WWWROOT}artefact/plans/delete/task.php?id={$task->id}{if $view}&view={$view}{/if}" title="{str tag='deletethistask' section='artefact.plans' arg1=$task->title}"><span class="icon icon-trash text-danger"></span></a>
</div>
{/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}
{if $task->description || $task->tags}<a class="link-block collapsed" href="#expand-task-{$task->id}{if $block}-{$block}{/if}{if $versioning}-{$versioning->version}{/if}" data-toggle="collapse" aria-expanded="false" aria-controls="expand-task-{$task->id}{if $block}-{$block}{/if}{if $versioning}-{$versioning->version}{/if}">{/if}
<span class="complete-task">
<div class="collapse-inline">
{if $task->completed == 1}
......@@ -70,7 +70,7 @@
{if $task->description || $task->tags}</a>{/if}
{if $task->description || $task->tags}
<div class="collapse" id="expand-task-{$task->id}{if $block}-{$block}{/if}">
<div class="collapse" id="expand-task-{$task->id}{if $block}-{$block}{/if}{if $versioning}-{$versioning->version}{/if}">
<div class="card-body">
{if $task->description}
{$task->description|clean_html|safe}
......
......@@ -47,6 +47,7 @@ if ($blocks) {
$bi->row = $oldblock->get('row');
$bi->column = $oldblock->get('column');
$bi->order = $oldblock->get('order');
$classname = generate_class_name('blocktype', $oldblock->get('blocktype'));
if (is_callable($classname . '::'. 'get_current_artefacts')) {
// The block is for one artefact so lets see if it displays more than one artefact
......
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