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 { ...@@ -72,7 +72,7 @@ class PluginArtefactFile extends PluginArtefact {
'path' => 'groups/files', 'path' => 'groups/files',
'url' => 'artefact/file/groupfiles.php?group='.$groupid, 'url' => 'artefact/file/groupfiles.php?group='.$groupid,
'title' => get_string('Files', 'artefact.file'), 'title' => get_string('Files', 'artefact.file'),
'weight' => 70, 'weight' => 80,
), ),
); );
} }
......
...@@ -1033,9 +1033,22 @@ class User { ...@@ -1033,9 +1033,22 @@ class User {
*/ */
public function can_edit_collection($c) { public function can_edit_collection($c) {
$owner = $c->get('owner'); $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; 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; return false;
} }
...@@ -1086,6 +1099,77 @@ class User { ...@@ -1086,6 +1099,77 @@ class User {
db_commit(); 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 { ...@@ -81,12 +81,24 @@ class PluginBlocktypeNavigation extends SystemBlocktype {
public static function instance_config_form($instance) { public static function instance_config_form($instance) {
$configdata = $instance->get('configdata'); $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(" ($collections = get_records_sql_array("
SELECT c.id, c.name SELECT c.id, c.name
FROM {collection} c FROM {collection} c
WHERE c.owner = ? WHERE " . $where . "
ORDER BY c.name, c.ctime ASC", array($userid))) ORDER BY c.name, c.ctime ASC", $values))
|| ($collections = array()); || ($collections = array());
$default = false; $default = false;
...@@ -126,11 +138,4 @@ class PluginBlocktypeNavigation extends SystemBlocktype { ...@@ -126,11 +138,4 @@ class PluginBlocktypeNavigation extends SystemBlocktype {
return 'full'; 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 @@ ...@@ -26,7 +26,6 @@
*/ */
define('INTERNAL', 1); define('INTERNAL', 1);
define('MENUITEM', 'myportfolio/collection');
define('SECTION_PLUGINTYPE', 'core'); define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'collection'); define('SECTION_PLUGINNAME', 'collection');
...@@ -35,14 +34,39 @@ define('SECTION_PAGE', 'delete'); ...@@ -35,14 +34,39 @@ define('SECTION_PAGE', 'delete');
require(dirname(dirname(__FILE__)) . '/init.php'); require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php'); require_once('pieforms/pieform.php');
require_once('collection.php'); require_once('collection.php');
define('TITLE', get_string('deletecollection', 'collection'));
$id = param_integer('id'); $id = param_integer('id');
$collection = new Collection($id); $collection = new Collection($id);
if (!$USER->can_edit_collection($collection)) { if (!$USER->can_edit_collection($collection)) {
$SESSION->add_error_msg(get_string('cantdeletecollection', 'collection')); throw new AccessDeniedException(get_string('cantdeletecollection', 'collection'));
redirect('/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()) { if ($collection->is_submitted()) {
...@@ -57,20 +81,20 @@ $form = pieform(array( ...@@ -57,20 +81,20 @@ $form = pieform(array(
'submit' => array( 'submit' => array(
'type' => 'submitcancel', 'type' => 'submitcancel',
'value' => array(get_string('yes'), get_string('no')), 'value' => array(get_string('yes'), get_string('no')),
'goto' => get_config('wwwroot') . 'collection/', 'goto' => $baseurl,
), ),
), ),
)); ));
$smarty = smarty(); $smarty = smarty();
$smarty->assign('subheading', TITLE); $smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('message', get_string('collectionconfirmdelete', 'collection')); $smarty->assign('message', get_string('collectionconfirmdelete', 'collection'));
$smarty->assign('form', $form); $smarty->assign('form', $form);
$smarty->display('collection/delete.tpl'); $smarty->display('collection/delete.tpl');
function deletecollection_submit(Pieform $form, $values) { function deletecollection_submit(Pieform $form, $values) {
global $SESSION, $collection; global $SESSION, $collection, $baseurl;
$collection->delete(); $collection->delete();
$SESSION->add_ok_msg(get_string('collectiondeleted', 'collection')); $SESSION->add_ok_msg(get_string('collectiondeleted', 'collection'));
redirect('/collection/'); redirect($baseurl);
} }
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
*/ */
define('INTERNAL', 1); define('INTERNAL', 1);
define('MENUITEM', 'myportfolio/collection');
define('SECTION_PLUGINTYPE', 'core'); define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'collection'); define('SECTION_PLUGINNAME', 'collection');
...@@ -37,33 +36,86 @@ require_once('pieforms/pieform.php'); ...@@ -37,33 +36,86 @@ require_once('pieforms/pieform.php');
require_once('collection.php'); require_once('collection.php');
$new = param_boolean('new', 0); $new = param_boolean('new', 0);
$id = !$new ? param_integer('id') : 0; $copy = param_boolean('copy', 0);
$collection = new Collection($id); if ($new) { // if creating a new collection
if (!$USER->can_edit_collection($collection)) { $owner = null;
$SESSION->add_error_msg(get_string('canteditdontown', 'collection')); $groupid = param_integer('group', 0);
redirect('/collection/'); $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()) { if ($collection->is_submitted()) {
$submitinfo = $collection->submitted_to(); $submitinfo = $collection->submitted_to();
throw new AccessDeniedException(get_string('canteditsubmitted', 'collection', $submitinfo->name)); throw new AccessDeniedException(get_string('canteditsubmitted', 'collection', $submitinfo->name));
} }
// if not a new collection $urlparams = array();
if (!$new) { if (!empty($groupid)) {
define('TITLE', $collection->get('name').': '.get_string('edittitleanddesc', 'collection')); 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 { 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(); $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( $elements['submit'] = array(
'type' => 'submitcancel', 'type' => $type,
'value' => $submitstr, 'value' => $submitstr,
'confirm' => $confirm, 'confirm' => $confirm,
); );
...@@ -77,24 +129,28 @@ $form = pieform(array( ...@@ -77,24 +129,28 @@ $form = pieform(array(
)); ));
$smarty = smarty(); $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->assign_by_ref('form', $form);
$smarty->display('collection/edit.tpl'); $smarty->display('collection/edit.tpl');
function submit(Pieform $form, $values) { function submit(Pieform $form, $values) {
global $SESSION, $new; global $SESSION, $new, $copy, $urlparams;
$values['navigation'] = (int) $values['navigation']; $values['navigation'] = (int) $values['navigation'];
$collection = Collection::save($values); $collection = Collection::save($values);
if (!$new) { if (!$new) {
$SESSION->add_ok_msg(get_string('collectionsaved', 'collection')); $SESSION->add_ok_msg(get_string('collectionsaved', 'collection'));
} }
$collection->post_edit_redirect($new); $collection->post_edit_redirect($new, $copy, $urlparams);
} }
function edit_cancel_submit() { function edit_cancel_submit() {
global $collection, $new; global $baseurl;
if ($new && $collection) { redirect($baseurl);
$collection->delete();
}
redirect('/collection/');
} }
...@@ -26,8 +26,6 @@ ...@@ -26,8 +26,6 @@
*/ */
define('INTERNAL', 1); define('INTERNAL', 1);
define('MENUITEM', 'myportfolio/collection');
define('SECTION_PLUGINTYPE', 'core'); define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'collection'); define('SECTION_PLUGINNAME', 'collection');
define('SECTION_PAGE', 'index'); define('SECTION_PAGE', 'index');
...@@ -35,13 +33,75 @@ define('SECTION_PAGE', 'index'); ...@@ -35,13 +33,75 @@ define('SECTION_PAGE', 'index');
require(dirname(dirname(__FILE__)) . '/init.php'); require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php'); require_once('pieforms/pieform.php');
require_once('collection.php'); require_once('collection.php');
define('TITLE', get_string('Collections', 'collection'));
// offset and limit for pagination // offset and limit for pagination
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
$limit = param_integer('limit', 5); $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) { foreach ($data->data as $value) {
$collection = new Collection($value->id); $collection = new Collection($value->id);
$views = $collection->get('views'); $views = $collection->get('views');
...@@ -53,7 +113,7 @@ foreach ($data->data as $value) { ...@@ -53,7 +113,7 @@ foreach ($data->data as $value) {
$pagination = build_pagination(array( $pagination = build_pagination(array(
'id' => 'collectionslist_pagination', 'id' => 'collectionslist_pagination',
'class' => 'center', 'class' => 'center',
'url' => get_config('wwwroot') . 'collection/index.php', 'url' => $baseurl,
'count' => $data->count, 'count' => $data->count,
'limit' => $data->limit, 'limit' => $data->limit,
'offset' => $data->offset, 'offset' => $data->offset,
...@@ -67,9 +127,20 @@ $pagination = build_pagination(array( ...@@ -67,9 +127,20 @@ $pagination = build_pagination(array(
)); ));
$smarty = smarty(array('paginator')); $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('collections', $data->data);
$smarty->assign('pagination', $pagination['html']); $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('PAGEHEADING', TITLE);
$smarty->assign('PAGESUBHEADING', SUBTITLE);
$smarty->display('collection/index.tpl'); $smarty->display('collection/index.tpl');
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
*/ */
define('INTERNAL', 1); define('INTERNAL', 1);
define('MENUITEM', 'myportfolio/collection');