Commit 51101717 authored by Penny Leach's avatar Penny Leach Committed by Nigel McNie
Browse files

view wizard and edit screens all done (this needs LOTS of testing)

parent 1687d1c6
......@@ -288,7 +288,6 @@ $string['saveaccess'] = 'Save Access';
$string['submitview'] = 'Submit View';
$string['submitviewfailed'] = 'Submit view failed';
$string['submitviewquestion'] = 'If you submit this view for assessment, you will not be able to edit the view or any of its associated artefacts until your tutor has finished marking the view. Are you sure you want to submit this view now?';
$string['viewaccesseditedsuccessfully'] = 'View access saved successfully';
$string['viewdeleted'] = 'View deleted';
$string['views'] = 'Views';
$string['viewsubmitted'] = 'View submitted';
......@@ -833,5 +832,6 @@ $string['system'] = 'System';
$string['preview'] = 'Preview';
$string['done'] = 'Done';
$string['next'] = 'Next';
$string['back'] = 'Back';
?>
......@@ -60,6 +60,7 @@ $string['format.rendermetadata'] = 'Display metadata for this Artefact';
$string['addtutors'] = 'Add Tutors';
$string['viewcreatedsuccessfully'] = 'View created successfully';
$string['viewaccesseditedsuccessfully'] = 'View access saved successfully';
$string['viewsavedsuccessfully'] = 'View saved successfully';
$string['invalidcolumn'] = 'Column %s out of range';
......
......@@ -275,7 +275,6 @@ class View {
delete_records('artefact_feedback','view',$this->id);
delete_records('view_feedback','view',$this->id);
delete_records('view_artefact','view',$this->id);
delete_records('view_content','view',$this->id);
delete_records('view_access','view',$this->id);
delete_records('view_access_group','view',$this->id);
delete_records('view_access_usr','view',$this->id);
......@@ -286,6 +285,137 @@ class View {
$this->deleted = true;
}
public function get_access() {
$data = get_records_sql_array('SELECT va.accesstype AS type, va.startdate, va.stopdate
FROM {view_access} va
LEFT JOIN {view} v ON (va.view = v.id)
WHERE v.id = ?
ORDER BY va.accesstype', array($this->id));
if (!$data) {
$data = array();
}
foreach ($data as &$item) {
$item = (array)$item;
}
// Get access for users and groups
$extradata = get_records_sql_array("
SELECT 'user' AS type, usr AS id, 0 AS tutoronly, startdate, stopdate
FROM {view_access_usr}
WHERE view = ?
UNION
SELECT 'group', \"group\", tutoronly, startdate, stopdate FROM {view_access_group}
WHERE view = ?", array($this->id, $this->id));
if ($extradata) {
foreach ($extradata as &$extraitem) {
$extraitem = (array)$extraitem;
$extraitem['tutoronly'] = (int)$extraitem['tutoronly'];
}
$data = array_merge($data, $extradata);
}
return $data;
}
public function set_access($accessdata) {
global $USER;
// For users who are being removed from having access to this view, they
// need to have the view and any attached artefacts removed from their
// watchlist.
$oldusers = array();
foreach ($this->get_access() as $item) {
if ($item['type'] == 'user') {
$oldusers[] = $item;
}
}
$newusers = array();
if ($accessdata) {
foreach ($accessdata as $item) {
if ($item['type'] == 'user') {
$newusers[] = $item;
}
}
}
$userstodelete = array();
foreach ($oldusers as $olduser) {
foreach ($newusers as $newuser) {
if ($olduser['id'] == $newuser['id']) {
continue(2);
}
}
$userstodelete[] = $olduser;
}
if ($userstodelete) {
$userids = array();
foreach ($userstodelete as $user) {
$userids[] = intval($user['id']);
}
$userids = implode(',', $userids);
execute_sql('DELETE FROM {usr_watchlist_view}
WHERE view = ' . $this->get('id') . '
AND usr IN (' . $userids . ')');
}
$beforeusers = activity_get_viewaccess_users($this->get('id'), $USER->get('id'), 'viewaccess');
// Procedure:
// get list of current friends - this is available in global $data
// compare with list of new friends
// work out which friends are being removed
// foreach friend
// // remove record from usr_watchlist_view where usr = ? and view = ?
// // remove records from usr_watchlist_artefact where usr = ? and view = ?
// endforeach
//
db_begin();
delete_records('view_access', 'view', $this->get('id'));
delete_records('view_access_usr', 'view', $this->get('id'));
delete_records('view_access_group', 'view', $this->get('id'));
$time = db_format_timestamp(time());
// View access
if ($accessdata) {
foreach ($accessdata as $item) {
$accessrecord = new StdClass;
$accessrecord->view = $this->get('id');
$accessrecord->startdate = db_format_timestamp($item['startdate']);
$accessrecord->stopdate = db_format_timestamp($item['stopdate']);
switch ($item['type']) {
case 'public':
case 'loggedin':
case 'friends':
$accessrecord->accesstype = $item['type'];
insert_record('view_access', $accessrecord);
break;
case 'user':
$accessrecord->usr = $item['id'];
insert_record('view_access_usr', $accessrecord);
break;
case 'group':
$accessrecord->group = $item['id'];
$accessrecord->tutoronly = $item['tutoronly'];
insert_record('view_access_group', $accessrecord);
break;
}
}
}
$data = new StdClass;
$data->view = $this->get('id');
$data->owner = $USER->get('id');
$data->oldusers = $beforeusers;
activity_occurred('viewaccess', $data);
handle_event('saveview', $this->get('id'));
db_commit();
}
public function release($groupid, $releaseuser=null) {
if ($this->get('submittedto') != $groupid) {
throw new ParameterException("View with id " . $this->get('id') .
......@@ -309,7 +439,7 @@ class View {
* @param string $defaultcategory The currently selected category
* @param View $view The view we're currently using
*/
public static function build_category_list($defaultcategory, View $view) {
public static function build_category_list($defaultcategory, View $view, $new=0) {
require_once(get_config('docroot') . '/blocktype/lib.php');
$cats = get_records_array('blocktype_category');
$categories = array_map(
......@@ -342,6 +472,7 @@ class View {
$smarty = smarty_core();
$smarty->assign('categories', $categories);
$smarty->assign('viewid', $view->get('id'));
$smarty->assign('new', $new);
return $smarty->fetch('view/blocktypecategorylist.tpl');
}
......@@ -369,7 +500,7 @@ class View {
* Process view changes. This function is used both by the json stuff and
* by normal posts
*/
public function process_changes() {
public function process_changes($category='', $new=0) {
global $SESSION, $USER;
// Security
......@@ -381,8 +512,6 @@ class View {
return;
}
$category = param_alpha('category', null);
$action = '';
foreach ($_POST as $key => $value) {
if (substr($key, 0, 7) == 'action_') {
......@@ -400,6 +529,10 @@ class View {
}
}
if (empty($action)) {
return;
}
$actionstring = $action;
$action = substr($action, 0, strpos($action, '_'));
$actionstring = substr($actionstring, strlen($action) + 1);
......@@ -417,8 +550,8 @@ class View {
case 'removeblockinstance': // requires action_removeblockinstance_id_\d
if (!defined('JSON')) {
if (!$sure = param_boolean('sure')) {
$yeslink = '/viewrework.php?view=1&category=file&action_' . $action . '_' . $actionstring . '=1&sure=true';
$baselink = '/viewrework.php?view=' . $this->get('id') . '&category=' . $category;
$yeslink = get_config('wwwroot') . '/view/blocks.php?id=1&c=file&new=' . $new . '&action_' . $action . '_' . $actionstring . '=1&sure=true';
$baselink = '/viewrework.php?id=' . $this->get('id') . '&c=' . $category . '&new=' . $new;
$SESSION->add_info_msg(get_string('confirmdeleteblockinstance', 'view')
. ' <a href="' . $yeslink . '">' . get_string('yes') . '</a>'
. ' <a href="' . $baselink . '">' . get_string('no') . '</a>', false);
......@@ -466,8 +599,7 @@ class View {
$fun = 'add_err_msg';
}
$SESSION->{$fun}($message);
// TODO fix this url
redirect('/viewrework.php?view=' . $this->get('id') . '&category=' . $category);
redirect('/view/blocks.php?id=' . $this->get('id') . 'c=' . $category . '&new=' . $new);
}
return array('message' => $message, 'data' => $returndata);
}
......
<ul>
{foreach from=$categories item=category}
<li class="{$category.class}"><a href="{$WWWROOT}view/blocks.php?id={$viewid}&amp;c={$category.name | escape}">{$category.title | escape}</a></li>
<li class="{$category.class}"><a href="{$WWWROOT}view/blocks.php?id={$viewid}&amp;c={$category.name | escape}&amp;new={$new}">{$category.title | escape}</a></li>
{/foreach}
</ul>
......@@ -35,8 +35,11 @@ require(dirname(dirname(__FILE__)) . '/init.php');
require_once(get_config('docroot') . 'lib/view.php');
$viewid = param_integer('id', 0); // if 0, we're creating a new view
$new = param_boolean('new');
if (empty($viewid)) {
define('TITLE', get_string('createview', 'view'));
$new = true;
}
else {
define('TITLE', get_string('editview', 'view'));
......@@ -79,6 +82,10 @@ $editview = pieform(array(
'type' => 'hidden',
'value' => $viewid,
),
'new' => array(
'type' => 'hidden',
'value' => $new,
),
'title' => array(
'type' => 'text',
'title' => get_string('title','view'),
......@@ -132,7 +139,7 @@ $editview = pieform(array(
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(isset($view) ? get_string('save') : get_string('next'), get_string('cancel')),
'value' => array(!isset($new) ? get_string('save') : get_string('next'), get_string('cancel')),
),
),
));
......@@ -165,7 +172,7 @@ function editview_submit(Pieform $form, $values) {
$view->commit();
if (empty($editing)) {
if ($values['new']) {
$redirecturl = '/view/blocks.php?id=' . $view->get('id') . '&new=1';
}
else {
......
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