added dect option for rooms

This commit is contained in:
Xu 2022-10-18 17:34:08 +02:00 committed by Igor Scheller
parent 88c727bf8e
commit 4d6da1894a
5 changed files with 66 additions and 5 deletions

View File

@ -0,0 +1,35 @@
<?php
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddDectToRooms extends Migration
{
/**
* Run the migration
*/
public function up()
{
$this->schema->table(
'rooms',
function (Blueprint $table) {
$table->text('dect')->nullable()->after('description');
}
);
}
/**
* Reverse the migration
*/
public function down()
{
$this->schema->table(
'rooms',
function (Blueprint $table) {
$table->dropColumn('dect');
}
);
}
}

View File

@ -72,16 +72,18 @@ function Room_delete(Room $room)
* *
* @return null|int * @return null|int
*/ */
function Room_create(string $name, string $map_url = null, string $description = null) function Room_create(string $name, string $map_url = null, string $description = null, string $dect = null)
{ {
$room = new Room(); $room = new Room();
$room->name = $name; $room->name = $name;
$room->description = $description; $room->description = $description;
$room->map_url = $map_url; $room->map_url = $map_url;
$room->dect = $dect;
$room->save(); $room->save();
engelsystem_log( engelsystem_log(
'Room created: ' . $name 'Room created: ' . $name
. ', dect: ' . $dect
. ', map_url: ' . $map_url . ', map_url: ' . $map_url
. ', description: ' . $description . ', description: ' . $description
); );
@ -97,16 +99,23 @@ function Room_create(string $name, string $map_url = null, string $description =
* @param string|null $map_url URL to a map tha can be displayed in an iframe * @param string|null $map_url URL to a map tha can be displayed in an iframe
* @param string|null $description Markdown description * @param string|null $description Markdown description
*/ */
function Room_update(int $room_id, string $name, string $map_url = null, string $description = null) function Room_update(
{ int $room_id,
string $name,
string $map_url = null,
string $description = null,
string $dect = null
) {
$room = Room::find($room_id); $room = Room::find($room_id);
$room->name = $name; $room->name = $name;
$room->description = $description ?: null; $room->description = $description ?: null;
$room->map_url = $map_url ?: null; $room->map_url = $map_url ?: null;
$room->dect = $dect ?: null;
$room->save(); $room->save();
engelsystem_log( engelsystem_log(
'Room updated: ' . $name . 'Room updated: ' . $name .
', dect: ' . $dect .
', map_url: ' . $map_url . ', map_url: ' . $map_url .
', description: ' . $description ', description: ' . $description
); );

View File

@ -24,6 +24,7 @@ function admin_rooms()
foreach ($rooms_source as $room) { foreach ($rooms_source as $room) {
$rooms[] = [ $rooms[] = [
'name' => Room_name_render($room), 'name' => Room_name_render($room),
'dect' => icon_bool($room->dect),
'map_url' => icon_bool($room->map_url), 'map_url' => icon_bool($room->map_url),
'actions' => table_buttons([ 'actions' => table_buttons([
button( button(
@ -46,6 +47,7 @@ function admin_rooms()
$name = ''; $name = '';
$map_url = null; $map_url = null;
$description = null; $description = null;
$dect = null;
$room_id = 0; $room_id = 0;
$angeltypes_source = AngelTypes(); $angeltypes_source = AngelTypes();
@ -66,6 +68,7 @@ function admin_rooms()
$name = $room->name; $name = $room->name;
$map_url = $room->map_url; $map_url = $room->map_url;
$description = $room->description; $description = $room->description;
$dect = $room->dect;
$needed_angeltypes = NeededAngelTypes_by_room($room_id); $needed_angeltypes = NeededAngelTypes_by_room($room_id);
foreach ($needed_angeltypes as $needed_angeltype) { foreach ($needed_angeltypes as $needed_angeltype) {
@ -97,6 +100,9 @@ function admin_rooms()
if ($request->has('description')) { if ($request->has('description')) {
$description = strip_request_item_nl('description'); $description = strip_request_item_nl('description');
} }
if ($request->has('dect')) {
$dect = strip_request_item_nl('dect');
}
foreach ($angeltypes as $angeltype_id => $angeltype) { foreach ($angeltypes as $angeltype_id => $angeltype) {
$angeltypes_count[$angeltype_id] = 0; $angeltypes_count[$angeltype_id] = 0;
@ -118,9 +124,9 @@ function admin_rooms()
if ($valid) { if ($valid) {
if (empty($room_id)) { if (empty($room_id)) {
$room_id = Room_create($name, $map_url, $description); $room_id = Room_create($name, $map_url, $description, $dect);
} else { } else {
Room_update($room_id, $name, $map_url, $description); Room_update($room_id, $name, $map_url, $description, $dect);
} }
NeededAngelTypes_delete_by_room($room_id); NeededAngelTypes_delete_by_room($room_id);
@ -159,6 +165,7 @@ function admin_rooms()
div('row', [ div('row', [
div('col-md-6', [ div('col-md-6', [
form_text('name', __('Name'), $name, false, 35), form_text('name', __('Name'), $name, false, 35),
form_text('dect', __('DECT'), $dect),
form_text('map_url', __('Map URL'), $map_url), form_text('map_url', __('Map URL'), $map_url),
form_info('', __('The map url is used to display an iframe on the room page.')), form_info('', __('The map url is used to display an iframe on the room page.')),
form_textarea('description', __('Description'), $description), form_textarea('description', __('Description'), $description),
@ -222,6 +229,7 @@ function admin_rooms()
msg(), msg(),
table([ table([
'name' => __('Name'), 'name' => __('Name'),
'dect' => __('DECT'),
'map_url' => __('Map'), 'map_url' => __('Map'),
'actions' => '' 'actions' => ''
], $rooms) ], $rooms)

View File

@ -27,6 +27,12 @@ function Room_view(Room $room, ShiftsFilterRenderer $shiftsFilterRenderer, Shift
$description .= $parsedown->parse($room->description); $description .= $parsedown->parse($room->description);
} }
$dect = '';
if (config('enable_dect') && $room->dect) {
$dect = heading(__('Contact'), 3)
. description([__('DECT') => sprintf('<a href="tel:%s">%1$s</a>', $room->dect)]);
}
$tabs = []; $tabs = [];
if ($room->map_url) { if ($room->map_url) {
$tabs[__('Map')] = sprintf( $tabs[__('Map')] = sprintf(
@ -65,6 +71,7 @@ function Room_view(Room $room, ShiftsFilterRenderer $shiftsFilterRenderer, Shift
'btn' 'btn'
) )
]) : '', ]) : '',
$dect,
$description, $description,
tabs($tabs, $selected_tab), tabs($tabs, $selected_tab),
], true); ], true);

View File

@ -13,6 +13,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
* @property string $name * @property string $name
* @property string $map_url * @property string $map_url
* @property string $description * @property string $description
* @property string $dect
* @property Carbon|null $created_at * @property Carbon|null $created_at
* @property Carbon|null $updated_at * @property Carbon|null $updated_at
* *
@ -33,6 +34,7 @@ class Room extends BaseModel
/** @var array */ /** @var array */
protected $fillable = [ protected $fillable = [
'name', 'name',
'dect',
'map_url', 'map_url',
'description', 'description',
]; ];