Commit d2987e63 authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic
Browse files

Bug 1661139: add delete option in view screen

option to delete page is enable for:
    - Normal user in its own pages
    - For group pages
        To admin user
        To other roles if they have Create and Edit permission
         in group setting and page is not locked
    - For institution, to site admin

behatnotneeded

Change-Id: I424c8a103e55d46178d779b77ebfb79db2d504f3
parent 359f3540
......@@ -872,7 +872,9 @@ class View {
delete_records('view_autocreate_grouptype', 'view', $this->id);
delete_records('view_tag','view',$this->id);
delete_records('view_visit','view',$this->id);
delete_records('collection_view','view',$this->id);
if ($collection = $this->get_collection()) {
$collection->remove_view($this->id);
}
delete_records('usr_watchlist_view','view',$this->id);
if ($blockinstanceids = get_column('block_instance', 'id', 'view', $this->id)) {
require_once(get_config('docroot') . 'blocktype/lib.php');
......
......@@ -59,24 +59,35 @@
{str tag=print section=view}
</a>
</li>
{if $LOGGEDIN && !$userisowner}
<li>
<a id="toggle_watchlist_link" class="watchlist" href="">
{if $viewbeingwatched}
<span class="icon icon-eye-slash left" role="presentation" aria-hidden="true"></span>
{str tag=removefromwatchlist section=view}
{else}
<span class="icon icon-eye left" role="presentation" aria-hidden="true"></span>
{str tag=addtowatchlist section=view}
{/if}
</a>
</li>
<li>
<a id="objection_link" href="#" data-toggle="modal" data-target="#report-form">
<span class="icon icon-lg icon-flag text-danger left" role="presentation" aria-hidden="true"></span>
{str tag=reportobjectionablematerial}
</a>
</li>
{if $LOGGEDIN}
{if !$userisowner}
<li>
<a id="toggle_watchlist_link" class="watchlist" href="">
{if $viewbeingwatched}
<span class="icon icon-eye-slash left" role="presentation" aria-hidden="true"></span>
{str tag=removefromwatchlist section=view}
{else}
<span class="icon icon-eye left" role="presentation" aria-hidden="true"></span>
{str tag=addtowatchlist section=view}
{/if}
</a>
</li>
<li>
<a id="objection_link" href="#" data-toggle="modal" data-target="#report-form">
<span class="icon icon-lg icon-flag text-danger left" role="presentation" aria-hidden="true"></span>
{str tag=reportobjectionablematerial}
</a>
</li>
{/if}
{if $userisowner || $canremove}
<li>
<a href="{$WWWROOT}view/delete.php?id={$viewid}" title="{str tag=deletethisview section=view}">
<span class="icon icon-lg icon-trash text-danger" role="presentation" aria-hidden="true"></span>
<span class="sr-only">{str(tag=deletespecific arg1=$maintitle)|escape:html|safe}</span>
{str tag=deletethisview section=view}
</a>
</li>
{/if}
{/if}
</ul>
</div>
......
......@@ -33,17 +33,41 @@ if ($collection) {
$institution = $view->get('institution');
View::set_nav($groupid, $institution);
if ($groupid) {
$goto = 'groupviews.php?group=' . $groupid;
//pressing the delete button from inside page view that belongs to a collection
if ($collection) {
$views = $collection->get_viewids();
if (($key = array_search($viewid, $views)) !== false) {
unset($views[$key]);
}
if ($id = reset($views)) {
if ($collection->has_framework()) {
$goto = 'module/framework/matrix.php?id=' . $collection->get('id');
}
else {
$goto = 'view/view.php?id=' . $id;
}
}
else {
$goto = 'collection/index.php';
if ($groupid) {
$goto .= '?group=' . $groupid;
}
else if ($institution) {
$goto .= '?institution=' . $institution;
}
}
}
else if ($groupid) {
$goto = 'view/groupviews.php?group=' . $groupid;
}
else if ($institution) {
$goto = 'institutionviews.php?institution=' . $institution;
$goto = 'view/institutionviews.php?institution=' . $institution;
}
else {
$query = get_querystring();
// remove the id
$query = preg_replace('/id=([0-9]+)\&/','',$query);
$goto = 'index.php?' . $query;
$goto = 'view/index.php?' . $query;
}
define('TITLE', get_string('deletespecifiedview', 'view', $view->get('title')));
......@@ -58,7 +82,7 @@ $form = pieform(array(
'type' => 'submitcancel',
'class' => 'btn-default',
'value' => array(get_string('yes'), get_string('no')),
'goto' => get_config('wwwroot') . 'view/' . $goto,
'goto' => get_config('wwwroot') . $goto,
)
),
));
......@@ -70,20 +94,19 @@ $smarty->assign('collectionnote', $collectionnote);
$smarty->display('view/delete.tpl');
function deleteview_submit(Pieform $form, $values) {
global $SESSION, $USER, $viewid, $groupid, $institution, $goto;
global $SESSION, $USER, $viewid, $groupid, $institution;
$submitelement = $form->get_element('submit');
$view = new View($viewid, null);
if (View::can_remove_viewtype($view->get('type')) || $USER->get('admin')) {
$collectionid = $view->collection_id();
$view->delete();
if ($collection = new Collection($collectionid)) {
$collection->update_display_order();
}
$SESSION->add_ok_msg(get_string('viewdeleted', 'view'));
}
else {
$SESSION->add_error_msg(get_string('cantdeleteview', 'view'));
}
if ($groupid) {
redirect('/view/groupviews.php?group='.$groupid);
}
if ($institution) {
redirect('/view/institutionviews.php?institution='.$institution);
}
redirect('/view/' . $goto);
redirect( $submitelement['goto']);
}
......@@ -346,6 +346,7 @@ if ($collection) {
}
}
$smarty->assign('canremove', $can_edit);
$smarty->assign('INLINEJAVASCRIPT', $javascript . $inlinejs);
$smarty->assign('new', $new);
$smarty->assign('viewid', $viewid);
......
Supports Markdown
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