blob: c9b77f893641d4aba0ecd13724d5503d084c954f (
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
|
<?php
namespace Courseware\ContainerTypes;
use DBManager;
use SimpleORMap;
/**
* This class represents the activation state of a container type.
*
* @SuppressWarnings(PHPMD.StaticAccess)
*/
class ContainerTypeState extends SimpleORMap
{
protected static function configure($config = [])
{
$config['db_table'] = 'cw_container_type_states';
parent::configure($config);
}
/**
* Returns all `ContainerType`s that are activated in this Stud.IP installation.
*
* @return iterable<string> an iterable of all `ContainerType` classes that are activated.
*/
public static function getActivatedContainerTypes(): iterable
{
$args = [
ContainerType::getContainerTypes(),
DBManager::get()->fetchFirst(
'SELECT `container_type` FROM `cw_container_type_states` WHERE `activated` = 0'
),
];
return [...array_diff(...$args)];
}
/**
* Activate the `ContainerType` this `ContainerTypeState` is relating to.
*
* @return `true` on success, `false` otherwise
*/
public function activate(): bool
{
$this->activated = 1;
return (bool) $this->store();
}
/**
* Deactivate the `ContainerType` this `ContainerTypeState` is relating to.
*
* @return `true` on success, `false` otherwise
*/
public function deactivate(): bool
{
$this->activated = 0;
return (bool) $this->store();
}
}
|