180 lines
5.2 KiB
PHP
180 lines
5.2 KiB
PHP
<?php
|
|
|
|
class ConstructionConsentFile extends mfBaseModel {
|
|
private $file;
|
|
private $creator;
|
|
private $editor;
|
|
|
|
|
|
public function getProperty($name) {
|
|
if($this->$name == null) {
|
|
|
|
if($name == "creator") {
|
|
$user = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
|
if($user) {
|
|
$this->creator = $user;
|
|
return $this->creator;
|
|
}
|
|
$this->creator = new User($this->create_by);
|
|
if($this->creator->id) {
|
|
mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator);
|
|
}
|
|
return $this->creator;
|
|
}
|
|
|
|
if($name == "editor") {
|
|
$this->editor = new User($this->edit_by);
|
|
return $this->editor;
|
|
}
|
|
|
|
$classname = ucfirst($name);
|
|
$idfield = $name."_id";
|
|
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
|
|
if(!$this->$name) {
|
|
$this->$name = new $classname($this->$idfield);
|
|
}
|
|
|
|
if($this->$name->id) {
|
|
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
|
|
return $this->$name;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
return $this->$name;
|
|
}
|
|
|
|
/********************************
|
|
* Begin static Model functions
|
|
*/
|
|
|
|
public static function create(Array $data) {
|
|
$model = new ConstructionConsentFile();
|
|
|
|
$table_fields = [
|
|
"constructionconsent_id", "file_id", "filename",
|
|
"create_by","edit_by","create","edit"
|
|
];
|
|
|
|
foreach($data as $field => $value) {
|
|
if(in_array($field, $table_fields)) {
|
|
$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("ConstructionConsentFile", "*", "1 = 1 ORDER BY file_id");
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new ConstructionConsentFile($data);
|
|
}
|
|
}
|
|
return $items;
|
|
|
|
}
|
|
|
|
public static function getFirst($filter = []) {
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$res = $db->select("ConstructionConsentFile", "*", "$where ORDER BY file_id LIMIT 1");
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new ConstructionConsentFile($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 `ConstructionConsentFile`
|
|
WHERE $where
|
|
";
|
|
|
|
mfLoghandler::singleton()->debug($sql);
|
|
$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 ConstructionConsentFile.* FROM `ConstructionConsentFile`
|
|
WHERE $where
|
|
ORDER BY file_id
|
|
";
|
|
|
|
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($limit['count'])) {
|
|
$sql .= " LIMIT ".$limit['count'];
|
|
}
|
|
}
|
|
|
|
$res = $db->query($sql);
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new ConstructionConsentFile($data);
|
|
}
|
|
}
|
|
return $items;
|
|
}
|
|
|
|
private static function getSqlFilter($filter) {
|
|
$where = "1=1 ";
|
|
|
|
$db = FronkDB::singleton();
|
|
|
|
//var_dump($filter);exit;
|
|
if(array_key_exists("constructionconsent_id", $filter)) {
|
|
$constructionconsent_id = $filter['constructionconsent_id'];
|
|
if(is_numeric($constructionconsent_id)) {
|
|
$where .= " AND ConstructionConsentFile.`constructionconsent_id` = $constructionconsent_id";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("file_id", $filter)) {
|
|
$file_id = $filter['file_id'];
|
|
if(is_numeric($file_id)) {
|
|
$where .= " AND ConstructionConsentFile.`file_id` = $file_id";
|
|
}
|
|
}
|
|
|
|
//var_dump($filter, $where);exit;
|
|
return $where;
|
|
}
|
|
} |