Features für Project 7832: * Das Pickerldatum Zusatzfeld * Auftrennen PKW und Anhänger * Dokumente Upload * Standardsortierung * Ausgeschieden Flag mit Datum * zusätzliche migration
154 lines
4.4 KiB
PHP
154 lines
4.4 KiB
PHP
<?php
|
|
|
|
class TimerecordingCarDocumentsModel
|
|
{
|
|
private $file_id;
|
|
private $file_size;
|
|
private $timerecordingCar_id;
|
|
private $name;
|
|
private $description;
|
|
private $sort;
|
|
|
|
public static $mimetypes = [
|
|
'application/pdf' => 'fa-file-pdf',
|
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'fa-file-doc',
|
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'fa-file-xls',
|
|
'application/octet-stream' => 'fa-file-csv',
|
|
'text/csv' => 'fa-file-csv',
|
|
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'fa-file-ppt',
|
|
'application/zip' => 'fa-file-zip',
|
|
'application/x-zip-compressed' => 'fa-file-zip',
|
|
'application/x-rar-compressed' => 'fa-file-archive',
|
|
'application/x-7z-compressed' => 'fa-file-archive',
|
|
'application/x-tar' => 'fa-file-archive',
|
|
'application/x-gzip' => 'fa-file-archive',
|
|
'application/x-bzip2' => 'fa-file-archive',
|
|
'text/xml' => 'fa-file-xml',
|
|
'application/xml' => 'fa-file-xml',
|
|
'audio/mpeg' => 'fa-file-mp3',
|
|
'image/png' => 'fa-file-png',
|
|
'image/jpeg' => 'fa-file-jpg',
|
|
];
|
|
|
|
public static function find($data)
|
|
{
|
|
|
|
}
|
|
|
|
public static function create(array $data)
|
|
{
|
|
$model = new TimerecordingCarDocuments();
|
|
|
|
foreach ($data as $field => $value) {
|
|
if (property_exists(get_called_class(), $field)) {
|
|
if (substr($field, 0, 5) == "vlan_" && !$value) {
|
|
$model->$field = null;
|
|
continue;
|
|
}
|
|
$model->$field = $value;
|
|
}
|
|
}
|
|
|
|
$me = mfValuecache::singleton()->get("me");
|
|
if (!$me) {
|
|
$me = new User();
|
|
$me->loadMe();
|
|
mfValuecache::singleton()->set("me", $me);
|
|
}
|
|
|
|
if ($model->create_by === null) {
|
|
$model->create_by = $me->id;
|
|
}
|
|
if ($model->edit_by === null) {
|
|
$model->edit_by = $me->id;
|
|
}
|
|
|
|
return $model;
|
|
}
|
|
|
|
public static function getOne($id)
|
|
{
|
|
if (!is_numeric($id) || !$id) {
|
|
throw new Exception("Invalid number", 400);
|
|
}
|
|
$item = [];
|
|
$db = FronkDB::singleton();
|
|
|
|
$res = $db->select("TimerecordingCarDocuments", "*", "id=$id LIMIT 1");
|
|
if ($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new TimerecordingCarDocuments($data);
|
|
}
|
|
return $item;
|
|
}
|
|
|
|
public static function getAll()
|
|
{
|
|
$items = [];
|
|
|
|
$db = FronkDB::singleton();
|
|
|
|
$res = $db->select("TimerecordingCarDocuments", "*", "1=1");
|
|
if ($db->num_rows($res)) {
|
|
while ($data = $db->fetch_object($res)) {
|
|
$items[] = new TimerecordingCarDocuments($data);
|
|
}
|
|
}
|
|
return $items;
|
|
|
|
}
|
|
|
|
public static function getFirst()
|
|
{
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$res = $db->select("TimerecordingCarDocuments", "*", "$where ");
|
|
if ($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new TimerecordingCarDocuments($data);
|
|
if ($item->id) {
|
|
return $item;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static function search($filter)
|
|
{
|
|
$items = [];
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$res = $db->select("TimerecordingCarDocuments", "*", "$where");
|
|
if ($db->num_rows($res)) {
|
|
while ($data = $db->fetch_object($res)) {
|
|
$items[] = new TimerecordingCarDocuments($data);
|
|
}
|
|
}
|
|
return $items;
|
|
}
|
|
|
|
private static function getSqlFilter($filter)
|
|
{
|
|
$where = "1=1 ";
|
|
|
|
//var_dump($filter);exit;
|
|
if (array_key_exists("file_name", $filter)) {
|
|
$file_name = $filter['file_name'];
|
|
$where .= " AND file_name=$file_name";
|
|
}
|
|
|
|
if (array_key_exists("timerecordingCar_id", $filter)) {
|
|
$timerecordingCar_id = $filter['timerecordingCar_id'];
|
|
$where .= " AND timerecordingCar_id=$timerecordingCar_id";
|
|
}
|
|
|
|
//var_dump($filter, $where);exit;
|
|
return $where;
|
|
}
|
|
|
|
}
|