-
Notifications
You must be signed in to change notification settings - Fork 1
/
LernkartenPlugin.php
123 lines (105 loc) · 3.13 KB
/
LernkartenPlugin.php
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
<?php
use DI\Container;
use DI\ContainerBuilder;
use Lernkarten\Http\Controllers\ExportPDF;
use Lernkarten\Http\Controllers\Wildcard;
use Lernkarten\JsonApi\Routes;
use Lernkarten\JsonApi\Schemas;
use Lernkarten\StudIP\Datenschutz;
use JsonApi\Contracts\JsonApiPlugin;
use Slim\App;
use Slim\Factory\AppFactory;
use Slim\Routing\RouteCollectorProxy;
require_once __DIR__ . '/vendor/autoload.php';
/**
* @SuppressWarnings(StaticAccess)
*/
class LernkartenPlugin extends StudIPPlugin implements SystemPlugin, StandardPlugin, JsonApiPlugin
{
use Routes;
use Schemas;
use Datenschutz;
public function __construct()
{
parent::__construct();
$this->addContentsNavigation();
}
/**
* {@inheritdoc}
*/
public function getTabNavigation($courseId)
{
return ['lernkarten' => $this->createNavigation($courseId)];
}
/**
* {@inheritdoc}
*/
public function getIconNavigation($courseId, $lastVisit, $userId)
{
$icon = new AutoNavigation(
$this->_('Lernkarten'),
PluginEngine::getURL($this, ['cid' => $courseId, 'iconnav' => 'true'], '', true)
);
$icon->setImage(Icon::create('dialog-cards', 'inactive', ['title' => 'Lernkarten']));
return $icon;
}
/**
* {@inheritdoc}
*
* @param string $courseId
* @return null|object
*/
public function getInfoTemplate($courseId)
{
return null;
}
/**
* @SuppressWarnings(PHPMD.Superglobals)
* @SuppressWarnings(UnusedFormalParameter)
* @param string $unconsumedPath
*/
public function perform($unconsumedPath)
{
$app = $this->getSlimApp();
$this->addRoutes($app);
$app->run();
}
private function addContentsNavigation(): void
{
Navigation::addItem('/contents/lernkarten', $this->createNavigation());
}
private function addRoutes(App $app): App
{
$app->get('/api/pdf/{id:[0-9]+}', ExportPDF::class);
$app->any('{path:.*}', Wildcard::class);
return $app;
}
private function createNavigation(string $cid = null): Navigation
{
$params = $cid ? ['cid' => $cid] : [];
$navigation = new Navigation($this->_('Lernkarten'));
$navigation->setDescription(
$this->_('Eigene Kartensätze erstellen, teilen und in Kurse einbinden')
);
$navigation->setImage(Icon::create('dialog-cards', 'navigation'));
$navigation->setURL(PluginEngine::getURL($this, $params, '', true));
// subnavigation
$navigation->addSubnavigation('index', clone $navigation);
return $navigation;
}
private function getSlimApp(): App
{
$app = AppFactory::createFromContainer($this->getSlimContainer());
$app->setBasePath(rtrim(PluginEngine::getLink($this, [], null, true), '/'));
return $app;
}
private function getSlimContainer(): Container
{
$builder = new ContainerBuilder();
$builder->addDefinitions([
'plugin' => $this,
User::class => User::findCurrent(),
]);
return $builder->build();
}
}