Commit 274bc533 authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic
Browse files

Bug 1790543: Portfolio instructions-Import/Export

- exporting instuctions field to html/leap2A
- importing instructions from leap2A
- fixing styles in collapsible instructions section

behatnotneeded
Change-Id: Ib9862cceefafac2e5d6a44f88516cd51c8f18962
parent 8d5c020b
......@@ -365,6 +365,7 @@ class PluginExportHtml extends PluginExport {
$this->notify_progress_callback(intval($progressstart + (++$i / $viewcount) * ($progressend - $progressstart)), get_string('exportingviewsprogress', 'export', $i, $viewcount));
$smarty->assign('page_heading', $view->get('title'));
$smarty->assign('viewdescription', $view->get('description'));
$smarty->assign('viewinstructions', $view->get('instructions'));
if ($this->exportingoneview) {
$smarty->assign('nobreadcrumbs', true);
......
......@@ -269,13 +269,26 @@ class PluginExportLeap extends PluginExport {
$this->smarty->assign('updated', self::format_rfc3339_date(strtotime($view->get('mtime'))));
$this->smarty->assign('created', self::format_rfc3339_date(strtotime($view->get('ctime'))));
$content = $config['description'];
if ($newcontent = self::parse_xhtmlish_content($content)) {
$this->smarty->assign('summarytype', 'xhtml');
$this->smarty->assign('summary', clean_html($newcontent, true));
} else {
}
else {
$this->smarty->assign('summarytype', 'text');
$this->smarty->assign('summary', clean_html($content));
}
$instructions = $config['instructions'];
if ($newinstructions = self::parse_xhtmlish_content($instructions)) {
$this->smarty->assign('instructionstype', 'xhtml');
$this->smarty->assign('instructions', clean_html($newinstructions, true));
}
else {
$this->smarty->assign('instructionstype', 'text');
$this->smarty->assign('instructions', clean_html($instructions));
}
$this->smarty->assign('contenttype', 'xhtml');
if ($viewcontent = self::parse_xhtmlish_content($view->build_rows(false, true), $view->get('id'))) {
$this->smarty->assign('content', clean_html($viewcontent, true));
......
......@@ -1046,6 +1046,14 @@ class PluginImportLeap extends PluginImport {
);
$view->set('description', $newdescription);
$newinstructions = EmbeddedImage::rewrite_embedded_image_urls_from_import(
$view->get('instructions'),
$this->artefactids,
'instructions',
$view->get('id')
);
$view->set('instructions', $newinstructions);
if (isset($viewdata->ctime)) {
$view->set('ctime', $viewdata->ctime);
}
......@@ -1166,7 +1174,6 @@ class PluginImportLeap extends PluginImport {
return $smarty->fetch('import/views.tpl');
}
/**
* Logic for processing an $entry into a Mahara view.
* @param SimpleXMLElement $entry
......@@ -1327,28 +1334,16 @@ class PluginImportLeap extends PluginImport {
}
// Extract the view description in the entry 'summary'
// A description may be wrapped in XHTML div
// and view instructions in entry 'subtitle'
// A description/instructions may be wrapped in XHTML div
// See more PluginExportLeap::parse_xhtmlish_content()
$description = '';
if ((string) $entry->summary['type'] === 'xhtml'
|| (string) $entry->summary['type'] === 'html'
) {
$summaryelements =
((string) $entry->summary['type'] === 'xhtml'
&& $entry->summary->div->div) ?
$entry->summary->div->div
: $entry->summary;
$summarychildren = $summaryelements->children();
foreach ($summarychildren as $c) {
$description .= $c->asXML();
}
}
else {
$description = (string)$entry->summary;
}
$description = $this->extract_view_entry_field($entry->summary);
$instructions = $this->extract_view_entry_field($entry->subtitle);
$config = array(
'title' => (string)$entry->title,
'description' => $description,
'instructions' => $instructions,
'type' => $type,
'layout' => $layout->id,
'tags' => self::get_entry_tags($entry),
......@@ -1420,6 +1415,32 @@ class PluginImportLeap extends PluginImport {
return $config;
}
/**
* Extracts html from an entry XML element field.
* @param SimpleXMLElement $entry field
* @return array entry data as html/xhtml
*/
private function extract_view_entry_field(SimpleXMLElement $xmlentryfield) {
$fieldtext = '';
if ((string) $xmlentryfield['type'] === 'xhtml'
|| (string) $xmlentryfield['type'] === 'html'
) {
$entryelements =
((string) $xmlentryfield['type'] === 'xhtml'
&& $xmlentryfield->div->div) ?
$xmlentryfield->div->div
: $xmlentryfield;
$entrychildren = $entryelements->children();
foreach ($entrychildren as $c) {
$fieldtext .= $c->asXML();
}
}
else {
$fieldtext = (string)$xmlentryfield;
}
return $fieldtext;
}
/**
* Attempts to import an entry as a mahara view
*
......
......@@ -6040,10 +6040,12 @@ class View {
if ($template->get('template') == self::SITE_TEMPLATE
&& $template->get('type') == 'portfolio') {
$this->set('description', '');
$this->set('instructions', '');
}
else {
require_once('embeddedimage.php');
$this->set('description', EmbeddedImage::prepare_embedded_images($this->copy_description($template, $artefactcopies), 'description', $this->get('id')));
$this->set('description', EmbeddedImage::prepare_embedded_images($this->copy_setting_info($template, $artefactcopies, 'description'), 'description', $this->get('id')));
$this->set('instructions', EmbeddedImage::prepare_embedded_images($this->copy_setting_info($template, $artefactcopies, 'instructions'), 'instructions', $this->get('id')));
}
$this->set('tags', $template->get('tags'));
$this->set('columnsperrow', $template->get('columnsperrow'));
......@@ -6098,20 +6100,21 @@ class View {
}
/**
* Copy the description of the view template
* Copy the description/instructions field of the view template
* and its embedded image artefacts
*
* @param View $template the view template
* @param array &$artefactcopies the artefact mapping
* @return string updated description
* @param string $type contains 'description' or 'instructions'
* @return string updated field
*/
private function copy_description(View $template, array &$artefactcopies) {
private function copy_setting_info(View $template, array &$artefactcopies, $type) {
safe_require('artefact', 'file');
$new_description = $template->get('description');
if (!empty($new_description)
&& strpos($new_description, 'artefact/file/download.php?file=') !== false) {
$new_setting_field = $template->get($type);
if (!empty($new_setting_field)
&& strpos($new_setting_field, 'artefact/file/download.php?file=') !== false) {
// Get all possible embedded artefacts
$artefactids = array_unique(artefact_get_references_in_html($new_description));
$artefactids = array_unique(artefact_get_references_in_html($new_setting_field));
// Copy these image artefacts
foreach ($artefactids as $aid) {
try {
......@@ -6128,11 +6131,11 @@ class View {
$artefactcopies[$aid]->newid = $a->copy_for_new_owner(
$this->get('owner'),
$this->get('group'),
$this->get('institution')
$this->get($type)
);
}
}
// Update the image urls in the description
// Update the image urls in the settings field
if (!empty($artefactcopies)) {
$regexp = array();
$replacetext = array();
......@@ -6149,10 +6152,10 @@ class View {
. 'artefact/file/download.php?file=' . $newobj->newid
. '&embedded=1"';
}
$new_description = preg_replace($regexp, $replacetext, $new_description);
$new_setting_field = preg_replace($regexp, $replacetext, $new_setting_field);
}
}
return $new_description;
return $new_setting_field;
}
/**
......
......@@ -13,6 +13,7 @@
{/if}
<p id="view-description">{$viewdescription|clean_html|safe}</p>
<p id="view-instructions">{$viewinstructions|clean_html|safe}</p>
{$view|safe}
......
......@@ -8,6 +8,7 @@
{if $updated} <updated>{$updated}</updated>{/if}
{if $created} <published>{$created}</published>{/if}
{if $summary} <summary{if $summarytype != 'text'} type="{$summarytype}"{/if}>{if $summarytype == 'xhtml'}<div xmlns="http://www.w3.org/1999/xhtml">{/if}{if $summarytype == 'xhtml'}{$summary|export_leap_rewrite_links|safe}{elseif $summarytype == 'html'}{$summary|export_leap_rewrite_links}{else}{$summary}{/if}{if $summarytype == 'xhtml'}</div>{/if}</summary>{/if}
{if $instructions} <subtitle{if $instructionstype != 'text'} type="{$instructionstype}"{/if}>{if $instructionstype == 'xhtml'}<div xmlns="http://www.w3.org/1999/xhtml">{/if}{if $instructionstype == 'xhtml'}{$instructions|export_leap_rewrite_links|safe}{elseif $instructionstype == 'html'}{$instructions|export_leap_rewrite_links}{else}{$instructions}{/if}{if $instructionstype == 'xhtml'}</div>{/if}</subtitle>{/if}
<content{if $contenttype != 'text' && $contenttype != ''} type="{$contenttype}"{/if}>{if $contenttype == 'xhtml'}<div xmlns="http://www.w3.org/1999/xhtml">{/if}{if $contenttype == 'xhtml'}{$content|export_leap_rewrite_links|safe}{elseif $contenttype == 'html'}{$content|export_leap_rewrite_links}{else}{$content}{/if}{if $contenttype == 'xhtml'}</div>{/if}</content>
<rdf:type rdf:resource="leap2:{$leaptype}"/>
{if $artefacttype} <mahara:artefactplugin mahara:type="{$artefacttype}" mahara:plugin="{$artefactplugin}"/>{/if}
......
......@@ -8,6 +8,9 @@
<p class="view-description">
{$viewdescription|clean_html|safe}
</p>
<p class="view-instructions">
{$viewinstructions|clean_html|safe}
</p>
<div id="view" class="view-container">
<div id="bottom-pane">
<div id="column-container">
......
......@@ -25,6 +25,7 @@ $smarty = smarty_core();
$smarty->assign('viewtitle', $view->get('title'));
$smarty->assign('ownername', $view->formatted_owner());
$smarty->assign('viewdescription', ArtefactTypeFolder::append_view_url($view->get('description'), $view->get('id')));
$smarty->assign('viewinstructions', ArtefactTypeFolder::append_view_url($view->get('instructions'), $view->get('id')));
$smarty->assign('viewcontent', $view->build_rows(false, true));
list($tagcount, $alltags) = $view->get_all_tags_for_view();
......
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