Commit 3e76e38e authored by Kevin Dibble's avatar Kevin Dibble Committed by Robert Lyon

Bug 1781844: Lock blocks on pages

A lot of users in Mahara create (Template) pages to share out to users.
This reduces the setup a new user will have to do to. There is an issue
that on their personal copy, the blocks that were so carefully setup can
be deleted.

This functionality creates a new column in the database called
"lockblocks" that can be enabled/disabled on the share page.

When the user copies the page, this setting is copied over and the
"delete" icon is hidden from view should the lockblocks setting be
enabled. This only happens on normal portfolio pages.

To unset - the user can edit the page settings and
disable the lock blocks feature to enable the deletion of the blocks as
per normal.

behatnotneeded
Change-Id: I7a2062f77431d6371f95d7f55bedcc499dd7caa2
parent 09f8cbb4
......@@ -1039,6 +1039,7 @@ class BlockInstance {
$smarty->assign('strmovetitletext', $title == '' ? get_string('movethisblock', 'view') : get_string('moveblock', 'view', "'$title'"));
$smarty->assign('strconfigtitletext', $title == '' ? get_string('configurethisblock1', 'view', $id) : get_string('configureblock1', 'view', "'$title'", $id));
$smarty->assign('strremovetitletext', $title == '' ? get_string('removethisblock1', 'view', $id) : get_string('removeblock1', 'view', "'$title'", $id));
$smarty->assign('lockblocks', ($this->get_view()->get('lockblocks') && $this->get_view()->get('owner'))); // Only lock blocks for user's portfolio pages
if (!$configure && $title) {
$configdata = $this->get('configdata');
......@@ -1459,7 +1460,7 @@ class BlockInstance {
}
public function delete() {
if (empty($this->id)) {
if (empty($this->id) || ($this->get_view()->get('lockblocks') && $this->get_view()->get('owner'))) {
$this->dirty = false;
return;
}
......
......@@ -511,3 +511,6 @@ $string['textbox1'] = 'Note';
$string['image'] = 'Image';
$string['addcontent'] = 'Add Content';
$string['theme'] = 'Theme';
$string['lockblocks'] = "Lock blocks";
$string['lockblocksdescription'] = "You can lock the blocks on the page and prevent that they are removed when people copy the page.";
\ No newline at end of file
......@@ -904,6 +904,7 @@ class Collection {
'allowcomments' => $firstview->get('allowcomments'),
'approvecomments' => (int) ($firstview->get('allowcomments') && $firstview->get('approvecomments')),
'accesslist' => $firstview->get_access(),
'lockblocks' => $firstview->get('lockblocks'),
);
View::update_view_access($viewconfig, $viewids);
}
......
......@@ -787,6 +787,7 @@
<FIELD NAME="locked" TYPE="int" LENGTH="1" DEFAULT="0" NOTNULL="true" />
<FIELD NAME="urlid" TYPE="char" LENGTH="100" NOTNULL="false" />
<FIELD NAME="anonymise" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="lockblocks" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
......
......@@ -5959,5 +5959,13 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2018080900) {
log_debug('Create a new "lockblock" field in "view" table');
$table = new XMLDBTable('view');
$field = new XMLDBField('lockblocks');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
add_field($table, $field);
}
return $status;
}
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2018080200;
$config->version = 2018080900;
$config->series = '18.10';
$config->release = '18.10dev';
$config->minupgradefrom = 2015030409;
......
......@@ -12,7 +12,6 @@
defined('INTERNAL') || die();
class View {
private $dirty;
private $deleted;
private $id;
......@@ -63,6 +62,7 @@ class View {
private $urlid;
private $skin;
private $anonymise = 0;
private $lockblocks = 0;
const UNSUBMITTED = 0;
const SUBMITTED = 1;
......@@ -464,6 +464,9 @@ class View {
return array(null, $template, array('quotaexceeded' => true));
}
// Lockblocks if set on template
$view->set('lockblocks', $template->get('lockblocks'));
$view->commit();
// if layout is set, and it's not a default layout
......@@ -604,6 +607,7 @@ class View {
'type' => 'portfolio',
'title' => (array_key_exists('title', $viewdata)) ? $viewdata['title'] : self::new_title(get_string('Untitled', 'view'), (object)$viewdata),
'anonymise' => 0,
'lockblocks' => 0,
);
$data = (object)array_merge($defaultdata, $viewdata);
......@@ -1131,7 +1135,8 @@ class View {
|| ($c = strcmp($a->startdate, $b->startdate))
|| ($c = !empty($a->stopdate) - !empty($b->stopdate))
|| ($c = strcmp($a->stopdate, $b->stopdate))
|| ($c = $a->allowcomments - $b->allowcomments)) {
|| ($c = $a->allowcomments - $b->allowcomments)
|| ($c = $a->lockblocks - $b->lockblocks)) {
return $c;
}
return $a->approvecomments - $b->approvecomments;
......@@ -5896,6 +5901,7 @@ class View {
public function copy_contents($template, &$artefactcopies) {
$this->set('lockblocks', $template->get('lockblocks'));
$this->set('numrows', $template->get('numrows'));
$this->set('layout', $template->get('layout'));
if ($template->get('template') == self::SITE_TEMPLATE
......
......@@ -780,6 +780,7 @@ EOD;
'allowcomments' => (int) (isset($record['allowcomments']) ? $record['allowcomments'] : 1),
'approvecomments' => (int) (isset($record['approvecomments']) ? $record['approvecomments'] : 0),
'accesslist' => $accesslist,
'lockblocks' => (int) (isset($record['lockblocks']) ? $record['lockblocks'] : 0),
);
require_once('view.php');
......
......@@ -23,9 +23,11 @@
<span class="icon icon-cog icon-lg" role="presentation" aria-hidden="true"></span>
</button>
{/if}
{if !$lockblocks}
<button class="deletebutton btn btn-inverse btn-xs" name="action_removeblockinstance_id_{$id}" alt="{$strremovetitletext}" data-id="{$id}">
<span class="icon icon-trash text-danger icon-lg" role="presentation" aria-hidden="true"></span>
</button>
{/if}
</span>
</span>
</h3>
......
......@@ -277,6 +277,12 @@ function get_basic_elements() {
'defaultvalue' => $view->get('description'),
'rules' => array('maxlength' => 65536),
),
'lockblocks' => array(
'type' => 'switchbox',
'title' => get_string('lockblocks', 'view'),
'description' => get_string('lockblocksdescription', 'view'),
'defaultvalue' => $view->get('lockblocks'),
),
'tags' => array(
'type' => 'tags',
'title' => get_string('tags'),
......@@ -928,6 +934,9 @@ function set_view_title_and_description(Pieform $form, $values){
if (isset($values['locked'])) {
$view->set('locked', (int)$values['locked']);
}
if (isset($values['lockblocks'])) {
$view->set('lockblocks', (int)$values['lockblocks']);
}
if (isset($values['ownerformat']) && $view->get('owner')) {
$view->set('ownerformat', $values['ownerformat']);
}
......
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