Files
thetool/application/Voiceplanzone/Voiceplanzone.php
2024-07-06 18:37:40 +02:00

75 lines
1.9 KiB
PHP

<?php
class Voiceplanzone extends mfBaseModel {
private $destinations;
private $voiceplan;
public $cloned_destinations = [];
public function getDestinationCountOrPrefix() {
$destinations = $this->getProperty("destinations");
if(count($destinations) == 1) {
return "+".$destinations[0]->prefix;
}
return count($destinations);
}
public function getProperty($name) {
if($this->$name == null) {
if(!$this->id) {
return null;
}
if($name == "destinations") {
$this->destinations = VoiceplandestinationModel::search(["voiceplanzone_id" => $this->id]);
return $this->destinations;
}
$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;
}
public function __clone() {
$me = new User;
$me->loadMe();
$old_id = $this->id;
$this->id = null;
$this->destinations = null;
$this->voiceplan = null;
// cleanup data
$this->create_by = $me->id;
$this->edit_by = $me->id;
$this->create = null;
$this->edit = null;
$this->saved = 0;
$this->mode = "new";
$this->_old_data = new StdClass();
// clone all destinations
$this->cloned_destinations = [];
foreach(VoiceplandestinationModel::search(['voiceplanzone_id' => $old_id]) as $old_destination) {
$this->cloned_destinations[] = clone($old_destination);
}
$this->log->debug("Cloned Voiceplanzone $old_id");
}
}