Files
thetool/application/Termination/Termination.php
2021-09-14 22:45:01 +02:00

121 lines
2.6 KiB
PHP

<?php
class Termination extends mfBaseModel {
protected $forcestr = ['phone','email','note'];
private $building;
private $status;
private $lineworker;
private $workflowitems;
private $files;
private $creator;
private $editor;
public function getAddress($singelLine = false) {
if(!$this->id) {
return false;
}
$b = $this->getProperty("building");
$address = $b->street;
if($this->name) {
$address .= " ".$this->name;
}
$address .= "\n".$b->zip." ".$b->city;
if($singelLine) {
$address = str_replace("\n", " ", $address);
}
return $address;
}
public function getNewObjectCode() {
if(!$this->building_id) {
return false;
}
$bcode = $this->getProperty("building")->code;
if(!$bcode) {
return false;
}
$codes = [];
// get existing codes
$res = $this->db->select("Termination", "code", "code like '$bcode.%'");
if($this->db->num_rows($res)) {
while($data = $this->db->fetch_object($res)) {
$codes[] = $data->code;
}
}
if(count($codes)) {
sort($codes);
}
$last_code = end($codes);
$m = [];
if(preg_match('/\.(\d+)$/', $last_code, $m)) {
if($m[1]) {
$last_num = $m[1];
}
} else {
return false;
}
$new_num = ++$last_num;
$code = $bcode.".".sprintf("%03d", $new_num);
return $code;
}
public function resetProperties() {
$this->building = null;
$this->status = null;
$this->lineworker = null;
$this->workflowitems = null;
$this->files = null;
$this->creator = null;
$this->editor = null;
}
public function getProperty($name) {
if($this->$name == null) {
if($name == "status") {
$this->status = TerminationstatusModel::getOne($this->status_id);
return $this->status;
}
if($name == "workflowitems") {
foreach(WorkflowitemModel::search(["object_type" => "Termination", "active" => 1]) as $item) {
$item->setObjectId($this->id);
$this->workflowitems[$item->name] = $item;
}
//var_dump($this->workflowitems);exit;
return $this->workflowitems;
}
if($name == "files") {
$this->files = TerminationFileModel::search(["termination_id" => $this->id]);
return $this->files;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = new $classname($this->$idfield);
if($this->$name->id) {
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
}