Skip to content

Commit

Permalink
Updating group entity to contain points limit (along with threshold).
Browse files Browse the repository at this point in the history
  • Loading branch information
krulis-martin committed Oct 10, 2024
1 parent 80ce053 commit d749b3e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
15 changes: 15 additions & 0 deletions app/model/entity/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public function __construct(
*/
protected $threshold;

/**
* @ORM\Column(type="integer", nullable=true)
*/
protected $pointsLimit;

/**
* @ORM\Column(type="boolean")
*/
Expand Down Expand Up @@ -944,6 +949,16 @@ public function setThreshold(?float $threshold): void
$this->threshold = $threshold;
}

public function getPointsLimit(): ?int
{
return $this->pointsLimit;
}

public function setPointsLimit(?int $pointsLimit): void
{
$this->pointsLimit = $pointsLimit;
}

public function getPublicStats(): bool
{
return $this->publicStats;
Expand Down
12 changes: 9 additions & 3 deletions app/model/view/GroupViewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,21 @@ private function getStudentStatsInternal(
];
}

$passesLimit = null; // null = no limit
if ($group->getPointsLimit() !== null && $group->getPointsLimit() > 0) {
$passesLimit = $gainedPoints >= $group->getPointsLimit();
} elseif ($group->getThreshold() !== null && $group->getThreshold() > 0) {
$passesLimit = $gainedPoints >= $maxPoints * $group->getThreshold();
}
return [
"userId" => $student->getId(),
"groupId" => $group->getId(),
"points" => [
"total" => $maxPoints,
"gained" => $gainedPoints
],
"hasLimit" => $group->getThreshold() !== null && $group->getThreshold() > 0,
"passesLimit" => $group->getThreshold(
) === null ? true : $gainedPoints >= $maxPoints * $group->getThreshold(),
"hasLimit" => $passesLimit !== null,
"passesLimit" => $passesLimit ?? true,
"assignments" => $assignments,
"shadowAssignments" => $shadowAssignments
];
Expand Down Expand Up @@ -251,6 +256,7 @@ function (ShadowAssignment $assignment) {
"publicStats" => $group->getPublicStats(),
"detaining" => $group->isDetaining(),
"threshold" => $group->getThreshold(),
"pointsLimit" => $group->getPointsLimit(),
"bindings" => $this->bindings->getBindingsForGroup($group),
"examBegin" => $group->hasExamPeriodSet() ? $group->getExamBegin()?->getTimestamp() : null,
"examEnd" => $group->hasExamPeriodSet() ? $group->getExamEnd()?->getTimestamp() : null,
Expand Down
31 changes: 31 additions & 0 deletions migrations/Version20241010152436.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20241010152436 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE `group` ADD points_limit INT DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE `group` DROP points_limit');
}
}

0 comments on commit d749b3e

Please sign in to comment.