Schedule import: Add overview
parent
251f2cbfa6
commit
ebab34ee67
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Engelsystem\Migrations;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Engelsystem\Database\Migration\Migration;
|
||||
use Engelsystem\Models\Shifts\Schedule;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class AddNameMinutesAndTimestampsToSchedules extends Migration
|
||||
{
|
||||
use Reference;
|
||||
|
||||
/**
|
||||
* Run the migration
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$this->schema->table(
|
||||
'schedules',
|
||||
function (Blueprint $table) {
|
||||
$table->string('name')->after('id');
|
||||
$table->integer('shift_type')->after('name');
|
||||
$table->integer('minutes_before')->after('shift_type');
|
||||
$table->integer('minutes_after')->after('minutes_before');
|
||||
$table->timestamps();
|
||||
}
|
||||
);
|
||||
|
||||
Schedule::query()
|
||||
->update([
|
||||
'created_at' => Carbon::now(),
|
||||
'minutes_before' => 15,
|
||||
'minutes_after' => 15,
|
||||
]);
|
||||
|
||||
// Add legacy reference
|
||||
if ($this->schema->hasTable('ShiftTypes')) {
|
||||
$connection = $this->schema->getConnection();
|
||||
$query = $connection
|
||||
->table('Shifts')
|
||||
->select('Shifts.shifttype_id')
|
||||
->join('schedule_shift', 'Shifts.SID', 'schedule_shift.shift_id')
|
||||
->where('schedule_shift.schedule_id', $connection->raw('schedules.id'))
|
||||
->limit(1);
|
||||
|
||||
Schedule::query()
|
||||
->update(['shift_type' => $connection->raw('(' . $query->toSql() . ')')]);
|
||||
|
||||
$this->schema->table(
|
||||
'schedules',
|
||||
function (Blueprint $table) {
|
||||
$this->addReference($table, 'shift_type', 'ShiftTypes');
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$this->schema->table(
|
||||
'schedules',
|
||||
function (Blueprint $table) {
|
||||
$table->dropForeign('schedules_shift_type_foreign');
|
||||
$table->dropColumn('name');
|
||||
$table->dropColumn('shift_type');
|
||||
$table->dropColumn('minutes_before');
|
||||
$table->dropColumn('minutes_after');
|
||||
$table->dropTimestamps();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
{% extends 'admin/schedule/index.twig' %}
|
||||
{% import 'macros/base.twig' as m %}
|
||||
{% import 'macros/form.twig' as f %}
|
||||
|
||||
{% block title %}{{ schedule ? __('schedule.edit.title') : __('schedule.import.title') }}{% endblock %}
|
||||
|
||||
{% block row_content %}
|
||||
{% if schedule and schedule.updated_at %}
|
||||
<div class="col-md-12">
|
||||
<p>{{ __('schedule.last_update', [schedule.updated_at.format(__('Y-m-d H:i'))]) }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<form method="post">
|
||||
{{ csrf() }}
|
||||
|
||||
<div class="col-lg-12">
|
||||
{{ f.input('name', __('schedule.name'), null, {'required': true, 'value': schedule ? schedule.name : ''}) }}
|
||||
{{ f.input('url', __('schedule.url'), 'url', {'required': true, 'value': schedule ? schedule.url : ''}) }}
|
||||
|
||||
{{ f.select('shift_type', shift_types|default([]), __('schedule.shift-type'), schedule ? schedule.shift_type : '') }}
|
||||
|
||||
{{ f.input('minutes_before', __('schedule.minutes-before'), 'number', {'required': true, 'value': schedule ? schedule.minutes_before : 15}) }}
|
||||
{{ f.input('minutes_after', __('schedule.minutes-after'), 'number', {'required': true, 'value': schedule ? schedule.minutes_after : 15}) }}
|
||||
|
||||
{{ f.submit(__('form.save')) }}
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue