diff --git a/app/model/entity/Group.php b/app/model/entity/Group.php index b063b5b7..2c679618 100644 --- a/app/model/entity/Group.php +++ b/app/model/entity/Group.php @@ -102,6 +102,11 @@ public function __construct( */ protected $threshold; + /** + * @ORM\Column(type="integer", nullable=true) + */ + protected $pointsLimit; + /** * @ORM\Column(type="boolean") */ @@ -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; diff --git a/app/model/view/GroupViewFactory.php b/app/model/view/GroupViewFactory.php index bfa46695..ed72b5b9 100644 --- a/app/model/view/GroupViewFactory.php +++ b/app/model/view/GroupViewFactory.php @@ -158,6 +158,12 @@ 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(), @@ -165,9 +171,8 @@ private function getStudentStatsInternal( "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 ]; @@ -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, diff --git a/migrations/Version20241010152436.php b/migrations/Version20241010152436.php new file mode 100644 index 00000000..0eee2464 --- /dev/null +++ b/migrations/Version20241010152436.php @@ -0,0 +1,31 @@ +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'); + } +}