2015-12-19 23:31:08 +01:00
|
|
|
<?php
|
|
|
|
|
2017-01-21 13:58:53 +01:00
|
|
|
use Engelsystem\Database\DB;
|
|
|
|
|
2016-11-17 14:35:04 +01:00
|
|
|
/**
|
|
|
|
* Returns a new empty UserDriverLicense
|
|
|
|
* FIXME entity object needed
|
2017-01-03 03:22:48 +01:00
|
|
|
*
|
|
|
|
* @return array
|
2016-11-17 14:35:04 +01:00
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function UserDriverLicense_new()
|
|
|
|
{
|
|
|
|
return [
|
2017-01-02 15:43:36 +01:00
|
|
|
'user_id' => null,
|
|
|
|
'has_car' => false,
|
|
|
|
'has_license_car' => false,
|
|
|
|
'has_license_3_5t_transporter' => false,
|
|
|
|
'has_license_7_5t_truck' => false,
|
|
|
|
'has_license_12_5t_truck' => false,
|
|
|
|
'has_license_forklift' => false
|
|
|
|
];
|
2016-11-17 14:35:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is it valid?
|
|
|
|
*
|
2017-01-03 03:22:48 +01:00
|
|
|
* @param array $user_driver_license The UserDriverLicense to check
|
2016-11-17 14:35:04 +01:00
|
|
|
* @return boolean
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function UserDriverLicense_valid($user_driver_license)
|
|
|
|
{
|
2017-07-17 23:43:47 +02:00
|
|
|
return
|
|
|
|
$user_driver_license['has_license_car']
|
2017-01-02 15:43:36 +01:00
|
|
|
|| $user_driver_license['has_license_3_5t_transporter']
|
|
|
|
|| $user_driver_license['has_license_7_5t_truck']
|
|
|
|
|| $user_driver_license['has_license_12_5t_truck']
|
|
|
|
|| $user_driver_license['has_license_forklift'];
|
2016-11-17 14:35:04 +01:00
|
|
|
}
|
|
|
|
|
2015-12-19 23:31:08 +01:00
|
|
|
/**
|
|
|
|
* Get a users driver license information
|
2016-11-17 14:35:04 +01:00
|
|
|
*
|
2017-01-03 03:22:48 +01:00
|
|
|
* @param int $user_id The users id
|
2018-01-14 23:07:34 +01:00
|
|
|
* @return array|null
|
2015-12-19 23:31:08 +01:00
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function UserDriverLicense($user_id)
|
|
|
|
{
|
2018-01-14 23:07:34 +01:00
|
|
|
$driverLicense = DB::selectOne('
|
2017-01-21 13:58:53 +01:00
|
|
|
SELECT *
|
|
|
|
FROM `UserDriverLicenses`
|
|
|
|
WHERE `user_id`=?', [$user_id]);
|
2018-01-14 23:07:34 +01:00
|
|
|
|
|
|
|
return empty($driverLicense) ? null : $driverLicense;
|
2015-12-19 23:31:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a user's driver license entry
|
|
|
|
*
|
2017-01-03 03:22:48 +01:00
|
|
|
* @param array $user_driver_license The UserDriverLicense to create
|
2018-10-09 21:47:31 +02:00
|
|
|
* @param int $userId
|
2017-01-03 03:22:48 +01:00
|
|
|
* @return array
|
2015-12-19 23:31:08 +01:00
|
|
|
*/
|
2018-10-09 21:47:31 +02:00
|
|
|
function UserDriverLicenses_create($user_driver_license, $userId)
|
2017-01-02 03:57:23 +01:00
|
|
|
{
|
2018-10-09 21:47:31 +02:00
|
|
|
$user_driver_license['user_id'] = $userId;
|
2017-01-21 13:58:53 +01:00
|
|
|
DB::insert('
|
2020-05-13 18:26:32 +02:00
|
|
|
INSERT INTO `UserDriverLicenses` (
|
|
|
|
`user_id`,
|
|
|
|
`has_car`,
|
|
|
|
`has_license_car`,
|
|
|
|
`has_license_3_5t_transporter`,
|
|
|
|
`has_license_7_5t_truck`,
|
|
|
|
`has_license_12_5t_truck`,
|
|
|
|
`has_license_forklift`
|
|
|
|
)
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
2017-01-21 13:58:53 +01:00
|
|
|
',
|
|
|
|
[
|
|
|
|
$user_driver_license['user_id'],
|
2017-11-19 13:17:34 +01:00
|
|
|
(int)$user_driver_license['has_car'],
|
|
|
|
(int)$user_driver_license['has_license_car'],
|
|
|
|
(int)$user_driver_license['has_license_3_5t_transporter'],
|
|
|
|
(int)$user_driver_license['has_license_7_5t_truck'],
|
|
|
|
(int)$user_driver_license['has_license_12_5t_truck'],
|
|
|
|
(int)$user_driver_license['has_license_forklift'],
|
2017-01-21 13:58:53 +01:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
return $user_driver_license;
|
2015-12-19 23:31:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update a user's driver license entry
|
|
|
|
*
|
2017-01-03 03:22:48 +01:00
|
|
|
* @param array $user_driver_license The UserDriverLicense to update
|
2015-12-19 23:31:08 +01:00
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function UserDriverLicenses_update($user_driver_license)
|
|
|
|
{
|
2017-07-23 11:46:54 +02:00
|
|
|
DB::update('
|
2020-05-13 18:26:32 +02:00
|
|
|
UPDATE `UserDriverLicenses`
|
|
|
|
SET
|
|
|
|
`has_car`=?,
|
|
|
|
`has_license_car`=?,
|
|
|
|
`has_license_3_5t_transporter`=?,
|
|
|
|
`has_license_7_5t_truck`=?,
|
|
|
|
`has_license_12_5t_truck`=?,
|
|
|
|
`has_license_forklift`=?
|
|
|
|
WHERE `user_id`=?
|
|
|
|
',
|
2017-01-21 13:58:53 +01:00
|
|
|
[
|
2017-11-19 13:17:34 +01:00
|
|
|
(int)$user_driver_license['has_car'],
|
|
|
|
(int)$user_driver_license['has_license_car'],
|
|
|
|
(int)$user_driver_license['has_license_3_5t_transporter'],
|
|
|
|
(int)$user_driver_license['has_license_7_5t_truck'],
|
|
|
|
(int)$user_driver_license['has_license_12_5t_truck'],
|
|
|
|
(int)$user_driver_license['has_license_forklift'],
|
2017-01-21 13:58:53 +01:00
|
|
|
$user_driver_license['user_id'],
|
|
|
|
]
|
|
|
|
);
|
2015-12-19 23:31:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a user's driver license entry
|
|
|
|
*
|
2017-01-02 03:57:23 +01:00
|
|
|
* @param int $user_id
|
2015-12-19 23:31:08 +01:00
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function UserDriverLicenses_delete($user_id)
|
|
|
|
{
|
2017-07-28 18:50:00 +02:00
|
|
|
DB::delete('DELETE FROM `UserDriverLicenses` WHERE `user_id`=?', [$user_id]);
|
2015-12-19 23:31:08 +01:00
|
|
|
}
|