160 lines
3.7 KiB
PHP
160 lines
3.7 KiB
PHP
<?php
|
|
|
|
class RimoWorkorderModel {
|
|
public $rimo_id;
|
|
public $rimo_name;
|
|
public $adb_wohneinheit_id;
|
|
public $termination_id;
|
|
public $rimo_team_id;
|
|
public $rimo_team_name;
|
|
public $create_data;
|
|
|
|
public $create_by;
|
|
public $edit_by;
|
|
public $create;
|
|
public $edit;
|
|
|
|
|
|
public static function create(Array $data) {
|
|
$model = new RimoWorkorder();
|
|
|
|
foreach($data as $field => $value) {
|
|
if(property_exists(get_called_class(), $field)) {
|
|
$model->$field = $value;
|
|
}
|
|
}
|
|
|
|
$me = new User();
|
|
$me->loadMe();
|
|
|
|
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 getAll() {
|
|
$items = [];
|
|
|
|
$db = FronkDB::singleton();
|
|
|
|
$res = $db->select("RimoWorkorder", "*", "1=1 ORDER BY `create`");
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new RimoWorkorder($data);
|
|
}
|
|
}
|
|
return $items;
|
|
|
|
}
|
|
|
|
public static function getFirst($filter = null) {
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
//mfLoghandler::singleton()->debug($where);
|
|
$res = $db->select("RimoWorkorder", "*", "$where ORDER BY `create`");
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new RimoWorkorder($data);
|
|
if($item->id) {
|
|
return $item;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
public static function count($filter) {
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT COUNT(*) as cnt FROM RimoWorkorder
|
|
WHERE $where
|
|
";
|
|
|
|
$res = $db->query($sql);
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
return $data->cnt;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public static function search($filter, $limit = false) {
|
|
$items = [];
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT * FROM RimoWorkorder
|
|
WHERE $where
|
|
ORDER BY `create`";
|
|
|
|
if(is_array($limit) && count($limit)) {
|
|
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
|
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
|
} elseif(is_numeric($count)) {
|
|
$sql .= " LIMIT ".$limit['count'];
|
|
}
|
|
}
|
|
|
|
$res = $db->query($sql);
|
|
|
|
//mfLoghandler::singleton()->debug($sql);
|
|
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new RimoWorkorder($data);
|
|
}
|
|
}
|
|
return $items;
|
|
}
|
|
|
|
private static function getSqlFilter($filter) {
|
|
$db = FronkDB::singleton();
|
|
$where = "1=1 ";
|
|
|
|
if(!is_array($filter)) {
|
|
return $where;
|
|
}
|
|
|
|
|
|
if(array_key_exists("adb_wohneinheit_id", $filter)) {
|
|
$adb_wohneinheit_id = $filter['adb_wohneinheit_id'];
|
|
if(is_numeric($adb_wohneinheit_id)) {
|
|
$where .= " AND adb_wohneinheit_id = $adb_wohneinheit_id";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("termination_id", $filter)) {
|
|
$termination_id = $filter['termination_id'];
|
|
if(is_numeric($termination_id)) {
|
|
$where .= " AND termination_id = $termination_id";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("rimo_id", $filter)) {
|
|
$rimo_id = $db->escape($filter['rimo_id']);
|
|
if($rimo_id) {
|
|
$where .= " AND rimo_id LIKE '$rimo_id'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("rimo_name", $filter)) {
|
|
$rimo_name = $db->escape($filter['rimo_name']);
|
|
if($rimo_name) {
|
|
$where .= " AND rimo_name LIKE '$rimo_name'";
|
|
}
|
|
}
|
|
|
|
//var_dump($filter, $where);exit;
|
|
return $where;
|
|
}
|
|
|
|
} |