133 lines
3.3 KiB
PHP
133 lines
3.3 KiB
PHP
<?php
|
|
|
|
class ContractconfigValueModel {
|
|
public $contract_id;
|
|
public $item_id;
|
|
public $string;
|
|
public $int;
|
|
public $text;
|
|
|
|
public $create_by = null;
|
|
public $edit_by = null;
|
|
public $create = null;
|
|
public $edit = null;
|
|
|
|
|
|
public static function create(Array $data) {
|
|
$model = new ContractconfigValue();
|
|
|
|
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("ContractconfigValue", "*", "1=1");
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new ContractconfigValue($data);
|
|
}
|
|
}
|
|
return $items;
|
|
|
|
}
|
|
|
|
public static function getFirst($filter) {
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$res = $db->select("ContractconfigValue", "*", "$where ORDER BY item_id, contract_id LIMIT 1");
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new ContractconfigValue($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("ContractconfigValue", "*", "$where ORDER BY item_id, contract_id");
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new ContractconfigValue($data);
|
|
}
|
|
}
|
|
return $items;
|
|
}
|
|
|
|
private static function getSqlFilter($filter) {
|
|
$where = "1=1 ";
|
|
|
|
//var_dump($filter);exit;
|
|
if(array_key_exists("contract_id", $filter)) {
|
|
$contract_id = $filter['contract_id'];
|
|
if(is_numeric($contract_id)) {
|
|
$where .= " AND contract_id=$contract_id";
|
|
} elseif(is_array($contract_id) && count($contract_id)) {
|
|
$where .= " AND contract_id IN (". implode(",", $contract_id).")";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("item_id", $filter)) {
|
|
$item_id = $filter['item_id'];
|
|
if(is_numeric($item_id)) {
|
|
$where .= " AND item_id=$item_id";
|
|
} elseif(is_array($item_id) && count($item_id)) {
|
|
$where .= " AND item_id IN (". implode(",", $item_id).")";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("int", $filter)) {
|
|
$int = $filter['int'];
|
|
if(is_numeric($int)) {
|
|
$where .= " AND int=$int";
|
|
} elseif(is_array($int) && count($int)) {
|
|
$where .= " AND `int` IN (". implode(",", $int).")";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("string", $filter)) {
|
|
$string = FronkDB::singleton()->escape($filter['string']);
|
|
if($string) {
|
|
$where .= " AND `string`='$string'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("text", $filter)) {
|
|
$text = FronkDB::singleton()->escape($filter['text']);
|
|
if($text) {
|
|
$where .= " AND `text`='$text'";
|
|
}
|
|
}
|
|
|
|
//var_dump($filter, $where);exit;
|
|
return $where;
|
|
}
|
|
|
|
} |