Commit 591a5855 authored by Hugh Davenport's avatar Hugh Davenport
Browse files

Add copy collection to copy page page



Change-Id: Ibf3847cac7ed1905146360ab72e81df14a3faaa2
Signed-off-by: default avatarHugh Davenport <hugh@catalyst.net.nz>
parent 1fe404c4
......@@ -54,6 +54,7 @@ $string['collectioncreatedsuccessfully'] = 'Collection created successfully.';
$string['collectioncreatedsuccessfullyshare'] = 'Your collection has been created successfully. Share your collection with others using the access links below.';
$string['collectiondeleted'] = 'Collection deleted successfully.';
$string['collectiondescription'] = 'A Collection is a set of pages that are linked to one another and have the same access permissions. You can create as many collections as you like, but a page cannot appear in more than one collection.';
$string['collectiontitle'] = 'Collection Title';
$string['confirmcancelcreatingcollection'] = 'This Collection has not been completed. Do you really want to cancel?';
$string['collectionsaved'] = 'Collection saved successfully.';
$string['created'] = 'Created';
......@@ -94,4 +95,7 @@ $string['viewnavigationdesc'] = 'Add a horizontal navigation bar to every page i
$string['viewsaddedtocollection'] = 'Pages added to collection. Collection updated to include access from new pages.';
$string['viewstobeadded'] = 'Pages to be added';
$string['viewconfirmremove'] = 'Are you sure you wish to remove this page from the collection?';
$string['collectioncopywouldexceedquota'] = 'Copying this collection would exceed your file quota.';
$string['copiedpagesblocksandartefactsfromtemplate'] = 'Copied %d pages, %d blocks and %d artefacts from %s';
$string['by'] = 'by';
$string['copycollection'] = 'Copy collection';
......@@ -50,6 +50,7 @@ $string['ownerformatdescription'] = 'How do you want people who look at your pag
$string['profileviewtitle'] = 'Profile page';
$string['dashboardviewtitle'] = 'Dashboard page';
$string['grouphomepageviewtitle'] = 'Group Homepage';
$string['viewname'] = 'Page Name';
// my views
$string['artefacts'] = 'Artefacts';
......@@ -276,7 +277,7 @@ $string['Template'] = 'Template';
$string['allowcopying'] = 'Allow copying';
$string['templatedescription'] = 'Check this box if you would like the people who can see your page to be able to make their own copies of it, along with any files and folders it contains.';
$string['templatedescriptionplural'] = 'Check this box if you would like the people who can see your pages to be able to make their own copies of them, along with any files and folders they contain.';
$string['choosetemplatepagedescription'] = '<p>Here you can search through the pages that you are allowed to copy as a starting point for making a new page. You can see a preview of each page by clicking on its name. Once you have found the page you wish to copy, click the corresponding "Copy Page" button to make a copy and begin customising it.</p>';
$string['choosetemplatepagedescription'] = '<p>Here you can search through the pages that you are allowed to copy as a starting point for making a new page. You can see a preview of each page by clicking on its name. Once you have found the page you wish to copy, click the corresponding "Copy Page" button to make a copy and begin customising it. You may also choose to copy the entire collection that the page belongs to by clicking the corresponding "Copy Collection" button.</p>';
$string['choosetemplategrouppagedescription'] = '<p>Here you can search through the pages that this group is allowed to copy as a starting point for making a new page. You can see a preview of each page by clicking on its name. Once you have found the page you wish to copy, click the corresponding "Copy Page" button to make a copy and begin customising it.</p><p><strong>Note:</strong> Groups cannot currently make copies of Journals or Journal Entriess.</p>';
$string['choosetemplateinstitutionpagedescription'] = '<p>Here you can search through the pages that this institution is allowed to copy as a starting point for making a new page. You can see a preview of each page by clicking on its name. Once you have found the page you wish to copy, click the corresponding "Copy Page" button to make a copy and begin customising it.</p><p><strong>Note:</strong> Institutions cannot currently make copies of Journals or Journal Entries.</p>';
$string['copiedblocksandartefactsfromtemplate'] = 'Copied %d blocks and %d artefacts from %s';
......@@ -287,7 +288,7 @@ $string['thisviewmaybecopied'] = 'Copying is allowed';
$string['copythisview'] = 'Copy this page';
$string['copyview'] = 'Copy page';
$string['createemptyview'] = 'Create empty page';
$string['copyaview'] = 'Copy a page';
$string['copyaview'] = 'Copy a page or collection';
$string['Untitled'] = 'Untitled';
$string['copyfornewusers'] = 'Copy for new users';
$string['copyfornewusersdescription'] = 'Whenever a new user is created, automatically make a personal copy of this page in the user\'s portfolio.';
......
......@@ -2600,9 +2600,10 @@ class View {
* @param bool $extra Return full set of properties on each view including an artefact list
* @param array $sort Order by, each element of the array is an array containing "column" (string) and "desc" (boolean)
* @param array $types List of view types to filter by
* @param bool $collection Use query against collection names and descriptions
*
*/
public static function view_search($query=null, $ownerquery=null, $ownedby=null, $copyableby=null, $limit=null, $offset=0, $extra=true, $sort=null, $types=null) {
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) {
global $USER;
$admin = $USER->get('admin');
$loggedin = $USER->is_logged_in();
......@@ -2636,8 +2637,13 @@ class View {
$like = db_ilike();
if ($query) {
$where .= "
AND (v.title $like '%' || ? || '%' OR v.description $like '%' || ? || '%' )";
$ph = array($query, $query);
AND (v.title $like '%' || ? || '%' OR v.description $like '%' || ? || '%' ";
if ($collection) {
$where .= "
OR c.name $like '%' || ? || '%' OR c.description $like '%' || ? || '%' ";
}
$where .= ")";
$ph = array($query, $query, $query, $query);
}
else {
$ph = array();
......@@ -2647,6 +2653,8 @@ class View {
// Unreachable and not tested yet:
$from = '
FROM {view} v
LEFT OUTER JOIN {collection_view} cv ON cv.view = v.id
LEFT OUTER JOIN {collection} c ON cv.collection = c.id
INNER JOIN {view_access} va ON (va.view = v.id)
';
$where .= "
......@@ -2659,6 +2667,8 @@ class View {
else {
$from = '
FROM {view} v
LEFT OUTER JOIN {collection_view} cv ON cv.view = v.id
LEFT OUTER JOIN {collection} c ON cv.collection = c.id
LEFT OUTER JOIN {group} gd ON v.group = gd.id
LEFT OUTER JOIN (
SELECT
......@@ -2760,11 +2770,12 @@ class View {
SELECT * FROM (
SELECT
v.id, v.title, v.description, v.owner, v.ownerformat, v.group, v.institution,
v.template, v.mtime, v.ctime
v.template, v.mtime, v.ctime,
c.id AS collid, c.name
' . $from . $where . '
GROUP BY
v.id, v.title, v.description, v.owner, v.ownerformat, v.group, v.institution,
v.template, v.mtime, v.ctime
v.template, v.mtime, v.ctime, c.id, c.name
) a
ORDER BY a.' . $orderby . ', a.id ASC',
$ph, $offset, $limit
......@@ -3223,10 +3234,10 @@ class View {
public static function get_templatesearch_data(&$search) {
require_once(get_config('libroot') . 'pieforms/pieform.php');
$results = self::view_search($search->query, $search->ownerquery, null, $search->copyableby, $search->limit, $search->offset, true);
$results = self::view_search($search->query, $search->ownerquery, null, $search->copyableby, $search->limit, $search->offset, true, null, null, true);
foreach ($results->data as &$r) {
$r['form'] = pieform(create_view_form($search->copyableby->group, $search->copyableby->institution, $r['id']));
$r['form'] = pieform(create_view_form($search->copyableby->group, $search->copyableby->institution, $r['id'], $r['collid']));
}
$params = array();
......@@ -3734,7 +3745,7 @@ class View {
}
function create_view_form($group=null, $institution=null, $template=null) {
function create_view_form($group=null, $institution=null, $template=null, $collection=null) {
global $USER;
$form = array(
'name' => 'createview',
......@@ -3748,6 +3759,10 @@ function create_view_form($group=null, $institution=null, $template=null) {
'type' => 'hidden',
'value' => true,
),
'submitcollection' => array(
'type' => 'hidden',
'value' => false,
),
'submit' => array(
'type' => 'submit',
'value' => get_string('createview', 'view'),
......@@ -3772,6 +3787,16 @@ function create_view_form($group=null, $institution=null, $template=null) {
'value' => $USER->get('id'),
);
}
if ($collection !== null) {
$form['elements']['copycollection'] = array(
'type' => 'hidden',
'value' => $collection,
);
$form['elements']['submitcollection'] = array(
'type' => 'submit',
'value' => get_string('copycollection', 'collection'),
);
}
if ($template !== null) {
$form['elements']['usetemplate'] = array(
'type' => 'hidden',
......@@ -3788,7 +3813,26 @@ function createview_submit(Pieform $form, $values) {
$values['template'] = !empty($values['istemplate']) ? 1 : 0; // Named 'istemplate' in the form to prevent confusion with 'usetemplate'
if (isset($values['usetemplate'])) {
if (!empty($values['submitcollection'])) {
require_once(get_config('libroot') . 'collection.php');
$templateid = $values['copycollection'];
unset($values['copycollection']);
unset($values['usetemplate']);
list($collection, $template, $copystatus) = Collection::create_from_template($values, $templateid);
if (isset($copystatus['quotaexceeded'])) {
$SESSION->add_error_msg(get_string('collectioncopywouldexceedquota', 'collection'));
redirect(get_config('wwwroot') . 'collection/choosetemplate.php');
}
$SESSION->add_ok_msg(get_string('copiedpagesblocksandartefactsfromtemplate', 'collection',
$copystatus['pages'],
$copystatus['blocks'],
$copystatus['artefacts'],
$template->get('name'))
);
redirect(get_config('wwwroot') . 'collection/edit.php?new=1&id=' . $collection->get('id'));
}
else if (isset($values['usetemplate'])) {
$templateid = $values['usetemplate'];
unset($values['usetemplate']);
list($view, $template, $copystatus) = View::create_from_template($values, $templateid);
......
{include file="header.tpl"}
<div class="rbuttons">
<a class="btn" href="{$WWWROOT}collection/edit.php?new=1">{str section=collection tag=newcollection}</a>
<a class="btn" href="{$WWWROOT}view/choosetemplate.php">{str section=view tag=copyaview}</a>
</div>
<p class="intro">{str tag=collectiondescription section=collection}</p>
{if $collections}
......
<table class="templateresults tablerenderer fullwidth">
<thead>
<tr>
<th>{str tag=name}</th>
<th>{str tag=viewname section=view}</th>
<th>{str tag=collectiontitle section=collection}</th>
<th>{str tag=Owner section=view}</th>
<th></th>
</tr>
......@@ -13,6 +14,11 @@
<td>
<strong><a class="viewlink" href="{$WWWROOT}view/view.php?id={$row.id}" target="_blank">{$row.title}</a></strong>
</td>
<td>
{if $row.collid}
<strong><a class="collectionlink" href="{$WWWROOT}view/view.php?id={$row.id}" target="_blank">{$row.name}</a></strong>
{/if}
</td>
{if $row.institution}
<td class="owner s">{$row.sharedby}</td>
{elseif $row.group}
......
......@@ -38,7 +38,7 @@ View::set_nav($group, $institution);
if ($usetemplate = param_integer('usetemplate', null)) {
// If a form has been submitted, build it now and pieforms will
// call the submit function straight away
pieform(create_view_form($group, $institution, $usetemplate));
pieform(create_view_form($group, $institution, $usetemplate, param_integer('copycollection', null)));
}
if ($group && !group_user_can_edit_views($group) || $institution && !$USER->can_edit_institution($institution)) {
......@@ -102,6 +102,16 @@ addLoadEvent(function() {
sendjsonrequest('viewcontent.json.php', params, 'POST', partial(showPreview, 'big'));
});
});
forEach(getElementsByTagAndClassName('a', 'collectionlink', 'templatesearch'), function(i) {
disconnectAll(i);
setNodeAttribute(i, 'title', {$strpreview});
connect(i, 'onclick', function (e) {
e.stop();
var href = getNodeAttribute(this, 'href');
var params = parseQueryString(href.substring(href.indexOf('?')+1, href.length));
sendjsonrequest('../collection/viewcontent.json.php', params, 'POST', partial(showPreview, 'big'));
});
});
};
templatelist.rewriteOther();
......
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