Skip to content
Snippets Groups Projects
Commit 9e850b04 authored by Paul Mrvik's avatar Paul Mrvik
Browse files

Issue #3487209 by globexplorer: Once an attempt has been set to closed it should stop to update!

parent 74758003
No related branches found
No related tags found
No related merge requests found
......@@ -188,7 +188,7 @@ final class AttemptFactory {
}
public function getAttemptFieldByProperty($entity, $property) {
public function getAttemptFieldByProperty(EntityInterface $entity, $property) {
$field_value = NULL;
......@@ -204,15 +204,10 @@ final class AttemptFactory {
$field = NULL;
if ($entity instanceof EntityInterface) {
$bundle = $entity->bundle();
if ($attempt_field = $this->getAvailableAttemptManagementField($entity->getEntityTypeId(), $entity->bundle())) {
if ($field = $entity->get($attempt_field)->getValue()) {
$field = $field[0];
}
}
if ($attempt_field = $this->getAvailableAttemptManagementField($entity->getEntityTypeId(), $entity->bundle())) {
if ($field = $entity->get($attempt_field)->getValue()) {
$field = $field[0];
}
}
return $field;
......@@ -311,10 +306,10 @@ final class AttemptFactory {
$update_previous_attempt = FALSE;
}
if ($entity instanceof EntityInterface) {
// Write attempt and return UUID
if ($attempt_type = $this->getAttemptFieldByProperty($entity, 'attempt_type')) {
if ($entity) {
// Write attempt and return UUID
if ($attempt_type = $this->getAttemptFieldByProperty($entity, 'attempt_type')) {
try {
$storage = $this->entityTypeManager->getStorage('attempt_mgmt_attempt');
......@@ -376,11 +371,34 @@ final class AttemptFactory {
}
}
/**
* Check if attempt closed
*
* @param string $attempt_uuid
* The uuid for the attempt
*
* @return bool
* TRUE | FALSE.
*/
protected function isAttemptClosed($attempt_uuid) {
$attempts = $this->entityTypeManager->getStorage('attempt_mgmt_attempt')->loadByProperties(['uuid' => $attempt_uuid, 'closed' => TRUE]);
if (!empty($attempts)) {
return TRUE;
}
return FALSE;
}
public function updateAttempt(string $attempt_uuid, array $field_data, EntityInterface $entity, $user_id, $finished = FALSE): bool {
$success = FALSE;
// First let's check if the attempt is closed. When closed no update should be done!
$attempt_closed = $this->isAttemptClosed($attempt_uuid);
if ($attempt_closed) {
return $success;
}
// For anon. user we need to save the session id.
if ($user_id == 0) {
$session_id = $this->getSessionIDForUnauthenticatedUsers();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment