-
Notifications
You must be signed in to change notification settings - Fork 1
/
Stundenzettel.class.php
179 lines (145 loc) · 5.82 KB
/
Stundenzettel.class.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
/**
* Stundenzettel.class.php
*
* ...
*
* @author Annelene Sudau <asudau@uos.de>
* @version 1.0
*/
require_once 'constants.inc.php';
require_once 'models/StundenzettelContract.class.php';
require_once 'models/StundenzettelTimesheet.class.php';
require_once 'models/StundenzettelInstituteSetting.class.php';
class Stundenzettel extends StudipPlugin implements SystemPlugin
{
public function __construct()
{
parent::__construct();
global $perm;
//Personen mit Verwaltungsrolle für Stumis oder Stumis mit in StudIP hinterlegtem Arbeitsvertrag
if( $GLOBALS['perm']->have_perm('tutor') && $this->hasStumiContract () ){
$this->setupStundenzettelNavigation();
} else if( $GLOBALS['perm']->have_perm('dozent') && $this->hasStumiAdminrole() ) {
$this->setupAdminNavigation();
} else if ($GLOBALS['perm']->have_perm('dozent') && $this->isStumiSupervisor()) {
$this->setupSupervisorNavigation();
}
}
public function initialize ()
{
}
private function setupAdminNavigation()
{
$navigation = new Navigation('Stundenzettelverwaltung');
$navigation->setURL(PluginEngine::getURL($this, array(), 'index'));
$item = new Navigation(_('Übersicht'), PluginEngine::getURL($this, array(), 'index'));
$navigation->addSubNavigation('index', $item);
$item = new Navigation(_('Stundenzettel verwalten'), PluginEngine::getURL($this, array(), 'timesheet/admin_index'));
$navigation->addSubNavigation('timesheets', $item);
Navigation::addItem('contents/stundenzettelverwaltung', $navigation);
}
private function setupStundenzettelNavigation()
{
$navigation = new Navigation('Stundenzettel');
$navigation->setURL(PluginEngine::getURL($this, array(), 'timesheet/timesheet'));
$item = new Navigation(_('Stundenerfassung'), PluginEngine::getURL($this, array(), 'timesheet/timesheet'));
$navigation->addSubNavigation('timetracking', $item);
$item = new Navigation(_('Alle Stundenzettel verwalten'), PluginEngine::getURL($this, array(), 'timesheet'));
$navigation->addSubNavigation('timesheets', $item);
$item = new Navigation(_('Vertragsübersicht'), PluginEngine::getURL($this, array(), 'index'));
$navigation->addSubNavigation('index', $item);
Navigation::addItem('contents/stundenzettelverwaltung', $navigation);
}
private function setupSupervisorNavigation()
{
$navigation = new Navigation('Stundenzettelverwaltung');
$navigation->setURL(PluginEngine::getURL($this, array(), 'index'));
$item = new Navigation(_('Übersicht'), PluginEngine::getURL($this, array(), 'index'));
$navigation->addSubNavigation('index', $item);
$item = new Navigation(_('Stundenzettel verwalten'), PluginEngine::getURL($this, array(), 'timesheet/admin_index'));
$navigation->addSubNavigation('timesheets', $item);
Navigation::addItem('contents/stundenzettelverwaltung', $navigation);
}
public function getCommentOptions ()
{
return array(
'Krank',
'Urlaub',
'Feiertag'
);
}
public function getMonths ()
{
return array('01', '02','03','04','05','06','07','08','09','10','11','12');
}
public function getYears ()
{
return array( '2020', '2021','2022','2023','2024','2025','2026','2027');
}
public function hasStumiAdminrole ()
{
return RolePersistence::isAssignedRole($GLOBALS['user']->user_id, \Stundenzettelverwaltung\STUNDENVERWALTUNG_ROLE);
}
public function getAdminInstIds ()
{
$roles = RolePersistence::getAllRoles();
foreach($roles as $role) {
if($role->getRolename() == \Stundenzettelverwaltung\STUNDENVERWALTUNG_ROLE) {
$role_id = $role->getRoleid();
}
}
$inst_ids = RolePersistence::getAssignedRoleInstitutes($GLOBALS['user']->user_id, $role_id);
//keine leeren Einträge
return array_filter($inst_ids);
}
public function isInstAdmin($inst_id)
{
return in_array($inst_id, self::getAdminInstIds () );
}
public function hasStumiContract ()
{
return StundenzettelContract::findByUser_id($GLOBALS['user']->user_id);
}
public function isStumiSupervisor ()
{
return StundenzettelContract::findBySupervisor($GLOBALS['user']->user_id);
}
//TODO gehört in die Models
public function can_access_contract_timesheets($contract_id)
{
$contract = StundenzettelContract::find($contract_id);
if ($contract->supervisor == User::findCurrent()->user_id || $contract->user_id == User::findCurrent()->user_id ){
return true;
} else {
return false;
}
}
//TODO gehört in die Models
public function can_access_timesheet($timesheet_id)
{
$timesheet = StundenzettelTimesheet::find($timesheet_id);
return self::can_access_contract_timesheets($timesheet->contract_id);
}
public function perform($unconsumed_path)
{
$this->setupAutoload();
$dispatcher = new Trails_Dispatcher(
$this->getPluginPath(),
rtrim(PluginEngine::getLink($this, array(), null), '/'),
'show'
);
$dispatcher->plugin = $this;
$dispatcher->dispatch($unconsumed_path);
}
private function setupAutoload()
{
if (class_exists('StudipAutoloader')) {
StudipAutoloader::addAutoloadPath(__DIR__ . '/models');
} else {
spl_autoload_register(function ($class) {
include_once __DIR__ . $class . '.php';
});
}
}
}