Finished MaintenanceNotification

This commit is contained in:
Frank Schubert
2024-11-13 18:15:24 +01:00
parent 97dc4446dc
commit 47f71f2310
8 changed files with 465 additions and 14 deletions

View File

@@ -0,0 +1,202 @@
<?php
class MaintenanceNotificationLog extends mfBaseModel {
public function getProperty($name) {
if($this->$name == null) {
if($name == "adb_hausnummer") {
if(!$this->adb_hausnummer_id) return null;
$hausnummer = new ADBHausnummer($this->adb_hausnummer_id);
if($hausnummer->id) {
$this->adb_hausnummer = $hausnummer;
}
return $this->adb_hausnummer;
}
if($name == "adb_strasse") {
if(!$this->adb_strasse_id) return null;
$strasse = new ADBStrasse($this->adb_strasse_id);
if($strasse->id) {
$this->adb_strasse = $strasse;
}
return $this->adb_strasse;
}
$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 MaintenanceNotificationLog();
$table_fields = [
"maintenancenotification_id", "email", "sent",
"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("MaintenanceNotificationLog", "*", "1 = 1 ORDER BY email");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new MaintenanceNotificationLog($data);
}
}
return $items;
}
public static function getFirst($filter) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM MaintenanceNotificationLog
WHERE $where
ORDER BY email LIMIT 1";
//var_dump($sql);exit;
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new MaintenanceNotificationLog($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 MaintenanceNotificationLog
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, $order = false) {
//var_dump($filter);exit;
$items = [];
if(!$order) {
$order = "adb_hausnummer_id ASC";
}
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM MaintenanceNotificationLog
WHERE $where
ORDER BY $order";
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'];
}
}
mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[$data->id] = new MaintenanceNotificationLog($data);
}
}
return $items;
}
private static function getSqlFilter($filter) {
$where = "1=1 ";
if(array_key_exists("maintenancenotification_id", $filter)) {
$maintenancenotification_id = $filter['maintenancenotification_id'];
if(is_numeric($maintenancenotification_id)) {
$where .= " AND MaintenanceNotificationLog.maintenancenotification_id=$maintenancenotification_id";
}
}
if(array_key_exists("email", $filter)) {
$email = FronkDB::singleton()->escape($filter["email"]);
if($email) {
$where .= " AND email='$email'";
}
}
if(array_key_exists("sent", $filter)) {
$sent = $filter['sent'];
if($sent === true) {
$where .= " AND `sent` > 0";
} elseif($sent === false || $sent === null) {
$where .= " AND (`sent` IS NULL OR `sent` = 0)";
} elseif(is_numeric($sent)) {
$where .= " AND `sent`=$sent";
}
}
if(array_key_exists("add-where", $filter)) {
$where .= " ".$filter['add-where'];
}
//var_dump($filter, $where);exit;
return $where;
}
}