Commit e71fe154 authored by Nigel McNie's avatar Nigel McNie
Browse files

Allow the View methods export_config and import_config to take an optional format parameter.



This allows us to hint that the View needs to export config suitable for
a certain format (e.g. leap), so it can give us data we can manage in an
easier form.
Signed-off-by: default avatarNigel McNie <nigel@catalyst.net.nz>
parent 50a7d5b1
......@@ -1504,16 +1504,16 @@ class View {
}
/**
* Exports the view configuration as a data structure. This does not
* include access rules or ownership information - only the information
* Exports the view configuration as a data structure. This does not
* include access rules or ownership information - only the information
* required to rebuild the view's layout, blocks and other such info.
*
* This structure can then be imported again, using {@link import_from_config()}
*
* @return array The configuration for this view, try calling this to see
* @return array The configuration for this view, try calling this to see
* what fields are available.
*/
public function export_config() {
public function export_config($format='') {
$data = $this->get_column_datastructure();
$config = array(
'title' => $this->get('title'),
......@@ -1529,10 +1529,15 @@ class View {
$config['columns'][$key] = array();
foreach ($column['blockinstances'] as $bi) {
safe_require('blocktype', $bi->get('blocktype'));
$classname = generate_class_name('blocktype', $bi->get('blocktype'));
$method = 'export_blockinstance_config';
if (method_exists($classname, $method . "_$format")) {
$method .= "_$format";
}
$config['columns'][$key][] = array(
'blocktype' => $bi->get('blocktype'),
'title' => $bi->get('title'),
'config' => call_static_method(generate_class_name('blocktype', $bi->get('blocktype')), 'export_blockinstance_config', $bi),
'config' => call_static_method($classname, $method, $bi),
);
}
}
......@@ -1541,17 +1546,17 @@ class View {
}
/**
* Given a data structure like the one created by {@link export_config},
* Given a data structure like the one created by {@link export_config},
* creates and returns a View object representing the config.
*
* @param array $config The config, as generated by export_config. Note
* that if you miss fields, this method will throw
* warnings.
* @param int $userid The user who issued the command to do the import
* @param int $userid The user who issued the command to do the import
* (defaults to the logged in user)
* @return View The created view
*/
public static function import_from_config(array $config, $userid=null) {
public static function import_from_config(array $config, $userid=null, $format='') {
$viewdata = array(
'title' => $config['title'],
'description' => $config['description'],
......@@ -1577,7 +1582,12 @@ class View {
$row = 1;
foreach ($column as $blockinstance) {
safe_require('blocktype', $blockinstance['type']);
$bi = call_static_method(generate_class_name('blocktype', $blockinstance['type']), 'import_create_blockinstance', $blockinstance);
$classname = generate_class_name('blocktype', $blockinstance['type']);
$method = 'import_create_blockinstance';
if (method_exists($classname, $method . "_$format")) {
$method .= "_$format";
}
$bi = call_static_method($classname, $method, $blockinstance, $config);
if ($bi) {
$bi->set('title', $blockinstance['title']);
$bi->set('column', $col);
......
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