summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/controller/angeltypes_controller.php61
-rw-r--r--includes/model/Room_model.php11
-rw-r--r--includes/model/Shifts_model.php25
-rw-r--r--includes/sys_template.php26
-rw-r--r--includes/view/AngelTypes_view.php111
-rw-r--r--includes/view/Rooms_view.php5
-rw-r--r--includes/view/ShiftCalendarRenderer.php2
-rw-r--r--includes/view/ShiftsFilterRenderer.php10
8 files changed, 211 insertions, 40 deletions
diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php
index eaaa9c0f..5c3bd859 100644
--- a/includes/controller/angeltypes_controller.php
+++ b/includes/controller/angeltypes_controller.php
@@ -1,5 +1,7 @@
<?php
+use Engelsystem\ShiftsFilter;
+use Engelsystem\ShiftsFilterRenderer;
/**
* Text for Angeltype related links.
*
@@ -182,6 +184,14 @@ function angeltype_controller()
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
$user_driver_license = UserDriverLicense($user['UID']);
$members = Users_by_angeltype($angeltype);
+
+ $days = angeltype_controller_shiftsFilterDays($angeltype);
+ $shiftsFilter = angeltype_controller_shiftsFilter($angeltype, $days);
+
+ $shiftsFilterRenderer = new ShiftsFilterRenderer($shiftsFilter);
+ $shiftsFilterRenderer->enableDaySelection($days);
+
+ $shiftCalendarRenderer = shiftCalendarRendererByShiftFilter($shiftsFilter);
return [
sprintf(_('Team %s'), $angeltype['name']),
@@ -193,12 +203,61 @@ function angeltype_controller()
in_array('admin_angel_types', $privileges),
$user_angeltype['supporter'],
$user_driver_license,
- $user
+ $user,
+ $shiftsFilterRenderer,
+ $shiftCalendarRenderer
)
];
}
/**
+ * On which days do shifts for this angeltype occur? Needed for shiftCalendar.
+ *
+ * @param Angeltype $angeltype
+ * @return array
+ */
+function angeltype_controller_shiftsFilterDays($angeltype) {
+ $all_shifts = Shifts_by_angeltype($angeltype);
+ $days = [];
+ foreach ($all_shifts as $shift) {
+ $day = date('Y-m-d', $shift['start']);
+ if (!in_array($day, $days)) {
+ $days[] = $day;
+ }
+ }
+ return $days;
+}
+
+/**
+ * Sets up the shift filter for the angeltype.
+ *
+ * @param Angeltype $angeltype
+ * @param array $days
+ * @return ShiftsFilter
+ */
+function angeltype_controller_shiftsFilter($angeltype, $days) {
+ global $privileges;
+
+ $request = request();
+ $shiftsFilter = new ShiftsFilter(
+ in_array('user_shifts_admin', $privileges),
+ Room_ids(),
+ [$angeltype['id']]
+ );
+ $selected_day = date('Y-m-d');
+ if (!empty($days)) {
+ $selected_day = $days[0];
+ }
+ if ($request->has('shifts_filter_day')) {
+ $selected_day = $request->input('shifts_filter_day');
+ }
+ $shiftsFilter->setStartTime(parse_date('Y-m-d H:i', $selected_day . ' 00:00'));
+ $shiftsFilter->setEndTime(parse_date('Y-m-d H:i', $selected_day . ' 23:59'));
+
+ return $shiftsFilter;
+}
+
+/**
* View a list of all angeltypes.
*
* @return array
diff --git a/includes/model/Room_model.php b/includes/model/Room_model.php
index 8425e5ad..74a08be4 100644
--- a/includes/model/Room_model.php
+++ b/includes/model/Room_model.php
@@ -14,6 +14,17 @@ function Rooms($show_all = false)
}
/**
+ * Returns Room id array
+ *
+ * @return array
+ */
+function Room_ids()
+{
+ $result = DB::select('SELECT `RID` FROM `Room`');
+ return select_array($result, 'RID', 'RID');
+}
+
+/**
* Delete a room
*
* @param int $room_id
diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php
index ef02aaab..8a1b69f9 100644
--- a/includes/model/Shifts_model.php
+++ b/includes/model/Shifts_model.php
@@ -5,6 +5,29 @@ use Engelsystem\ShiftsFilter;
use Engelsystem\ShiftSignupState;
/**
+ * @param array $angeltype
+ * @return array
+ */
+function Shifts_by_angeltype($angeltype) {
+ return DB::select('
+ SELECT DISTINCT `Shifts`.* FROM `Shifts`
+ JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id` = `Shifts`.`SID`
+ WHERE `NeededAngelTypes`.`angel_type_id` = ?
+ AND `NeededAngelTypes`.`count` > 0
+ AND `Shifts`.`PSID` IS NULL
+
+ UNION
+
+ SELECT DISTINCT `Shifts`.* FROM `Shifts`
+ JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`room_id` = `Shifts`.`RID`
+ WHERE `NeededAngelTypes`.`angel_type_id` = ?
+ AND `NeededAngelTypes`.`count` > 0
+ AND NOT `Shifts`.`PSID` IS NULL
+ ', [$angeltype['id'], $angeltype['id']]);
+}
+
+
+/**
* @param array $room
* @return array
*/
@@ -24,7 +47,7 @@ function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
FROM `Shifts`
JOIN `Room` USING (`RID`)
JOIN `ShiftTypes` ON `ShiftTypes`.`id` = `Shifts`.`shifttype_id`
- JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`
+ JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id` = `Shifts`.`SID`
WHERE `Shifts`.`RID` IN (' . implode(',', $shiftsFilter->getRooms()) . ')
AND `start` BETWEEN ? AND ?
AND `NeededAngelTypes`.`angel_type_id` IN (' . implode(',', $shiftsFilter->getTypes()) . ')
diff --git a/includes/sys_template.php b/includes/sys_template.php
index 662283b1..96290062 100644
--- a/includes/sys_template.php
+++ b/includes/sys_template.php
@@ -1,6 +1,32 @@
<?php
/**
+ * Renders tabs from the array. Array key is tab name, array value is tab content.
+ *
+ * @param array $tabs
+ * @return string HTML
+ */
+function tabs($tabs)
+{
+ $tab_header = [];
+ $tab_content = [];
+ foreach($tabs as $header => $content) {
+ $class = '';
+ if(count($tab_header) == 0) {
+ $class = 'active';
+ }
+ $tab_header[] = '<li role="presentation" class="' . $class . '">
+ <a href="#' . $header . '" aria-controls="' . $header . '" role="tab" data-toggle="tab">'
+ . $header . '</a></li>';
+ $tab_content[] = '<div role="tabpanel" class="tab-pane ' . $class . '" id="' . $header . '">' . $content . '</div>';
+ }
+ return div('', [
+ '<ul class="nav nav-tabs" role="tablist">' . join($tab_header) . '</ul>',
+ '<div class="tab-content">' . join($tab_content) . '</div>'
+ ]);
+}
+
+/**
* Display muted (grey) text.
*
* @param string $text
diff --git a/includes/view/AngelTypes_view.php b/includes/view/AngelTypes_view.php
index 6e70b3be..e42321af 100644
--- a/includes/view/AngelTypes_view.php
+++ b/includes/view/AngelTypes_view.php
@@ -1,5 +1,7 @@
<?php
+use Engelsystem\ShiftsFilterRenderer;
+use Engelsystem\ShiftCalendarRenderer;
/**
* AngelTypes
*/
@@ -320,36 +322,86 @@ function AngelType_view(
$admin_angeltypes,
$supporter,
$user_driver_license,
- $user
+ $user,
+ ShiftsFilterRenderer $shiftsFilterRenderer,
+ ShiftCalendarRenderer $shiftCalendarRenderer
) {
- $page = [
+ return page_with_title(sprintf(_('Team %s'), $angeltype['name']), [
AngelType_view_buttons($angeltype, $user_angeltype, $admin_angeltypes, $supporter, $user_driver_license, $user),
- msg()
- ];
+ msg(),
+ tabs([
+ _('Info') => AngelType_view_info(
+ $angeltype,
+ $members,
+ $admin_user_angeltypes,
+ $admin_angeltypes,
+ $supporter
+ ),
+ _('Shifts') => AngelType_view_shifts(
+ $angeltype,
+ $shiftsFilterRenderer,
+ $shiftCalendarRenderer
+ )
+ ])
+ ]);
+}
+/**
+ * @param Angeltype $angeltype
+ * @param ShiftsFilterRenderer $shiftsFilterRenderer
+ * @param ShiftCalendarRenderer $shiftCalendarRenderer
+ * @return string HTML
+ */
+function AngelType_view_shifts($angeltype, $shiftsFilterRenderer, $shiftCalendarRenderer)
+{
+ $shifts = $shiftsFilterRenderer->render(page_link_to('angeltypes', [
+ 'action' => 'view',
+ 'angeltype_id' => $angeltype['id']
+ ]));
+ $shifts .= $shiftCalendarRenderer->render();
+
+ return div('first', $shifts);
+}
+
+/**
+ * @param Angeltype $angeltype
+ * @param array $members
+ * @param bool $admin_user_angeltypes
+ * @param bool $admin_angeltypes
+ * @param bool $supporter
+ * @return string HTML
+ */
+function AngelType_view_info(
+ $angeltype,
+ $members,
+ $admin_user_angeltypes,
+ $admin_angeltypes,
+ $supporter
+) {
+ $info = [];
if(AngelType_has_contact_info($angeltype)) {
- $page[] = AngelTypes_render_contact_info($angeltype);
+ $info[] = AngelTypes_render_contact_info($angeltype);
}
- $page[] = '<h3>' . _('Description') . '</h3>';
+ $info[] = '<h3>' . _('Description') . '</h3>';
$parsedown = new Parsedown();
if ($angeltype['description'] != '') {
- $page[] = '<div class="well">' . $parsedown->parse($angeltype['description']) . '</div>';
+ $info[] = '<div class="well">' . $parsedown->parse($angeltype['description']) . '</div>';
}
-
+
list($supporters, $members_confirmed, $members_unconfirmed) = AngelType_view_members(
$angeltype,
$members,
$admin_user_angeltypes,
$admin_angeltypes
- );
+ );
$table_headers = AngelType_view_table_headers($angeltype, $supporter, $admin_angeltypes);
-
+
if (count($supporters) > 0) {
- $page[] = '<h3>' . _('supporters') . '</h3>';
- $page[] = table($table_headers, $supporters);
+ $info[] = '<h3>' . _('supporters') . '</h3>';
+ $info[] = table($table_headers, $supporters);
}
-
+
if (count($members_confirmed) > 0) {
$members_confirmed[] = [
'Nick' => _('Sum'),
@@ -357,7 +409,7 @@ function AngelType_view(
'actions' => ''
];
}
-
+
if (count($members_unconfirmed) > 0) {
$members_unconfirmed[] = [
'Nick' => _('Sum'),
@@ -365,40 +417,40 @@ function AngelType_view(
'actions' => ''
];
}
-
- $page[] = '<h3>' . _('Members') . '</h3>';
+
+ $info[] = '<h3>' . _('Members') . '</h3>';
if ($admin_user_angeltypes) {
- $page[] = buttons([
+ $info[] = buttons([
button(
page_link_to(
'user_angeltypes',
['action' => 'add', 'angeltype_id' => $angeltype['id']]
- ),
+ ),
_('Add'),
'add'
- )
+ )
]);
}
- $page[] = table($table_headers, $members_confirmed);
-
+ $info[] = table($table_headers, $members_confirmed);
+
if ($admin_user_angeltypes && $angeltype['restricted'] && count($members_unconfirmed) > 0) {
- $page[] = '<h3>' . _('Unconfirmed') . '</h3>';
- $page[] = buttons([
+ $info[] = '<h3>' . _('Unconfirmed') . '</h3>';
+ $info[] = buttons([
button(
page_link_to('user_angeltypes', ['action' => 'confirm_all', 'angeltype_id' => $angeltype['id']]),
_('confirm all'),
'ok'
- ),
+ ),
button(
page_link_to('user_angeltypes', ['action' => 'delete_all', 'angeltype_id' => $angeltype['id']]),
_('deny all'),
'cancel'
- )
+ )
]);
- $page[] = table($table_headers, $members_unconfirmed);
+ $info[] = table($table_headers, $members_unconfirmed);
}
-
- return page_with_title(sprintf(_('Team %s'), $angeltype['name']), $page);
+
+ return join($info);
}
/**
@@ -407,7 +459,8 @@ function AngelType_view(
* @param Anteltype $angeltype
* @return string HTML
*/
-function AngelTypes_render_contact_info($angeltype) {
+function AngelTypes_render_contact_info($angeltype)
+{
return heading(_('Contact'), 3) . description([
_('Name') => $angeltype['contact_name'],
_('DECT') => $angeltype['contact_dect'],
diff --git a/includes/view/Rooms_view.php b/includes/view/Rooms_view.php
index adb58a9a..bd6138e1 100644
--- a/includes/view/Rooms_view.php
+++ b/includes/view/Rooms_view.php
@@ -19,7 +19,10 @@ function Room_view($room, ShiftsFilterRenderer $shiftsFilterRenderer, ShiftCalen
}
return page_with_title(glyph('map-marker') . $room['Name'], [
- $shiftsFilterRenderer->render($room),
+ $shiftsFilterRenderer->render(page_link_to('rooms', [
+ 'action' => 'view',
+ 'room_id' => $room['RID']
+ ])),
$assignNotice,
$shiftCalendarRenderer->render()
]);
diff --git a/includes/view/ShiftCalendarRenderer.php b/includes/view/ShiftCalendarRenderer.php
index d2becb58..354d0336 100644
--- a/includes/view/ShiftCalendarRenderer.php
+++ b/includes/view/ShiftCalendarRenderer.php
@@ -143,7 +143,7 @@ class ShiftCalendarRenderer
public function render()
{
if (count($this->lanes) == 0) {
- return '';
+ return info(_('No shifts found.'), true);
}
return div('shift-calendar', [
$this->renderTimeLane(),
diff --git a/includes/view/ShiftsFilterRenderer.php b/includes/view/ShiftsFilterRenderer.php
index c3e0ccf1..27c6240a 100644
--- a/includes/view/ShiftsFilterRenderer.php
+++ b/includes/view/ShiftsFilterRenderer.php
@@ -39,21 +39,17 @@ class ShiftsFilterRenderer
/**
* Renders the filter.
*
- * @param array $room
+ * @param string $page_link Link pointing to the actual page.
* @return string Generated HTML
*/
- public function render($room)
+ public function render($page_link)
{
$toolbar = [];
if ($this->daySelectionEnabled && !empty($this->days)) {
$selected_day = date('Y-m-d', $this->shiftsFilter->getStartTime());
$day_dropdown_items = [];
foreach ($this->days as $day) {
- $link = page_link_to('rooms', [
- 'action' => 'view',
- 'room_id' => $room['RID'],
- 'shifts_filter_day' => $day,
- ]);
+ $link = $page_link . '&shifts_filter_day=' . $day;
$day_dropdown_items[] = toolbar_item_link($link, '', $day);
}
$toolbar[] = toolbar_dropdown('', $selected_day, $day_dropdown_items, 'active');