2
2
3
3
namespace App \Form \Type ;
4
4
5
+ use App \Entity \Clarification ;
5
6
use App \Entity \ContestProblem ;
6
7
use App \Entity \Team ;
7
8
use App \Service \ConfigurationService ;
8
9
use App \Service \DOMJudgeService ;
9
10
use Doctrine \ORM \EntityManagerInterface ;
10
11
use Symfony \Component \Form \AbstractType ;
11
12
use Symfony \Component \Form \Extension \Core \Type \ChoiceType ;
13
+ use Symfony \Component \Form \Extension \Core \Type \HiddenType ;
12
14
use Symfony \Component \Form \Extension \Core \Type \TextareaType ;
13
15
use Symfony \Component \Form \FormBuilderInterface ;
14
16
use Symfony \Component \OptionsResolver \OptionsResolver ;
15
17
use Symfony \Component \Validator \Constraints \NotEqualTo ;
18
+ use Symfony \Component \Validator \Constraints \Callback ;
19
+ use Symfony \Component \Validator \Context \ExecutionContextInterface ;
16
20
17
21
class JuryClarificationType extends AbstractType
18
22
{
19
23
public const RECIPIENT_MUST_SELECT = 'domjudge-must-select ' ;
20
24
25
+ /** @var int The clarification entity id if the entity exists in the database */
26
+ private $ clarid ;
27
+
21
28
public function __construct (
22
29
private readonly EntityManagerInterface $ em ,
23
30
private readonly ConfigurationService $ config ,
@@ -26,6 +33,7 @@ public function __construct(
26
33
27
34
public function buildForm (FormBuilderInterface $ builder , array $ options ): void
28
35
{
36
+ $ this ->clarid = $ options ['clarid ' ];
29
37
$ recipientOptions = [
30
38
'(select...) ' => static ::RECIPIENT_MUST_SELECT ,
31
39
'ALL ' => '' ,
@@ -104,11 +112,18 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
104
112
'cols ' => 85 ,
105
113
],
106
114
]);
115
+
116
+ $ builder ->add ('jurymember ' , HiddenType::class, [
117
+ 'constraints ' => [
118
+ new Callback ([$ this , 'checkJuryMember ' ])
119
+ ]
120
+ ]);
107
121
}
108
122
109
123
public function configureOptions (OptionsResolver $ resolver ): void
110
124
{
111
125
$ resolver ->setDefault ('limit_to_team ' , null );
126
+ $ resolver ->setDefault ('clarid ' , null );
112
127
}
113
128
114
129
private function getTeamLabel (Team $ team ): string
@@ -119,4 +134,25 @@ private function getTeamLabel(Team $team): string
119
134
120
135
return sprintf ('%s (%s) ' , $ team ->getEffectiveName (), $ team ->getExternalId ());
121
136
}
137
+
138
+ public function checkJuryMember (mixed $ value , ExecutionContextInterface $ context , mixed $ payload ): void
139
+ {
140
+ if ($ this ->clarid ) {
141
+ $ juryMember = $ this ->em ->createQueryBuilder ()
142
+ ->select ('clar.jury_member ' )
143
+ ->from (Clarification::class, 'clar ' )
144
+ ->where ('clar.clarid = :clarid ' )
145
+ ->setParameter ('clarid ' , $ this ->clarid )
146
+ ->getQuery ()
147
+ ->getSingleResult ()['jury_member ' ];
148
+
149
+ // If jury member changed, and we are not currently assigned, warn.
150
+ if ($ value !== $ juryMember && $ this ->dj ->getUser ()->getUserIdentifier () !== $ juryMember ) {
151
+ $ context ->buildViolation ("Jury Member '%jury%' claimed this clarification in the meantime.
152
+ Please resubmit if you want to continue. " )
153
+ ->setParameter ('%jury% ' , $ juryMember )
154
+ ->addViolation ();
155
+ }
156
+ }
157
+ }
122
158
}
0 commit comments