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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
<?php
class MyInstitutesController extends AuthenticatedController
{
public function before_filter(&$action, &$args)
{
parent::before_filter($action, $args);
if (!$GLOBALS['perm']->have_perm("root")) {
Navigation::activateItem('/browse/my_institutes');
}
$this->user_id = $GLOBALS['user']->id;
PageLayout::setHelpKeyword('Basis.MeineEinrichtungen');
PageLayout::setTitle(_('Meine Einrichtungen'));
}
public function index_action()
{
$this->institutes = MyRealmModel::getMyInstitutes();
if ($this->check_for_new($this->institutes)) {
$this->reset = true;
}
$this->nav_elements = MyRealmModel::calc_single_navigation($this->institutes);
$this->setupSidebar(
$this->institutes,
$this->check_for_new($this->institutes)
);
}
public function decline_inst_action($inst_id)
{
$institut = Institute::find($inst_id);
$ticket_check = check_ticket(Request::option('studipticket'));
if (Request::option('cmd') !== 'kill' && Request::get('cmd') !== 'back') {
$this->flash['decline_inst'] = true;
$this->flash['inst_id'] = $inst_id;
$this->flash['name'] = $institut->name;
$this->flash['studipticket'] = get_ticket();
} elseif (Request::get('cmd') === 'kill' && $ticket_check && Request::get('cmd') !== 'back') {
$changed = InstituteMember::deleteBySQL(
"user_id = ? AND Institut_id = ? AND inst_perms = 'user'",
[$this->user_id, $inst_id]
);
if ($changed > 0) {
PageLayout::postSuccess(sprintf(
_('Die Zuordnung zur Einrichtung %s wurde aufgehoben.'),
'<strong>' . htmlReady($institut->name) . '</strong>'
));
} else {
PageLayout::postError(_('Datenbankfehler'));
}
}
$this->redirect('my_institutes/index');
}
public function tabularasa_action($timestamp = null)
{
$institutes = MyRealmModel::getMyInstitutes();
// This is ugly but since the above does not return object, we need to
// load the institutes again
Institute::findEachMany(
function (Institute $institute) use ($timestamp) {
MyRealmModel::setObjectVisits($institute, $this->user_id, $timestamp);
},
array_column($institutes, 'institut_id')
);
PageLayout::postSuccess(_('Alles als gelesen markiert!'));
$this->redirect('my_institutes/index');
}
protected function check_for_new($my_obj): bool
{
if(!empty($my_obj)) {
foreach ($my_obj as $inst) {
if ($this->check_institute($inst)) {
return true;
}
}
}
return false;
}
protected function check_institute($institute): bool
{
if ($institute['visitdate'] <= $institute['chdate']) {
return true;
}
$plugins = $institute['navigation'];
foreach ($plugins as $navigation) {
if ($navigation && $navigation->isVisible(true) && $navigation->hasBadgeNumber()) {
return true;
}
}
return false;
}
private function setupSidebar(array $institutes, bool $reset)
{
$links = Sidebar::Get()->addWidget(new ActionsWidget());
if ($reset) {
$links->addLink(
_('Alles als gelesen markieren'),
$this->tabularasaURL(time()),
Icon::create('accept'),
[
'data-confirm' => implode("\n", [
_('Sie sind dabei alle Einrichtungen auf gelesen zu setzen.'),
_('Diesen Schritt können sie nicht rückgängig machen.')
]),
]
);
}
if ($GLOBALS['perm']->have_perm('dozent') && count($institutes) > 0) {
$links->addLink(
_('Einrichtungsdaten bearbeiten'),
URLHelper::getURL('dispatch.php/settings/statusgruppen'),
Icon::create('edit')
);
}
if ($GLOBALS['perm']->have_perm('autor')) {
$links->addLink(
_('Einrichtungen suchen'),
URLHelper::getURL('dispatch.php/search/globalsearch#GlobalSearchInstitutes'),
Icon::create('search')
);
$links->addLink(
_('Studiendaten bearbeiten'),
URLHelper::getURL('dispatch.php/settings/studies'),
Icon::create('person')
);
}
}
}
|