Commit bf0d8393 authored by Aaron Wells's avatar Aaron Wells Committed by Gerrit Code Review
Browse files

Merge changes I93b6e505,I083d9254

* changes:
  Adding the dealing with collections (Bug #745418)
  Allow view to be copied from view/view.php (Bug #745418)
parents d4d399fe 6826f6a4
......@@ -163,3 +163,41 @@ addLoadEvent(function () {
});
}
});
jQuery(function($j) {
$j(".copyview").each(function() {
$j(this).click(function(e) {
if (e.target.href.match(/collection=(.*)/)) {
e.preventDefault();
// We need to let user choose from collection or view only
var collection = e.target.href.match(/collection=(.*)/)[1];
if (!$j('#dialog-confirm').length) {
$j('body').append('<div id="dialog-confirm" title="' + get_string('confirmcopytitle') + '">' + get_string('confirmcopydesc') + '</div>');
}
$j('#dialog-confirm').dialog({
resizable: false,
height: 200,
modal: true,
buttons: [
{
text: get_string('View'),
click: function() {
// drop the collection bit from the url
var url = e.target.href.replace(/collection=(.*)/, '');
console.log('copypage');
window.location = url;
}
},
{
text: get_string('Collection'),
click: function() {
console.log('copycollection');
window.location = e.target.href;
}
}
]
});
}
});
});
});
\ No newline at end of file
......@@ -15,6 +15,7 @@ defined('INTERNAL') || die();
$string['add'] = 'Add';
$string['addone'] = 'Add one';
$string['cancel'] = 'Cancel';
$string['copy'] = 'Copy';
$string['copytoclipboard'] = 'Copy secret URL to the clipboard';
$string['delete'] = 'Delete';
$string['deletespecific'] = 'Delete "%s"';
......
......@@ -367,11 +367,14 @@ $string['filescopiedfromviewtemplate'] = 'Files copied from %s';
$string['viewfilesdirname'] = 'viewfiles';
$string['viewfilesdirdesc'] = 'Files from copied pages';
$string['thisviewmaybecopied'] = 'Copying is allowed';
$string['thisviewmaynotbecopied'] = 'Copying is not allowed';
$string['copythisview'] = 'Copy this page';
$string['copyview'] = 'Copy page';
$string['createemptyview'] = 'Create empty page';
$string['copyaview'] = 'Copy a page';
$string['copyvieworcollection'] = 'Copy a page or collection';
$string['confirmcopytitle'] = 'Confirm copy';
$string['confirmcopydesc'] = 'Please choose which you would like to copy:';
$string['Untitled'] = 'Untitled';
$string['copyfornewusers'] = 'Copy for new users';
$string['copyfornewusersdescription1'] = 'Whenever a new user is created, automatically make a personal copy of the selected pages / collections in the user\'s portfolio.';
......
......@@ -3843,6 +3843,24 @@ class View {
return array(self::owner_sql($ownerobj), array());
}
/**
* Check if the view is copyable by the user.
*
* @return bool
*/
public function is_copyable() {
global $USER;
$search = new StdClass;
$search->copyableby = (object) array('group' => null, 'institution' => null, 'owner' => $USER->get('id'));
$results = self::view_search('', '', null, $search->copyableby, null, null, true, null, null, false, null, null, $this->id);
// Check that the this view is one the user is allowed to copy
if (!empty($results->count)) {
return true;
}
return false;
}
/**
* Get all views visible to a user. Complicated because a view v
* is visible to a user u at time t if any of the following are
......@@ -3871,10 +3889,11 @@ class View {
* @param bool $collection Use query against collection names and descriptions
* @param array $accesstypes Only return views visible due to the given access types
* @param array $tag Only return views with this tag
* @param integer $viewid Only return a particular view (find by view id)
*
*/
public static function view_search($query=null, $ownerquery=null, $ownedby=null, $copyableby=null, $limit=null, $offset=0,
$extra=true, $sort=null, $types=null, $collection=false, $accesstypes=null, $tag=null) {
$extra=true, $sort=null, $types=null, $collection=false, $accesstypes=null, $tag=null, $viewid=null) {
global $USER;
$admin = $USER->get('admin');
$loggedin = $USER->is_logged_in();
......@@ -4147,7 +4166,11 @@ class View {
}
}
}
// if we need to just check one view
if (!empty($viewid)) {
$where .= " AND v.id = ?";
$whereparams = array_merge($whereparams, array($viewid));
}
$ph = array_merge($fromparams, $whereparams);
$count = count_records_sql('SELECT COUNT(*) ' . $from . $where, $ph);
......@@ -6002,6 +6025,64 @@ function createview_submit(Pieform $form, $values) {
redirect(get_config('wwwroot') . 'view/edit.php?new=1&id=' . $view->get('id'));
}
/**
* Copy a view via a 'copy' url
* Currently for copying a page via a 'copy' button on view/view.php
*
* @param integer $id View id
* @param bool $istemplate (optional) If you want to mark as template
* @param integer $groupid (optional) The group to copy the view to
* @param integer $collectionid (optional) Provide the collection id to indicate we want
* to copy collection the view belongs to
*/
function copyview($id, $istemplate = false, $groupid = null, $collectionid = null) {
global $USER, $SESSION;
// check that the user can copy view
$view = new View($id);
if (!$view->is_copyable()) {
throw new AccessDeniedException(get_string('thisviewmaynotbecopied', 'view'));
}
// set up a packet of values to send to the create_from_template function
$values = array('new' => 1,
'owner' => $USER->get('id'),
'template' => (int) $istemplate,
);
if (!empty($groupid) && is_int($groupid)) {
$values['group'] = $groupid;
}
if (!empty($collectionid)) {
require_once(get_config('libroot') . 'collection.php');
list($collection, $template, $copystatus) = Collection::create_from_template($values, $collectionid);
if (isset($copystatus['quotaexceeded'])) {
$SESSION->add_error_msg(get_string('collectioncopywouldexceedquota', 'collection'));
redirect(get_config('wwwroot') . 'view/view.php?id=' . $id);
}
$SESSION->add_ok_msg(get_string('copiedpagesblocksandartefactsfromtemplate', 'collection',
$copystatus['pages'],
$copystatus['blocks'],
$copystatus['artefacts'],
$template->get('name'))
);
redirect(get_config('wwwroot') . 'collection/edit.php?copy=1&id=' . $collection->get('id'));
}
else {
list($view, $template, $copystatus) = View::create_from_template($values, $id);
if (isset($copystatus['quotaexceeded'])) {
$SESSION->add_error_msg(get_string('viewcopywouldexceedquota', 'view'));
redirect(get_config('wwwroot') . 'view/view.php?id=' . $id);
}
$SESSION->add_ok_msg(get_string('copiedblocksandartefactsfromtemplate', 'view',
$copystatus['blocks'],
$copystatus['artefacts'],
$template->get('title'))
);
redirect(get_config('wwwroot') . 'view/edit.php?new=1&id=' . $view->get('id'));
}
}
function createview_cancel_submit(Pieform $form, $values) {
if (isset($values['group'])) {
redirect(get_config('wwwroot') . 'view/groupviews.php?group=' . $values['group']);
......
......@@ -41,7 +41,7 @@
<div class="fr links">
{if $microheaderlinks}
{foreach from=$microheaderlinks item=item}
<a class="btn" href="{$item.url}">{$item.name}</a>
<a class="btn{if $item.class} {$item.class}{/if}" href="{$item.url}">{$item.name}</a>
{/foreach}
{/if}
<a class="btn nojs-hidden-inline" href="javascript:history.back()"><span class="btn-back">{str tag=back}</span></a>
......
......@@ -2,15 +2,18 @@
{if $notrudeform}<div class="message deletemessage">{$notrudeform|safe}</div>{/if}
{if !$microheaders && ($mnethost || $editurl)}
{if !$microheaders && ($mnethost || $editurl || $copyurl)}
<div class="viewrbuttons">
{if $editurl}{strip}
{if $new}
<a class="btn" href="{$editurl}">{str tag=back}</a>
{else}
<a title="{str tag=editthisview section=view}" href="{$editurl}" class="btn editview">{str tag=editthisview section=view}</a>
<a title="{str tag=editthisview section=view}" href="{$editurl}" class="btn editview">{str tag=edit section=mahara}</a>
{/if}
{/strip}{/if}
{if $copyurl}{strip}
<a title="{str tag=copythisview section=view}" href="{$copyurl}" class="btn copyview">{str tag=copy section=mahara}</a>
{/strip}{/if}
{if $mnethost}<a href="{$mnethost.url}" class="btn">{str tag=backto arg1=$mnethost.name}</a>{/if}
</div>
{/if}
......
......@@ -42,7 +42,7 @@
<div class="fr links">
{if $microheaderlinks}
{foreach from=$microheaderlinks item=item}
<a class="btn" href="{$item.url}">{$item.name}</a>
<a class="btn{if $item.class} {$item.class}{/if}" href="{$item.url}">{$item.name}</a>
{/foreach}
{/if}
<a class="btn nojs-hidden-inline" href="javascript:history.back()"><span class="btn-back">{str tag=back}</span></a>
......
<?php
/**
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
define('INTERNAL', 1);
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'view');
define('SECTION_PAGE', 'copy');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'group.php');
$viewid = param_integer('id');
$collection = param_integer('collection', null);
$groupid = param_integer('group', null);
$view = new View($viewid);
if (!$view->is_copyable()) {
throw new AccessDeniedException(get_string('thisviewmaynotbecopied', 'view'));
}
copyview($view->get('id'), 0, $groupid, $collection);
......@@ -185,7 +185,7 @@ function releaseview_submit() {
redirect($view->get_url());
}
$javascript = array('paginator', 'viewmenu', 'expandable', 'author');
$javascript = array('paginator', 'viewmenu', 'expandable', 'author', 'js/jquery/jquery-ui/js/jquery-ui-1.10.2.min.js');
$blocktype_js = $view->get_all_blocktype_javascript();
$javascript = array_merge($javascript, $blocktype_js['jsfiles']);
$inlinejs = "addLoadEvent( function() {\n" . join("\n", $blocktype_js['initjs']) . "\n});";
......@@ -222,6 +222,7 @@ if ($viewtheme && $THEME->basename != $viewtheme) {
$THEME = new Theme($viewtheme);
}
$headers = array('<link rel="stylesheet" type="text/css" href="' . append_version_number(get_config('wwwroot') . 'theme/views.css') . '">');
$headers[] = '<link rel="stylesheet" type="text/css" href="' . append_version_number(get_config('wwwroot') . 'js/jquery/jquery-ui/css/ui-lightness/jquery-ui-1.10.2.min.css') . '">';
$headers = array_merge($headers, $view->get_all_blocktype_css());
// Set up skin, if the page has one
$viewskin = $view->get('skin');
......@@ -248,6 +249,7 @@ if (get_config_plugin('blocktype', 'gallery', 'useslimbox2')) {
}
$can_edit = $USER->can_edit_view($view) && !$submittedgroup && !$view->is_submitted();
$can_copy = $view->is_copyable($view);
$viewgroupform = false;
if ($owner && $owner == $USER->get('id')) {
......@@ -263,7 +265,10 @@ $viewcontent = $view->build_rows(); // Build content before initialising smarty
$smarty = smarty(
$javascript,
$headers,
array(),
array('confirmcopytitle' => 'view',
'confirmcopydesc' => 'view',
'View' => 'view',
'Collection' => 'collection'),
array(
'stylesheets' => $extrastylesheets,
'sidebars' => false,
......@@ -347,6 +352,7 @@ if ($view->is_anonymous()) {
$titletext = ($collection && $shownav) ? hsc($collection->get('name')) : $view->display_title(true, false, false);
$smarty->assign('visitstring', $view->visit_message());
if (get_config('viewmicroheaders')) {
$microheaderlinks = array();
$smarty->assign('microheaders', true);
$smarty->assign('microheadertitle', $titletext);
......@@ -364,28 +370,37 @@ if (get_config('viewmicroheaders')) {
if ($can_edit) {
if ($new) {
$microheaderlinks = array(
array(
'name' => get_string('back'),
'url' => get_config('wwwroot') . 'view/blocks.php?id=' . $viewid . '&new=1',
'type' => 'reply',
),
$microheaderlinks[] = array(
'name' => get_string('back'),
'url' => get_config('wwwroot') . 'view/blocks.php?id=' . $viewid . '&new=1',
'type' => 'reply',
);
}
else {
$microheaderlinks = array(
array(
'name' => get_string('editthisview', 'view'),
'image' => $THEME->get_url('images/btn_edit.png'),
'url' => get_config('wwwroot') . 'view/blocks.php?id=' . $viewid,
),
$microheaderlinks[] = array(
'name' => get_string('edit', 'mahara'),
'image' => $THEME->get_url('images/btn_edit.png'),
'url' => get_config('wwwroot') . 'view/blocks.php?id=' . $viewid,
);
}
$smarty->assign('microheaderlinks', $microheaderlinks);
}
if ($can_copy) {
$microheaderlinks[] = array(
'name' => get_string('copy', 'mahara'),
'image' => $THEME->get_url('images/btn_edit.png'),
'url' => get_config('wwwroot') . 'view/copy.php?id=' . $viewid . (!empty($collection) ? '&collection=' . $collection->get('id') : ''),
'class' => 'copyview',
);
}
$smarty->assign('microheaderlinks', $microheaderlinks);
}
else if ($can_edit) {
$smarty->assign('editurl', get_config('wwwroot') . 'view/blocks.php?id=' . $viewid . ($new ? '&new=1' : ''));
else {
if ($can_edit) {
$smarty->assign('editurl', get_config('wwwroot') . 'view/blocks.php?id=' . $viewid . ($new ? '&new=1' : ''));
}
if ($can_copy) {
$smarty->assign('copyurl', get_config('wwwroot') . 'view/copy.php?id=' . $viewid . (!empty($collection) ? '&collection=' . $collection->get('id') : ''));
}
}
$title = hsc(TITLE);
......
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