blob: 41b4f7171fb58c5f941582711eb80742d4700ff4 (
plain)
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
|
<?php
namespace Grading;
/**
* @license GPL2 or any later version
*
* @property int $id database column
* @property string $course_id database column
* @property string $item database column
* @property string $name database column
* @property string $tool database column
* @property string $category database column
* @property int $position database column
* @property float $weight database column
* @property int $mkdate database column
* @property int $chdate database column
* @property \SimpleORMapCollection|Instance[] $instances has_many Instance
* @property \Course $course belongs_to \Course
*/
class Definition extends \SimpleORMap
{
const CUSTOM_DEFINITIONS_CATEGORY = 'xyzzy';
protected static function configure($config = [])
{
$config['db_table'] = 'grading_definitions';
$config['belongs_to']['course'] = [
'class_name' => \Course::class,
'foreign_key' => 'course_id',
];
$config['has_many']['instances'] = [
'class_name' => Instance::class,
'assoc_foreign_key' => 'definition_id',
'on_delete' => 'delete',
'on_store' => 'store',
];
parent::configure($config);
}
public static function getCategoriesByCourse(\Course $course)
{
$query = 'SELECT category FROM grading_definitions
WHERE course_id = ?
GROUP BY category
ORDER BY category ASC';
$stmt = \DBManager::get()->prepare($query);
$stmt->execute([$course->id]);
$categories = $stmt->fetchAll(\PDO::FETCH_COLUMN);
$customIndex = array_search(self::CUSTOM_DEFINITIONS_CATEGORY, $categories);
if (false !== $customIndex) {
unset($categories[$customIndex]);
array_unshift($categories, self::CUSTOM_DEFINITIONS_CATEGORY);
}
return $categories;
}
public static function findByCourse(\Course $course)
{
return Definition::findBySQL('course_id = ? ORDER BY position ASC, name ASC', [$course->id]);
}
}
|