Formatting

This commit is contained in:
Bot 2017-08-30 00:07:01 +02:00 committed by Igor Scheller
parent 341c076d98
commit a473a56f1d
8 changed files with 50 additions and 54 deletions

View File

@ -45,7 +45,7 @@ function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
AND NOT `Shifts`.`PSID` IS NULL) AS tmp_shifts AND NOT `Shifts`.`PSID` IS NULL) AS tmp_shifts
ORDER BY `start`'; ORDER BY `start`';
return DB::select( return DB::select(
$sql, $sql,
[ [
@ -444,6 +444,7 @@ function Shift_update($shift)
* *
* @param array $shift * @param array $shift
* @return bool|null * @return bool|null
* @throws Exception
*/ */
function Shift_update_by_psid($shift) function Shift_update_by_psid($shift)
{ {

View File

@ -241,7 +241,7 @@ function Users_by_angeltype($angeltype)
`UserAngelTypes`.`id` AS `user_angeltype_id`, `UserAngelTypes`.`id` AS `user_angeltype_id`,
`UserAngelTypes`.`confirm_user_id`, `UserAngelTypes`.`confirm_user_id`,
`UserAngelTypes`.`supporter`, `UserAngelTypes`.`supporter`,
(`UserDriverLicenses`.`user_id` IS NOT NULL) as `wants_to_drive`, (`UserDriverLicenses`.`user_id` IS NOT NULL) AS `wants_to_drive`,
`UserDriverLicenses`.* `UserDriverLicenses`.*
FROM `User` FROM `User`
JOIN `UserAngelTypes` ON `User`.`UID`=`UserAngelTypes`.`user_id` JOIN `UserAngelTypes` ON `User`.`UID`=`UserAngelTypes`.`user_id`

View File

@ -248,7 +248,7 @@ function admin_import()
list($rooms_new, $rooms_deleted) = prepare_rooms($import_file); list($rooms_new, $rooms_deleted) = prepare_rooms($import_file);
foreach ($rooms_new as $room) { foreach ($rooms_new as $room) {
$result = Room_create($room, true, true); $result = Room_create($room, true, true);
$rooms_import[trim($room)] = $result; $rooms_import[trim($room)] = $result;
} }
foreach ($rooms_deleted as $room) { foreach ($rooms_deleted as $room) {

View File

@ -1,4 +1,5 @@
<?php <?php
use Engelsystem\ShiftCalendarRenderer; use Engelsystem\ShiftCalendarRenderer;
use Engelsystem\ShiftsFilterRenderer; use Engelsystem\ShiftsFilterRenderer;

View File

@ -1,11 +1,9 @@
<?php <?php
namespace Engelsystem;
use Exception; namespace Engelsystem;
class ShiftCalendarRenderer class ShiftCalendarRenderer
{ {
/** /**
* 15m * 60s/m = 900s * 15m * 60s/m = 900s
*/ */
@ -51,10 +49,10 @@ class ShiftCalendarRenderer
/** /**
* ShiftCalendarRenderer constructor. * ShiftCalendarRenderer constructor.
* *
* @param array[] $shifts * @param array[] $shifts
* @param array[] $needed_angeltypes * @param array[] $needed_angeltypes
* @param array[] $shift_entries * @param array[] $shift_entries
* @param ShiftsFilter $shiftsFilter * @param ShiftsFilter $shiftsFilter
*/ */
public function __construct($shifts, $needed_angeltypes, $shift_entries, ShiftsFilter $shiftsFilter) public function __construct($shifts, $needed_angeltypes, $shift_entries, ShiftsFilter $shiftsFilter)
{ {
@ -69,23 +67,21 @@ class ShiftCalendarRenderer
/** /**
* Assigns the shifts to different lanes per room if they collide * Assigns the shifts to different lanes per room if they collide
* *
* @param array[] $shifts * @param array[] $shifts The shifts to assign
* The shifts to assign
*
* @return array Returns an array that assigns a room_id to an array of ShiftCalendarLane containing the shifts * @return array Returns an array that assigns a room_id to an array of ShiftCalendarLane containing the shifts
*/ */
private function assignShiftsToLanes($shifts) private function assignShiftsToLanes($shifts)
{ {
// array that assigns a room id to a list of lanes (per room) // array that assigns a room id to a list of lanes (per room)
$lanes = []; $lanes = [];
foreach ($shifts as $shift) { foreach ($shifts as $shift) {
$room_id = $shift['RID']; $room_id = $shift['RID'];
$header = Room_name_render([ $header = Room_name_render([
'RID' => $room_id, 'RID' => $room_id,
'Name' => $shift['room_name'] 'Name' => $shift['room_name']
]); ]);
if (! isset($lanes[$room_id])) { if (!isset($lanes[$room_id])) {
// initialize room with one lane // initialize room with one lane
$lanes[$room_id] = [ $lanes[$room_id] = [
new ShiftCalendarLane($header, $this->getFirstBlockStartTime(), $this->getBlocksPerSlot()) new ShiftCalendarLane($header, $this->getFirstBlockStartTime(), $this->getBlocksPerSlot())
@ -95,7 +91,7 @@ class ShiftCalendarRenderer
$shift_added = false; $shift_added = false;
foreach ($lanes[$room_id] as $lane) { foreach ($lanes[$room_id] as $lane) {
/** @var ShiftCalendarLane $lane */ /** @var ShiftCalendarLane $lane */
if($lane->shiftFits($shift)) { if ($lane->shiftFits($shift)) {
$lane->addShift($shift); $lane->addShift($shift);
$shift_added = true; $shift_added = true;
break; break;
@ -108,12 +104,11 @@ class ShiftCalendarRenderer
$lanes[$room_id][] = $newLane; $lanes[$room_id][] = $newLane;
} }
} }
return $lanes; return $lanes;
} }
/** /**
*
* @return int * @return int
*/ */
public function getFirstBlockStartTime() public function getFirstBlockStartTime()
@ -122,7 +117,6 @@ class ShiftCalendarRenderer
} }
/** /**
*
* @return int * @return int
*/ */
public function getLastBlockEndTime() public function getLastBlockEndTime()
@ -131,7 +125,6 @@ class ShiftCalendarRenderer
} }
/** /**
*
* @return float * @return float
*/ */
public function getBlocksPerSlot() public function getBlocksPerSlot()
@ -153,9 +146,9 @@ class ShiftCalendarRenderer
return ''; return '';
} }
return div('shift-calendar', [ return div('shift-calendar', [
$this->renderTimeLane(), $this->renderTimeLane(),
$this->renderShiftLanes() $this->renderShiftLanes()
]) . $this->renderLegend(); ]) . $this->renderLegend();
} }
/** /**
@ -171,41 +164,45 @@ class ShiftCalendarRenderer
$html .= $this->renderLane($lane); $html .= $this->renderLane($lane);
} }
} }
return $html; return $html;
} }
/** /**
* Renders a single lane * Renders a single lane
* *
* @param ShiftCalendarLane $lane * @param ShiftCalendarLane $lane The lane to render
* The lane to render
* @return string * @return string
*/ */
private function renderLane(ShiftCalendarLane $lane) private function renderLane(ShiftCalendarLane $lane)
{ {
global $user; global $user;
$shift_renderer = new ShiftCalendarShiftRenderer(); $shift_renderer = new ShiftCalendarShiftRenderer();
$html = ''; $html = '';
$rendered_until = $this->getFirstBlockStartTime(); $rendered_until = $this->getFirstBlockStartTime();
foreach ($lane->getShifts() as $shift) { foreach ($lane->getShifts() as $shift) {
while ($rendered_until + ShiftCalendarRenderer::SECONDS_PER_ROW <= $shift['start']) { while ($rendered_until + ShiftCalendarRenderer::SECONDS_PER_ROW <= $shift['start']) {
$html .= $this->renderTick($rendered_until); $html .= $this->renderTick($rendered_until);
$rendered_until += ShiftCalendarRenderer::SECONDS_PER_ROW; $rendered_until += ShiftCalendarRenderer::SECONDS_PER_ROW;
} }
list ($shift_height, $shift_html) = $shift_renderer->render($shift, $this->needed_angeltypes[$shift['SID']], $this->shift_entries[$shift['SID']], $user); list ($shift_height, $shift_html) = $shift_renderer->render(
$shift,
$this->needed_angeltypes[$shift['SID']],
$this->shift_entries[$shift['SID']],
$user
);
$html .= $shift_html; $html .= $shift_html;
$rendered_until += $shift_height * ShiftCalendarRenderer::SECONDS_PER_ROW; $rendered_until += $shift_height * ShiftCalendarRenderer::SECONDS_PER_ROW;
} }
while ($rendered_until < $this->getLastBlockEndTime()) { while ($rendered_until < $this->getLastBlockEndTime()) {
$html .= $this->renderTick($rendered_until); $html .= $this->renderTick($rendered_until);
$rendered_until += ShiftCalendarRenderer::SECONDS_PER_ROW; $rendered_until += ShiftCalendarRenderer::SECONDS_PER_ROW;
} }
return div('lane', [ return div('lane', [
div('header', $lane->getHeader()), div('header', $lane->getHeader()),
$html $html
@ -215,23 +212,21 @@ class ShiftCalendarRenderer
/** /**
* Renders a tick/block for given time * Renders a tick/block for given time
* *
* @param int $time * @param int $time unix timestamp
* unix timestamp * @param boolean $label Should time labels be generated?
* @param boolean $label
* Should time labels be generated?
* @return string rendered tick html * @return string rendered tick html
*/ */
private function renderTick($time, $label = false) private function renderTick($time, $label = false)
{ {
if ($time % (24 * 60 * 60) == 23 * 60 * 60) { if ($time % (24 * 60 * 60) == 23 * 60 * 60) {
if (! $label) { if (!$label) {
return div('tick day'); return div('tick day');
} }
return div('tick day', [ return div('tick day', [
date('m-d<b\r />H:i', $time) date('m-d<b\r />H:i', $time)
]); ]);
} elseif ($time % (60 * 60) == 0) { } elseif ($time % (60 * 60) == 0) {
if (! $label) { if (!$label) {
return div('tick hour'); return div('tick hour');
} }
return div('tick hour', [ return div('tick hour', [
@ -253,7 +248,7 @@ class ShiftCalendarRenderer
_('Time') _('Time')
]) ])
]; ];
for ($block = 0; $block < $this->getBlocksPerSlot(); $block ++) { for ($block = 0; $block < $this->getBlocksPerSlot(); $block++) {
$thistime = $this->getFirstBlockStartTime() + ($block * ShiftCalendarRenderer::SECONDS_PER_ROW); $thistime = $this->getFirstBlockStartTime() + ($block * ShiftCalendarRenderer::SECONDS_PER_ROW);
$time_slot[] = $this->renderTick($thistime, true); $time_slot[] = $this->renderTick($thistime, true);
} }
@ -261,8 +256,7 @@ class ShiftCalendarRenderer
} }
/** /**
* * @param array[] $shifts
* @param array[] $shifts
* @return int * @return int
*/ */
private function calcFirstBlockStartTime($shifts) private function calcFirstBlockStartTime($shifts)
@ -277,8 +271,7 @@ class ShiftCalendarRenderer
} }
/** /**
* * @param array[] $shifts
* @param array[] $shifts
* @return int * @return int
*/ */
private function calcLastBlockEndTime($shifts) private function calcLastBlockEndTime($shifts)
@ -293,7 +286,6 @@ class ShiftCalendarRenderer
} }
/** /**
*
* @return int * @return int
*/ */
private function calcBlocksPerSlot() private function calcBlocksPerSlot()

View File

@ -79,9 +79,10 @@ class Db
return self::$stm->fetchAll(PDO::FETCH_ASSOC); return self::$stm->fetchAll(PDO::FETCH_ASSOC);
} }
/** /**
* Run a select query and return only the first result or null if no result is found. * Run a select query and return only the first result or null if no result is found.
*
* @param string $query * @param string $query
* @param array $bindings * @param array $bindings
* @return array|null * @return array|null
@ -89,11 +90,11 @@ class Db
public static function selectOne($query, array $bindings = []) public static function selectOne($query, array $bindings = [])
{ {
$result = self::select($query, $bindings); $result = self::select($query, $bindings);
if(empty($result)) { if (empty($result)) {
return null; return null;
} }
return array_shift($result); return array_shift($result);
} }

View File

@ -20,11 +20,10 @@
<div class="col-md-4"> <div class="col-md-4">
<h2>Hosting</h2> <h2>Hosting</h2>
<p> <p>
Webspace, development platform and domain on <a href="https://engelsystem.de">engelsystem.de</a> is currently provided by Webspace, development platform and domain on <a href="https://engelsystem.de">engelsystem.de</a>
<a href="https://www.wybt.net/">would you buy this?</a> (ichdasich) is currently provided by <a href="https://www.wybt.net/">would you buy this?</a> (ichdasich)
and adminstrated by <a href="http://mortzu.de/">mortzu</a>, and adminstrated by <a href="http://mortzu.de/">mortzu</a>,
<a href="http://derf.homelinux.org/">derf</a> <a href="http://derf.homelinux.org/">derf</a> and ichdasich.
and ichdasich.
</p> </p>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">

View File

@ -22,7 +22,9 @@
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
</button> </button>
<a class="navbar-brand" href="%start_page_url%"><span class="icon-icon_angel"></span> <strong class="visible-lg-inline">ENGELSYSTEM</strong></a> <a class="navbar-brand" href="%start_page_url%">
<span class="icon-icon_angel"></span> <strong class="visible-lg-inline">ENGELSYSTEM</strong>
</a>
</div> </div>
<div class="collapse navbar-collapse" id="navbar-collapse-1">%menu% %header_toolbar%</div> <div class="collapse navbar-collapse" id="navbar-collapse-1">%menu% %header_toolbar%</div>
</div> </div>