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
|
<?php
/**
* Abstract controller for the consultation app.
*
* @author Jan-Hendrik Willms <tleilax+studip@gmail.com>
* @license GPL2 or any later version
* @since Stud.IP 4.3
*/
abstract class ConsultationController extends AuthenticatedController
{
public function before_filter(&$action, &$args)
{
parent::before_filter($action, $args);
$type = 'person';
if (Request::has('username')) {
$this->range = User::findByUsername(Request::username('username'));
} elseif (Request::has('cid')) {
$this->range = Context::get();
$type = 'object';
} else {
$this->range = User::findCurrent();
}
if (!$this->range) {
$this->redirect($this->not_foundURL($type));
return;
}
if ($this->range instanceof User) {
URLHelper::addLinkParam('username', $this->range->username);
} elseif ($this->range instanceof Course || $this->range instanceof Institute) {
URLHelper::addLinkParam('cid', $this->range->id);
}
// This defines the function to display a note. Not really a partial,
// not a controller method. This has no real place...
$this->displayNote = function ($what, $length = 40, $position = 'above') {
$what = trim($what);
if (!$what) {
return '';
}
if (mb_strlen($what) < $length) {
return '<div class="consultation-note consultation-note-' . $position . '">' . formatLinks($what) . '</div>';
}
return sprintf(
'<div class="consultation-note consultation-note-%s shortened" data-tooltip=\'%s\'>%s…</div>',
$position,
json_encode(['html' => formatLinks($what)]),
htmlReady(substr($what, 0, $length))
);
};
}
public function not_found_action(string $type): void
{
$this->type = $type;
$this->render_template('consultation/not_found', $this->layout);
}
protected function activateNavigation($path): void
{
$path = ltrim($path, '/');
if ($this->range instanceof User) {
Navigation::activateItem("/profile/consultation/{$path}");
} elseif ($this->range instanceof Course || $this->range instanceof Institute) {
Navigation::activateItem("/course/consultation/{$path}");
} else {
throw new Exception('Not implemented yet');
}
}
protected function getConsultationTitle(): string
{
return $this->range->getConfiguration()->CONSULTATION_TAB_TITLE;
}
/**
* @param $block_id
*
* @return ConsultationBlock|ConsultationBlock[]
* @throws AccessDeniedException
*/
protected function loadBlock($block_id)
{
if (is_array($block_id)) {
return array_map([$this, 'loadBlock'], $block_id);
}
$block = ConsultationBlock::find($block_id);
if (!$block || !$block->range) {
throw new Exception(_('Dieser Terminblock ist ungültig.'));
}
if (!$block->range->isAccessibleToUser()) {
throw new AccessDeniedException();
}
return $block;
}
protected function loadSlot($block_id, $slot_id): ConsultationSlot
{
$block = $this->loadBlock($block_id);
$slot = $block->slots->find($slot_id);
if (!$slot) {
throw new Exception(_('Dieser Termin existiert nicht'));
}
return $slot;
}
protected function loadBooking($block_id, $slot_id, $booking_id): ConsultationBooking
{
$slot = $this->loadSlot($block_id, $slot_id);
$booking = $slot->bookings->find($booking_id);
if (!$booking) {
throw new Exception(_('Diese Buchung existiert nicht'));
}
return $booking;
}
}
|