Merge branch 'fronkdev' into 'master'
Added timestamps to AddressDB export See merge request fronk/thetool!607
This commit is contained in:
@@ -17,7 +17,7 @@ foreach(ADBStatusflagModel::getAll() as $sflag) {
|
||||
}
|
||||
|
||||
?>
|
||||
AddressDB_ID;Extref;Adrcd;OAID;Status Code;Status Name;"<?=implode('";"', $status_flags_header)?>";Netzgebiet_Extref;Netzgebiet;Rimo Building External ID;GKZ;Gemeinde;OKZ;Ortschaft;PLZ;SKZ;Strasse;Hausnummer;Grundstueck;GPS Breite;GPS Laenge;Rollout;Rollout_Info;Freigabe;Nutzungseinheiten;GDA-Eigenschaft;Meridian;RW;HW;Sichtbarkeit
|
||||
AddressDB_ID;Extref;Adrcd;OAID;Status Code;Status Name;"<?=implode('";"', $status_flags_header)?>";Netzgebiet_Extref;Netzgebiet;Rimo Building External ID;GKZ;Gemeinde;OKZ;Ortschaft;PLZ;SKZ;Strasse;Hausnummer;Grundstueck;GPS Breite;GPS Laenge;Rollout;Rollout_Info;Freigabe;Nutzungseinheiten;GDA-Eigenschaft;Meridian;RW;HW;Sichtbarkeit;Erstellt;Letzte Bearbeitung
|
||||
<?php
|
||||
$line = 0;
|
||||
|
||||
@@ -43,8 +43,7 @@ while($data = mysqli_fetch_object($res)):
|
||||
}
|
||||
|
||||
?>
|
||||
<?=$data->id?>;"<?=$data->extref?>";<?=$data->adrcd?>;"<?=$data->oaid?>";"<?=$status->code?>";"<?=$status->name?>";<?=implode(";", $statusflags)?>;"<?=$netzgebiet->extref?>";"<?=$netzgebiet->name?>";"<?=$data->rimo_id?>";<?=$gemeinde->kennziffer?>;"<?=$gemeinde->name?>";<?=$ortschaft->kennziffer?>;"<?=$ortschaft->name?>";"<?=$plz->plz?>";<?=$strasse->kennziffer?>;"<?=$strasse->name?>";"<?=$data->hausnummer?>";"<?=$data->grund_nr?>";<?=$data->gps_lat?>;<?=$data->gps_long?>;<?=$data->rollout?>;"<?=$data->rollout_info?>";"<?=$freigabe?>";<?=$unit_count?>;"<?=$data->gdaeigenschaft?>";"<?=$data->meridian?>";<?=$data->rw?>;<?=$data->hw?>;<?=$data->visibility?>
|
||||
|
||||
<?=$data->id?>;"<?=$data->extref?>";<?=$data->adrcd?>;"<?=$data->oaid?>";"<?=$status->code?>";"<?=$status->name?>";<?=implode(";", $statusflags)?>;"<?=$netzgebiet->extref?>";"<?=$netzgebiet->name?>";"<?=$data->rimo_id?>";<?=$gemeinde->kennziffer?>;"<?=$gemeinde->name?>";<?=$ortschaft->kennziffer?>;"<?=$ortschaft->name?>";"<?=$plz->plz?>";<?=$strasse->kennziffer?>;"<?=$strasse->name?>";"<?=$data->hausnummer?>";"<?=$data->grund_nr?>";<?=$data->gps_lat?>;<?=$data->gps_long?>;<?=$data->rollout?>;"<?=$data->rollout_info?>";"<?=$freigabe?>";<?=$unit_count?>;"<?=$data->gdaeigenschaft?>";"<?=$data->meridian?>";<?=$data->rw?>;<?=$data->hw?>;<?=$data->visibility?>;"<?=date("Y-m-d H:i:s",$hausnummer->create)?>";"<?=date("Y-m-d H:i:s",$hausnummer->edit)?>"
|
||||
<?php
|
||||
$i++;
|
||||
if($line % 1000 === 0) {
|
||||
|
||||
179
Layout/default/Mailtemplate/Form.php
Normal file
179
Layout/default/Mailtemplate/Form.php
Normal file
@@ -0,0 +1,179 @@
|
||||
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/header.php"); ?>
|
||||
|
||||
<!-- start page title -->
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="page-title-box">
|
||||
<div class="page-title-right">
|
||||
<ol class="breadcrumb m-0">
|
||||
<li class="breadcrumb-item"><a href="<?=self::getUrl("Dashboard")?>"><?=MFAPPNAME_SLUG?></a></li>
|
||||
<li class="breadcrumb-item"><a href="<?=self::getUrl("Mailtemplate")?>">Emailtemplates</a></li>
|
||||
<li class="breadcrumb-item active"><?=($template->id) ? "bearbeiten" : "Neu" ?></li>
|
||||
</ol>
|
||||
</div>
|
||||
<h4 class="page-title"><?=($template->id) ? "Emailtemplate bearbeiten" : "Neues Emailtemplate" ?></h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end page title -->
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
|
||||
<div class="card bg-light">
|
||||
<div class="card-body">
|
||||
|
||||
<form class="form-horizontal" method="post" action="<?=self::getUrl("Mailtemplate", "save")?>" enctype="multipart/form-data">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
|
||||
<input type="hidden" name="id" value="<?=$template->id?>" />
|
||||
|
||||
<div class="form-group row col-12">
|
||||
<label class="form-label" for="name">Template Name:</label>
|
||||
<input type="text" class="form-control" name="name" id="name" value="<?=$template->name?>" placeholder="Template Name" style="border-radius:0;" />
|
||||
</div>
|
||||
|
||||
<h4 class="mt-4">Emailtemplate</h4>
|
||||
|
||||
|
||||
<div class="form-group row mt-3 col-12">
|
||||
<label class="form-label" for="subject">Betreff:</label>
|
||||
<input type="text" class="form-control" name="subject" id="subject" value="<?=$template->subject?>" placeholder="Betreff" style="border-radius:0;" />
|
||||
</div>
|
||||
<textarea id="body_html" name="body_html" placeholder="Bitte geben Sie hier den Emailinhalt ein..." rows="12" style="width: 100%; height: 600px; padding: 10px;"><?= htmlentities($template->body)?></textarea>
|
||||
|
||||
|
||||
<h4 class="mt-4">Dateianhänge</h4>
|
||||
<div class="form-group row mb-3">
|
||||
<div class="col-xl-5 input-grop">
|
||||
<div class="custom-file">
|
||||
<input type="file" name="attachment[]" id="attachment" class="custom-file-input" multiple="multiple" />
|
||||
<label class="custom-file-label" for="attachment"> Datei(en) auswählen</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if(is_array($template->files) && count($template->files)): ?>
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<div class="card" style="">
|
||||
<ul class="list-group list-group-flush">
|
||||
<?php foreach($template->files as $file): ?>
|
||||
<li id="file-<?=$file->id?>" class="list-group-item"><input type="hidden" name="deletefile[<?=$file->id?>]" id="deletefile-<?=$file->id?>" value="" /><a href="#" onclick="deleteFile(<?=$file->id?>)" class="mr-2"><i class="far fa-trash text-danger"></i></a> <span class="filename"><i class="far fa-file"></i> <?=$file->filename?></span></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="note">Interne Notiz</label>
|
||||
<div class="col-lg-10">
|
||||
<textarea id="note" class="form-control" name="note" rows="5"><?=$template->note?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2"></label>
|
||||
<div class="col-lg-10">
|
||||
<button type="submit" name="return" value="form" class="btn btn-primary mr-1">Speichern</button>
|
||||
<button type="submit" name="return" value="index" class="btn btn-primary">Speichern und zur Übersicht</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript" src="<?=self::getResourcePath()?>plugins/tinymce/tinymce.min.js"></script>
|
||||
<script type="text/javascript" src="<?=self::getResourcePath()?>plugins/bs-custom-file-input/bs-custom-file-input.min.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var menu_vars = [
|
||||
['vorname', "Vorname"],
|
||||
['nachname', "Nachname"],
|
||||
['firma', "Firma"],
|
||||
['firma_oder_name', "Firma oder Name"],
|
||||
['email', "Emailadresse"],
|
||||
['anschluss_oaid', "Anschluss OAID"],
|
||||
['anschluss_strasse', "Anschluss Straße"],
|
||||
['anschluss_hausnummer', "Anschluss Hausnummer"],
|
||||
['anschluss_plz', "Anschluss PLZ"],
|
||||
['anschluss_ort', "Anschluss Ort"],
|
||||
['anschluss_gemeinde', "Anschluss Gemeinde"],
|
||||
['preorder_code', "Bestellcode"],
|
||||
];
|
||||
|
||||
var menu_vars_items = "";
|
||||
menu_vars.forEach((item) => { menu_vars_items += " " + item[0]});
|
||||
menu_vars_items = menu_vars_items.trim();
|
||||
console.log(menu_vars_items);
|
||||
|
||||
$(function () {
|
||||
tinymce.init({
|
||||
//font_formats: "Arial=arial,sans-serif;",
|
||||
selector: '#body_html',
|
||||
language: 'de',
|
||||
skin: "tinymce-5",
|
||||
plugins: ' code link autolink lists table',
|
||||
paste_block_drop: true,
|
||||
paste_as_text: true,
|
||||
paste_data_images: false,
|
||||
promotion: false,
|
||||
toolbar1: 'undo redo | styles | bold italic underline strikethrough | fontfamily fontsize fontcolor | alignleft aligncenter alignright alignjustify | bullist numlist | outdent indent | table | link unlink | code',
|
||||
toolbar2: 'vorname nachname firma',
|
||||
content_css: "<?=self::getResourcePath()?>/assets/css/tinymce.css",
|
||||
font_family_formats: "Arial=arial,sans-serif; Courier New=courier new,courier,monospace; Georgia=georgia,palatino,serif; Helvetica=helvetica,sans-serif; Lucida Sans=lucida sans unicode,sans-serif; Tahoma=tahoma,arial,helvetica,sans-serif; Times New Roman=times new roman,times,serif",
|
||||
menubar: 'file edit view insert format tools table variables',
|
||||
menu: {
|
||||
variables: { title: 'Textbausteine', items: menu_vars_items }
|
||||
},
|
||||
setup: function (editor) {
|
||||
menu_vars.forEach(function(item) {
|
||||
editor.ui.registry.addMenuItem(item[0], {
|
||||
text: item[1],
|
||||
onAction: function () {
|
||||
editor.insertContent('{{' + item[0].toUpperCase() + '}}');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
bsCustomFileInput.init();
|
||||
|
||||
});
|
||||
|
||||
function deleteFile(id) {
|
||||
event.preventDefault();
|
||||
console.log($("#deletefile-" + id).val());
|
||||
if(!$("#deletefile-" + id).val()) {
|
||||
$('#file-' + id + " .filename").css("text-decoration", "line-through");
|
||||
$('#file-' + id + " .filename").css("color", "red");
|
||||
$("#deletefile-" + id).val("1");
|
||||
} else {
|
||||
$('#file-' + id + " .filename").removeAttr("style");
|
||||
$("#deletefile-" + id).val("");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>
|
||||
89
Layout/default/Mailtemplate/Index.php
Normal file
89
Layout/default/Mailtemplate/Index.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/header.php"); ?>
|
||||
|
||||
<!-- start page title -->
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="page-title-box">
|
||||
<div class="page-title-right">
|
||||
<ol class="breadcrumb m-0">
|
||||
<li class="breadcrumb-item"><a href="<?=self::getUrl("Dashboard")?>"><?=MFAPPNAME_SLUG?></a></li>
|
||||
<li class="breadcrumb-item active">Emailtemplates</li>
|
||||
</ol>
|
||||
</div>
|
||||
<h4 class="page-title">Emailtemplates</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end page title -->
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body mb-3">
|
||||
<h4 class="header-title mb-3">Filter</h4>
|
||||
|
||||
<form method="get" action="<?=self::getUrl("Mailtemplate")?>">
|
||||
<div class="row">
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_name">Name</label>
|
||||
<input type="text" class="form-control" name="filter[name]" id="filter_name" value="<?=$filter['name']?>" />
|
||||
</div>
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_subject">Betreff</label>
|
||||
<input type="text" class="form-control" name="filter[subject]" id="filter_betreff" value="<?=$filter['subject']?>" />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="row mt-2">
|
||||
<div class="col">
|
||||
<button type="submit" class="btn btn-primary">Filter anwenden</button>
|
||||
<a class="btn btn-secondary" href="<?=self::getUrl("Mailtemplate")?>">Filter zurücksetzen</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body mb-3">
|
||||
<div class="float-left">
|
||||
<h4 class="header-title">Liste aller Emailtemplates</h4>
|
||||
</div>
|
||||
<div class="float-right">
|
||||
<a class="btn btn-primary mb-2" href="<?=self::getUrl("Mailtemplate", "add")?>"><i class="fas fa-plus"></i> Neues Emailtemplate erstellen</a>
|
||||
</div>
|
||||
|
||||
<table class="table table-striped table-hover">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Betreff</th>
|
||||
<th>Erstellt</th>
|
||||
<th>Bearbeitet</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
<?php foreach($templates as $template): ?>
|
||||
<tr>
|
||||
<td><?=$template->name?></td>
|
||||
<td><?=$template->subject?></td>
|
||||
<td><?=date("d.m.Y H:i",$template->edit)?> (<?=$template->editor->name?>)</td>
|
||||
<td><?=date("d.m.Y H:i",$template->create)?> (<?=$template->creator->name?>)</td>
|
||||
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
|
||||
<a href="<?=self::getUrl("Mailtemplate", "edit", ["id" => $template->id])?>"><i class="far fa-edit" title="Emailtemplate bearbeiten"></i></a>
|
||||
<a href="<?=self::getUrl("Mailtemplate", "delete", ["id" => $template->id])?>" class="text-danger" onclick="if(!confirm('Emailtemplate wirklich löschen?')) return false;" title="Emailtemplate Löschen"><i class="fas fa-trash"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>
|
||||
@@ -49,7 +49,24 @@ class ADBHausnummer extends mfBaseModel {
|
||||
$this->log->debug(__METHOD__.": Want new Hausnummer (".$this->id.") Status ".$new_status_code);
|
||||
|
||||
$new_status = ADBStatusModel::getFirst(["code" => $new_status_code]);
|
||||
if(!$new_status) return false;
|
||||
|
||||
if(!$new_status) {
|
||||
// try flag
|
||||
$flag = ADBStatusflagModel::getFirst(["code" => $new_status_code]);
|
||||
if(!$flag) return false;
|
||||
|
||||
$this->log->debug(__METHOD__.": Statuscode $new_status_code is Flag");
|
||||
$flag_value = ADBHausnummerStatusflagValueModel::getFirst(["flag_id" => $flag->id, "hausnummer_id" => $this->id]);
|
||||
if(!$flag_value) {
|
||||
$flag_value = ADBHausnummerStatusflagValueModel::create([
|
||||
"hausnummer_id" => $this->id,
|
||||
"flag_id" => $flag->id
|
||||
]);
|
||||
}
|
||||
$flag_value->value = 1;
|
||||
$flag_value->save();
|
||||
return true;
|
||||
}
|
||||
|
||||
$old_status = $this->getProperty("status");
|
||||
if($old_status->code < $new_status->code) {
|
||||
|
||||
@@ -167,6 +167,8 @@ class AddressDB {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
|
||||
46
application/Mailtemplate/Mailtemplate.php
Normal file
46
application/Mailtemplate/Mailtemplate.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
class Mailtemplate extends mfBaseModel {
|
||||
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;
|
||||
}
|
||||
}
|
||||
105
application/Mailtemplate/MailtemplateController.php
Normal file
105
application/Mailtemplate/MailtemplateController.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
class MailtemplateController extends mfBaseController {
|
||||
|
||||
protected function init() {
|
||||
$this->needlogin=true;
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
|
||||
if(!$me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
}
|
||||
|
||||
protected function indexAction() {
|
||||
if($this->request->resetFilter) {
|
||||
unset($_SESSION[MFAPPNAME.'-Mailtemplate-filter']);
|
||||
}
|
||||
|
||||
$filter = [];
|
||||
if(is_array($this->request->filter)) {
|
||||
$filter = $this->request->filter;
|
||||
$_SESSION[MFAPPNAME.'-Mailtemplate-filter'] = $filter;
|
||||
} else {
|
||||
if(array_key_exists(MFAPPNAME.'-Mailtemplate-filter', $_SESSION) && count($_SESSION[MFAPPNAME.'-Mailtemplate-filter'])) {
|
||||
$filter = $_SESSION[MFAPPNAME.'-Mailtemplate-filter'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->layout->set("filter", $filter);
|
||||
$filter = $this->getPreparedFilter($filter);
|
||||
|
||||
|
||||
// pagination defaults
|
||||
$pagination = [];
|
||||
$pagination['start'] = 0;
|
||||
$pagination['count'] = 20;
|
||||
$pagination['maxItems'] = 0;
|
||||
|
||||
if(is_numeric($this->request->s)) {
|
||||
$pagination['start'] = intval($this->request->s);
|
||||
}
|
||||
|
||||
$pagination['maxItems'] = MailtemplateModel::count($filter);
|
||||
$this->layout()->set("pagination", $pagination);
|
||||
|
||||
$templates = MailtemplateModel::search($filter, $pagination);
|
||||
$this->layout()->set("templates", $templates);
|
||||
}
|
||||
|
||||
private function getPreparedFilter($filter) {
|
||||
$new_filter = [];
|
||||
|
||||
foreach($filter as $name => $value) {
|
||||
$new_filter[$name] = $value;
|
||||
}
|
||||
|
||||
return $new_filter;
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
$this->layout()->setTemplate("Mailtemplate/Form");
|
||||
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
$id = $this->request->id;
|
||||
$template = new Mailtemplate($id);
|
||||
if(!$template->id) {
|
||||
$this->layout()->setFlash("Emailtemplate nicht gefunden.", "error");
|
||||
$this->redirect("Mailtemplate");
|
||||
}
|
||||
|
||||
$this->layout()->set("template", $template);
|
||||
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
var_dump($r->get());exit;
|
||||
$id = $r->id;
|
||||
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$template = new Mailtemplate($id);
|
||||
if(!$template->id) {
|
||||
$this->layout()->setFlash("Emailtemplate nicht gefunden", "error");
|
||||
$this->redirect("Mailtemplate");
|
||||
}
|
||||
} else {
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data["name"] = $r->name;
|
||||
$data["subject"] = $r->subject;
|
||||
//$data[""] = $r->;
|
||||
//$data[""] = $r->;
|
||||
//$data[""] = $r->;
|
||||
|
||||
}
|
||||
}
|
||||
139
application/Mailtemplate/MailtemplateModel.php
Normal file
139
application/Mailtemplate/MailtemplateModel.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
class MailtemplateModel {
|
||||
public $name;
|
||||
public $subject;
|
||||
public $body;
|
||||
|
||||
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 Mailtemplate();
|
||||
|
||||
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("Mailtemplate", "*", "1 = 1 ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Mailtemplate($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter = []) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Mailtemplate", "*", "$where ORDER BY name LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Mailtemplate($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 `Mailtemplate`
|
||||
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 Mailtemplate.* FROM `Mailtemplate`
|
||||
WHERE $where
|
||||
ORDER BY name
|
||||
";
|
||||
|
||||
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 Mailtemplate($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if(array_key_exists("name", $filter)) {
|
||||
$name = $db->escape($filter['name']);
|
||||
if($name) {
|
||||
$where .= " AND Mailtemplate.`name` = '$name'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("subject", $filter)) {
|
||||
$subject = $db->escape($filter['subject']);
|
||||
if($subject) {
|
||||
$where .= " AND Mailtemplate.`subject` = '$subject'";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
40
db/migrations/20240822153505_create_mailtemplate.php
Normal file
40
db/migrations/20240822153505_create_mailtemplate.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateMailtemplate extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$table = $this->table("Mailtemplate");
|
||||
$table->addColumn("name", "string", ["null" => false, "limit" => 255]);
|
||||
$table->addColumn("description", "string", ["null" => true, "default" => true, "limit" => 1024]);
|
||||
$table->addColumn("subject", "string", ["null" => false, "limit" => 255]);
|
||||
$table->addColumn("body", "text", ["null" => false]);
|
||||
$table->addColumn("note", "text", ["null" => false]);
|
||||
$table->addColumn("create_by", "integer", ["null" => false]);
|
||||
$table->addColumn("edit_by", "integer", ["null" => false]);
|
||||
$table->addColumn("create", "integer", ["null" => false]);
|
||||
$table->addColumn("edit", "integer", ["null" => false]);
|
||||
|
||||
$table->create();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$this->table("Mailtemplate")->drop()->save();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user