1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
<?php
namespace Grading;
class Instance extends \SimpleORMap
{
protected static function configure($config = [])
{
$config['db_table'] = 'grading_instances';
$config['belongs_to']['user'] = [
'class_name' => \User::class,
'foreign_key' => 'user_id',
];
$config['belongs_to']['definition'] = [
'class_name' => Definition::class,
'foreign_key' => 'definition_id',
];
parent::configure($config);
}
public static function findByCourse(\Course $course)
{
$definitionIds = Definition::findAndMapBySQL(
function ($def) {
return $def->id;
},
'course_id = ?',
[$course->id]
);
if (!count($definitionIds)) {
return [];
}
return self::findBySql('definition_id IN (?)', [$definitionIds]);
}
public static function findByCourseAndUser(\Course $course, \User $user)
{
$definitionIds = Definition::findAndMapBySQL(
function ($def) {
return $def->id;
},
'course_id = ?',
[$course->id]
);
if (!count($definitionIds)) {
return [];
}
return self::findBySql('definition_id IN (?) AND user_id = ?', [$definitionIds, $user->id]);
}
/**
* setter for the rawgrade column. The database type is decimal(6,5) UNSIGNED, therefore
* the setter mimics the database behaviour to get valid results from ::isFieldDirty()
*
* @param mixed $grade
* @return string
*/
public function setRawgrade($grade = 0): string
{
if ($grade < 0) {
$grade = 0;
}
if ($grade >= 10) {
$grade = 9.99999;
}
return $this->content['rawgrade'] = number_format($grade, 5, '.', '');
}
}
|