Commit 728f9986 authored by Son Nguyen's avatar Son Nguyen Committed by Robert Lyon

Include collections in HTML export. Bug 1457663

behatnotneeded

Change-Id: I26b1a5aa14fd4f151a4ee0d80a7bab3c96b55029
(cherry picked from commit 57cc85e9)
parent afe9e661
......@@ -142,7 +142,7 @@ function bulkexport_submit(Pieform $form, $values) {
continue; // Skip non-existent users
}
$exporter = new PluginExportLeap($user, PluginExport::EXPORT_ALL_VIEWS, PluginExport::EXPORT_ALL_ARTEFACTS);
$exporter = new PluginExportLeap($user, PluginExport::EXPORT_ALL_VIEWS_COLLECTIONS, PluginExport::EXPORT_ALL_ARTEFACTS);
try {
$zipfile = $exporter->export();
}
......
......@@ -17,7 +17,7 @@ class HtmlExportInternal extends HtmlExportArtefactPlugin {
public function dump_export_data() {
if (($this->exporter->get('viewexportmode') == PluginExport::EXPORT_LIST_OF_VIEWS
|| $this->exporter->get('viewexportmode') == PluginExport::EXPORT_COLLECTIONS)
|| $this->exporter->get('viewexportmode') == PluginExport::EXPORT_LIST_OF_COLLECTIONS)
&& $this->exporter->get('artefactexportmode') == PluginExport::EXPORT_ARTEFACTS_FOR_VIEWS) {
// Dont' care about profile information in this case
return;
......
......@@ -18,7 +18,7 @@ class HtmlExportResume extends HtmlExportArtefactPlugin {
public function dump_export_data() {
if (($this->exporter->get('viewexportmode') == PluginExport::EXPORT_LIST_OF_VIEWS
|| $this->exporter->get('viewexportmode') == PluginExport::EXPORT_COLLECTIONS)
|| $this->exporter->get('viewexportmode') == PluginExport::EXPORT_LIST_OF_COLLECTIONS)
&& $this->exporter->get('artefactexportmode') == PluginExport::EXPORT_ARTEFACTS_FOR_VIEWS) {
// Dont' care about resume in this case
return;
......
......@@ -74,13 +74,13 @@ $class = generate_class_name('export', $exportdata['format']);
switch($exportdata['what']) {
case 'all':
$exporter = new $class($user, PluginExport::EXPORT_ALL_VIEWS, PluginExport::EXPORT_ALL_ARTEFACTS, 'export_iframe_progress_handler');
$exporter = new $class($user, PluginExport::EXPORT_ALL_VIEWS_COLLECTIONS, PluginExport::EXPORT_ALL_ARTEFACTS, 'export_iframe_progress_handler');
break;
case 'views':
$exporter = new $class($user, $exportdata['views'], PluginExport::EXPORT_ARTEFACTS_FOR_VIEWS, 'export_iframe_progress_handler');
break;
case 'collections':
$exporter = new $class($user, $exportdata['views'], PluginExport::EXPORT_COLLECTIONS, 'export_iframe_progress_handler');
$exporter = new $class($user, $exportdata['views'], PluginExport::EXPORT_LIST_OF_COLLECTIONS, 'export_iframe_progress_handler');
break;
default:
export_iframe_die(get_string('unabletoexportportfoliousingoptions', 'export'));
......
......@@ -160,7 +160,7 @@ class PluginExportHtml extends PluginExport {
$artefactexporter = new $classname($this);
$artefactexporter->dump_export_data();
// If just exporting a list of views, we don't care about the summaries for each artefact plugin
if (!(($this->viewexportmode == PluginExport::EXPORT_LIST_OF_VIEWS || $this->viewexportmode == PluginExport::EXPORT_COLLECTIONS)
if (!(($this->viewexportmode == PluginExport::EXPORT_LIST_OF_VIEWS || $this->viewexportmode == PluginExport::EXPORT_LIST_OF_COLLECTIONS)
&& $this->artefactexportmode == PluginExport::EXPORT_ARTEFACTS_FOR_VIEWS)) {
$summaries[$plugin] = array($artefactexporter->get_summary_weight(), $artefactexporter->get_summary());
}
......@@ -187,16 +187,20 @@ class PluginExportHtml extends PluginExport {
$this->dump_view_export_data();
if (!$this->exportingoneview) {
$summaries['view'] = array(100, $this->get_view_summary());
$viewcollectionsumary = $this->get_view_collection_summary();
$summaries['view'] = array(100, $viewcollectionsumary['view']);
$summaries['collection'] = array(110, $viewcollectionsumary['collection']);
// Sort by weight (then drop the weight information)
$this->notify_progress_callback(75, get_string('buildingindexpage', 'export.html'));
uasort($summaries, create_function('$a, $b', 'return $a[0] > $b[0];'));
uasort($summaries, function ($a, $b) {
return $a[0] > $b[0];
});
foreach ($summaries as &$summary) {
$summary = $summary[1];
}
// Build index.html
$this->notify_progress_callback(75, get_string('buildingindexpage', 'export.html'));
$this->build_index_page($summaries);
}
......@@ -367,7 +371,9 @@ class PluginExportHtml extends PluginExport {
}
// Collection menu data
if (isset($this->viewcollection[$viewid]) && $this->viewexportmode == PluginExport::EXPORT_COLLECTIONS) {
if (isset($this->viewcollection[$viewid])
&& ($this->viewexportmode == PluginExport::EXPORT_LIST_OF_COLLECTIONS
|| $this->viewexportmode == PluginExport::EXPORT_ALL_VIEWS_COLLECTIONS)) {
$smarty->assign_by_ref('collectionname', $this->collections[$this->viewcollection[$viewid]]->get('name'));
$smarty->assign_by_ref('collectionmenu', $this->collection_menu($this->viewcollection[$viewid]));
$smarty->assign('viewid', $viewid);
......@@ -395,12 +401,24 @@ class PluginExportHtml extends PluginExport {
}
}
private function get_view_summary() {
$smarty = $this->get_smarty('../');
/**
* Returns a summary about views and/or collections
*
* @return array(
* 'view' => array(
* 'title' => ...
* 'description' => ...
* )
* 'collection' => array(
* 'title' => ...
* 'description' => ...
* )
*/
private function get_view_collection_summary() {
$list = array();
foreach ($this->collections as $id => $collection) {
$list['c' . $id] = array(
$list['collections'][$id] = array(
'title' => $collection->get('name'),
'views' => array(),
);
......@@ -414,51 +432,63 @@ class PluginExportHtml extends PluginExport {
'title' => $view->get('title'),
'folder' => self::text_to_filename($view->get('title')),
);
if (isset($this->viewcollection[$id])) {
$list['c' . $this->viewcollection[$id]]['views'][] = $item;
if (isset($this->viewcollection[$id])
&& ($this->viewexportmode == self::EXPORT_ALL_VIEWS_COLLECTIONS
|| $this->viewexportmode == self::EXPORT_LIST_OF_COLLECTIONS)) {
$list['collections'][$this->viewcollection[$id]]['views'][$id] = $item;
}
else {
$list[$id] = $item;
$list['views'][$id] = $item;
$nviews++;
}
$nviews++;
}
}
function sort_by_title($a, $b) {
return strnatcasecmp($a['title'], $b['title']);
}
foreach (array_keys($this->collections) as $id) {
usort($list['c' . $id]['views'], 'sort_by_title');
usort($list['collections'][$id]['views'], 'sort_by_title');
}
usort($list['views'], 'sort_by_title');
if ($ncollections) {
usort($list['collections'], 'sort_by_title');
}
usort($list, 'sort_by_title');
$smarty->assign('list', $list);
if ($list) {
if ($this->viewexportmode != PluginExport::EXPORT_COLLECTIONS) {
$stryouhaveviews = ($nviews == 1)
? get_string('youhaveoneview', 'view')
: get_string('youhaveviews', 'view', $nviews);
}
else {
$stryouhavecollections = ($ncollections == 1)
? get_string('youhaveonecollection', 'collection')
: get_string('youhavecollections', 'collection', $ncollections);
$smarty->assign('stryouhavecollections', $stryouhavecollections);
return array(
'title' => get_string('Collections', 'collection'),
'description' => $smarty->fetch('export:html:collectionsummary.tpl'),
);
}
// View summary
$summary['view'] = array();
$smarty = $this->get_smarty('../');
if (!empty($list['views'])
&& ($this->viewexportmode == self::EXPORT_ALL_VIEWS_COLLECTIONS
|| $this->viewexportmode == self::EXPORT_LIST_OF_VIEWS)) {
$stryouhaveviews = ($nviews == 1)
? get_string('youhaveoneview', 'view')
: get_string('youhaveviews', 'view', $nviews);
$smarty->assign('stryouhaveviews', $stryouhaveviews);
$smarty->assign('list', $list['views']);
$summary['view'] = array(
'title' => get_string('Views', 'view'),
'description' => $smarty->fetch('export:html:viewsummary.tpl'),
);
}
else {
$stryouhaveviews = get_string('youhavenoviews', 'view');
// Collection summary
$summary['collection'] = array();
$smarty = $this->get_smarty('../');
if (!empty($list['collections'])
&& ($this->viewexportmode == self::EXPORT_ALL_VIEWS_COLLECTIONS
|| $this->viewexportmode == self::EXPORT_LIST_OF_COLLECTIONS)) {
$stryouhavecollections = ($ncollections == 1)
? get_string('youhaveonecollection', 'collection')
: get_string('youhavecollections', 'collection', $ncollections);
$smarty->assign('stryouhavecollections', $stryouhavecollections);
$smarty->assign('list', $list['collections']);
$summary['collection'] = array(
'title' => get_string('Collections', 'collection'),
'description' => $smarty->fetch('export:html:collectionsummary.tpl'),
);
}
$smarty->assign('stryouhaveviews', $stryouhaveviews);
return array(
'title' => get_string('Views', 'view'),
'description' => $smarty->fetch('export:html:viewsummary.tpl'),
);
return $summary;
}
/**
......@@ -483,10 +513,6 @@ class PluginExportHtml extends PluginExport {
// Smilies
$directoriestocopy[get_config('docroot') . 'js/tinymce/plugins/emoticons/img'] = $staticdir . 'smilies/';
$filestocopy = array(
get_config('docroot') . 'theme/views.css' => $staticdir . 'views.css',
);
foreach ($this->pluginstaticdirs as $dir) {
$destinationdir = str_replace('export/html/', '', $dir);
if (!check_dir_exists($staticdir . $destinationdir)) {
......@@ -505,11 +531,6 @@ class PluginExportHtml extends PluginExport {
}
}
foreach ($filestocopy as $from => $to) {
if (!is_file($from) || !copy($from, $to)) {
$SESSION->add_error_msg(get_string('couldnotcopystaticfile', 'export', $from));
}
}
}
}
......
......@@ -127,8 +127,8 @@ class PluginExportLeap extends PluginExport {
$this->export_header();
$this->setup_links();
$this->notify_progress_callback(10, get_string('exportingviews', 'export'));
if ($this->viewexportmode == PluginExport::EXPORT_COLLECTIONS
|| $this->viewexportmode == PluginExport::EXPORT_ALL_VIEWS) {
if ($this->viewexportmode == PluginExport::EXPORT_LIST_OF_COLLECTIONS
|| $this->viewexportmode == PluginExport::EXPORT_ALL_VIEWS_COLLECTIONS) {
$this->export_collections();
}
$this->export_views();
......
......@@ -43,9 +43,9 @@ interface IPluginExport {
abstract class PluginExport extends Plugin implements IPluginExport {
/**
* Export all views owned by this user
* Export all views and collections owned by this user
*/
const EXPORT_ALL_VIEWS = -1;
const EXPORT_ALL_VIEWS_COLLECTIONS = -1;
/**
* Export only certain views - used internally when a list of views is
......@@ -72,7 +72,7 @@ abstract class PluginExport extends Plugin implements IPluginExport {
/*
* Export only certain collections and their artefacts
*/
const EXPORT_COLLECTIONS = -6;
const EXPORT_LIST_OF_COLLECTIONS = -6;
/**
* Maximum filename length in UTF-8 encoding characters
......@@ -175,7 +175,7 @@ abstract class PluginExport extends Plugin implements IPluginExport {
*
* @param User $user The user to export data for
* @param mixed $views can be:
* - PluginExport::EXPORT_ALL_VIEWS
* - PluginExport::EXPORT_ALL_VIEWS_COLLECTIONS
* - array, containing:
* - int - view ids
* - stdclass objects - db rows
......@@ -183,7 +183,7 @@ abstract class PluginExport extends Plugin implements IPluginExport {
* @param mixed $artefacts can be:
* - PluginExport::EXPORT_ALL_ARTEFACTS
* - PluginExport::EXPORT_ARTEFACTS_FOR_VIEWS
* - PluginExport::EXPORT_COLLECTIONS
* - PluginExport::EXPORT_LIST_OF_COLLECTIONS
* - array, containing:
* - int - artefact ids
* - stdclass objects - db rows
......@@ -208,13 +208,13 @@ abstract class PluginExport extends Plugin implements IPluginExport {
$tmpartefacts = array();
// Get the list of views to export
if ($views == self::EXPORT_ALL_VIEWS) {
if ($views == self::EXPORT_ALL_VIEWS_COLLECTIONS) {
$tmpviews = get_column_sql('SELECT id FROM {view} WHERE owner = ? ORDER BY id', array($userid));
$this->viewexportmode = $views;
}
else if (is_array($views) && $artefacts == self::EXPORT_COLLECTIONS) {
else if (is_array($views) && $artefacts == self::EXPORT_LIST_OF_COLLECTIONS) {
$tmpviews = $views;
$this->viewexportmode = self::EXPORT_COLLECTIONS;
$this->viewexportmode = self::EXPORT_LIST_OF_COLLECTIONS;
}
else if (is_array($views)) {
$tmpviews = $views;
......@@ -272,7 +272,7 @@ abstract class PluginExport extends Plugin implements IPluginExport {
if ($artefacts == self::EXPORT_ARTEFACTS_FOR_VIEWS) {
$this->artefactexportmode = $artefacts;
}
else if ($artefacts == self::EXPORT_COLLECTIONS) {
else if ($artefacts == self::EXPORT_LIST_OF_COLLECTIONS) {
$this->artefactexportmode = self::EXPORT_ARTEFACTS_FOR_VIEWS;
}
else {
......@@ -626,13 +626,13 @@ function export_process_queue($id = false) {
switch($row->what) {
case 'all':
$exporter = new $class($user, PluginExport::EXPORT_ALL_VIEWS, PluginExport::EXPORT_ALL_ARTEFACTS);
$exporter = new $class($user, PluginExport::EXPORT_ALL_VIEWS_COLLECTIONS, PluginExport::EXPORT_ALL_ARTEFACTS);
break;
case 'views':
$exporter = new $class($user, $views, PluginExport::EXPORT_ARTEFACTS_FOR_VIEWS);
break;
case 'collections':
$exporter = new $class($user, $views, PluginExport::EXPORT_COLLECTIONS);
$exporter = new $class($user, $views, PluginExport::EXPORT_LIST_OF_COLLECTIONS);
break;
default:
$errors[] = get_string('unabletoexportportfoliousingoptionsadmin', 'export');
......
......@@ -110,6 +110,7 @@ $string['by'] = 'by';
$string['copycollection'] = 'Copy collection';
$string['youhaveonecollection'] = 'You have 1 collection.';
$string['youhavecollections'] = 'You have %s collections.';
$string['youhavenocollections'] = 'You have no collections.';
$string['collectionssharedtogroup'] = 'Collections shared with this group';
$string['nosharedcollectionsyet'] = 'There are no collections shared with this group yet';
$string['nextpage'] = 'Next page';
......
{if $list}
<p>{$stryouhavecollections}</p>
<ul>
{foreach from=$list item=item}
......@@ -14,3 +15,6 @@
{/if}
{/foreach}
</ul>
{else}
<p>{str tag=youhavenocollections section=collection}</p>
{/if}
{if $list}
<p>{$stryouhaveviews}</p>
<ul>
{foreach from=$list item=item}
......@@ -10,3 +11,6 @@
{/if}
{/foreach}
</ul>
{else}
<p>{str tag=youhavenoviews section=view}</p>
{/if}
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