2020use App \Security \ACL \IShadowAssignmentPermissions ;
2121use App \Security \ACL \IGroupPermissions ;
2222use Nette \Utils \Arrays ;
23+ use Doctrine \Common \Collections \Collection ;
2324
2425/**
2526 * Factory for group views which somehow do not fit into json serialization of
@@ -94,6 +95,30 @@ function ($carry, ShadowAssignmentPoints $points) {
9495 );
9596 }
9697
98+ /**
99+ * Get assignments of the group which current user can view.
100+ */
101+ private function getAssignments (Group $ group ): Collection
102+ {
103+ return $ group ->getAssignments ()->filter (
104+ function (Assignment $ assignment ) {
105+ return $ this ->assignmentAcl ->canViewDetail ($ assignment );
106+ }
107+ );
108+ }
109+
110+ /**
111+ * Get shadow assignments of the group which current user can view.
112+ */
113+ private function getShadowAssignments (Group $ group ): Collection
114+ {
115+ return $ group ->getShadowAssignments ()->filter (
116+ function (ShadowAssignment $ assignment ) {
117+ return $ this ->shadowAssignmentAcl ->canViewDetail ($ assignment );
118+ }
119+ );
120+ }
121+
97122 /**
98123 * Get the statistics of an individual student.
99124 * @param Group $group
@@ -108,9 +133,9 @@ private function getStudentStatsInternal(
108133 array $ assignmentSolutions ,
109134 array $ reviewRequests
110135 ) {
111- $ maxPoints = $ group -> getMaxPoints () ;
136+ $ maxPoints = 0 ;
112137 $ shadowPointsMap = $ this ->shadowAssignmentPointsRepository ->findPointsForAssignments (
113- $ group ->getShadowAssignments ()->getValues (),
138+ $ this ->getShadowAssignments ($ group )->getValues (),
114139 $ student
115140 );
116141 $ gainedPoints = $ this ->getPointsGainedByStudentForSolutions ($ assignmentSolutions );
@@ -119,10 +144,11 @@ private function getStudentStatsInternal(
119144 $ studentReviewRequests = $ reviewRequests [$ student ->getId ()] ?? [];
120145
121146 $ assignments = [];
122- foreach ($ group ->getAssignments ()-> getValues ( ) as $ assignment ) {
147+ foreach ($ this ->getAssignments ($ group ) as $ assignment ) {
123148 /**
124149 * @var Assignment $assignment
125150 */
151+ $ maxPoints += $ assignment ->getGroupPoints ();
126152 $ best = Arrays::get ($ assignmentSolutions , $ assignment ->getId (), null );
127153 $ submission = $ best ? $ best ->getLastSubmission () : null ;
128154
@@ -141,10 +167,11 @@ private function getStudentStatsInternal(
141167 }
142168
143169 $ shadowAssignments = [];
144- foreach ($ group ->getShadowAssignments ()-> getValues ( ) as $ shadowAssignment ) {
170+ foreach ($ this ->getShadowAssignments ($ group ) as $ shadowAssignment ) {
145171 /**
146172 * @var ShadowAssignment $shadowAssignment
147173 */
174+ $ maxPoints += $ shadowAssignment ->getGroupPoints ();
148175 $ shadowPoints = Arrays::get ($ shadowPointsMap , $ shadowAssignment ->getId (), null );
149176
150177 $ shadowAssignments [] = [
@@ -189,7 +216,7 @@ private function getStudentStatsInternal(
189216 public function getStudentsStats (Group $ group , User $ student )
190217 {
191218 $ assignmentSolutions = $ this ->assignmentSolutions ->findBestUserSolutionsForAssignments (
192- $ group ->getAssignments ()->getValues (),
219+ $ this ->getAssignments ($ group )->getValues (),
193220 $ student
194221 );
195222 $ reviewRequestSolutions = $ this ->assignmentSolutions ->findReviewRequestSolutionsIndexed ($ group , $ student );
@@ -204,7 +231,7 @@ public function getStudentsStats(Group $group, User $student)
204231 public function getAllStudentsStats (Group $ group )
205232 {
206233 $ assignmentSolutions = $ this ->assignmentSolutions ->findBestSolutionsForAssignments (
207- $ group ->getAssignments ()->getValues ()
234+ $ this ->getAssignments ($ group )->getValues ()
208235 );
209236 $ reviewRequestSolutions = $ this ->assignmentSolutions ->findReviewRequestSolutionsIndexed ($ group );
210237 return array_map (
@@ -237,20 +264,12 @@ public function getGroup(Group $group, bool $ignoreArchived = true): array
237264 "students " => $ this ->groupAcl ->canViewStudents ($ group ) ? $ group ->getStudentsIds () : [],
238265 "instanceId " => $ group ->getInstance () ? $ group ->getInstance ()->getId () : null ,
239266 "hasValidLicence " => $ group ->hasValidLicense (),
240- "assignments " => $ group ->getAssignments ()->filter (
241- function (Assignment $ assignment ) {
242- return $ this ->assignmentAcl ->canViewDetail ($ assignment );
243- }
244- )->map (
267+ "assignments " => $ this ->getAssignments ($ group )->map (
245268 function (Assignment $ assignment ) {
246269 return $ assignment ->getId ();
247270 }
248271 )->getValues (),
249- "shadowAssignments " => $ group ->getShadowAssignments ()->filter (
250- function (ShadowAssignment $ assignment ) {
251- return $ this ->shadowAssignmentAcl ->canViewDetail ($ assignment );
252- }
253- )->map (
272+ "shadowAssignments " => $ this ->getShadowAssignments ($ group )->map (
254273 function (ShadowAssignment $ assignment ) {
255274 return $ assignment ->getId ();
256275 }
0 commit comments