Newer
Older
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
<?php
/**
* ToolActivation.class.php
* model class for table tools_activated
*
* 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.
*
* @author André Noack <noack@data-quest.de>
* @copyright 2021 Stud.IP Core-Group
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
*
* @property string range_id database column
* @property string range_type database column
* @property string plugin_id database column
* @property string position database column
* @property string metadata database column
* @property string mkdate database column
* @property string chdate database column
*/
class ToolActivation extends SimpleORMap
{
protected static function configure($config = [])
{
$config['db_table'] = 'tools_activated';
$config['belongs_to']['institute'] = [
'class_name' => Institute::class,
'foreign_key' => 'range_id',
];
$config['belongs_to']['course'] = [
'class_name' => Course::class,
'foreign_key' => 'range_id',
];
$config['serialized_fields']['metadata'] = 'JSONArrayObject';
$config['registered_callbacks']['before_create'][] = 'setMaxPosition';
parent::configure($config);
}
public function setSerializedValue($field, $value)
{
if ($value === null) {
$value = [];
}
return parent::setSerializedValue($field, $value);
}
public function getStudipModule()
{
return PluginManager::getInstance()->getPluginById($this->plugin_id);
}
public function setStudipModule(StudipModule $module)
{
$this->plugin_id = $module->getPluginId();
}
public function setMaxPosition()
{
$max_position = DBManager::get()->fetchColumn(
"SELECT MAX(position) FROM tools_activated WHERE range_id = ?",
[$this->range_id]
);
$this->position = $max_position === null ? 0 : $max_position + 1;
}
public function getDisplayname()
{
if (isset($this->metadata['displayname'])) {
return $this->metadata['displayname'];
}
return $this->getDefaultDisplayname();
}
public function getDefaultDisplayname()
{
$module = $this->getStudipModule();
if ($module) {
$metadata = $module->getMetadata();
$name = $metadata['displayname'] ?: $module->getPluginName();
return $name;
}
}
public function getVisibilityPermission()
{
if ($this->metadata['visibility'] === 'tutor') {
return 'tutor';
} else {