Added User\License model
This commit is contained in:
parent
1c993522c6
commit
676a2113b4
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories\Engelsystem\Models\User;
|
||||||
|
|
||||||
|
use Engelsystem\Models\User\License;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
class LicenseFactory extends Factory
|
||||||
|
{
|
||||||
|
/** @var string */
|
||||||
|
protected $model = License::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function definition()
|
||||||
|
{
|
||||||
|
$drive_car = $this->faker->boolean(.8);
|
||||||
|
$drive_3_5t = $drive_car && $this->faker->boolean(.7);
|
||||||
|
$drive_7_5t = $drive_3_5t && $this->faker->boolean();
|
||||||
|
$drive_12t = $drive_7_5t && $this->faker->boolean(.3);
|
||||||
|
$drive_forklift = ($drive_car && $this->faker->boolean(.1))
|
||||||
|
|| ($drive_12t && $this->faker->boolean(.7));
|
||||||
|
|
||||||
|
return [
|
||||||
|
'has_car' => $drive_car && $this->faker->boolean(.7),
|
||||||
|
'drive_forklift' => $drive_forklift,
|
||||||
|
'drive_car' => $drive_car,
|
||||||
|
'drive_3_5t' => $drive_3_5t,
|
||||||
|
'drive_7_5t' => $drive_7_5t,
|
||||||
|
'drive_12t' => $drive_12t,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Engelsystem\Migrations;
|
||||||
|
|
||||||
|
use Engelsystem\Database\Migration\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
|
||||||
|
class CreateUserLicensesTable extends Migration
|
||||||
|
{
|
||||||
|
use Reference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the migration
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
$this->schema->create('users_licenses', function (Blueprint $table) {
|
||||||
|
$this->referencesUser($table, true);
|
||||||
|
$table->boolean('has_car')->default(false);
|
||||||
|
$table->boolean('drive_forklift')->default(false);
|
||||||
|
$table->boolean('drive_car')->default(false);
|
||||||
|
$table->boolean('drive_3_5t')->default(false);
|
||||||
|
$table->boolean('drive_7_5t')->default(false);
|
||||||
|
$table->boolean('drive_12t')->default(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
if ($this->schema->hasTable('UserDriverLicenses')) {
|
||||||
|
$licenses = $this->schema->getConnection()
|
||||||
|
->table('UserDriverLicenses')
|
||||||
|
->get();
|
||||||
|
$table = $this->schema->getConnection()
|
||||||
|
->table('users_licenses');
|
||||||
|
|
||||||
|
foreach ($licenses as $license) {
|
||||||
|
$table->insert([
|
||||||
|
'user_id' => $license->user_id,
|
||||||
|
'has_car' => $license->has_car,
|
||||||
|
'drive_forklift' => $license->has_license_forklift,
|
||||||
|
'drive_car' => $license->has_license_car,
|
||||||
|
'drive_3_5t' => $license->has_license_3_5t_transporter,
|
||||||
|
'drive_7_5t' => $license->has_license_7_5t_truck,
|
||||||
|
'drive_12t' => $license->has_license_12_5t_truck,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->schema->drop('UserDriverLicenses');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migration
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
$this->schema->create('UserDriverLicenses', function (Blueprint $table) {
|
||||||
|
$this->referencesUser($table, true);
|
||||||
|
$table->boolean('has_car');
|
||||||
|
$table->boolean('has_license_car');
|
||||||
|
$table->boolean('has_license_3_5t_transporter');
|
||||||
|
$table->boolean('has_license_7_5t_truck');
|
||||||
|
$table->boolean('has_license_12_5t_truck');
|
||||||
|
$table->boolean('has_license_forklift');
|
||||||
|
});
|
||||||
|
|
||||||
|
$licenses = $this->schema->getConnection()
|
||||||
|
->table('users_licenses')
|
||||||
|
->get();
|
||||||
|
$table = $this->schema->getConnection()
|
||||||
|
->table('UserDriverLicenses');
|
||||||
|
|
||||||
|
foreach ($licenses as $license) {
|
||||||
|
$table->insert([
|
||||||
|
'user_id' => $license->user_id,
|
||||||
|
'has_car' => $license->has_car,
|
||||||
|
'has_license_car' => $license->drive_car,
|
||||||
|
'has_license_3_5t_transporter' => $license->drive_3_5t,
|
||||||
|
'has_license_7_5t_truck' => $license->drive_7_5t,
|
||||||
|
'has_license_12_5t_truck' => $license->drive_12t,
|
||||||
|
'has_license_forklift' => $license->drive_forklift,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->schema->drop('users_licenses');
|
||||||
|
}
|
||||||
|
}
|
|
@ -182,7 +182,6 @@ function angeltype_controller()
|
||||||
|
|
||||||
$angeltype = load_angeltype();
|
$angeltype = load_angeltype();
|
||||||
$user_angeltype = UserAngelType_by_User_and_AngelType($user->id, $angeltype);
|
$user_angeltype = UserAngelType_by_User_and_AngelType($user->id, $angeltype);
|
||||||
$user_driver_license = UserDriverLicense($user->id);
|
|
||||||
$members = Users_by_angeltype($angeltype);
|
$members = Users_by_angeltype($angeltype);
|
||||||
|
|
||||||
$days = angeltype_controller_shiftsFilterDays($angeltype);
|
$days = angeltype_controller_shiftsFilterDays($angeltype);
|
||||||
|
@ -209,7 +208,7 @@ function angeltype_controller()
|
||||||
auth()->can('admin_user_angeltypes') || $isSupporter,
|
auth()->can('admin_user_angeltypes') || $isSupporter,
|
||||||
auth()->can('admin_angel_types'),
|
auth()->can('admin_angel_types'),
|
||||||
$isSupporter,
|
$isSupporter,
|
||||||
$user_driver_license,
|
$user->license,
|
||||||
$user,
|
$user,
|
||||||
$shiftsFilterRenderer,
|
$shiftsFilterRenderer,
|
||||||
$shiftCalendarRenderer,
|
$shiftCalendarRenderer,
|
||||||
|
|
|
@ -12,14 +12,12 @@ function user_driver_license_required_hint()
|
||||||
{
|
{
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
|
|
||||||
$angeltypes = User_angeltypes($user->id);
|
|
||||||
$user_driver_license = UserDriverLicense($user->id);
|
|
||||||
|
|
||||||
// User has already entered data, no hint needed.
|
// User has already entered data, no hint needed.
|
||||||
if (!empty($user_driver_license)) {
|
if ($user->license->wantsToDrive()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$angeltypes = User_angeltypes($user->id);
|
||||||
foreach ($angeltypes as $angeltype) {
|
foreach ($angeltypes as $angeltype) {
|
||||||
if ($angeltype['requires_driver_license']) {
|
if ($angeltype['requires_driver_license']) {
|
||||||
return sprintf(
|
return sprintf(
|
||||||
|
@ -105,38 +103,34 @@ function user_driver_license_edit_controller()
|
||||||
throw_redirect(user_driver_license_edit_link());
|
throw_redirect(user_driver_license_edit_link());
|
||||||
}
|
}
|
||||||
|
|
||||||
$user_driver_license = UserDriverLicense($user_source->id);
|
$driverLicense = $user_source->license;
|
||||||
if (empty($user_driver_license)) {
|
|
||||||
$wants_to_drive = false;
|
|
||||||
$user_driver_license = UserDriverLicense_new();
|
|
||||||
} else {
|
|
||||||
$wants_to_drive = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->hasPostData('submit')) {
|
if ($request->hasPostData('submit')) {
|
||||||
$wants_to_drive = $request->has('wants_to_drive');
|
if ($request->has('wants_to_drive')) {
|
||||||
if ($wants_to_drive) {
|
$driverLicense->has_car = $request->has('has_car');
|
||||||
$user_driver_license['has_car'] = $request->has('has_car');
|
$driverLicense->drive_car = $request->has('has_license_car');
|
||||||
$user_driver_license['has_license_car'] = $request->has('has_license_car');
|
$driverLicense->drive_3_5t = $request->has('has_license_3_5t_transporter');
|
||||||
$user_driver_license['has_license_3_5t_transporter'] = $request->has('has_license_3_5t_transporter');
|
$driverLicense->drive_7_5t = $request->has('has_license_7_5t_truck');
|
||||||
$user_driver_license['has_license_7_5t_truck'] = $request->has('has_license_7_5t_truck');
|
$driverLicense->drive_12t= $request->has('has_license_12t_truck');
|
||||||
$user_driver_license['has_license_12_5t_truck'] = $request->has('has_license_12_5t_truck');
|
$driverLicense->drive_forklift = $request->has('has_license_forklift');
|
||||||
$user_driver_license['has_license_forklift'] = $request->has('has_license_forklift');
|
|
||||||
|
if ($driverLicense->wantsToDrive()) {
|
||||||
|
$driverLicense->save();
|
||||||
|
|
||||||
if (UserDriverLicense_valid($user_driver_license)) {
|
|
||||||
if (empty($user_driver_license['user_id'])) {
|
|
||||||
$user_driver_license = UserDriverLicenses_create($user_driver_license, $user_source->id);
|
|
||||||
} else {
|
|
||||||
UserDriverLicenses_update($user_driver_license);
|
|
||||||
}
|
|
||||||
engelsystem_log('Driver license information updated.');
|
engelsystem_log('Driver license information updated.');
|
||||||
success(__('Your driver license information has been saved.'));
|
success(__('Your driver license information has been saved.'));
|
||||||
throw_redirect(user_link($user_source->id));
|
throw_redirect(user_link($user_source->id));
|
||||||
} else {
|
} else {
|
||||||
error(__('Please select at least one driving license.'));
|
error(__('Please select at least one driving license.'));
|
||||||
}
|
}
|
||||||
} elseif (!empty($user_driver_license['user_id'])) {
|
} else {
|
||||||
UserDriverLicenses_delete($user_source->id);
|
$driverLicense->has_car = false;
|
||||||
|
$driverLicense->drive_car = false;
|
||||||
|
$driverLicense->drive_3_5t = false;
|
||||||
|
$driverLicense->drive_7_5t = false;
|
||||||
|
$driverLicense->drive_12t = false;
|
||||||
|
$driverLicense->drive_forklift = false;
|
||||||
|
$driverLicense->save();
|
||||||
|
|
||||||
engelsystem_log('Driver license information removed.');
|
engelsystem_log('Driver license information removed.');
|
||||||
success(__('Your driver license information has been removed.'));
|
success(__('Your driver license information has been removed.'));
|
||||||
throw_redirect(user_link($user_source->id));
|
throw_redirect(user_link($user_source->id));
|
||||||
|
@ -145,6 +139,6 @@ function user_driver_license_edit_controller()
|
||||||
|
|
||||||
return [
|
return [
|
||||||
sprintf(__('Edit %s driving license information'), $user_source->name),
|
sprintf(__('Edit %s driving license information'), $user_source->name),
|
||||||
UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver_license)
|
UserDriverLicense_edit_view($user_source, $driverLicense)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ $includeFiles = [
|
||||||
__DIR__ . '/../includes/model/ShiftTypes_model.php',
|
__DIR__ . '/../includes/model/ShiftTypes_model.php',
|
||||||
__DIR__ . '/../includes/model/Stats.php',
|
__DIR__ . '/../includes/model/Stats.php',
|
||||||
__DIR__ . '/../includes/model/UserAngelTypes_model.php',
|
__DIR__ . '/../includes/model/UserAngelTypes_model.php',
|
||||||
__DIR__ . '/../includes/model/UserDriverLicenses_model.php',
|
|
||||||
__DIR__ . '/../includes/model/UserGroups_model.php',
|
__DIR__ . '/../includes/model/UserGroups_model.php',
|
||||||
__DIR__ . '/../includes/model/User_model.php',
|
__DIR__ . '/../includes/model/User_model.php',
|
||||||
__DIR__ . '/../includes/model/UserWorkLog_model.php',
|
__DIR__ . '/../includes/model/UserWorkLog_model.php',
|
||||||
|
|
|
@ -91,11 +91,10 @@ 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 AS wants_to_drive',
|
'users_licenses.*'
|
||||||
'UserDriverLicenses.*'
|
|
||||||
)
|
)
|
||||||
->join('UserAngelTypes', 'users.id', '=', 'UserAngelTypes.user_id')
|
->join('UserAngelTypes', 'users.id', '=', 'UserAngelTypes.user_id')
|
||||||
->leftJoin('UserDriverLicenses', 'users.id', '=', 'UserDriverLicenses.user_id')
|
->leftJoin('users_licenses', 'users.id', '=', 'users_licenses.user_id')
|
||||||
->where('UserAngelTypes.angeltype_id', '=', $angeltype['id'])
|
->where('UserAngelTypes.angeltype_id', '=', $angeltype['id'])
|
||||||
->orderBy('users.name')
|
->orderBy('users.name')
|
||||||
->get();
|
->get();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Engelsystem\Models\User\License;
|
||||||
use Engelsystem\Models\User\User;
|
use Engelsystem\Models\User\User;
|
||||||
use Engelsystem\ShiftCalendarRenderer;
|
use Engelsystem\ShiftCalendarRenderer;
|
||||||
use Engelsystem\ShiftsFilterRenderer;
|
use Engelsystem\ShiftsFilterRenderer;
|
||||||
|
@ -129,7 +130,7 @@ function AngelType_edit_view($angeltype, $supporter_mode)
|
||||||
* @param array|null $user_angeltype
|
* @param array|null $user_angeltype
|
||||||
* @param bool $admin_angeltypes
|
* @param bool $admin_angeltypes
|
||||||
* @param bool $supporter
|
* @param bool $supporter
|
||||||
* @param array|null $user_driver_license
|
* @param License $user_driver_license
|
||||||
* @param User|null $user
|
* @param User|null $user
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
@ -153,7 +154,7 @@ function AngelType_view_buttons($angeltype, $user_angeltype, $admin_angeltypes,
|
||||||
'add'
|
'add'
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if ($angeltype['requires_driver_license'] && empty($user_driver_license)) {
|
if ($angeltype['requires_driver_license'] && !$user_driver_license->wantsToDrive()) {
|
||||||
error(__('This angeltype requires a driver license. Please enter your driver license information!'));
|
error(__('This angeltype requires a driver license. Please enter your driver license information!'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,13 +206,13 @@ function AngelType_view_members($angeltype, $members, $admin_user_angeltypes, $a
|
||||||
$member->name = User_Nick_render($member) . User_Pronoun_render($member);
|
$member->name = User_Nick_render($member) . User_Pronoun_render($member);
|
||||||
$member['dect'] = $member->contact->dect;
|
$member['dect'] = $member->contact->dect;
|
||||||
if ($angeltype['requires_driver_license']) {
|
if ($angeltype['requires_driver_license']) {
|
||||||
$member['wants_to_drive'] = icon_bool($member['wants_to_drive']);
|
$member['wants_to_drive'] = icon_bool($member->license->wantsToDrive());
|
||||||
$member['has_car'] = icon_bool($member['has_car']);
|
$member['has_car'] = icon_bool($member->license->has_car);
|
||||||
$member['has_license_car'] = icon_bool($member['has_license_car']);
|
$member['has_license_car'] = icon_bool($member->license->drive_car);
|
||||||
$member['has_license_3_5t_transporter'] = icon_bool($member['has_license_3_5t_transporter']);
|
$member['has_license_3_5t_transporter'] = icon_bool($member->license->drive_3_5t);
|
||||||
$member['has_license_7_5t_truck'] = icon_bool($member['has_license_7_5t_truck']);
|
$member['has_license_7_5t_truck'] = icon_bool($member->license->drive_7_5t);
|
||||||
$member['has_license_12_5t_truck'] = icon_bool($member['has_license_12_5t_truck']);
|
$member['has_license_12t_truck'] = icon_bool($member->license->drive_12t);
|
||||||
$member['has_license_forklift'] = icon_bool($member['has_license_forklift']);
|
$member['has_license_forklift'] = icon_bool($member->license->drive_forklift);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($angeltype['restricted'] && empty($member['confirm_user_id'])) {
|
if ($angeltype['restricted'] && empty($member['confirm_user_id'])) {
|
||||||
|
@ -302,7 +303,7 @@ function AngelType_view_table_headers($angeltype, $supporter, $admin_angeltypes)
|
||||||
'has_license_car' => __('Car'),
|
'has_license_car' => __('Car'),
|
||||||
'has_license_3_5t_transporter' => __('3,5t Transporter'),
|
'has_license_3_5t_transporter' => __('3,5t Transporter'),
|
||||||
'has_license_7_5t_truck' => __('7,5t Truck'),
|
'has_license_7_5t_truck' => __('7,5t Truck'),
|
||||||
'has_license_12_5t_truck' => __('12,5t Truck'),
|
'has_license_12t_truck' => __('12t Truck'),
|
||||||
'has_license_forklift' => __('Forklift'),
|
'has_license_forklift' => __('Forklift'),
|
||||||
'actions' => ''
|
'actions' => ''
|
||||||
];
|
];
|
||||||
|
@ -323,7 +324,7 @@ function AngelType_view_table_headers($angeltype, $supporter, $admin_angeltypes)
|
||||||
* @param bool $admin_user_angeltypes
|
* @param bool $admin_user_angeltypes
|
||||||
* @param bool $admin_angeltypes
|
* @param bool $admin_angeltypes
|
||||||
* @param bool $supporter
|
* @param bool $supporter
|
||||||
* @param array $user_driver_license
|
* @param License $user_driver_license
|
||||||
* @param User $user
|
* @param User $user
|
||||||
* @param ShiftsFilterRenderer $shiftsFilterRenderer
|
* @param ShiftsFilterRenderer $shiftsFilterRenderer
|
||||||
* @param ShiftCalendarRenderer $shiftCalendarRenderer
|
* @param ShiftCalendarRenderer $shiftCalendarRenderer
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Engelsystem\Models\User\License;
|
||||||
use Engelsystem\Models\User\User;
|
use Engelsystem\Models\User\User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edit a user's driving license information.
|
* Edit a user's driving license information.
|
||||||
*
|
*
|
||||||
* @param User $user_source The user
|
* @param User $user_source The user
|
||||||
* @param bool $wants_to_drive true, if the user wants to drive
|
* @param License $user_driver_license The user driver license
|
||||||
* @param array $user_driver_license The user driver license
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver_license)
|
function UserDriverLicense_edit_view($user_source, $user_driver_license)
|
||||||
{
|
{
|
||||||
return page_with_title(sprintf(__('Edit %s driving license information'), User_Nick_render($user_source)), [
|
return page_with_title(sprintf(__('Edit %s driving license information'), User_Nick_render($user_source)), [
|
||||||
buttons([
|
buttons([
|
||||||
|
@ -19,34 +19,34 @@ function UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver
|
||||||
msg(),
|
msg(),
|
||||||
form([
|
form([
|
||||||
form_info(__('Privacy'), __('Your driving license information is only visible for supporters and admins.')),
|
form_info(__('Privacy'), __('Your driving license information is only visible for supporters and admins.')),
|
||||||
form_checkbox('wants_to_drive', __('I am willing to drive a car for the event'), $wants_to_drive),
|
form_checkbox('wants_to_drive', __('I am willing to drive a car for the event'), $user_driver_license->wantsToDrive()),
|
||||||
div('m-3', [
|
div('m-3', [
|
||||||
form_checkbox(
|
form_checkbox(
|
||||||
'has_car',
|
'has_car',
|
||||||
__('I have my own car with me and am willing to use it for the event (You\'ll get reimbursed for fuel)'),
|
__('I have my own car with me and am willing to use it for the event (You\'ll get reimbursed for fuel)'),
|
||||||
$user_driver_license['has_car']
|
$user_driver_license->has_car
|
||||||
),
|
),
|
||||||
heading(__('Driver license'), 3),
|
heading(__('Driver license'), 3),
|
||||||
form_checkbox('has_license_car', __('Car'), $user_driver_license['has_license_car']),
|
form_checkbox('has_license_car', __('Car'), $user_driver_license->drive_car),
|
||||||
form_checkbox(
|
form_checkbox(
|
||||||
'has_license_3_5t_transporter',
|
'has_license_3_5t_transporter',
|
||||||
__('Transporter 3,5t'),
|
__('Transporter 3,5t'),
|
||||||
$user_driver_license['has_license_3_5t_transporter']
|
$user_driver_license->drive_3_5t
|
||||||
),
|
),
|
||||||
form_checkbox(
|
form_checkbox(
|
||||||
'has_license_7_5t_truck',
|
'has_license_7_5t_truck',
|
||||||
__('Truck 7,5t'),
|
__('Truck 7,5t'),
|
||||||
$user_driver_license['has_license_7_5t_truck']
|
$user_driver_license->drive_7_5t
|
||||||
),
|
),
|
||||||
form_checkbox(
|
form_checkbox(
|
||||||
'has_license_12_5t_truck',
|
'has_license_12t_truck',
|
||||||
__('Truck 12,5t'),
|
__('Truck 12t'),
|
||||||
$user_driver_license['has_license_12_5t_truck']
|
$user_driver_license->drive_12t
|
||||||
),
|
),
|
||||||
form_checkbox(
|
form_checkbox(
|
||||||
'has_license_forklift',
|
'has_license_forklift',
|
||||||
__('Forklift'),
|
__('Forklift'),
|
||||||
$user_driver_license['has_license_forklift']
|
$user_driver_license->drive_forklift
|
||||||
)
|
)
|
||||||
], 'driving_license'),
|
], 'driving_license'),
|
||||||
form_submit('submit', __('Save'))
|
form_submit('submit', __('Save'))
|
||||||
|
|
|
@ -2059,8 +2059,8 @@ msgid "7,5t Truck"
|
||||||
msgstr "7,5t LKW"
|
msgstr "7,5t LKW"
|
||||||
|
|
||||||
#: includes/view/AngelTypes_view.php:305
|
#: includes/view/AngelTypes_view.php:305
|
||||||
msgid "12,5t Truck"
|
msgid "12t Truck"
|
||||||
msgstr "12,5t LKW"
|
msgstr "12t LKW"
|
||||||
|
|
||||||
#: includes/view/AngelTypes_view.php:306
|
#: includes/view/AngelTypes_view.php:306
|
||||||
#: includes/view/UserDriverLicenses_view.php:49
|
#: includes/view/UserDriverLicenses_view.php:49
|
||||||
|
@ -2462,8 +2462,8 @@ msgid "Truck 7,5t"
|
||||||
msgstr "7,5t LKW"
|
msgstr "7,5t LKW"
|
||||||
|
|
||||||
#: includes/view/UserDriverLicenses_view.php:44
|
#: includes/view/UserDriverLicenses_view.php:44
|
||||||
msgid "Truck 12,5t"
|
msgid "Truck 12t"
|
||||||
msgstr "12,5t LKW"
|
msgstr "12t LKW"
|
||||||
|
|
||||||
#: includes/view/UserWorkLog_view.php:15
|
#: includes/view/UserWorkLog_view.php:15
|
||||||
#, php-format
|
#, php-format
|
||||||
|
|
|
@ -1821,8 +1821,8 @@ msgid "7,5t Truck"
|
||||||
msgstr "Caminhão 7,5t"
|
msgstr "Caminhão 7,5t"
|
||||||
|
|
||||||
#: includes/view/AngelTypes_view.php:184
|
#: includes/view/AngelTypes_view.php:184
|
||||||
msgid "12,5t Truck"
|
msgid "12t Truck"
|
||||||
msgstr "Caminhão 12,5t"
|
msgstr "Caminhão 12t"
|
||||||
|
|
||||||
#: includes/view/AngelTypes_view.php:185
|
#: includes/view/AngelTypes_view.php:185
|
||||||
#: includes/view/UserDriverLicenses_view.php:31
|
#: includes/view/UserDriverLicenses_view.php:31
|
||||||
|
@ -2184,8 +2184,8 @@ msgid "Truck 7,5t"
|
||||||
msgstr "Caminhão 7,5t"
|
msgstr "Caminhão 7,5t"
|
||||||
|
|
||||||
#: includes/view/UserDriverLicenses_view.php:30
|
#: includes/view/UserDriverLicenses_view.php:30
|
||||||
msgid "Truck 12,5t"
|
msgid "Truck 12t"
|
||||||
msgstr "Caminhão 12,5t"
|
msgstr "Caminhão 12t"
|
||||||
|
|
||||||
#: includes/view/User_view.php:7
|
#: includes/view/User_view.php:7
|
||||||
msgid "Please select..."
|
msgid "Please select..."
|
||||||
|
|
|
@ -110,11 +110,12 @@ class Controller extends BaseController
|
||||||
'licenses' => [
|
'licenses' => [
|
||||||
'type' => 'gauge',
|
'type' => 'gauge',
|
||||||
'help' => 'The total number of licenses',
|
'help' => 'The total number of licenses',
|
||||||
|
['labels' => ['type' => 'has_car'], 'value' => $this->stats->licenses('has_car')],
|
||||||
['labels' => ['type' => 'forklift'], 'value' => $this->stats->licenses('forklift')],
|
['labels' => ['type' => 'forklift'], 'value' => $this->stats->licenses('forklift')],
|
||||||
['labels' => ['type' => 'car'], 'value' => $this->stats->licenses('car')],
|
['labels' => ['type' => 'car'], 'value' => $this->stats->licenses('car')],
|
||||||
['labels' => ['type' => '3.5t'], 'value' => $this->stats->licenses('3.5t')],
|
['labels' => ['type' => '3.5t'], 'value' => $this->stats->licenses('3.5t')],
|
||||||
['labels' => ['type' => '7.5t'], 'value' => $this->stats->licenses('7.5t')],
|
['labels' => ['type' => '7.5t'], 'value' => $this->stats->licenses('7.5t')],
|
||||||
['labels' => ['type' => '12.5t'], 'value' => $this->stats->licenses('12.5t')],
|
['labels' => ['type' => '12t'], 'value' => $this->stats->licenses('12t')],
|
||||||
],
|
],
|
||||||
'users_email' => [
|
'users_email' => [
|
||||||
'type' => 'gauge',
|
'type' => 'gauge',
|
||||||
|
|
|
@ -15,6 +15,7 @@ use Engelsystem\Models\NewsComment;
|
||||||
use Engelsystem\Models\OAuth;
|
use Engelsystem\Models\OAuth;
|
||||||
use Engelsystem\Models\Question;
|
use Engelsystem\Models\Question;
|
||||||
use Engelsystem\Models\Room;
|
use Engelsystem\Models\Room;
|
||||||
|
use Engelsystem\Models\User\License;
|
||||||
use Engelsystem\Models\User\PasswordReset;
|
use Engelsystem\Models\User\PasswordReset;
|
||||||
use Engelsystem\Models\User\PersonalData;
|
use Engelsystem\Models\User\PersonalData;
|
||||||
use Engelsystem\Models\User\Settings;
|
use Engelsystem\Models\User\Settings;
|
||||||
|
@ -232,24 +233,21 @@ class Stats
|
||||||
/**
|
/**
|
||||||
* @param string|null $vehicle
|
* @param string|null $vehicle
|
||||||
* @return int
|
* @return int
|
||||||
* @codeCoverageIgnore
|
|
||||||
*/
|
*/
|
||||||
public function licenses(string $vehicle = null): int
|
public function licenses(string $vehicle): int
|
||||||
{
|
{
|
||||||
$mapping = [
|
$mapping = [
|
||||||
'forklift' => 'has_license_forklift',
|
'has_car' => 'has_car',
|
||||||
'car' => 'has_license_car',
|
'forklift' => 'drive_forklift',
|
||||||
'3.5t' => 'has_license_3_5t_transporter',
|
'car' => 'drive_car',
|
||||||
'7.5t' => 'has_license_7_5t_truck',
|
'3.5t' => 'drive_3_5t',
|
||||||
'12.5t' => 'has_license_12_5t_truck',
|
'7.5t' => 'drive_7_5t',
|
||||||
|
'12t' => 'drive_12t',
|
||||||
];
|
];
|
||||||
|
|
||||||
$query = $this
|
$query = (new License())
|
||||||
->getQuery('UserDriverLicenses');
|
->getQuery()
|
||||||
|
->where($mapping[$vehicle], true);
|
||||||
if (!is_null($vehicle)) {
|
|
||||||
$query->where($mapping[$vehicle], '=', true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $query->count();
|
return $query->count();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem\Models\User;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Query\Builder as QueryBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property bool $has_car
|
||||||
|
* @property bool $drive_forklift
|
||||||
|
* @property bool $drive_car
|
||||||
|
* @property bool $drive_3_5t
|
||||||
|
* @property bool $drive_7_5t
|
||||||
|
* @property bool $drive_12t
|
||||||
|
*
|
||||||
|
* @method static QueryBuilder|License[] whereHasCar($value)
|
||||||
|
* @method static QueryBuilder|License[] whereDriveForklift($value)
|
||||||
|
* @method static QueryBuilder|License[] whereDriveCar($value)
|
||||||
|
* @method static QueryBuilder|License[] whereDrive35T($value)
|
||||||
|
* @method static QueryBuilder|License[] whereDrive75T($value)
|
||||||
|
* @method static QueryBuilder|License[] whereDrive12T($value)
|
||||||
|
*/
|
||||||
|
class License extends HasUserModel
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
/** @var string The table associated with the model */
|
||||||
|
protected $table = 'users_licenses';
|
||||||
|
|
||||||
|
/** @var array Default attributes */
|
||||||
|
protected $attributes = [
|
||||||
|
'has_car' => false,
|
||||||
|
'drive_forklift' => false,
|
||||||
|
'drive_car' => false,
|
||||||
|
'drive_3_5t' => false,
|
||||||
|
'drive_7_5t' => false,
|
||||||
|
'drive_12t' => false,
|
||||||
|
];
|
||||||
|
|
||||||
|
/** The attributes that are mass assignable */
|
||||||
|
protected $fillable = [
|
||||||
|
'user_id',
|
||||||
|
'has_car',
|
||||||
|
'drive_forklift',
|
||||||
|
'drive_car',
|
||||||
|
'drive_3_5t',
|
||||||
|
'drive_7_5t',
|
||||||
|
'drive_12t',
|
||||||
|
];
|
||||||
|
|
||||||
|
/** @var string[] */
|
||||||
|
protected $casts = [
|
||||||
|
'has_car' => 'boolean',
|
||||||
|
'drive_forklift' => 'boolean',
|
||||||
|
'drive_car' => 'boolean',
|
||||||
|
'drive_3_5t' => 'boolean',
|
||||||
|
'drive_7_5t' => 'boolean',
|
||||||
|
'drive_12t' => 'boolean',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the user wants to drive at the event
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function wantsToDrive(): bool
|
||||||
|
{
|
||||||
|
return $this->drive_forklift
|
||||||
|
|| $this->drive_car
|
||||||
|
|| $this->drive_3_5t
|
||||||
|
|| $this->drive_7_5t
|
||||||
|
|| $this->drive_12t;
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,6 +27,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
|
||||||
* @property Carbon $updated_at
|
* @property Carbon $updated_at
|
||||||
*
|
*
|
||||||
* @property-read QueryBuilder|Contact $contact
|
* @property-read QueryBuilder|Contact $contact
|
||||||
|
* @property-read QueryBuilder|License $license
|
||||||
* @property-read QueryBuilder|PersonalData $personalData
|
* @property-read QueryBuilder|PersonalData $personalData
|
||||||
* @property-read QueryBuilder|Settings $settings
|
* @property-read QueryBuilder|Settings $settings
|
||||||
* @property-read QueryBuilder|State $state
|
* @property-read QueryBuilder|State $state
|
||||||
|
@ -93,6 +94,16 @@ class User extends BaseModel
|
||||||
->withDefault();
|
->withDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return HasOne
|
||||||
|
*/
|
||||||
|
public function license()
|
||||||
|
{
|
||||||
|
return $this
|
||||||
|
->hasOne(License::class)
|
||||||
|
->withDefault();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return HasOne
|
* @return HasOne
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -84,10 +84,10 @@ class ControllerTest extends TestCase
|
||||||
->with('metrics return')
|
->with('metrics return')
|
||||||
->willReturn($response);
|
->willReturn($response);
|
||||||
|
|
||||||
$stats->expects($this->exactly(5))
|
$stats->expects($this->exactly(6))
|
||||||
->method('licenses')
|
->method('licenses')
|
||||||
->withConsecutive(['forklift'], ['car'], ['3.5t'], ['7.5t'], ['12.5t'])
|
->withConsecutive(['has_car'], ['forklift'], ['car'], ['3.5t'], ['7.5t'], ['12t'])
|
||||||
->willReturnOnConsecutiveCalls(3, 15, 9, 7, 1);
|
->willReturnOnConsecutiveCalls(6, 3, 15, 9, 7, 1);
|
||||||
$stats->expects($this->exactly(2))
|
$stats->expects($this->exactly(2))
|
||||||
->method('arrivedUsers')
|
->method('arrivedUsers')
|
||||||
->withConsecutive([false], [true])
|
->withConsecutive([false], [true])
|
||||||
|
|
|
@ -12,6 +12,7 @@ use Engelsystem\Models\NewsComment;
|
||||||
use Engelsystem\Models\OAuth;
|
use Engelsystem\Models\OAuth;
|
||||||
use Engelsystem\Models\Question;
|
use Engelsystem\Models\Question;
|
||||||
use Engelsystem\Models\Room;
|
use Engelsystem\Models\Room;
|
||||||
|
use Engelsystem\Models\User\License;
|
||||||
use Engelsystem\Models\User\PasswordReset;
|
use Engelsystem\Models\User\PasswordReset;
|
||||||
use Engelsystem\Models\User\PersonalData;
|
use Engelsystem\Models\User\PersonalData;
|
||||||
use Engelsystem\Models\User\Settings;
|
use Engelsystem\Models\User\Settings;
|
||||||
|
@ -123,6 +124,22 @@ class StatsTest extends TestCase
|
||||||
], $themes->toArray());
|
], $themes->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Engelsystem\Controllers\Metrics\Stats::licenses
|
||||||
|
*/
|
||||||
|
public function testLicenses()
|
||||||
|
{
|
||||||
|
$this->addUsers();
|
||||||
|
|
||||||
|
$stats = new Stats($this->database);
|
||||||
|
$this->assertEquals(1, $stats->licenses('has_car'));
|
||||||
|
$this->assertEquals(1, $stats->licenses('forklift'));
|
||||||
|
$this->assertEquals(2, $stats->licenses('car'));
|
||||||
|
$this->assertEquals(0, $stats->licenses('3.5t'));
|
||||||
|
$this->assertEquals(0, $stats->licenses('7.5t'));
|
||||||
|
$this->assertEquals(1, $stats->licenses('12t'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \Engelsystem\Controllers\Metrics\Stats::worklogSeconds
|
* @covers \Engelsystem\Controllers\Metrics\Stats::worklogSeconds
|
||||||
*/
|
*/
|
||||||
|
@ -394,11 +411,17 @@ class StatsTest extends TestCase
|
||||||
$this->addUser(['arrived' => 1], [], ['email_human' => true, 'email_goody' => true, 'email_news' => true]);
|
$this->addUser(['arrived' => 1], [], ['email_human' => true, 'email_goody' => true, 'email_news' => true]);
|
||||||
$this->addUser(['arrived' => 1], ['pronoun' => 'unicorn'], ['language' => 'lo_RM', 'email_shiftinfo' => true]);
|
$this->addUser(['arrived' => 1], ['pronoun' => 'unicorn'], ['language' => 'lo_RM', 'email_shiftinfo' => true]);
|
||||||
$this->addUser(['arrived' => 1, 'got_voucher' => 2], ['shirt_size' => 'XXL'], ['language' => 'lo_RM']);
|
$this->addUser(['arrived' => 1, 'got_voucher' => 2], ['shirt_size' => 'XXL'], ['language' => 'lo_RM']);
|
||||||
$this->addUser(['arrived' => 1, 'got_voucher' => 9, 'force_active' => true], [], ['theme' => 1]);
|
$this->addUser(
|
||||||
|
['arrived' => 1, 'got_voucher' => 9, 'force_active' => true],
|
||||||
|
[],
|
||||||
|
['theme' => 1],
|
||||||
|
['drive_car' => true, 'drive_12t' => true]
|
||||||
|
);
|
||||||
$this->addUser(
|
$this->addUser(
|
||||||
['arrived' => 1, 'got_voucher' => 3],
|
['arrived' => 1, 'got_voucher' => 3],
|
||||||
['pronoun' => 'per'],
|
['pronoun' => 'per'],
|
||||||
['theme' => 1, 'email_human' => true]
|
['theme' => 1, 'email_human' => true],
|
||||||
|
['has_car' => true, 'drive_forklift' => true, 'drive_car' => true]
|
||||||
);
|
);
|
||||||
$this->addUser(['arrived' => 1, 'active' => 1, 'got_shirt' => true, 'force_active' => true]);
|
$this->addUser(['arrived' => 1, 'active' => 1, 'got_shirt' => true, 'force_active' => true]);
|
||||||
$this->addUser(['arrived' => 1, 'active' => 1, 'got_shirt' => true], ['shirt_size' => 'L'], ['theme' => 4]);
|
$this->addUser(['arrived' => 1, 'active' => 1, 'got_shirt' => true], ['shirt_size' => 'L'], ['theme' => 4]);
|
||||||
|
@ -411,7 +434,7 @@ class StatsTest extends TestCase
|
||||||
*
|
*
|
||||||
* @return User
|
* @return User
|
||||||
*/
|
*/
|
||||||
protected function addUser(array $state = [], $personalData = [], $settings = []): User
|
protected function addUser(array $state = [], $personalData = [], $settings = [], $license = []): User
|
||||||
{
|
{
|
||||||
$name = 'user_' . Str::random(5);
|
$name = 'user_' . Str::random(5);
|
||||||
|
|
||||||
|
@ -443,6 +466,11 @@ class StatsTest extends TestCase
|
||||||
->associate($user)
|
->associate($user)
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
|
$license = new License($license);
|
||||||
|
$license->user()
|
||||||
|
->associate($user)
|
||||||
|
->save();
|
||||||
|
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem\Test\Unit\Models\User;
|
||||||
|
|
||||||
|
use Engelsystem\Models\User\License;
|
||||||
|
use Engelsystem\Test\Unit\Models\ModelTest;
|
||||||
|
|
||||||
|
class LicenseTest extends ModelTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers \Engelsystem\Models\User\License::wantsToDrive
|
||||||
|
*/
|
||||||
|
public function testWantsToDrive()
|
||||||
|
{
|
||||||
|
$license = new License();
|
||||||
|
$this->assertFalse($license->wantsToDrive());
|
||||||
|
|
||||||
|
$license->has_car = true;
|
||||||
|
$this->assertFalse($license->wantsToDrive());
|
||||||
|
|
||||||
|
$license->drive_car = true;
|
||||||
|
$this->assertTrue($license->wantsToDrive());
|
||||||
|
|
||||||
|
// True if a user wants to drive anything
|
||||||
|
$license = new License(['drive_forklift' => true]);
|
||||||
|
$this->assertTrue($license->wantsToDrive());
|
||||||
|
|
||||||
|
$license = new License(['drive_car' => true]);
|
||||||
|
$this->assertTrue($license->wantsToDrive());
|
||||||
|
|
||||||
|
$license = new License(['drive_3_5t' => true]);
|
||||||
|
$this->assertTrue($license->wantsToDrive());
|
||||||
|
|
||||||
|
$license = new License(['drive_7_5t' => true]);
|
||||||
|
$this->assertTrue($license->wantsToDrive());
|
||||||
|
|
||||||
|
$license = new License(['drive_12t' => true]);
|
||||||
|
$this->assertTrue($license->wantsToDrive());
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ use Engelsystem\Models\OAuth;
|
||||||
use Engelsystem\Models\Question;
|
use Engelsystem\Models\Question;
|
||||||
use Engelsystem\Models\User\Contact;
|
use Engelsystem\Models\User\Contact;
|
||||||
use Engelsystem\Models\User\HasUserModel;
|
use Engelsystem\Models\User\HasUserModel;
|
||||||
|
use Engelsystem\Models\User\License;
|
||||||
use Engelsystem\Models\User\PersonalData;
|
use Engelsystem\Models\User\PersonalData;
|
||||||
use Engelsystem\Models\User\Settings;
|
use Engelsystem\Models\User\Settings;
|
||||||
use Engelsystem\Models\User\State;
|
use Engelsystem\Models\User\State;
|
||||||
|
@ -69,11 +70,20 @@ class UserTest extends ModelTest
|
||||||
'force_active' => true,
|
'force_active' => true,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
License::class,
|
||||||
|
'license',
|
||||||
|
[
|
||||||
|
'has_car' => true,
|
||||||
|
'drive_car' => true,
|
||||||
|
],
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \Engelsystem\Models\User\User::contact
|
* @covers \Engelsystem\Models\User\User::contact
|
||||||
|
* @covers \Engelsystem\Models\User\User::license
|
||||||
* @covers \Engelsystem\Models\User\User::personalData
|
* @covers \Engelsystem\Models\User\User::personalData
|
||||||
* @covers \Engelsystem\Models\User\User::settings
|
* @covers \Engelsystem\Models\User\User::settings
|
||||||
* @covers \Engelsystem\Models\User\User::state
|
* @covers \Engelsystem\Models\User\User::state
|
||||||
|
|
Loading…
Reference in New Issue