Patching readonly

This commit is contained in:
Frank Schubert
2021-09-21 23:12:53 +02:00
parent 1d162fedb7
commit 3cc3f3f50c
8 changed files with 428 additions and 4 deletions

View File

@@ -0,0 +1,164 @@
<?php
class PatchingModel {
public $termination_id = null;
public $linework_port = null;
public $device_type = null;
public $device_name = null;
public $device_ports = null;
public $patched = null;
public $create_by = null;
public $edit_by = null;
public $create = null;
public $edit = null;
public static function create(Array $data) {
$model = new Patching();
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 getOne($id) {
if(!is_numeric($id) || !$id) {
throw new Exception("Invalid number", 400);
}
$item = [];
$db = FronkDB::singleton();
$res = $db->select("Patching", "*", "id=$id LIMIT 1");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new Patching($data);
}
return $item;
}
public static function getAll() {
$items = [];
$db = FronkDB::singleton();
$res = $db->select("Patching", "*");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new Patching($data);
}
}
return $items;
}
public static function getFirst() {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("Patching", "*", "$where ORDER BY termination_id");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new Patching($data);
if($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function searchByTermination($filter = false) {
$items = [];
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT Termination.id as termination_id FROM `Order`
LEFT JOIN OrderProduct ON (OrderProduct.order_id = `Order`.id)
LEFT JOIN Product ON (Product.id = OrderProduct.product_id)
LEFT JOIN Termination ON (Termination.id = OrderProduct.termination_id)
LEFT JOIN Building ON (Building.id = Termination.building_id)
LEFT JOIN Terminationstatus ON (Terminationstatus.id = Termination.status_id)
LEFT JOIN Buildingstatus ON (Buildingstatus.id = Building.status_id)
LEFT JOIN Patching ON (Patching.Termination_id = OrderProduct.termination_id)
LEFT JOIN Workflowitem ON (Workflowitem.object_type = 'Termination')
LEFT JOIN Workflowvalue ON (Workflowvalue.item_id = Workflowitem.id)
WHERE Workflowitem.name = 'customer_passive_finished'
AND Workflowvalue.object_id = OrderProduct.termination_id
AND Workflowvalue.value_int = 1
AND (Patching.termination_id IS NULL OR Patching.patched = 0)
GROUP BY Termination.id
ORDER BY Termination.id ASC";
//mfLoghandler::singleton()->debug($sql);
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);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new Termination($data->termination_id);
}
}
return $items;
}
public static function search($filter = false) {
$items = [];
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("Patching", "*", "$where ORDER BY termination_id");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new Patching($data);
}
}
return $items;
}
private function getSqlFilter($filter = []) {
$where = "1=1 ";
if(!is_array($filter) || !count($filter)) {
return $where;
}
//var_dump($filter);exit;
if(array_key_exists("termination_id", $filter)) {
$termination_id = $filter['termination_id'];
if(is_numeric($termination_id)) {
$where .= " AND termination_id=$termination_id";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}