Added Mailtemplate

This commit is contained in:
Frank Schubert
2024-08-29 23:22:49 +02:00
parent 42d2541f6a
commit ebd5d6182a
9 changed files with 527 additions and 41 deletions

View File

@@ -0,0 +1,140 @@
<?php
class MailtemplateFileModel {
public $mailtemplate_id;
public $file_id;
public $filename;
public $note = null;
public $create_by = null;
public $edit_by = null;
public $create = null;
public $edit = null;
public static function create(Array $data) {
$model = new MailtemplateFile();
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("MailtemplateFile", "*", "1 = 1 ORDER BY filename");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new MailtemplateFile($data);
}
}
return $items;
}
public static function getFirst($filter = []) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("MailtemplateFile", "*", "$where ORDER BY filename LIMIT 1");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new MailtemplateFile($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 `MailtemplateFile`
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 MailtemplateFile.* FROM `MailtemplateFile`
WHERE $where
ORDER BY filename
";
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 MailtemplateFile($data);
}
}
return $items;
}
private static function getSqlFilter($filter) {
$where = "1=1 ";
$db = FronkDB::singleton();
//var_dump($filter);exit;
if(array_key_exists("mailtemplate_id", $filter)) {
$mailtemplate_id = $filter['mailtemplate_id'];
if(is_numeric($mailtemplate_id)) {
$where .= " AND MailtemplateFile.`mailtemplate_id` = $mailtemplate_id";
}
}
if(array_key_exists("file_id", $filter)) {
$file_id = $filter['file_id'];
if(is_numeric($file_id)) {
$where .= " AND MailtemplateFile.`file_id` = $file_id";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}