Commit e24210b8 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Plans html export (bug #619597)


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent d315d579
...@@ -58,14 +58,36 @@ class PluginBlocktypePlans extends PluginBlocktype { ...@@ -58,14 +58,36 @@ class PluginBlocktypePlans extends PluginBlocktype {
} }
public static function render_instance(BlockInstance $instance, $editing=false) { public static function render_instance(BlockInstance $instance, $editing=false) {
global $exporter;
require_once(get_config('docroot') . 'artefact/lib.php'); require_once(get_config('docroot') . 'artefact/lib.php');
safe_require('artefact','plans'); safe_require('artefact','plans');
$configdata = $instance->get('configdata'); $configdata = $instance->get('configdata');
$smarty = smarty_core(); $smarty = smarty_core();
if (isset($configdata['artefactid'])) { if (isset($configdata['artefactid'])) {
$tasks = ArtefactTypeTask::get_tasks($configdata['artefactid']); $tasks = ArtefactTypeTask::get_tasks($configdata['artefactid']);
self::build_plans_html($tasks, $editing, $instance); $template = 'artefact:plans:taskrows.tpl';
$blockid = $instance->get('id');
if ($exporter) {
$pagination = false;
}
else {
$pagination = array(
'baseurl' => $instance->get_view()->get_url() . '&block=' . $blockid,
'id' => 'block' . $blockid . '_pagination',
'datatable' => 'tasktable_' . $blockid,
'jsonscript' => 'artefact/plans/viewtasks.json.php',
);
}
ArtefactTypeTask::render_tasks($tasks, $template, $configdata, $pagination);
if ($exporter && $tasks['count'] > $tasks['limit']) {
$artefacturl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $configdata['artefactid']
. '&amp;view=' . $instance->get('view');
$tasks['pagination'] = '<a href="' . $artefacturl . '">' . get_string('alltasks', 'artefact.plans') . '</a>';
}
$smarty->assign('tasks',$tasks); $smarty->assign('tasks',$tasks);
} }
else { else {
...@@ -75,32 +97,6 @@ class PluginBlocktypePlans extends PluginBlocktype { ...@@ -75,32 +97,6 @@ class PluginBlocktypePlans extends PluginBlocktype {
return $smarty->fetch('blocktype:plans:content.tpl'); return $smarty->fetch('blocktype:plans:content.tpl');
} }
public static function build_plans_html(&$tasks, $editing=false, BlockInstance $instance) {
$smarty = smarty_core();
$smarty->assign_by_ref('tasks', $tasks);
$tasks['tablerows'] = $smarty->fetch('artefact:plans:taskrows.tpl');
if ($editing) {
return;
}
$blockid = $instance->get('id');
$baseurl = $instance->get_view()->get_url() . '&block=' . $blockid;
$pagination = build_pagination(array(
'id' => 'block' . $blockid . '_pagination',
'class' => 'center nojs-hidden-block',
'datatable' => 'tasktable_' . $blockid,
'url' => $baseurl,
'jsonscript' => 'artefact/plans/viewtasks.json.php',
'count' => $tasks['count'],
'limit' => $tasks['limit'],
'offset' => $tasks['offset'],
'numbersincludefirstlast' => false,
'resultcounttextsingular' => get_string('task', 'artefact.plans'),
'resultcounttextplural' => get_string('tasks', 'artefact.plans'),
));
$tasks['pagination'] = $pagination['html'];
$tasks['pagination_js'] = 'var paginator' . $blockid . ' = ' . $pagination['javascript'];
}
// My Plans blocktype only has 'title' option so next two functions return as normal // My Plans blocktype only has 'title' option so next two functions return as normal
public static function has_instance_config() { public static function has_instance_config() {
return true; return true;
......
...@@ -13,7 +13,10 @@ ...@@ -13,7 +13,10 @@
{$tasks.tablerows|safe} {$tasks.tablerows|safe}
</tbody> </tbody>
</table> </table>
{if $tasks.pagination}
<div id="plans_page_container">{$tasks.pagination|safe}</div> <div id="plans_page_container">{$tasks.pagination|safe}</div>
{/if}
{if $tasks.pagination_js}
<script> <script>
{literal} {literal}
function rewriteTaskTitles() { function rewriteTaskTitles() {
...@@ -45,6 +48,7 @@ function TaskPager_{$blockid}() {literal}{ ...@@ -45,6 +48,7 @@ function TaskPager_{$blockid}() {literal}{
var taskPager_{$blockid} = new TaskPager_{$blockid}(); var taskPager_{$blockid} = new TaskPager_{$blockid}();
addLoadEvent(rewriteTaskTitles); addLoadEvent(rewriteTaskTitles);
</script> </script>
{/if} {* pagination_js *}
{else} {else}
<p>{str tag='notasks' section='artefact.plans'}</p> <p>{str tag='notasks' section='artefact.plans'}</p>
{/if} {/if}
......
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage artefact-plans-export-html
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
class HtmlExportPlans extends HtmlExportArtefactPlugin {
public function pagination_data($artefact) {
if ($artefact instanceof ArtefactTypePlan) {
return array(
'perpage' => 10,
'childcount' => $artefact->count_children(),
'plural' => get_string('plans', 'artefact.plans'),
);
}
}
public function dump_export_data() {
foreach ($this->exporter->get('artefacts') as $artefact) {
if ($artefact instanceof ArtefactTypePlan) {
$this->paginate($artefact);
}
}
}
public function get_summary() {
$smarty = $this->exporter->get_smarty();
$plans = array();
foreach ($this->exporter->get('artefacts') as $artefact) {
if ($artefact instanceof ArtefactTypePlan) {
$plans[] = array(
'link' => 'files/plans/' . PluginExportHtml::text_to_path($artefact->get('title')) . '/index.html',
'title' => $artefact->get('title'),
);
}
}
$smarty->assign('plans', $plans);
return array(
'title' => get_string('plans', 'artefact.plans'),
'description' => $smarty->fetch('export:html/plans:summary.tpl'),
);
}
public function get_summary_weight() {
return 40;
}
}
{if $plans}
<ul>
{foreach from=$plans item=plan}
<li><a href="{$plan.link}">{$plan.title}</a></li>
{/foreach}
</ul>
{/if}
...@@ -51,6 +51,7 @@ $string['title'] = 'Title'; ...@@ -51,6 +51,7 @@ $string['title'] = 'Title';
$string['titledesc'] = 'The title will be used to display each task in the My Plans blocktype.'; $string['titledesc'] = 'The title will be used to display each task in the My Plans blocktype.';
/* Tasks */ /* Tasks */
$string['alltasks'] = 'All tasks';
$string['completed'] = 'Completed'; $string['completed'] = 'Completed';
$string['completiondate'] = 'Completion date'; $string['completiondate'] = 'Completion date';
$string['completeddesc'] = 'Mark your task completed.'; $string['completeddesc'] = 'Mark your task completed.';
......
...@@ -243,10 +243,18 @@ class ArtefactTypePlan extends ArtefactType { ...@@ -243,10 +243,18 @@ class ArtefactTypePlan extends ArtefactType {
public function render_self($options) { public function render_self($options) {
$this->add_to_render_path($options); $this->add_to_render_path($options);
$tasks = ArtefactTypeTask::get_tasks($this->id); $limit = !isset($options['limit']) ? 10 : (int) $options['limit'];
$offset = isset($options['offset']) ? intval($options['offset']) : 0;
$tasks = ArtefactTypeTask::get_tasks($this->id, $offset, $limit);
$template = 'artefact:plans:taskrows.tpl'; $template = 'artefact:plans:taskrows.tpl';
$baseurl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $this->id . '&view=' . $options['viewid'];
$baseurl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $this->id;
if (!empty($options['viewid'])) {
$baseurl .= '&view=' . $options['viewid'];
}
$pagination = array( $pagination = array(
'baseurl' => $baseurl, 'baseurl' => $baseurl,
'id' => 'task_pagination', 'id' => 'task_pagination',
...@@ -258,11 +266,12 @@ class ArtefactTypePlan extends ArtefactType { ...@@ -258,11 +266,12 @@ class ArtefactTypePlan extends ArtefactType {
$smarty = smarty_core(); $smarty = smarty_core();
$smarty->assign_by_ref('tasks', $tasks); $smarty->assign_by_ref('tasks', $tasks);
$smarty->assign( if (isset($options['viewid'])) {
'artefacttitle', $smarty->assign('artefacttitle', '<a href="' . $baseurl . '">' . hsc($this->get('title')) . '</a>');
'<a href="' . get_config('wwwroot') . 'view/artefact.php?artefact=' . $this->id }
. '&view=' . $options['viewid'] . '">' . hsc($this->title) . '</a>' else {
); $smarty->assign('artefacttitle', hsc($this->get('title')));
}
$smarty->assign('plan', $this); $smarty->assign('plan', $this);
return array('html' => $smarty->fetch('artefact:plans:viewplan.tpl'), 'javascript' => ''); return array('html' => $smarty->fetch('artefact:plans:viewplan.tpl'), 'javascript' => '');
...@@ -571,7 +580,7 @@ class ArtefactTypeTask extends ArtefactType { ...@@ -571,7 +580,7 @@ class ArtefactTypeTask extends ArtefactType {
$smarty->assign_by_ref('options', $options); $smarty->assign_by_ref('options', $options);
$tasks['tablerows'] = $smarty->fetch($template); $tasks['tablerows'] = $smarty->fetch($template);
if ($tasks['limit']) { if ($tasks['limit'] && $pagination) {
$pagination = build_pagination(array( $pagination = build_pagination(array(
'id' => $pagination['id'], 'id' => $pagination['id'],
'class' => 'center', 'class' => 'center',
......
...@@ -38,9 +38,17 @@ $limit = param_integer('limit', 10); ...@@ -38,9 +38,17 @@ $limit = param_integer('limit', 10);
if ($blockid = param_integer('block', null)) { if ($blockid = param_integer('block', null)) {
$bi = new BlockInstance($blockid); $bi = new BlockInstance($blockid);
$configdata = $bi->get('configdata'); $options = $configdata = $bi->get('configdata');
$tasks = ArtefactTypeTask::get_tasks($configdata['artefactid'], $offset, $limit); $tasks = ArtefactTypeTask::get_tasks($configdata['artefactid'], $offset, $limit);
PluginBlocktypePlans::build_plans_html($tasks, false, $bi);
$template = 'artefact:plans:taskrows.tpl';
$pagination = array(
'baseurl' => $bi->get_view()->get_url() . '&block=' . $blockid,
'id' => 'block' . $blockid . '_pagination',
'datatable' => 'tasktable_' . $blockid,
'jsonscript' => 'artefact/plans/viewtasks.json.php',
);
} }
else { else {
$planid = param_integer('artefact'); $planid = param_integer('artefact');
...@@ -57,7 +65,7 @@ else { ...@@ -57,7 +65,7 @@ else {
'jsonscript' => 'artefact/plans/viewtasks.json.php', 'jsonscript' => 'artefact/plans/viewtasks.json.php',
); );
ArtefactTypeTask::render_tasks($tasks, $template, $options, $pagination);
} }
ArtefactTypeTask::render_tasks($tasks, $template, $options, $pagination);
json_reply(false, (object) array('message' => false, 'data' => $tasks)); json_reply(false, (object) array('message' => false, 'data' => $tasks));
...@@ -620,11 +620,14 @@ class HtmlExportOutputFilter { ...@@ -620,11 +620,14 @@ class HtmlExportOutputFilter {
$artefactid = $matches[2]; $artefactid = $matches[2];
$artefact = artefact_instance_from_id($artefactid); $artefact = artefact_instance_from_id($artefactid);
switch ($artefact->get('artefacttype')) { $artefacttype = $artefact->get('artefacttype');
switch ($artefacttype) {
case 'blog': case 'blog':
case 'plan':
$dir = $artefacttype == 'plan' ? 'plans' : $artefacttype;
$offset = ($matches[4]) ? intval(substr($matches[4], strlen('&amp;offset='))) : 0; $offset = ($matches[4]) ? intval(substr($matches[4], strlen('&amp;offset='))) : 0;
$offset = ($offset == 0) ? 'index' : $offset; $offset = ($offset == 0) ? 'index' : $offset;
return '<a href="' . $this->basepath . '/files/blog/' . PluginExportHtml::text_to_path($artefact->get('title')) . '/' . $offset . '.html">' . $matches[5] . '</a>'; return '<a href="' . $this->basepath . "/files/$dir/" . PluginExportHtml::text_to_path($artefact->get('title')) . '/' . $offset . '.html">' . $matches[5] . '</a>';
case 'file': case 'file':
case 'folder': case 'folder':
case 'image': case 'image':
......
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