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

Bug 1813987: Importing views with grid layout

Importing views and collection with new grid layout

- leap2A files containing views/collections with
new grid layout are imported and created with the new layout

- leap2A files containing collections/view with old layout
will be created with a grid layout. This new layout is
the translation of the old layout they had in the leap2A file.
The heights of the blocks will be updated when the
views are first displayed in the browser.

behatnotneeded

Change-Id: Ia43b7a5c11109023d3caa65ba16e3b6aebcdbe75
parent b6cd876f
......@@ -1651,9 +1651,10 @@ class BlockInstance {
$this->rebuild_artefact_list();
// check the table exists in case we need to update a block in the upgrade before the creation of the table
if (db_table_exists('block_instance_dimension')) {
if (db_table_exists('block_instance_dimension') && isset($this->positionx)) {
$this->set_block_dimensions($this->positionx, $this->positiony, $this->width, $this->height);
}
// Tell stuff about this
handle_event('blockinstancecommit', $this);
......
This diff is collapsed.
......@@ -29,7 +29,7 @@ function save_blocks_in_new_layout($viewid) {
if ($newlayoutcontent) {
foreach ($newlayoutcontent as $block) {
insert_record('block_instance_dimension', $block);
insert_record('block_instance_dimension', (object) $block);
}
}
}
......@@ -54,13 +54,19 @@ function translate_to_new_layout($blocks) {
foreach ($row as $column) {
if (isset($column['blocks'])) {
foreach ($column['blocks'] as $order => $block) {
$gridblocks[] = (object) array(
'block' => $block,
$gridblock = array(
'positionx' => $x,
'positiony' => $y + $order - 1,
'width' => $column['width'],
'height' => 1,
);
if (is_array($block)) {
$gridblock = array_merge($block, $gridblock);
}
else {
$gridblock['block'] = $block;
}
$gridblocks[] = $gridblock;
$maxorder = max($maxorder, $order);
}
}
......
......@@ -2535,14 +2535,16 @@ public function get_blocks($editing=false, $exporting=false, $versioning=false)
* block => block to add
*/
public function addblockinstance(BlockInstance $bi) {
if (!$bi->get('row')) {
$bi->set('row', 1);
}
if (!$bi->get('column')) {
$bi->set('column', 1);
}
if (!$bi->get('order')) {
$bi->set('order', 1);
if ($this->uses_new_layout()) {
if (!$bi->get('row')) {
$bi->set('row', 1);
}
if (!$bi->get('column')) {
$bi->set('column', 1);
}
if (!$bi->get('order')) {
$bi->set('order', 1);
}
}
if (!$bi->get('view')) {
$bi->set('view', $this->get('id'));
......@@ -3250,12 +3252,19 @@ public function get_blocks($editing=false, $exporting=false, $versioning=false)
'title' => $config['title'],
'description' => $config['description'],
'type' => $config['type'],
'layout' => $config['layout'],
'tags' => $config['tags'],
'numrows' => $config['numrows'],
'ownerformat' => $config['ownerformat'],
'instructions' => $config['instructions'],
);
if (isset($config['layout'])) {
$viewdata['layout'] = $config['layout'];
}
if (isset($config['numrows'])) {
$viewdata['numrows'] = $config['numrows'];
}
$viewdata['newlayout'] = true;
if (isset($config['owner'])) {
$viewdata['owner'] = $config['owner'];
}
......@@ -3267,33 +3276,35 @@ public function get_blocks($editing=false, $exporting=false, $versioning=false)
$viewdata['institution'] = $config['institution'];
}
$view = View::create($viewdata, $userid);
foreach ($config['rows'] as $rowkey => $row) {
foreach ($row['columns'] as $colkey => $column) {
$order = 1;
foreach ($column as $blockinstance) {
safe_require('blocktype', $blockinstance['type']);
$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('row', $rowkey);
$bi->set('column', $colkey);
$bi->set('order', $order);
$view->addblockinstance($bi);
$order++;
}
else {
log_debug("Blocktype {$blockinstance['type']}'s import_create_blockinstance did not give us a blockinstance, so not importing this block");
if (isset($config['grid'])) {
foreach ($config['grid'] as $blockinstance) {
safe_require('blocktype', $blockinstance['type']);
$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('positionx', $blockinstance['positionx']);
$bi->set('positiony', $blockinstance['positiony']);
$bi->set('width', $blockinstance['width']);
$bi->set('height', $blockinstance['height']);
if (isset($blockinstance['row'])) {
// if we are importing and the layout is not a grid one,
// we'll need this values whn updating the heights of the blocks
$bi->set('row', $blockinstance['row']);
$bi->set('column', $blockinstance['column']);
$bi->set('order', $blockinstance['order']);
}
$view->addblockinstance($bi);
}
} // cols
} // rows
else {
log_debug("Blocktype {$blockinstance['type']}'s import_create_blockinstance did not give us a blockinstance, so not importing this block");
}
}
}
if ($viewdata['type'] == 'profile') {
$view->set_access(array(
......
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