You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
engelsystem/includes/model/UserDriverLicenses_model.php

153 lines
4.3 KiB
PHTML

<?php
use Engelsystem\Database\DB;
/**
* Returns a new empty UserDriverLicense
* FIXME entity object needed
*
* @return array
*/
8 years ago
function UserDriverLicense_new()
{
return [
8 years ago
'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
];
}
/**
* Is it valid?
*
* @param array $user_driver_license The UserDriverLicense to check
* @return boolean
*/
8 years ago
function UserDriverLicense_valid($user_driver_license)
{
8 years ago
return $user_driver_license['has_car']
|| $user_driver_license['has_license_car']
|| $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'];
}
/**
* Get a users driver license information
*
* @param int $user_id The users id
* @return array|false|null
*/
8 years ago
function UserDriverLicense($user_id)
{
$user_driver_license = DB::select('
SELECT *
FROM `UserDriverLicenses`
WHERE `user_id`=?', [$user_id]);
if (DB::getStm()->errorCode() != '00000') {
8 years ago
engelsystem_error('Unable to load user driver license.');
return false;
}
if (empty($user_driver_license)) {
return null;
8 years ago
}
return array_shift($user_driver_license);
}
/**
* Create a user's driver license entry
*
* @param array $user_driver_license The UserDriverLicense to create
* @param array $user
* @return array
*/
8 years ago
function UserDriverLicenses_create($user_driver_license, $user)
{
$user_driver_license['user_id'] = $user['UID'];
DB::insert('
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 (?, ?, ?, ?, ?, ?, ?)
',
[
$user_driver_license['user_id'],
(bool)$user_driver_license['has_car'],
(bool)$user_driver_license['has_license_car'],
(bool)$user_driver_license['has_license_3_5t_transporter'],
(bool)$user_driver_license['has_license_7_5t_truck'],
(bool)$user_driver_license['has_license_12_5t_truck'],
(bool)$user_driver_license['has_license_forklift'],
]
);
if (DB::getStm()->errorCode() != '00000') {
8 years ago
engelsystem_error('Unable to create user driver license');
}
8 years ago
return $user_driver_license;
}
/**
* Update a user's driver license entry
*
* @param array $user_driver_license The UserDriverLicense to update
* @return bool
*/
8 years ago
function UserDriverLicenses_update($user_driver_license)
{
$result = DB::update('
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`=?
',
[
(bool)$user_driver_license['has_car'],
(bool)$user_driver_license['has_license_car'],
(bool)$user_driver_license['has_license_3_5t_transporter'],
(bool)$user_driver_license['has_license_7_5t_truck'],
(bool)$user_driver_license['has_license_12_5t_truck'],
(bool)$user_driver_license['has_license_forklift'],
$user_driver_license['user_id'],
]
);
if (DB::getStm()->errorCode() != '00000') {
engelsystem_error('Unable to update user driver license information');
8 years ago
}
return $result;
}
/**
* Delete a user's driver license entry
*
8 years ago
* @param int $user_id
* @return bool
*/
8 years ago
function UserDriverLicenses_delete($user_id)
{
$result = DB::delete('DELETE FROM `UserDriverLicenses` WHERE `user_id`=?', [$user_id]);
if (DB::getStm()->errorCode() != '00000') {
engelsystem_error('Unable to remove user driver license information');
8 years ago
}
return $result;
}