Commit 4c7546a4 authored by Alexander Del Ponte's avatar Alexander Del Ponte Committed by Robert Lyon
Browse files

Bug 1952771: Fix PHP warnings for submissions

When portfolios are deleted, don't show error any more
in Main menu -> Share -> Submissions.

Also optimised DB access and feedback related issues.

Change-Id: I1ba68e81073cf3fd24cd202b8caae51845a56754
(cherry picked from commit 3f375a42)
parent 7adcfbfd
......@@ -80,6 +80,7 @@ class Controller {
if (!group_user_access($this->group->id, $this->user->get('id'))) {
throw new \AccessDeniedException(get_string('notamember', 'group'));
}
// We use Context::ContentUser here until Context::GroupSubmitter functionality is implemented
$this->context = Context::ContentUser; // Context::GroupSubmitter;
$this->group = null;
}
......@@ -210,14 +211,15 @@ class Controller {
$record->portfolioElementTitleHtml = SubmissionTools::createPortfolioElementTitleHtmlForTableBySubmissionRecord($record, $this->settings->showPortfolioButtons);
$record->isEditable = (bool)$record->liveUserIsAssessor && (int)$record->status === Submission::StatusSubmitted;
$record->isFixable = (bool)$record->liveUserIsAssessor && (int)$record->status === Submission::StatusIncomplete;
if ($this->settings->showNameAsLastnameFirstname) {
$record->ownerName = SubmissionTools::concatLastAndFirstName($record->ownerLastName, $record->ownerFirstName);
$record->evaluatorName = ($record->evaluatorId ? SubmissionTools::concatLastAndFirstName($record->evaluatorLastName, $record->evaluatorFirstName) : null);
$record->ownerName = (bool)$record->ownerDeleted ? get_string('deleteduser1') : SubmissionTools::createOwnerName($record, $this->settings->showNameAsLastnameFirstname);
if ($record->evaluatorId) {
$record->evaluatorName = (bool)$record->evaluatorDeleted ? get_string('deleteduser1') : SubmissionTools::createEvaluatorName($record, $this->settings->showNameAsLastnameFirstname);
}
else {
$record->ownerName = ($record->ownerId ? SubmissionTools::concatFirstAndLastName($record->ownerId, true) : null);
$record->evaluatorName = ($record->evaluatorId ? SubmissionTools::concatFirstAndLastName($record->evaluatorId) : null);
$record->evaluatorName = null;
}
$record->userElementTitleHtml = SubmissionTools::createHtmlLinkWithTitle(get_config('wwwroot') . 'user/view.php?id=' . $record->ownerId, $record->ownerName, '', '');
if ($record->evaluatorId) {
$record->evaluatorElementTitleHtml = SubmissionTools::createHtmlLinkWithTitle(get_config('wwwroot') . 'user/view.php?id=' . $record->evaluatorId, $record->evaluatorName, '', '');
......@@ -226,15 +228,15 @@ class Controller {
$record->portfolioElementGroupHtml = SubmissionTools::createHtmlLinkWithTitle(get_config('wwwroot') . 'group/view.php?id=' . $record->groupId, $record->groupName, '', '');
}
// If submission has not been released yet and so the comment field in the evaluation table is empty, get last comment of currently set evaluator or live user
$comment = SubmissionRepository::findLatestEvaluatorComment($record->portfolioElementType, $record->portfolioElementId, $record->evaluatorId, $record->submissionDate);
if (!is_null($comment)) {
$record->feedback = $comment->get('description');
$record->rating = $comment->get('rating');
}
// If submission is not released yet
if ((bool)$record->liveUserIsAssessor && ((int)$record->status === Submission::StatusSubmitted || (int)$record->status === Submission::StatusReleasing)) {
// If submission has not been released yet and so the comment field in the evaluation table is empty, get last comment of currently set evaluator or live user
$comment = SubmissionRepository::findLatestEvaluatorComment($record->portfolioElementType, $record->portfolioElementId, $record->evaluatorId, $record->submissionDate);
if (!is_null($comment)) {
$record->feedback = $comment->get('description');
$record->rating = $comment->get('rating');
}
// Because we now use the new Mahara collection preview functionality, we provide the portfolio view id(s)
// in the row data to the frontend
if ($record->portfolioElementType === 'collection') {
......
......@@ -109,6 +109,8 @@ class Submission extends AbstractModel {
$selectArray[] = $dbField . ' AS "' . $property . '"';
}
$selectArray[] = 'evaluation.id AS "evaluationId"';
$selectArray[] = '(owner.deleted = 1)' . $pgBooleanConversion . ' AS "ownerDeleted"';
$selectArray[] = '(evaluator.deleted = 1) ' . $pgBooleanConversion . ' AS "evaluatorDeleted"';
$selectArray[] = '(grouptyperoles.see_submitted_views = 1)' . $pgBooleanConversion . ' AS "liveUserIsAssessor"';
return 'SELECT ' . implode(', ', $selectArray);
......
......@@ -328,8 +328,7 @@ class SubmissionRepository {
require_once(get_config('libroot') . 'collection.php');
$collection = new \Collection($portfolioElementId);
list ($comment, $viewid) = $collection->get_latest_comment(true);
$portfolioElementId = $viewid;
$portfolioElementId = $collection->get_viewids()[0];
break;
default:
throw new \SystemException(get_string('unsupportedportfoliotype'), 'module.submissions');
......
......@@ -162,7 +162,7 @@ class SubmissionTools {
/** @var \User $user */
foreach ($users as $user) {
$userArray[$user->get('id')] = ($showNameAsLastnameFirstname ? self::getUserNameAsLastNameFirstName($user) : self::getUserNameAsFirstNameLastName($user));
$userArray[$user->get('id')] = ($showNameAsLastnameFirstname ? self::getEvaluatorNameAsLastNameFirstName($user) : self::getEvaluatorNameAsFirstNameLastName($user));
}
asort($userArray);
......@@ -181,7 +181,7 @@ class SubmissionTools {
/** @var \User $user */
foreach ($users as $user) {
$userArray[] = ['value' => $user->get('id'), 'text' => ($showNameAsLastnameFirstname ? self::getUserNameAsLastNameFirstName($user) : self::getUserNameAsFirstNameLastName($user))];
$userArray[] = ['value' => $user->get('id'), 'text' => ($showNameAsLastnameFirstname ? self::getEvaluatorNameAsLastNameFirstName($user) : self::getEvaluatorNameAsFirstNameLastName($user))];
}
asort($userArray);
......@@ -209,7 +209,7 @@ class SubmissionTools {
if ($users) {
foreach ($users as $user) {
$userArray[$user->id] = ($showNameAsLastnameFirstname ? self::concatLastAndFirstName($user->id) : self::concatFirstAndLastName($user->id));
$userArray[$user->id] = ($showNameAsLastnameFirstname ? self::concatLastAndFirstName($user->lastname, $user->firstname) : self::concatFirstAndLastName($user->firstname, $user->lastname));
}
asort($userArray);
}
......@@ -554,23 +554,57 @@ class SubmissionTools {
return param_integer($name);
}
public static function concatFirstAndLastName($id, $fullname=false) {
$user = get_user_for_display($id);
if ($fullname) {
return full_name($user);
}
return empty($user->preferredname) ? full_name($user) : $user->preferredname;
/**
* @param string $firstName
* @param string $lastName
* @return string
*/
public static function concatFirstAndLastName(string $firstName, string $lastName) {
return $firstName . ' ' . $lastName;
}
public static function concatLastAndFirstName($lastName, $firstName, $divider = ', ') {
/**
* @param string $lastName
* @param string $firstName
* @param string $divider
* @return string
*/
public static function concatLastAndFirstName(string $lastName, string $firstName, string $divider = ', ') {
return $lastName . $divider . $firstName;
}
/**
* @param \stdClass $record
* @param bool $showNameAsLastnameFirstname
* @return string
*/
public static function createOwnerName(\stdClass $record, bool $showNameAsLastnameFirstname) {
if ($showNameAsLastnameFirstname) {
return self::concatLastAndFirstName($record->ownerLastName, $record->ownerFirstName);
}
return self::concatFirstAndLastName($record->ownerFirstName, $record->ownerLastName);
}
/**
* @param \stdClass $record
* @param bool $showNameAsLastnameFirstname
* @return string
*/
public static function createEvaluatorName(\stdClass $record, bool $showNameAsLastnameFirstname) {
if ($record->evaluatorPreferredName) {
return $record->evaluatorPreferredName;
}
if ($showNameAsLastnameFirstname) {
return self::concatLastAndFirstName($record->evaluatorLastName, $record->evaluatorFirstName);
}
return self::concatFirstAndLastName($record->evaluatorFirstName, $record->evaluatorLastName);
}
/**
* @param \User $user
* @return string
*/
public static function getUserNameAsLastNameFirstName(\User $user) {
public static function getEvaluatorNameAsLastNameFirstName(\User $user) {
return self::concatLastAndFirstName($user->get('lastname'), $user->get('firstname'));
}
......@@ -578,8 +612,8 @@ class SubmissionTools {
* @param \User $user
* @return string
*/
public static function getUserNameAsFirstNameLastName(\User $user) {
return self::concatFirstAndLastName($user->get('id'));
public static function getEvaluatorNameAsFirstNameLastName(\User $user) {
return self::concatFirstAndLastName($user->get('firstname'), $user->get('lastname'));
}
/**
......
Supports Markdown
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