blob: 181fff641298697bda6f2f7ac2f74a98b27443cf (
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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
<?php
/*
* TestBlock.php - Courseware Vips test block
* Copyright (c) 2022 Elmar Ludwig
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
namespace Courseware\BlockTypes;
use VipsAssignment;
use VipsModule;
class TestBlock extends BlockType
{
/**
* Get a short string describing this type of block.
*/
public static function getType(): string
{
return 'test';
}
/**
* Get the title of this type of block.
*/
public static function getTitle(): string
{
return _('Aufgabenblatt');
}
/**
* Get the description of this type of block.
*/
public static function getDescription(): string
{
return _('Stellt ein vorhandenes Aufgabenblatt bereit.');
}
/**
* Get the initial payload of every instance of this block.
*/
public function initialPayload(): array
{
return ['assignment' => ''];
}
/**
* Get the JSON schema for the payload of this block type.
*/
public static function getJsonSchema(): string
{
$schema = [
'type' => 'object',
'properties' => [
'assignment' => [
'type' => 'string'
]
]
];
return json_encode($schema);
}
/**
* Get the list of categories for this block type.
*/
public static function getCategories(): array
{
return ['interaction'];
}
/**
* Get the list of content types for this block type.
*/
public static function getContentTypes(): array
{
return ['rich'];
}
/**
* Get the list of file types for this block type.
*/
public static function getFileTypes(): array
{
return [];
}
/**
* Copy the payload of this block into the given range id.
*/
public function copyPayload(string $rangeId = ''): array
{
static $assignments = [];
$context = $rangeId === $GLOBALS['user']->id ? 'user' : 'course';
$payload = $this->getPayload();
if ($payload['assignment']) {
$assignment = VipsAssignment::find($payload['assignment']);
}
if (!$assignment || !$assignment->checkEditPermission()) {
return $this->initialPayload();
}
if ($context === 'course' && !VipsModule::hasStatus('tutor', $rangeId)) {
return $this->initialPayload();
}
if ($assignment->range_id !== $rangeId) {
if (!isset($assignments[$assignment->id])) {
$copy = $assignment->copyIntoCourse($rangeId, $context);
$assignments[$assignment->id] = $copy->id;
}
$payload['assignment'] = $assignments[$assignment->id];
}
return $payload;
}
}
|