Commit cc4e8534 authored by Hugh Davenport's avatar Hugh Davenport Committed by Gerrit Code Review
Browse files

Merge changes...

Merge changes I63522438,I11957609,I421e168c,I2f181f4f,I49b245f7,Icc209c64,If893af92,I0ffcb3f3,Ib32058fa,I799bcfaf,I208ee9ee,Ieb7d19b1

* changes:
  Manually and automatically copying of institution and site collections (Bug #886080)
  Show the lang string "Copying is allowed" for collections (Bug #886080)
  Fix the bug when copying a collection from another user (Bug #886080)
  Change lang strings in Edit access (Bug #886080)
  Enable Navigation block for group, institution and site collections (Bug #886080)
  Copy institution views and collection to the new member's portfolio (Bug #886080)
  Copy site views and collections to the new user's profile (Bug #886080)
  Copy site collections for the new group (Bug #886080)
  Add new parameter to template creation functions (Bug #886080)
  Enable collections in groups and institutions (Bug #886080)
  Add 2 new fields: "group" and "institution" into the table "collection"
  Fix a bug in Collection::_construct($data)
parents 21f28f0b 42d47dd6
......@@ -72,7 +72,7 @@ class PluginArtefactFile extends PluginArtefact {
'path' => 'groups/files',
'url' => 'artefact/file/groupfiles.php?group='.$groupid,
'title' => get_string('Files', 'artefact.file'),
'weight' => 70,
'weight' => 80,
),
);
}
......
......@@ -1033,9 +1033,22 @@ class User {
*/
public function can_edit_collection($c) {
$owner = $c->get('owner');
if ($owner == $this->get('id')) {
if ($owner > 0 && $owner == $this->get('id')) {
return true;
}
$institution = $c->get('institution');
if ($institution && $this->can_edit_institution($institution)) {
return true;
}
$group = $c->get('group');
if ($group) {
$this->reset_grouproles();
if (!isset($this->grouproles[$group])) {
return false;
}
require_once('group.php');
return group_role_can_edit_views($group, $this->grouproles[$group]);
}
return false;
}
......@@ -1086,6 +1099,77 @@ class User {
db_commit();
}
/**
* Makes a literal copy of a list of views and collections for the new user.
* All site views and collections which set to "copy to new user"
* will be copied to this user's profile.
*
* @param $checkviewaccess.
*/
public function copy_site_views_collections_to_new_user($checkviewaccess=true) {
// Get list of available views which are not in collections
$templateviewids = get_column_sql("
SELECT v.id
FROM {view} v
LEFT JOIN {collection_view} cv ON v.id = cv.view
WHERE cv.view IS NULL
AND v.institution = 'mahara'
AND v.copynewuser = 1", array());
$this->copy_views($templateviewids, $checkviewaccess);
// Get list of available collections
$templatecollectionids = get_column_sql("
SELECT DISTINCT c.id
FROM {view} v
INNER JOIN {collection_view} cv ON v.id = cv.view
INNER JOIN {collection} c ON cv.collection = c.id
WHERE v.copynewuser = 1
AND v.institution = 'mahara'", array());
if ($templatecollectionids) {
require_once('collection.php');
foreach ($templatecollectionids as $templateid) {
Collection::create_from_template(array('owner' => $this->get('id')), $templateid, null, null, true);
}
}
}
/**
* Makes a literal copy of a list of views and collections for the new institution member.
* All institution views and collections which set to "copy to new institution member"
* will be copied to this user's profile.
*
* @param $institution: ID of the institution to join
* @param $checkviewaccess.
*/
public function copy_institution_views_collections_to_new_member($institution, $checkviewaccess=true) {
if (empty($institution)) {
return;
}
// Get list of available views which are not in collections
$templateviewids = get_column_sql("
SELECT v.id
FROM {view} v
LEFT JOIN {collection_view} cv ON v.id = cv.view
WHERE cv.view IS NULL
AND v.institution = ?
AND v.copynewuser = 1", array($institution));
$this->copy_views($templateviewids, $checkviewaccess);
// Get list of available collections
$templatecollectionids = get_column_sql("
SELECT DISTINCT c.id
FROM {view} v
INNER JOIN {collection_view} cv ON v.id = cv.view
INNER JOIN {collection} c ON cv.collection = c.id
WHERE v.copynewuser = 1
AND v.institution = ?", array($institution));
if ($templatecollectionids) {
require_once('collection.php');
foreach ($templatecollectionids as $templateid) {
Collection::create_from_template(array('owner' => $this->get('id')), $templateid, null, null, true);
}
}
}
}
......
......@@ -81,12 +81,24 @@ class PluginBlocktypeNavigation extends SystemBlocktype {
public static function instance_config_form($instance) {
$configdata = $instance->get('configdata');
$userid = $instance->get_view()->get('owner');
$view = $instance->get_view();
$groupid = $view->get('group');
$institutionid = $view->get('institution');
$userid = $view->get('owner');
if (!empty($groupid)) {
$where = 'c.group = ?'; $values = array($groupid);
}
else if (!empty($institutionid)) {
$where = 'c.institution = ?'; $values = array($institutionid);
}
else {
$where = 'c.owner = ?'; $values = array($userid);
}
($collections = get_records_sql_array("
SELECT c.id, c.name
FROM {collection} c
WHERE c.owner = ?
ORDER BY c.name, c.ctime ASC", array($userid)))
WHERE " . $where . "
ORDER BY c.name, c.ctime ASC", $values))
|| ($collections = array());
$default = false;
......@@ -126,11 +138,4 @@ class PluginBlocktypeNavigation extends SystemBlocktype {
return 'full';
}
/**
* Navigation only makes sense for personal views
*/
public static function allowed_in_view(View $view) {
return $view->get('owner') != null;
}
}
......@@ -26,7 +26,6 @@
*/
define('INTERNAL', 1);
define('MENUITEM', 'myportfolio/collection');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'collection');
......@@ -35,14 +34,39 @@ define('SECTION_PAGE', 'delete');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require_once('collection.php');
define('TITLE', get_string('deletecollection', 'collection'));
$id = param_integer('id');
$collection = new Collection($id);
if (!$USER->can_edit_collection($collection)) {
$SESSION->add_error_msg(get_string('cantdeletecollection', 'collection'));
redirect('/collection/');
throw new AccessDeniedException(get_string('cantdeletecollection', 'collection'));
}
$groupid = $collection->get('group');
$institutionname = $collection->get('institution');
$urlparams = array();
if (!empty($groupid)) {
define('MENUITEM', 'groups/collections');
define('GROUP', $groupid);
$urlparams['group'] = $groupid;
}
else if (!empty($institutionname)) {
if ($institutionname == 'mahara') {
define('ADMIN', 1);
define('MENUITEM', 'configsite/collections');
}
else {
define('INSTITUTIONALADMIN', 1);
define('MENUITEM', 'manageinstitutions/institutioncollections');
}
$urlparams['institution'] = $institutionname;
}
else {
define('MENUITEM', 'myportfolio/collection');
}
define('TITLE', get_string('deletespecifiedcollection', 'collection', $collection->get('name')));
$baseurl = get_config('wwwroot') . 'collection/index.php';
if ($urlparams) {
$baseurl .= '?' . http_build_query($urlparams);
}
if ($collection->is_submitted()) {
......@@ -57,20 +81,20 @@ $form = pieform(array(
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('yes'), get_string('no')),
'goto' => get_config('wwwroot') . 'collection/',
'goto' => $baseurl,
),
),
));
$smarty = smarty();
$smarty->assign('subheading', TITLE);
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('message', get_string('collectionconfirmdelete', 'collection'));
$smarty->assign('form', $form);
$smarty->display('collection/delete.tpl');
function deletecollection_submit(Pieform $form, $values) {
global $SESSION, $collection;
global $SESSION, $collection, $baseurl;
$collection->delete();
$SESSION->add_ok_msg(get_string('collectiondeleted', 'collection'));
redirect('/collection/');
redirect($baseurl);
}
......@@ -26,7 +26,6 @@
*/
define('INTERNAL', 1);
define('MENUITEM', 'myportfolio/collection');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'collection');
......@@ -37,33 +36,86 @@ require_once('pieforms/pieform.php');
require_once('collection.php');
$new = param_boolean('new', 0);
$id = !$new ? param_integer('id') : 0;
$copy = param_boolean('copy', 0);
$collection = new Collection($id);
if (!$USER->can_edit_collection($collection)) {
$SESSION->add_error_msg(get_string('canteditdontown', 'collection'));
redirect('/collection/');
if ($new) { // if creating a new collection
$owner = null;
$groupid = param_integer('group', 0);
$institutionname = param_alphanum('institution', false);
if (empty($groupid) && empty($institutionname)) {
$owner = $USER->get('id');
}
$collection = new Collection(null, array('owner' => $owner, 'group' => $groupid, 'institution' => $institutionname));
define('SUBTITLE', get_string('edittitleanddesc', 'collection'));
}
else { // if editing an existing or copied collection
$id = param_integer('id');
$collection = new Collection($id);
$owner = $collection->get('owner');
$groupid = $collection->get('group');
$institutionname = $collection->get('institution');
define('SUBTITLE', $collection->get('name').': '.get_string('edittitleanddesc', 'collection'));
}
if ($collection->is_submitted()) {
$submitinfo = $collection->submitted_to();
throw new AccessDeniedException(get_string('canteditsubmitted', 'collection', $submitinfo->name));
}
// if not a new collection
if (!$new) {
define('TITLE', $collection->get('name').': '.get_string('edittitleanddesc', 'collection'));
$urlparams = array();
if (!empty($groupid)) {
define('MENUITEM', 'groups/collections');
define('GROUP', $groupid);
$group = group_current_group();
define('TITLE', $group->name . ' - ' . get_string('editcollection', 'collection'));
$urlparams['group'] = $groupid;
}
else if (!empty($institutionname)) {
if ($institutionname == 'mahara') {
define('ADMIN', 1);
define('MENUITEM', 'configsite/collections');
}
else {
define('INSTITUTIONALADMIN', 1);
define('MENUITEM', 'manageinstitutions/institutioncollections');
}
define('TITLE', get_string('editcollection', 'collection'));
$urlparams['institution'] = $institutionname;
}
else {
define('TITLE', get_string('edittitleanddesc', 'collection'));
define('MENUITEM', 'myportfolio/collection');
define('TITLE', get_string('editcollection', 'collection'));
}
if (!$USER->can_edit_collection($collection)) {
throw new AccessDeniedException(get_string('canteditcollection', 'collection'));
}
$baseurl = get_config('wwwroot') . 'collection/index.php';
if ($urlparams) {
$baseurl .= '?' . http_build_query($urlparams);
}
$elements = $collection->get_collectionform_elements();
$submitstr = $new ? array('cancel' => get_string('cancel'), 'submit' => get_string('next') . ': ' . get_string('editviews', 'collection'))
: array(get_string('save'), get_string('cancel'));
$confirm = $new ? array('cancel' => get_string('confirmcancelcreatingcollection','collection')) : null;
if ($copy) {
$type = 'submit';
$submitstr = get_string('next') . ': ' . get_string('editviews', 'collection');
$confirm = null;
}
else {
$type = 'submitcancel';
if ($new) {
$submitstr = array('cancel' => get_string('cancel'), 'submit' => get_string('next') . ': ' . get_string('editviews', 'collection'));
$confirm = array('cancel' => get_string('confirmcancelcreatingcollection','collection'));
}
else {
$submitstr = array(get_string('save'), get_string('cancel'));
$confirm = null;
}
}
$elements['submit'] = array(
'type' => 'submitcancel',
'type' => $type,
'value' => $submitstr,
'confirm' => $confirm,
);
......@@ -77,24 +129,28 @@ $form = pieform(array(
));
$smarty = smarty();
$smarty->assign('PAGEHEADING', TITLE);
if (!empty($groupid)) {
$smarty->assign('PAGESUBHEADING', SUBTITLE);
$smarty->assign('PAGEHELPNAME', '0');
$smarty->assign('SUBPAGEHELPNAME', '1');
}
else {
$smarty->assign('PAGEHEADING', SUBTITLE);
}
$smarty->assign_by_ref('form', $form);
$smarty->display('collection/edit.tpl');
function submit(Pieform $form, $values) {
global $SESSION, $new;
global $SESSION, $new, $copy, $urlparams;
$values['navigation'] = (int) $values['navigation'];
$collection = Collection::save($values);
if (!$new) {
$SESSION->add_ok_msg(get_string('collectionsaved', 'collection'));
}
$collection->post_edit_redirect($new);
$collection->post_edit_redirect($new, $copy, $urlparams);
}
function edit_cancel_submit() {
global $collection, $new;
if ($new && $collection) {
$collection->delete();
}
redirect('/collection/');
global $baseurl;
redirect($baseurl);
}
......@@ -26,8 +26,6 @@
*/
define('INTERNAL', 1);
define('MENUITEM', 'myportfolio/collection');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'collection');
define('SECTION_PAGE', 'index');
......@@ -35,13 +33,75 @@ define('SECTION_PAGE', 'index');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require_once('collection.php');
define('TITLE', get_string('Collections', 'collection'));
// offset and limit for pagination
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 5);
$data = Collection::get_mycollections_data($offset, $limit);
$owner = null;
$groupid = param_integer('group', 0);
$institutionname = param_alphanum('institution', false);
$urlparams = array();
if (!empty($groupid)) {
define('MENUITEM', 'groups/collections');
define('GROUP', $groupid);
$group = group_current_group();
// Check if user can edit group collections <-> user can edit group views
$role = group_user_access($group->id);
$canedit = $role && group_role_can_edit_views($group, $role);
if (!$canedit) {
throw new GroupAccessDeniedException(get_string('cantlistgroupcollections', 'collection'));
}
define('SUBTITLE', get_string('groupcollections', 'collection'));
define('TITLE', $group->name);
$urlparams['group'] = $groupid;
}
else if (!empty($institutionname)) {
if ($institutionname == 'mahara') {
define('ADMIN', 1);
define('MENUITEM', 'configsite/collections');
define('TITLE', get_string('sitecollections', 'collection'));
// Check if user is a site admin
$canedit = $USER->get('admin');
if (!$canedit) {
throw new AccessDeniedException(get_string('cantlistinstitutioncollections', 'collection'));
}
}
else {
define('INSTITUTIONALADMIN', 1);
define('MENUITEM', 'manageinstitutions/institutioncollections');
define('TITLE', get_string('institutioncollections', 'collection'));
// Check if user is a institution admin
$canedit = $USER->get('admin') || $USER->is_institutional_admin();
if (!$canedit) {
throw new AccessDeniedException(get_string('cantlistinstitutioncollections', 'collection'));
}
require_once('institution.php');
// Get list of availlable institutions
$s = institution_selector_for_page($institutionname, get_config('wwwroot') . 'collection/index.php');
$institutionname = $s['institution'];
if ($institutionname === false) {
$smarty = smarty();
$smarty->display('admin/users/noinstitutions.tpl');
exit;
}
}
define('SUBTITLE', '');
$urlparams['institution'] = $institutionname;
}
else {
define('MENUITEM', 'myportfolio/collection');
$owner = $USER->get('id');
define('SUBTITLE', '');
define('TITLE', get_string('Collections', 'collection'));
}
$baseurl = get_config('wwwroot') . 'collection/index.php';
if ($urlparams) {
$baseurl .= '?' . http_build_query($urlparams);
}
$data = Collection::get_mycollections_data($offset, $limit, $owner, $groupid, $institutionname);
foreach ($data->data as $value) {
$collection = new Collection($value->id);
$views = $collection->get('views');
......@@ -53,7 +113,7 @@ foreach ($data->data as $value) {
$pagination = build_pagination(array(
'id' => 'collectionslist_pagination',
'class' => 'center',
'url' => get_config('wwwroot') . 'collection/index.php',
'url' => $baseurl,
'count' => $data->count,
'limit' => $data->limit,
'offset' => $data->offset,
......@@ -67,9 +127,20 @@ $pagination = build_pagination(array(
));
$smarty = smarty(array('paginator'));
$urlparamsstr = '';
if ($urlparams) {
$urlparamsstr = '&' . http_build_query($urlparams);
}
$smarty->assign('addonelink', get_config('wwwroot') . 'collection/edit.php?new=1' . $urlparamsstr);
if (!empty($institutionname) && ($institutionname != 'mahara')) {
$smarty->assign('institution', $institutionname);
$smarty->assign('institutionselector', $s['institutionselector']);
$smarty->assign('INLINEJAVASCRIPT', $s['institutionselectorjs']);
}
$smarty->assign('urlparamsstr', $urlparamsstr);
$smarty->assign('collections', $data->data);
$smarty->assign('pagination', $pagination['html']);
$smarty->assign('strnocollectionsaddone',
get_string('nocollectionsaddone','collection','<a href="' . get_config('wwwroot') . 'collection/edit.php?new=1">', '</a>'));
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('PAGESUBHEADING', SUBTITLE);
$smarty->display('collection/index.tpl');
......@@ -26,7 +26,6 @@
*/
define('INTERNAL', 1);
define('MENUITEM', 'myportfolio/collection');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'collection');
......@@ -44,16 +43,45 @@ $direction = param_variable('direction','');
$collection = new Collection($id);
if (!$USER->can_edit_collection($collection)) {
$SESSION->add_error_msg(get_string('canteditdontown', 'collection'));
redirect('/collection/');
throw new AccessDeniedException(get_string('canteditcollection', 'collection'));
}
$owner = $collection->get('owner');
$groupid = $collection->get('group');
$institutionname = $collection->get('institution');
$urlparams = array();
if (!empty($groupid)) {
define('MENUITEM', 'groups/collections');
define('GROUP', $groupid);
$group = group_current_group();
define('TITLE', $group->name . ' - ' . get_string('editcollection', 'collection'));
$urlparams['group'] = $groupid;
}
else if (!empty($institutionname)) {
if ($institutionname == 'mahara') {
define('ADMIN', 1);
define('MENUITEM', 'configsite/collections');
}
else {
define('INSTITUTIONALADMIN', 1);
define('MENUITEM', 'manageinstitutions/institutioncollections');
}
define('TITLE', get_string('editcollection', 'collection'));
$urlparams['institution'] = $institutionname;
}
else {
define('MENUITEM', 'myportfolio/collection');
define('TITLE', get_string('editcollection', 'collection'));
}
define('SUBTITLE', $collection->get('name'). ': ' . get_string('editviews', 'collection'));
$baseurl = get_config('wwwroot') . 'collection/index.php';
if ($urlparams) {
$baseurl .= '?' . http_build_query($urlparams);
}
if ($collection->is_submitted()) {
$submitinfo = $collection->submitted_to();
throw new AccessDeniedException(get_string('canteditsubmitted', 'collection', $submitinfo->name));
}
define('TITLE', $collection->get('name') . ': ' . get_string('editviews', 'collection'));
if ($view AND !empty($direction)) {
$collection->set_viewdisplayorder($view,$direction);
redirect('/collection/views.php?id='.$id);
......@@ -83,7 +111,7 @@ if ($views) {
$elements = array();
$viewsform = null;
if ($available = Collection::available_views()) {
if ($available = Collection::available_views($owner, $groupid, $institutionname)) {
foreach ($available as $a) {
$elements['view_'.$a->id] = array(
'type' => 'checkbox',
......@@ -108,7 +136,15 @@ if ($available = Collection::available_views()) {
$smarty = smarty();
$smarty->assign('PAGEHEADING', TITLE);
if (!empty($groupid)) {
$smarty->assign('PAGESUBHEADING', SUBTITLE);
$smarty->assign('PAGEHELPNAME', '0');
$smarty->assign('SUBPAGEHELPNAME', '1');
}
else {
$smarty->assign('PAGEHEADING', SUBTITLE);
}
$smarty->assign('baseurl', $baseurl);
$smarty->assign('displayurl',get_config('wwwroot').'collection/views.php?id='.$id);
$smarty->assign('removeurl',get_config('wwwroot').'collection/deleteview.php?id='.$id);
$smarty->assign_by_ref('views', $views);
......
......@@ -40,6 +40,12 @@ $string['add'] = 'Add';
$string['addviews'] = 'Add pages';
$string['addviewstocollection'] = 'Add pages to collection';
$string['back'] = 'Back';
$string['cantlistgroupcollections'] = 'You are not allowed to list group collections.';
$string['cantlistinstitutioncollections'] = 'You are not allowed to list institution collections.';
$string['canteditgroupcollections'] = 'You are not allowed to edit group collections.';
$string['canteditinstitutioncollections'] = 'You are not allowed to edit institution collections.';
$string['canteditcollection'] = 'You are not allowed to edit this collection.';
$string['cantcreatecollection'] = 'You are not allowed to create this collection.';
$string['cantdeletecollection'] = 'You cannot delete this collection.';
$string['canteditdontown'] = 'You cannot edit this collection because you do not own it.';
$string['canteditsubmitted'] = 'You cannot edit this collection because it has been submitted for assessment to %s. You will have to wait until it is released.';
......@@ -47,6 +53,9 @@ $string['collection'] = 'collection';
$string['Collection'] = 'Collection';
$string['collections'] = 'Collections';
$string['Collections'] = 'Collections';
$string['groupcollections'] = 'Group collections';
$string['institutioncollections'] = 'Institution collections';
$string['sitecollections'] = 'Site collections';
$string['collectionaccess'] = 'Collection access';
$string['collectionaccesseditedsuccessfully'] = 'Collection access saved successfully';
$string['collectioneditaccess'] = 'You are editing access for %d pages in this collection';
......@@ -76,6 +85,7 @@ $string['emptycollection'] = 'Empty collection';
$string['manageviews'] = 'Manage pages';
$string['name'] = 'Collection name';
$string['newcollection'] = 'New collection';
$string['nocollections'] = 'No collections yet.';