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
@@ -110,7 +135,7 @@ private function getStudentStatsInternal(
110135 ) {
111136 $ maxPoints = $ group ->getMaxPoints ();
112137 $ shadowPointsMap = $ this ->shadowAssignmentPointsRepository ->findPointsForAssignments (
113- $ group ->getShadowAssignments ()->getValues (),
138+ $ this ->getShadowAssignments ($ group )->getValues (),
114139 $ student
115140 );
116141 $ gainedPoints = $ this ->getPointsGainedByStudentForSolutions ($ assignmentSolutions );
@@ -119,7 +144,7 @@ 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 */
@@ -141,7 +166,7 @@ private function getStudentStatsInternal(
141166 }
142167
143168 $ shadowAssignments = [];
144- foreach ($ group ->getShadowAssignments ()-> getValues ( ) as $ shadowAssignment ) {
169+ foreach ($ this ->getShadowAssignments ($ group ) as $ shadowAssignment ) {
145170 /**
146171 * @var ShadowAssignment $shadowAssignment
147172 */
@@ -189,7 +214,7 @@ private function getStudentStatsInternal(
189214 public function getStudentsStats (Group $ group , User $ student )
190215 {
191216 $ assignmentSolutions = $ this ->assignmentSolutions ->findBestUserSolutionsForAssignments (
192- $ group ->getAssignments ()->getValues (),
217+ $ this ->getAssignments ($ group )->getValues (),
193218 $ student
194219 );
195220 $ reviewRequestSolutions = $ this ->assignmentSolutions ->findReviewRequestSolutionsIndexed ($ group , $ student );
@@ -204,7 +229,7 @@ public function getStudentsStats(Group $group, User $student)
204229 public function getAllStudentsStats (Group $ group )
205230 {
206231 $ assignmentSolutions = $ this ->assignmentSolutions ->findBestSolutionsForAssignments (
207- $ group ->getAssignments ()->getValues ()
232+ $ this ->getAssignments ($ group )->getValues ()
208233 );
209234 $ reviewRequestSolutions = $ this ->assignmentSolutions ->findReviewRequestSolutionsIndexed ($ group );
210235 return array_map (
@@ -237,20 +262,12 @@ public function getGroup(Group $group, bool $ignoreArchived = true): array
237262 "students " => $ this ->groupAcl ->canViewStudents ($ group ) ? $ group ->getStudentsIds () : [],
238263 "instanceId " => $ group ->getInstance () ? $ group ->getInstance ()->getId () : null ,
239264 "hasValidLicence " => $ group ->hasValidLicense (),
240- "assignments " => $ group ->getAssignments ()->filter (
241- function (Assignment $ assignment ) {
242- return $ this ->assignmentAcl ->canViewDetail ($ assignment );
243- }
244- )->map (
265+ "assignments " => $ this ->getAssignments ($ group )->map (
245266 function (Assignment $ assignment ) {
246267 return $ assignment ->getId ();
247268 }
248269 )->getValues (),
249- "shadowAssignments " => $ group ->getShadowAssignments ()->filter (
250- function (ShadowAssignment $ assignment ) {
251- return $ this ->shadowAssignmentAcl ->canViewDetail ($ assignment );
252- }
253- )->map (
270+ "shadowAssignments " => $ this ->getShadowAssignments ($ group )->map (
254271 function (ShadowAssignment $ assignment ) {
255272 return $ assignment ->getId ();
256273 }
0 commit comments