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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
<?php
namespace Grading;
use OAT\Library\Lti1p3Ags\Model\LineItem\LineItem;
use OAT\Library\Lti1p3Ags\Model\LineItem\LineItemInterface;
use OAT\Library\Lti1p3Ags\Model\LineItem\LineItemSubmissionReview;
/**
* @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]);
}
public function toLineItem() : LineItemInterface
{
//Build the resource link identifier first:
$studip_ids = explode('-', $this->tool ?? '');
$tool_id = $studip_ids[1] ?? '';
$deployment_id = $studip_ids[2] ?? '';
$resource_link_identifier = sprintf('%s_%s_%s', $tool_id, $deployment_id, $this->course_id);
$identifier = \URLHelper::getURL(
'dispatch.php/lti/ags/line_item',
[
'cid' => $this->course_id,
'definition_id' => $this->id,
'deployment_id' => $deployment_id,
'tool_id' => $tool_id
]
);
return new LineItem(
PHP_FLOAT_MAX,
$this->name,
$identifier,
$deployment_id,
$resource_link_identifier
);
}
}
|