Commit d849234e authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic Committed by Robert Lyon
Browse files

Bug 1801160: adjustements for versioned peer assessment block

- hide edit/delete buttons for versioned peer assessment block
- save the list of assessment in the block version

behatnotneeded

Change-Id: I33b7fe62db8ccbe39697aced8ce54328a77b87a7
parent 642ec673
......@@ -71,13 +71,13 @@ class PluginBlocktypePeerassessment extends MaharaCoreBlocktype {
$options->showcomment = $showcomment;
$options->view = $instance->get_view();
$options->block = $instance->get('id');
$feedback = ArtefactTypePeerassessment::get_assessments($options);
$feedback = ArtefactTypePeerassessment::get_assessments($options, $versioning);
$feedbackform = ArtefactTypePeerassessment::add_assessment_form(true, $instance->get('id'), 0);
$smarty = smarty_core();
$smarty->assign('blockid', $instance->get('id'));
$smarty->assign('instructions', $instructions);
$smarty->assign('allowfeedback', $feedback->canedit);
$smarty->assign('allowfeedback', $feedback->canedit && !$versioning);
$smarty->assign('addassessmentfeedbackform', pieform($feedbackform));
if ($feedback && !$editing) {
$smarty->assign('feedback', $feedback);
......@@ -156,4 +156,16 @@ class PluginBlocktypePeerassessment extends MaharaCoreBlocktype {
}
}
}
public static function get_current_artefacts(BlockInstance $instance) {
$values = array($instance->get('id'));
$sql = "SELECT a.description, a.ctime, a.mtime, apa.assessment as id, apa.usr as author, apa.private
FROM {artefact} a
JOIN {artefact_peer_assessment} apa
ON a.id = apa.assessment
WHERE block = ?";
$artefacts = get_records_sql_array($sql, $values);
return $artefacts;
}
}
......@@ -355,7 +355,7 @@ class ArtefactTypePeerassessment extends ArtefactType {
* - defaults can be retrieved from get_assessment_options()
* @return object $result Assessment data object
*/
public static function get_assessments($options) {
public static function get_assessments($options, $versioning=null) {
global $USER;
$allowedoptions = self::get_assessment_options();
// set the object's key/val pairs as variables
......@@ -383,109 +383,153 @@ class ArtefactTypePeerassessment extends ArtefactType {
'data' => array(),
);
$where = 'pa.view = ? ';
// If the signoff block is also present on the page then we restrict things differently
$withsignoff = record_exists('block_instance', 'view', $viewid, 'blocktype', 'signoff');
if ($withsignoff) {
// If the view is signed off, select public assessments
// or if viewing as page owner, select public assessments
// or if viewing as assessment author, select assessments owned by author
$where.= 'AND ((vsv.signoff = 1 AND pa.private = 0) ';
$where.= ' OR (a.author = ?)';
$where.= ' OR (pa.private = 0 AND a.owner = ?))';
$values = array($viewid, $userid, $userid, $block);
$joinsignoff = ' JOIN {view_signoff_verify} vsv ON vsv.view = pa.view ';
if ($versioning) {
$result->data = self::get_assessment_data_for_versioning($versioning, $viewid);
$result->count = sizeof($result->data);
}
else {
// select assessments that are published
// or select assessments where the user is the author, published or not
$where.= 'AND ( (pa.private = 0) ';
$where.= ' OR (a.author = ?))';
$values = array($viewid, $userid, $block);
$joinsignoff = '';
}
$where = 'pa.view = ? ';
// If the signoff block is also present on the page then we restrict things differently
$withsignoff = record_exists('block_instance', 'view', $viewid, 'blocktype', 'signoff');
if ($withsignoff) {
// If the view is signed off, select public assessments
// or if viewing as page owner, select public assessments
// or if viewing as assessment author, select assessments owned by author
$where.= 'AND ((vsv.signoff = 1 AND pa.private = 0) ';
$where.= ' OR (a.author = ?)';
$where.= ' OR (pa.private = 0 AND a.owner = ?))';
$values = array($viewid, $userid, $userid, $block);
$joinsignoff = ' JOIN {view_signoff_verify} vsv ON vsv.view = pa.view ';
}
else {
// select assessments that are published
// or select assessments where the user is the author, published or not
$where.= 'AND ( (pa.private = 0) ';
$where.= ' OR (a.author = ?))';
$result->count = count_records_sql('
SELECT COUNT(*)
FROM
{artefact} a
JOIN {artefact_peer_assessment} pa
ON a.id = pa.assessment' . $joinsignoff . '
LEFT JOIN {artefact} p
ON a.parent = p.id
WHERE ' . $where . '
AND pa.block = ?', $values);
if ($result->count > 0) {
// Figure out sortorder
$orderby = 'a.ctime ' . ($sort == 'latest' ? 'DESC' : 'ASC');
// If pagination is in use, see if we want to get a page with particular assessment
if ($limit) {
if ($showcomment == 'last') {
// If we have limit (pagination is used) ignore $offset and just get the last page of comments.
$result->forceoffset = $offset = (ceil($result->count / $limit) - 1) * $limit;
}
else if (is_numeric($showcomment)) {
// Ignore $offset and get the page that has the assessment
// with id $showcomment on it.
// Fetch everything and figure out which page $showcomment is in.
// This will get ugly if there are 1000s of assessments
$ids = get_column_sql('
SELECT a.id
FROM {artefact} a JOIN {artefact_peer_assessment} pa ON a.id = pa.assessment
' . $joinsignoff . '
LEFT JOIN {artefact} p ON a.parent = p.id
WHERE ' . $where . '
AND pa.block = ?
ORDER BY ' . $orderby,
$values
);
$found = false;
foreach ($ids as $k => $v) {
if ($v == $showcomment) {
$found = $k;
break;
}
}
if ($found !== false) {
// Add 1 because array index starts from 0 and therefore key value is offset by 1.
$rank = $found + 1;
$result->forceoffset = $offset = ((ceil($rank / $limit) - 1) * $limit);
$result->showcomment = $showcomment;
}
}
$values = array($viewid, $userid, $block);
$joinsignoff = '';
}
$assessments = get_records_sql_assoc('
SELECT
a.id, a.title, a.author, a.authorname, a.ctime, a.mtime, a.description, a.group, a.path,
pa.private, pa.view, pa.block,
u.username, u.firstname, u.lastname, u.preferredname, u.email, u.staff, u.admin,
u.deleted, u.profileicon, u.urlid, p.id AS parent, p.author AS parentauthor
FROM {artefact} a
INNER JOIN {artefact_peer_assessment} pa ON a.id = pa.assessment
' . $joinsignoff . '
$result->count = count_records_sql('
SELECT COUNT(*)
FROM
{artefact} a
JOIN {artefact_peer_assessment} pa
ON a.id = pa.assessment' . $joinsignoff . '
LEFT JOIN {artefact} p
ON a.parent = p.id
LEFT JOIN {usr} u ON a.author = u.id
WHERE ' . $where . '
AND pa.block = ?
ORDER BY ' . $orderby, $values, $offset, $limit);
AND pa.block = ?', $values);
if ($result->count > 0) {
// Figure out sortorder
$orderby = 'a.ctime ' . ($sort == 'latest' ? 'DESC' : 'ASC');
$result->data = array_values($assessments);
// If pagination is in use, see if we want to get a page with particular assessment
if ($limit) {
if ($showcomment == 'last') {
// If we have limit (pagination is used) ignore $offset and just get the last page of comments.
$result->forceoffset = $offset = (ceil($result->count / $limit) - 1) * $limit;
}
else if (is_numeric($showcomment)) {
// Ignore $offset and get the page that has the assessment
// with id $showcomment on it.
// Fetch everything and figure out which page $showcomment is in.
// This will get ugly if there are 1000s of assessments
$ids = get_column_sql('
SELECT a.id
FROM {artefact} a JOIN {artefact_peer_assessment} pa ON a.id = pa.assessment
' . $joinsignoff . '
LEFT JOIN {artefact} p ON a.parent = p.id
WHERE ' . $where . '
AND pa.block = ?
ORDER BY ' . $orderby,
$values
);
$found = false;
foreach ($ids as $k => $v) {
if ($v == $showcomment) {
$found = $k;
break;
}
}
if ($found !== false) {
// Add 1 because array index starts from 0 and therefore key value is offset by 1.
$rank = $found + 1;
$result->forceoffset = $offset = ((ceil($rank / $limit) - 1) * $limit);
$result->showcomment = $showcomment;
}
}
}
$assessments = get_records_sql_assoc('
SELECT
a.id, a.title, a.author, a.authorname, a.ctime, a.mtime, a.description, a.group, a.path,
pa.private, pa.view, pa.block,
u.username, u.firstname, u.lastname, u.preferredname, u.email, u.staff, u.admin,
u.deleted, u.profileicon, u.urlid, p.id AS parent, p.author AS parentauthor
FROM {artefact} a
INNER JOIN {artefact_peer_assessment} pa ON a.id = pa.assessment
' . $joinsignoff . '
LEFT JOIN {artefact} p
ON a.parent = p.id
LEFT JOIN {usr} u ON a.author = u.id
WHERE ' . $where . '
AND pa.block = ?
ORDER BY ' . $orderby, $values, $offset, $limit);
$result->data = array_values($assessments);
}
}
$result->position = 'blockinstance';
self::build_html($result);
self::build_html($result, $versioning);
return $result;
}
private static function get_assessment_data_for_versioning($versioning, $viewid) {
global $USER;
foreach ($versioning->blocks as $blockversion) {
//find the assessment block
if ($blockversion->blocktype == 'peerassessment') {
$existing_artefacts= array();
if (isset($blockversion->configdata->existing_artefacts)) {
$existing_artefacts = $blockversion->configdata->existing_artefacts;
}
// populate the version with data to display
$assessmentsversion = array();
foreach ($existing_artefacts as &$assessment) {
// select assessments that are published
// or select assessments where the user is the author, published or not
if ($assessment->author == $USER->get('id') || !$assessment->private ) {
$assessment->view = $viewid;
$assessment->block = $blockversion->originalblockid;
$user = new User();
$user->find_by_id($assessment->author);
$assessment->username = $user->get('username');
$assessment->firstname = $user->get('firstname');
$assessment->lastname = $user->get('lastname');
$assessment->preferredname = $user->get('preferredname');
$assessment->email = $user->get('email');
$assessment->admin = $user->get('admin');
$assessment->staff = $user->get('staff');
$assessment->deleted = $user->get('deleted');
$assessment->profileicon = $user->get('profileicon');
$assessmentsversion[] = $assessment;
}
}
return $assessmentsversion;
}
}
return 0;
}
public static function is_signable(View $view) {
global $USER;
......@@ -547,7 +591,7 @@ class ArtefactTypePeerassessment extends ArtefactType {
return $newest[0];
}
public static function build_html(&$data) {
public static function build_html(&$data, $versioning=null) {
global $USER, $THEME;
$candelete = $data->canedit || $USER->get('admin');
......@@ -591,16 +635,18 @@ class ArtefactTypePeerassessment extends ArtefactType {
$item->canedit = 0;
}
$submittedcheck = get_record_sql('SELECT v.* FROM {view} v WHERE v.id = ?', array($data->view), ERROR_MULTIPLE);
if (($candelete || ($item->isauthor && !$signedoff && !$is_export_preview)) && $submittedcheck->submittedstatus == View::UNSUBMITTED) {
$item->deleteform = pieform(self::delete_assessment_form($item->id, $item->view, $item->block));
}
if ($item->canedit && $submittedcheck->submittedstatus == View::UNSUBMITTED) {
$smarty = smarty_core();
$smarty->assign('id', $item->id);
$smarty->assign('block', $item->block);
$smarty->assign('title', $item->title);
$item->editlink = $smarty->fetch('artefact:peerassessment:editlink.tpl');
if (!$versioning) {
$submittedcheck = get_record_sql('SELECT v.* FROM {view} v WHERE v.id = ?', array($data->view), ERROR_MULTIPLE);
if (($candelete || ($item->isauthor && !$signedoff && !$is_export_preview)) && $submittedcheck->submittedstatus == View::UNSUBMITTED) {
$item->deleteform = pieform(self::delete_assessment_form($item->id, $item->view, $item->block));
}
if ($item->canedit && $submittedcheck->submittedstatus == View::UNSUBMITTED) {
$smarty = smarty_core();
$smarty->assign('id', $item->id);
$smarty->assign('block', $item->block);
$smarty->assign('title', $item->title);
$item->editlink = $smarty->fetch('artefact:peerassessment:editlink.tpl');
}
}
if ($item->author) {
......
......@@ -1131,5 +1131,56 @@ function xmldb_core_upgrade($oldversion=0) {
// Just need to fire off upgrade to get the cache to clear
}
if ($oldversion < 2019031500) {
log_debug('Add existing assessments to peerassessment block version for timeline');
require_once(get_config('docroot') . '/blocktype/lib.php');
safe_require('blocktype', 'peerassessment');
// get all versions that could possibly contain 'peerassessment' blocks
$versions = get_records_sql_array("SELECT * FROM {view_versioning} WHERE blockdata LIKE '%peerassessment%'");
// to keep the currect artefacts of a peerassessment block
$existing_artefacts = array();
foreach ($versions as $version) {
if (isset($version->blockdata)) {
$needsupdate = false;
$blockdata = json_decode($version->blockdata);
foreach ($blockdata->blocks as &$block) {
if ($block->blocktype == 'peerassessment') {
$blockid = $block->originalblockid;
if (!isset($existing_artefacts[$blockid])) {
//in case there are no artefacts in the block
// or the blockinstance was deleted, we won't check again
$existing_artefacts[$blockid] = null;
try {
// get the artefacts use in the block
$bi = new BlockInstance($blockid);
if ($bi && $artefacts = PluginBlocktypePeerassessment::get_current_artefacts($bi)) {
foreach ($artefacts as $key => $artefact) {
if (isset($bi->configdata['artefactid']) && $bi->configdata['artefactid'] == $artefact) {
unset($artefacts[$key]);
}
}
$existing_artefacts[$blockid] = $artefacts;
}
}
catch (BlockInstanceNotFoundException $e) {}
}
// if we actually have artefact ids, save them in the version
if ($existing_artefacts[$blockid]) {
$block->configdata->existing_artefacts = $existing_artefacts[$blockid];
$needsupdate = true;
}
}
}
$version->blockdata = json_encode($blockdata);
if ($needsupdate) {
update_record('view_versioning', $version);
}
}
}
}
return $status;
}
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2019020400;
$config->version = 2019031500;
$config->series = '19.04';
$config->release = '19.04dev';
$config->minupgradefrom = 2017031605;
......
......@@ -181,6 +181,9 @@ a {
display: inline-block;
}
}
&.js-peerassessment-modal {
float: none;
}
}
img {
......
......@@ -47,12 +47,13 @@ if ($blocks) {
$bi->row = $oldblock->get('row');
$bi->column = $oldblock->get('column');
$bi->order = $oldblock->get('order');
if (isset($bi->configdata['artefactid']) && !empty($bi->configdata['artefactid'])) {
$classname = generate_class_name('blocktype', $oldblock->get('blocktype'));
if (is_callable($classname . '::'. 'get_current_artefacts')) {
// The block is for one artefact so lets see if it displays more than one artefact
if ($artefacts = call_static_method(generate_class_name('blocktype', $oldblock->get('blocktype')), 'get_current_artefacts', $oldblock)) {
if ($artefacts = call_static_method($classname, 'get_current_artefacts', $oldblock)) {
// We need to ignore the parent artefactid
foreach ($artefacts as $key => $artefact) {
if ($bi->configdata['artefactid'] == $artefact) {
if (isset($bi->configdata['artefactid']) && $bi->configdata['artefactid'] == $artefact) {
unset($artefacts[$key]);
}
}
......
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