Removed referenced angeltype from shift type
This commit is contained in:
parent
354ec084eb
commit
ac162f4411
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Engelsystem\Migrations;
|
||||
|
||||
use Engelsystem\Database\Migration\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class ShifttypeRemoveAngeltype extends Migration
|
||||
{
|
||||
use Reference;
|
||||
|
||||
/**
|
||||
* Run the migration
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
if (!$this->schema->hasTable('ShiftTypes')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->schema->table(
|
||||
'ShiftTypes',
|
||||
function (Blueprint $table) {
|
||||
$table->dropForeign('shifttypes_ibfk_1');
|
||||
$table->dropColumn('angeltype_id');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
if (!$this->schema->hasTable('ShiftTypes')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->schema->table(
|
||||
'ShiftTypes',
|
||||
function (Blueprint $table) {
|
||||
$table->integer('angeltype_id')
|
||||
->after('name')
|
||||
->index()
|
||||
->nullable();
|
||||
$this->addReference($table, 'angeltype_id', 'AngelTypes', null, 'shifttypes_ibfk_1');
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
|
@ -57,9 +57,10 @@ trait Reference
|
|||
Blueprint $table,
|
||||
string $fromColumn,
|
||||
string $targetTable,
|
||||
?string $targetColumn = null
|
||||
) {
|
||||
$table->foreign($fromColumn)
|
||||
?string $targetColumn = null,
|
||||
?string $name = null
|
||||
): void {
|
||||
$table->foreign($fromColumn, $name)
|
||||
->references($targetColumn ?: 'id')->on($targetTable)
|
||||
->onUpdate('cascade')
|
||||
->onDelete('cascade');
|
||||
|
|
|
@ -49,10 +49,8 @@ function shifttype_edit_controller()
|
|||
{
|
||||
$shifttype_id = null;
|
||||
$name = '';
|
||||
$angeltype_id = null;
|
||||
$description = '';
|
||||
|
||||
$angeltypes = AngelTypes();
|
||||
$request = request();
|
||||
|
||||
if ($request->has('shifttype_id')) {
|
||||
|
@ -63,7 +61,6 @@ function shifttype_edit_controller()
|
|||
}
|
||||
$shifttype_id = $shifttype['id'];
|
||||
$name = $shifttype['name'];
|
||||
$angeltype_id = $shifttype['angeltype_id'];
|
||||
$description = $shifttype['description'];
|
||||
}
|
||||
|
||||
|
@ -77,24 +74,18 @@ function shifttype_edit_controller()
|
|||
error(__('Please enter a name.'));
|
||||
}
|
||||
|
||||
if ($request->has('angeltype_id') && preg_match('/^\d+$/', $request->input('angeltype_id'))) {
|
||||
$angeltype_id = $request->input('angeltype_id');
|
||||
} else {
|
||||
$angeltype_id = null;
|
||||
}
|
||||
|
||||
if ($request->has('description')) {
|
||||
$description = strip_request_item_nl('description');
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
if ($shifttype_id) {
|
||||
ShiftType_update($shifttype_id, $name, $angeltype_id, $description);
|
||||
ShiftType_update($shifttype_id, $name, $description);
|
||||
|
||||
engelsystem_log('Updated shifttype ' . $name);
|
||||
success(__('Updated shifttype.'));
|
||||
} else {
|
||||
$shifttype_id = ShiftType_create($name, $angeltype_id, $description);
|
||||
$shifttype_id = ShiftType_create($name, $description);
|
||||
|
||||
engelsystem_log('Created shifttype ' . $name);
|
||||
success(__('Created shifttype.'));
|
||||
|
@ -105,7 +96,7 @@ function shifttype_edit_controller()
|
|||
|
||||
return [
|
||||
shifttypes_title(),
|
||||
ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id)
|
||||
ShiftType_edit_view($name, $description, $shifttype_id)
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -123,14 +114,9 @@ function shifttype_controller()
|
|||
throw_redirect(page_link_to('shifttypes'));
|
||||
}
|
||||
|
||||
$angeltype = [];
|
||||
if (!empty($shifttype['angeltype_id'])) {
|
||||
$angeltype = AngelType($shifttype['angeltype_id']);
|
||||
}
|
||||
|
||||
return [
|
||||
$shifttype['name'],
|
||||
ShiftType_view($shifttype, $angeltype)
|
||||
ShiftType_view($shifttype)
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -17,22 +17,19 @@ function ShiftType_delete($shifttype_id)
|
|||
*
|
||||
* @param int $shifttype_id
|
||||
* @param string $name
|
||||
* @param int $angeltype_id
|
||||
* @param string $description
|
||||
*/
|
||||
function ShiftType_update($shifttype_id, $name, $angeltype_id, $description)
|
||||
function ShiftType_update($shifttype_id, $name, $description)
|
||||
{
|
||||
Db::update(
|
||||
'
|
||||
UPDATE `ShiftTypes` SET
|
||||
`name`=?,
|
||||
`angeltype_id`=?,
|
||||
`description`=?
|
||||
WHERE `id`=?
|
||||
',
|
||||
[
|
||||
$name,
|
||||
$angeltype_id,
|
||||
$description,
|
||||
$shifttype_id,
|
||||
]
|
||||
|
@ -43,20 +40,18 @@ function ShiftType_update($shifttype_id, $name, $angeltype_id, $description)
|
|||
* Create a shift type.
|
||||
*
|
||||
* @param string $name
|
||||
* @param int $angeltype_id
|
||||
* @param string $description
|
||||
* @return int|false new shifttype id
|
||||
*/
|
||||
function ShiftType_create($name, $angeltype_id, $description)
|
||||
function ShiftType_create($name, $description)
|
||||
{
|
||||
Db::insert(
|
||||
'
|
||||
INSERT INTO `ShiftTypes` (`name`, `angeltype_id`, `description`)
|
||||
VALUES(?, ?, ?)
|
||||
INSERT INTO `ShiftTypes` (`name`, `description`)
|
||||
VALUES(?, ?)
|
||||
',
|
||||
[
|
||||
$name,
|
||||
$angeltype_id,
|
||||
$description
|
||||
]
|
||||
);
|
||||
|
|
|
@ -36,21 +36,12 @@ function ShiftType_delete_view($shifttype)
|
|||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param int $angeltype_id
|
||||
* @param array[] $angeltypes
|
||||
* @param string $description
|
||||
* @param int|bool $shifttype_id
|
||||
* @return string
|
||||
*/
|
||||
function ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id)
|
||||
function ShiftType_edit_view($name, $description, $shifttype_id)
|
||||
{
|
||||
$angeltypes_select = [
|
||||
'' => __('All')
|
||||
];
|
||||
foreach ($angeltypes as $angeltype) {
|
||||
$angeltypes_select[$angeltype['id']] = $angeltype['name'];
|
||||
}
|
||||
|
||||
return page_with_title($shifttype_id ? __('Edit shifttype') : __('Create shifttype'), [
|
||||
msg(),
|
||||
buttons([
|
||||
|
@ -58,7 +49,6 @@ function ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $s
|
|||
]),
|
||||
form([
|
||||
form_text('name', __('Name'), $name),
|
||||
form_select('angeltype_id', __('Angeltype'), $angeltypes_select, $angeltype_id),
|
||||
form_textarea('description', __('Description'), $description),
|
||||
form_info('', __('Please use markdown for the description.')),
|
||||
form_submit('submit', __('Save'))
|
||||
|
@ -68,24 +58,16 @@ function ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $s
|
|||
|
||||
/**
|
||||
* @param array $shifttype
|
||||
* @param array $angeltype
|
||||
* @return string
|
||||
*/
|
||||
function ShiftType_view($shifttype, $angeltype)
|
||||
function ShiftType_view($shifttype)
|
||||
{
|
||||
$parsedown = new Parsedown();
|
||||
$title = $shifttype['name'];
|
||||
if ($angeltype) {
|
||||
$title .= ' <small>' . sprintf(__('for team %s'), $angeltype['name']) . '</small>';
|
||||
}
|
||||
return page_with_title($title, [
|
||||
msg(),
|
||||
buttons([
|
||||
button(page_link_to('shifttypes'), shifttypes_title(), 'back'),
|
||||
$angeltype ? button(
|
||||
page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']]),
|
||||
$angeltype['name']
|
||||
) : '',
|
||||
button(
|
||||
page_link_to('shifttypes', ['action' => 'edit', 'shifttype_id' => $shifttype['id']]),
|
||||
__('edit'),
|
||||
|
|
|
@ -60,6 +60,7 @@ trait HasDatabase
|
|||
['migration' => '2022_06_03_000000_shifts_add_transaction_id'],
|
||||
['migration' => '2022_07_21_000000_fix_old_groups_table_id_and_name'],
|
||||
['migration' => '2022_10_21_000000_add_hide_register_to_angeltypes'],
|
||||
['migration' => '2022_11_06_000000_shifttype_remove_angeltype'],
|
||||
]
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue