22
33namespace App \Model \Entity ;
44
5+ use App \Model \GroupExamLockType ;
56use Doctrine \ORM \Mapping as ORM ;
67use DateTime ;
78use JsonSerializable ;
1112 * @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(columns={"group_id", "begin"})})
1213 * Holds history record of an exam that took place in a group.
1314 * The `examBegin`, `examEnd` fields are copied from group to `begin`, `end` fields here,
14- * `examLockStrict ` is copied to `lockStrict ` field.
15+ * `examLockType ` is copied to `lockType ` field.
1516 * This entity is created when the first user locks in (i.e., only exams with users are recorded in history).
1617 */
1718class GroupExam implements JsonSerializable
@@ -20,58 +21,61 @@ class GroupExam implements JsonSerializable
2021 * @ORM\Id
2122 * @ORM\Column(type="integer")
2223 * @ORM\GeneratedValue(strategy="AUTO")
24+ * @var int|null
2325 */
2426 protected $ id ;
2527
2628 /**
2729 * @ORM\ManyToOne(targetEntity="Group", inversedBy="exams")
30+ * @var Group
2831 */
2932 protected $ group ;
3033
3134 /**
3235 * @ORM\Column(type="datetime")
33- * @var DateTime
36+ * @var DateTime|null
3437 */
3538 protected $ begin = null ;
3639
3740 /**
3841 * @ORM\Column(type="datetime")
39- * @var DateTime
42+ * @var DateTime|null
4043 */
4144 protected $ end = null ;
4245
4346 /**
44- * @ORM\Column(type="boolean")
45- * Saved value from examLockStrict flag.
47+ * @ORM\Column(type="string")
48+ * Saved value from examLockType flag.
49+ * @var string
4650 */
47- protected $ lockStrict = false ;
51+ protected $ lockType = GroupExamLockType::Visible-> value ;
4852
4953 /**
5054 * Constructor
5155 * @param Group $group
5256 * @param DateTime $begin
5357 * @param DateTime $end
54- * @param bool $strict
58+ * @param GroupExamLockType $type
5559 */
56- public function __construct (Group $ group , DateTime $ begin , DateTime $ end , bool $ strict )
60+ public function __construct (Group $ group , DateTime $ begin , DateTime $ end , GroupExamLockType $ type )
5761 {
5862 $ this ->group = $ group ;
5963 $ this ->begin = $ begin ;
6064 $ this ->end = $ end ;
61- $ this ->lockStrict = $ strict ;
65+ $ this ->lockType = $ type -> value ;
6266 }
6367
6468 /**
6569 * Update the parameters (happens if pending exam is cut short, for instance).
6670 * @param DateTime $begin
6771 * @param DateTime $end
68- * @param bool $strict
72+ * @param GroupExamLockType $type
6973 */
70- public function update (DateTime $ begin , DateTime $ end , bool $ strict ): void
74+ public function update (DateTime $ begin , DateTime $ end , GroupExamLockType $ type ): void
7175 {
7276 $ this ->begin = $ begin ;
7377 $ this ->end = $ end ;
74- $ this ->lockStrict = $ strict ;
78+ $ this ->lockType = $ type -> value ;
7579 }
7680
7781 public function jsonSerialize (): mixed
@@ -82,7 +86,9 @@ public function jsonSerialize(): mixed
8286 "groupId " => $ group ? $ group ->getId () : null ,
8387 "begin " => $ this ->getBegin ()->getTimestamp (),
8488 "end " => $ this ->getEnd ()->getTimestamp (),
85- "strict " => $ this ->lockStrict ,
89+ "type " => $ this ->lockType ,
90+ // BC only, DEPRECATED
91+ "strict " => $ this ->lockType === GroupExamLockType::Restricted->value ,
8692 ];
8793 }
8894
@@ -113,6 +119,11 @@ public function getEnd(): DateTime
113119
114120 public function isLockStrict (): bool
115121 {
116- return $ this ->lockStrict ;
122+ return $ this ->lockType === GroupExamLockType::Restricted->value ;
123+ }
124+
125+ public function getLockType (): GroupExamLockType
126+ {
127+ return GroupExamLockType::from ($ this ->lockType );
117128 }
118129}
0 commit comments