Commit 2d97e862 authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1801057: Add navigation block to all pages in collection



This patch allows:
- Ability to add navigation block to all pages of collection
- Places the navigation block in same place on all pages
- Only adds it to pages that don't already have a navigation block
with particular collection chosen

behatnotneeded

Change-Id: Ie4c793bbe2d0f8f1601c16cada444b4c3855ae0e
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent df539084
......@@ -16,3 +16,5 @@ $string['collection'] = 'Collection';
$string['title'] = 'Navigation';
$string['description'] = 'Navigation for a collection of pages (see Portfolio -> Collections, or the Collections tab when inside a group)';
$string['nocollections1'] = 'No collections. <a href="%s">Create one</a>.';
$string['copytoall'] = 'Add to all pages';
$string['copytoalldesc'] = 'Add the navigation block to all the current pages in the collection this page belongs to that do not already have it.';
......@@ -97,8 +97,7 @@ class PluginBlocktypeNavigation extends MaharaCoreBlocktype {
}
$options[$collection->id] = $collection->name;
}
return array(
$elements = array(
'collection' => array(
'type' => 'select',
'title' => get_string('collection','blocktype.navigation'),
......@@ -107,6 +106,15 @@ class PluginBlocktypeNavigation extends MaharaCoreBlocktype {
'defaultvalue' => !empty($configdata['collection']) ? $configdata['collection'] : $default,
),
);
if ($pageincollection = $view->get_collection()) {
$elements['copytoall'] = array(
'type' => 'switchbox',
'title' => get_string('copytoall', 'blocktype.navigation'),
'description' => get_string('copytoalldesc', 'blocktype.navigation'),
'defaultvalue' => false,
);
}
return $elements;
}
else {
$baseurl = get_config('wwwroot') . 'collection/edit.php';
......@@ -125,6 +133,50 @@ class PluginBlocktypeNavigation extends MaharaCoreBlocktype {
}
public static function instance_config_save($values, $instance) {
if (!empty($values['copytoall'])) {
$view = $instance->get('view_obj');
if ($collection = $view->get_collection()) {
foreach ($viewids = $collection->get_viewids() as $vid) {
if ($vid !== (int)$view->get('id')) {
$needsblock = true;
if ($blocks = get_records_sql_array("SELECT id FROM {block_instance} WHERE blocktype = ? AND view = ?", array('navigation', $vid))) {
foreach ($blocks as $block) {
// need to check the block to see if it's for this navigation
$bi = new BlockInstance($block->id);
$configdata = $bi->get('configdata');
if (!empty($configdata['collection']) && $configdata['collection'] == $values['collection']) {
$needsblock = false;
}
}
}
if ($needsblock) {
// need to add new navigation block
$otherview = new View($vid);
$bi = new BlockInstance(0,
array(
'blocktype' => 'navigation',
'title' => '',
'row' => $instance->get('row'),
'column' => $instance->get('column'),
'order' => 1,
'configdata' => array(
'collection' => $values['collection'],
'retractable' => $values['retractable'],
'retractedonload' => $values['retractedonload'],
),
)
);
$otherview->addblockinstance($bi);
}
}
}
}
}
unset($values['copytoall']);
return $values;
}
public static function default_copy_type() {
return 'full';
}
......
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