11
11
use App \Model \Entity \AssignmentSolution ;
12
12
use App \Model \Entity \Group ;
13
13
use App \Model \Entity \LocalizedGroup ;
14
+ use App \Model \Entity \ShadowAssignment ;
15
+ use App \Model \Entity \ShadowAssignmentEvaluation ;
14
16
use App \Model \Entity \User ;
15
17
use App \Model \Repository \AssignmentSolutions ;
18
+ use App \Model \Repository \ShadowAssignmentEvaluations ;
16
19
use App \Security \ACL \IAssignmentPermissions ;
17
20
use App \Security \ACL \IGroupPermissions ;
18
21
use Doctrine \Common \Collections \Collection ;
24
27
*/
25
28
class GroupViewFactory {
26
29
27
- /**
28
- * @var AssignmentSolutions
29
- */
30
+ /** @var AssignmentSolutions */
30
31
private $ assignmentSolutions ;
31
32
32
- /**
33
- * @var IGroupPermissions
34
- */
33
+ /** @var IGroupPermissions */
35
34
private $ groupAcl ;
36
35
37
- /**
38
- * @var IAssignmentPermissions
39
- */
36
+ /** @var IAssignmentPermissions */
40
37
private $ assignmentAcl ;
41
38
42
39
/** @var GroupBindingAccessor */
43
40
private $ bindings ;
44
41
42
+ /** @var ShadowAssignmentEvaluations */
43
+ private $ shadowAssignmentEvaluations ;
44
+
45
45
public function __construct (AssignmentSolutions $ assignmentSolutions , IGroupPermissions $ groupAcl ,
46
- IAssignmentPermissions $ assignmentAcl , GroupBindingAccessor $ bindings ) {
46
+ IAssignmentPermissions $ assignmentAcl , GroupBindingAccessor $ bindings ,
47
+ ShadowAssignmentEvaluations $ shadowAssignmentEvaluations ) {
47
48
$ this ->assignmentSolutions = $ assignmentSolutions ;
48
49
$ this ->groupAcl = $ groupAcl ;
49
50
$ this ->assignmentAcl = $ assignmentAcl ;
50
51
$ this ->bindings = $ bindings ;
52
+ $ this ->shadowAssignmentEvaluations = $ shadowAssignmentEvaluations ;
51
53
}
52
54
53
55
@@ -72,12 +74,16 @@ function ($carry, Pair $solutionPair) {
72
74
}
73
75
74
76
/**
75
- * @param Group $group
76
- * @param User $user
77
+ * Get total sum of points which given user gained in given shadow assignments.
78
+ * @param ShadowAssignmentEvaluation[] $shadowEvaluations
77
79
* @return int
78
80
*/
79
- private function getPointsForShadowAssignments (Group $ group , User $ user ): int {
80
- // TODO
81
+ private function getPointsForShadowAssignments (array $ shadowEvaluations ): int {
82
+ return array_reduce ($ shadowEvaluations ,
83
+ function ($ carry , ShadowAssignmentEvaluation $ evaluation ) {
84
+ return $ carry + $ evaluation ->getPoints ();
85
+ },
86
+ 0 );
81
87
}
82
88
83
89
/**
@@ -88,12 +94,13 @@ private function getPointsForShadowAssignments(Group $group, User $user): int {
88
94
*/
89
95
public function getStudentsStats (Group $ group , User $ student ) {
90
96
$ maxPoints = $ group ->getMaxPoints ();
91
- $ solutions = $ this ->assignmentSolutions ->findBestSolutionsForAssignments ($ group ->getAssignments ()->getValues (), $ student );
92
- $ gainedPoints = $ this ->getPointsGainedByStudentForSolutions ($ solutions );
93
- $ gainedPoints += $ this ->getPointsForShadowAssignments ($ group , $ student );
97
+ $ assignmentSolutions = $ this ->assignmentSolutions ->findBestSolutionsForAssignments ($ group ->getAssignments ()->getValues (), $ student );
98
+ $ shadowEvaluations = $ this ->shadowAssignmentEvaluations ->findEvaluationsForAssignment ($ group ->getShadowAssignments ()->getValues (), $ student );
99
+ $ gainedPoints = $ this ->getPointsGainedByStudentForSolutions ($ assignmentSolutions );
100
+ $ gainedPoints += $ this ->getPointsForShadowAssignments ($ shadowEvaluations );
94
101
95
102
$ assignments = [];
96
- foreach ($ solutions as $ solutionPair ) {
103
+ foreach ($ assignmentSolutions as $ solutionPair ) {
97
104
/**
98
105
* @var Assignment $assignment
99
106
* @var AssignmentSolution $best
@@ -113,8 +120,17 @@ public function getStudentsStats(Group $group, User $student) {
113
120
];
114
121
}
115
122
116
- // TODO: points assignments
117
- $ shadowAssignments = null ;
123
+ $ shadowAssignments = [];
124
+ foreach ($ shadowEvaluations as $ evaluation ) {
125
+ $ assignment = $ evaluation ->getShadowAssignment ();
126
+ $ shadowAssignments [] = [
127
+ "id " => $ assignment ->getId (),
128
+ "points " => [
129
+ "total " => $ assignment ->getMaxPoints (),
130
+ "gained " => $ evaluation ->getPoints ()
131
+ ]
132
+ ];
133
+ }
118
134
119
135
return [
120
136
"userId " => $ student ->getId (),
0 commit comments