1616use App \Model \Entity \LocalizedGroup ;
1717use App \Model \Entity \GroupMembership ;
1818use App \Model \Entity \AssignmentSolution ;
19- use App \Model \Entity \SecurityEvent ;
2019use App \Model \Repository \Assignments ;
2120use App \Model \Repository \Groups ;
2221use App \Model \Repository \GroupExams ;
@@ -194,6 +193,36 @@ public function actionDefault(
194193 $ this ->sendSuccessResponse ($ this ->groupViewFactory ->getGroups ($ groups , false ));
195194 }
196195
196+ /**
197+ * Helper method that handles updating points limit and threshold to a group entity (from a request).
198+ * @param Request $req request data
199+ * @param Group $group to be updated
200+ */
201+ private function setGroupPoints (Request $ req , Group $ group ): void
202+ {
203+ $ threshold = $ req ->getPost ("threshold " );
204+ $ pointsLimit = $ req ->getPost ("pointsLimit " );
205+ if ($ threshold !== null && $ pointsLimit !== null ) {
206+ throw new InvalidArgumentException ("A group may have either a threshold or points limit, not both. " );
207+ }
208+ if ($ threshold !== null ) {
209+ if ($ threshold <= 0 || $ threshold > 100 ) {
210+ throw new InvalidArgumentException ("A threshold must be in the (0, 100] (%) range. " );
211+ }
212+ $ group ->setThreshold ($ threshold / 100 );
213+ } else {
214+ $ group ->setThreshold (null );
215+ }
216+ if ($ pointsLimit !== null ) {
217+ if ($ pointsLimit <= 0 ) {
218+ throw new InvalidArgumentException ("A points limit must be a positive number. " );
219+ }
220+ $ group ->setPointsLimit ($ pointsLimit );
221+ } else {
222+ $ group ->setPointsLimit (null );
223+ }
224+ }
225+
197226 /**
198227 * Create a new group
199228 * @POST
@@ -215,10 +244,10 @@ public function actionDefault(
215244 * description="Whether the group is an exam group.")
216245 * @Param(type="post", name="localizedTexts", validation="array", required=false,
217246 * description="Localized names and descriptions")
218- * @Param(type="post", name="hasThreshold", validation="bool",
219- * description="True if threshold was given, false if it should be unset")
220247 * @Param(type="post", name="threshold", validation="numericint", required=false,
221248 * description="A minimum percentage of points needed to pass the course")
249+ * @Param(type="post", name="pointsLimit", validation="numericint", required=false,
250+ * description="A minimum of (absolute) points needed to pass the course")
222251 * @Param(type="post", name="noAdmin", validation="bool", required=false,
223252 * description="If true, no admin is assigned to group (current user is assigned as admin by default.")
224253 * @throws ForbiddenRequestException
@@ -249,7 +278,6 @@ public function actionAddGroup()
249278 $ isPublic = filter_var ($ req ->getPost ("isPublic " ), FILTER_VALIDATE_BOOLEAN );
250279 $ isOrganizational = filter_var ($ req ->getPost ("isOrganizational " ), FILTER_VALIDATE_BOOLEAN );
251280 $ isExam = filter_var ($ req ->getPost ("isExam " ), FILTER_VALIDATE_BOOLEAN );
252- $ hasThreshold = filter_var ($ req ->getPost ("hasThreshold " ), FILTER_VALIDATE_BOOLEAN );
253281 $ noAdmin = filter_var ($ req ->getPost ("noAdmin " ), FILTER_VALIDATE_BOOLEAN );
254282
255283 if ($ isOrganizational && $ isExam ) {
@@ -267,12 +295,8 @@ public function actionAddGroup()
267295 $ detaining ,
268296 $ isExam ,
269297 );
270- if ($ hasThreshold ) {
271- $ threshold = $ req ->getPost ("threshold " ) !== null
272- ? $ req ->getPost ("threshold " ) / 100
273- : $ group ->getThreshold ();
274- $ group ->setThreshold ($ threshold );
275- }
298+
299+ $ this ->setGroupPoints ($ req , $ group );
276300 $ this ->updateLocalizations ($ req , $ group );
277301
278302 $ this ->groups ->persist ($ group , false );
@@ -329,10 +353,10 @@ public function checkUpdateGroup(string $id)
329353 * required=false, description="Are students prevented from leaving the group on their own?")
330354 * @Param(type="post", name="isPublic", validation="bool",
331355 * description="Should the group be visible to all student?")
332- * @Param(type="post", name="hasThreshold", validation="bool",
333- * description="True if threshold was given, false if it should be unset")
334356 * @Param(type="post", name="threshold", validation="numericint", required=false,
335357 * description="A minimum percentage of points needed to pass the course")
358+ * @Param(type="post", name="pointsLimit", validation="numericint", required=false,
359+ * description="A minimum of (absolute) points needed to pass the course")
336360 * @Param(type="post", name="localizedTexts", validation="array", description="Localized names and descriptions")
337361 * @param string $id An identifier of the updated group
338362 * @throws InvalidArgumentException
@@ -343,22 +367,14 @@ public function actionUpdateGroup(string $id)
343367 $ publicStats = filter_var ($ req ->getPost ("publicStats " ), FILTER_VALIDATE_BOOLEAN );
344368 $ detaining = filter_var ($ req ->getPost ("detaining " ), FILTER_VALIDATE_BOOLEAN );
345369 $ isPublic = filter_var ($ req ->getPost ("isPublic " ), FILTER_VALIDATE_BOOLEAN );
346- $ hasThreshold = filter_var ($ req ->getPost ("hasThreshold " ), FILTER_VALIDATE_BOOLEAN );
347370
348371 $ group = $ this ->groups ->findOrThrow ($ id );
349372 $ group ->setExternalId ($ req ->getPost ("externalId " ));
350373 $ group ->setPublicStats ($ publicStats );
351374 $ group ->setDetaining ($ detaining );
352375 $ group ->setIsPublic ($ isPublic );
353376
354- if ($ hasThreshold ) {
355- $ threshold = $ req ->getPost ("threshold " ) !== null ? $ req ->getPost ("threshold " ) / 100 : $ group ->getThreshold (
356- );
357- $ group ->setThreshold ($ threshold );
358- } else {
359- $ group ->setThreshold (null );
360- }
361-
377+ $ this ->setGroupPoints ($ req , $ group );
362378 $ this ->updateLocalizations ($ req , $ group );
363379
364380 $ this ->groups ->persist ($ group );
0 commit comments