Files
thetool/application/Mailtemplate/Mailtemplate.php
2024-08-29 23:22:49 +02:00

74 lines
2.2 KiB
PHP

<?php
class Mailtemplate extends mfBaseModel {
private $files;
private $creator;
private $editor;
public function getVariableReplacedSubject($replaceVars) {
return $this->replaceVariables($this->subject, $replaceVars);
}
public function getVariableReplacedBody($replaceVars) {
return $this->replaceVariables($this->body, $replaceVars);
}
private function replaceVariables($text, $replaceVars) {
if(!is_array($replaceVars)) return false;
foreach($replaceVars as $key => $replacement) {
$body = str_replace("{{".$key."}}", $replacement, $body);
}
return $body;
}
public function getProperty($name) {
if($this->$name == null) {
if($name == "files") {
$files = MailtemplateFileModel::search(["mailtemplate_id" => $this->id]);
if(!count($files)) {
return [];
}
$this->files = $files;
return $this->files;
}
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;
}
}