|
1
|
|
|
<?php |
|
2
|
|
|
/* For licensing terms, see /license.txt */ |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Class to be used as basis for links referring to Evaluation objects. |
|
6
|
|
|
* |
|
7
|
|
|
* @author Bert Steppé |
|
8
|
|
|
* |
|
9
|
|
|
* @package chamilo.gradebook |
|
10
|
|
|
* @package chamilo.gradebook |
|
11
|
|
|
*/ |
|
12
|
|
|
abstract class EvalLink extends AbstractLink |
|
13
|
|
|
{ |
|
14
|
|
|
protected $evaluation; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @return bool |
|
18
|
|
|
*/ |
|
19
|
|
|
public function has_results() |
|
20
|
|
|
{ |
|
21
|
|
|
$eval = $this->get_evaluation(); |
|
22
|
|
|
|
|
23
|
|
|
return $eval->has_results(); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param int $userId |
|
28
|
|
|
* @param string $type |
|
29
|
|
|
* |
|
30
|
|
|
* @return array |
|
31
|
|
|
*/ |
|
32
|
|
|
public function calc_score($userId = null, $type = null) |
|
33
|
|
|
{ |
|
34
|
|
|
$eval = $this->get_evaluation(); |
|
35
|
|
|
|
|
36
|
|
|
return $eval->calc_score($userId, $type); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function get_link() |
|
40
|
|
|
{ |
|
41
|
|
|
$eval = $this->get_evaluation(); |
|
42
|
|
|
// course/platform admin can go to the view_results page |
|
43
|
|
|
if (api_is_allowed_to_edit()) { |
|
44
|
|
|
return 'gradebook_view_result.php?'.api_get_cidreq().'&selecteval='.$eval->get_id(); |
|
45
|
|
|
} elseif (ScoreDisplay::instance()->is_custom()) { |
|
46
|
|
|
// students can go to the statistics page (if custom display enabled) |
|
47
|
|
|
|
|
48
|
|
|
return 'gradebook_statistics.php?'.api_get_cidreq().'&selecteval='.$eval->get_id(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return null; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function get_name() |
|
55
|
|
|
{ |
|
56
|
|
|
$eval = $this->get_evaluation(); |
|
57
|
|
|
|
|
58
|
|
|
return $eval->get_name(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function get_description() |
|
62
|
|
|
{ |
|
63
|
|
|
$eval = $this->get_evaluation(); |
|
64
|
|
|
|
|
65
|
|
|
return $eval->get_description(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function get_max() |
|
69
|
|
|
{ |
|
70
|
|
|
$eval = $this->get_evaluation(); |
|
71
|
|
|
|
|
72
|
|
|
return $eval->get_max(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function is_valid_link() |
|
76
|
|
|
{ |
|
77
|
|
|
$eval = $this->get_evaluation(); |
|
78
|
|
|
|
|
79
|
|
|
return isset($eval); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function needs_name_and_description() |
|
83
|
|
|
{ |
|
84
|
|
|
return true; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function needs_max() |
|
88
|
|
|
{ |
|
89
|
|
|
return true; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function needs_results() |
|
93
|
|
|
{ |
|
94
|
|
|
return true; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function add_linked_data() |
|
98
|
|
|
{ |
|
99
|
|
|
if ($this->is_valid_link()) { |
|
100
|
|
|
$this->evaluation->add(); |
|
101
|
|
|
$this->set_ref_id($this->evaluation->get_id()); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function save_linked_data() |
|
106
|
|
|
{ |
|
107
|
|
|
if ($this->is_valid_link()) { |
|
108
|
|
|
$this->evaluation->save(); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function delete_linked_data() |
|
113
|
|
|
{ |
|
114
|
|
|
if ($this->is_valid_link()) { |
|
115
|
|
|
$this->evaluation->delete_with_results(); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function set_name($name) |
|
120
|
|
|
{ |
|
121
|
|
|
if ($this->is_valid_link()) { |
|
122
|
|
|
$this->evaluation->set_name($name); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
public function set_description($description) |
|
127
|
|
|
{ |
|
128
|
|
|
if ($this->is_valid_link()) { |
|
129
|
|
|
$this->evaluation->set_description($description); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function set_max($max) |
|
134
|
|
|
{ |
|
135
|
|
|
if ($this->is_valid_link()) { |
|
136
|
|
|
$this->evaluation->set_max($max); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
// Functions overriding non-trivial implementations from AbstractLink |
|
141
|
|
|
public function set_date($date) |
|
142
|
|
|
{ |
|
143
|
|
|
$this->created_at = $date; |
|
144
|
|
|
if ($this->is_valid_link()) { |
|
145
|
|
|
$this->evaluation->set_date($date); |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
public function set_weight($weight) |
|
150
|
|
|
{ |
|
151
|
|
|
$this->weight = $weight; |
|
152
|
|
|
if ($this->is_valid_link()) { |
|
153
|
|
|
$this->evaluation->set_weight($weight); |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
public function set_visible($visible) |
|
158
|
|
|
{ |
|
159
|
|
|
$this->visible = $visible; |
|
160
|
|
|
if ($this->is_valid_link()) { |
|
161
|
|
|
$this->evaluation->set_visible($visible); |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Lazy load function to get the linked evaluation. |
|
167
|
|
|
*/ |
|
168
|
|
|
protected function get_evaluation() |
|
169
|
|
|
{ |
|
170
|
|
|
if (!isset($this->evaluation)) { |
|
171
|
|
|
if (isset($this->ref_id)) { |
|
172
|
|
|
$evalarray = Evaluation::load($this->get_ref_id()); |
|
173
|
|
|
$this->evaluation = $evalarray[0]; |
|
174
|
|
|
} else { |
|
175
|
|
|
$eval = new Evaluation(); |
|
176
|
|
|
$eval->set_category_id(-1); |
|
177
|
|
|
$eval->set_date(api_get_utc_datetime()); // these values will be changed |
|
178
|
|
|
$eval->set_weight(0); // when the link setter |
|
179
|
|
|
$eval->set_visible(0); // is called |
|
180
|
|
|
$eval->set_id(-1); // a 'real' id will be set when eval is added to db |
|
181
|
|
|
$eval->set_user_id($this->get_user_id()); |
|
182
|
|
|
$eval->set_course_code($this->get_course_code()); |
|
183
|
|
|
$this->evaluation = $eval; |
|
184
|
|
|
$this->set_ref_id($eval->get_id()); |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
return $this->evaluation; |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|