128 lines
2.9 KiB
PHP
128 lines
2.9 KiB
PHP
<?php
|
|
|
|
class ContractjournalModel {
|
|
public $contract_id;
|
|
public $type;
|
|
public $value;
|
|
public $text;
|
|
|
|
public $create_by = null;
|
|
public $edit_by = null;
|
|
public $create = null;
|
|
public $edit = null;
|
|
|
|
|
|
public static function create(Array $data) {
|
|
$model = new Contractjournal();
|
|
|
|
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("Contractjournal", "*", "1=1 ORDER BY contract_id,`create`");
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new Contractjournal($data);
|
|
}
|
|
}
|
|
return $items;
|
|
|
|
}
|
|
|
|
public static function getFirst($filter = false) {
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$res = $db->select("Contractjournal", "*", "$where ORDER BY contract_id,`create`");
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new Contractjournal($data);
|
|
if($item->id) {
|
|
return $item;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static function search($filter) {
|
|
$items = [];
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
/*
|
|
$sql = "SELECT Contractjournal.* FROM Contractjournal
|
|
LEFT JOIN File ON (Contractjournal.file_id = File.id)
|
|
WHERE $where
|
|
ORDER BY order_id, name";
|
|
|
|
$res = $db->query($sql);
|
|
*/
|
|
$res = $db->select("Contractjournal", "*", $where);
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new Contractjournal($data);
|
|
}
|
|
}
|
|
return $items;
|
|
}
|
|
|
|
private static function getSqlFilter($filter) {
|
|
$where = "1=1 ";
|
|
|
|
|
|
if(array_key_exists("contract_id", $filter)) {
|
|
$contract_id = $filter['contract_id'];
|
|
if(is_numeric($contract_id)) {
|
|
$where .= " AND contract_id=$contract_id";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("order_id", $filter)) {
|
|
$order_id = $filter['order_id'];
|
|
if(is_numeric($order_id)) {
|
|
$where .= " AND order_id=$order_id";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("type", $filter)) {
|
|
$type = FronkDB::singleton()->escape($filter['type']);
|
|
if($type) {
|
|
$where .= " AND type='$type'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("value", $filter)) {
|
|
$value = FronkDB::singleton()->escape($filter['value']);
|
|
if($value) {
|
|
$where .= " AND value='$value'";
|
|
}
|
|
}
|
|
|
|
|
|
//var_dump($filter, $where);exit;
|
|
return $where;
|
|
}
|
|
|
|
} |