221 lines
5.5 KiB
PHP
221 lines
5.5 KiB
PHP
<?php
|
|
|
|
class OpenAccessIdModel {
|
|
public $oaid;
|
|
public $active;
|
|
public $origin;
|
|
public $origin_id;
|
|
public $owner_id;
|
|
public $assigned;
|
|
public $adb_wohneinheit_id;
|
|
public $termination_id;
|
|
public $exported;
|
|
public $exported_to;
|
|
public $export_data;
|
|
public $address;
|
|
public $unit_string;
|
|
|
|
public $create_by;
|
|
public $edit_by;
|
|
public $create;
|
|
public $edit;
|
|
|
|
|
|
public static function create(Array $data) {
|
|
$model = new OpenAccessId();
|
|
|
|
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("OpenAccessId", "*", "1=1 ORDER BY id");
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new OpenAccessId($data);
|
|
}
|
|
}
|
|
return $items;
|
|
|
|
}
|
|
|
|
public static function getFirst($filter = null) {
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
mfLoghandler::singleton()->debug($where);
|
|
$res = $db->select("OpenAccessId", "*", "$where ORDER BY id");
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new OpenAccessId($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 OpenAccessId
|
|
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 OpenAccessId
|
|
WHERE $where
|
|
ORDER BY id";
|
|
|
|
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 OpenAccessId($data);
|
|
}
|
|
}
|
|
return $items;
|
|
}
|
|
|
|
private static function getSqlFilter($filter) {
|
|
$db = FronkDB::singleton();
|
|
$where = "1=1 ";
|
|
|
|
if(!is_array($filter)) {
|
|
return $where;
|
|
}
|
|
|
|
if(array_key_exists("owner_id", $filter)) {
|
|
$owner_id = $filter['owner_id'];
|
|
if(is_numeric($owner_id)) {
|
|
$where .= " AND owner_id = $owner_id";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("assigned", $filter)) {
|
|
$assigned = $filter['assigned'];
|
|
if(is_numeric($assigned)) {
|
|
$where .= " AND assigned = $assigned";
|
|
} elseif($assigned === true) {
|
|
$where .= " AND assigned > 0";
|
|
} elseif($assigned === false || $assigned === null) {
|
|
$where .= " AND (assigned = 0 OR assigned IS NULL)";
|
|
}
|
|
}
|
|
|
|
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("exported", $filter)) {
|
|
$exported = $filter['exported'];
|
|
if(is_numeric($exported)) {
|
|
$where .= " AND exported = $exported";
|
|
} elseif($exported === true) {
|
|
$where .= " AND exported > 0";
|
|
} elseif($exported === false || $exported === null) {
|
|
$where .= " AND (exported = 0 OR exported IS NULL)";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("exported_to", $filter)) {
|
|
$exported_to = $db->escape($filter['exported_to']);
|
|
if($exported_to) {
|
|
$where .= " AND exported_to = '$exported_to'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("oaid", $filter)) {
|
|
$oaid = $db->escape($filter['oaid']);
|
|
if($oaid) {
|
|
$where .= " AND oaid LIKE '$oaid'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("origin", $filter)) {
|
|
$origin = $db->escape($filter['origin']);
|
|
if($origin) {
|
|
$where .= " AND origin = '$origin'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("origin_id", $filter)) {
|
|
$origin_id = $db->escape($filter['origin_id']);
|
|
if($origin_id) {
|
|
$where .= " AND origin_id LIKE '$origin_id'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("address", $filter)) {
|
|
$address = $db->escape($filter['address']);
|
|
if($address) {
|
|
$where .= " AND address LIKE '$address'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("unit_string", $filter)) {
|
|
$unit_string = $db->escape($filter['unit_string']);
|
|
if($unit_string) {
|
|
$where .= " AND unit_string LIKE '$unit_string'";
|
|
}
|
|
}
|
|
|
|
//var_dump($filter, $where);exit;
|
|
return $where;
|
|
}
|
|
|
|
} |