378 lines
10 KiB
PHP
378 lines
10 KiB
PHP
<?php
|
|
|
|
class Termination extends mfBaseModel {
|
|
protected $forcestr = ['phone','email','note'];
|
|
|
|
private $building;
|
|
private $status;
|
|
private $lineworker;
|
|
private $workflowitems;
|
|
private $cpeprovisioning;
|
|
private $files;
|
|
private $patching;
|
|
private $linework_enabler;
|
|
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 loadWorkflowItems() {
|
|
//$this->log->debug("in loadWorkflowItems() - terminstaiton_id: ".$this->id);
|
|
|
|
$term_wfitems = mfValuecache::singleton()->get("wfitems-term-active");
|
|
if(!$term_wfitems) {
|
|
$term_wfitems = WorkflowitemModel::search(["object_type" => "Termination", "active" => 1]);
|
|
mfValuecache::singleton()->set("wfitems-term-active", $term_wfitems);
|
|
}
|
|
|
|
foreach($term_wfitems as $item) {
|
|
mfValuecache::singleton()->set("wfTerm-name-".$item->name, $item);
|
|
mfValuecache::singleton()->set("wfTerm-id-".$item->id, $item);
|
|
$item->setObjectId($this->id);
|
|
|
|
$new_value = WorkflowvalueModel::create(['item_id' => $item->id, 'object_id' => $this->id]);
|
|
|
|
/*$new_value = new Workflowvalue();
|
|
$new_value->item_id = $item->id;
|
|
$new_value->object_id = $this->id;*/
|
|
//$this->log->debug("empty value has item_id: ".$new_value->item_id." - object_id: ".$new_value->object_id. ". Goes into cache as wfItemvalue-item-".$item->id."-object-".$this->id." value: ".$new_value->value_string);
|
|
|
|
mfValuecache::singleton()->set("wfItemvalue-item-".$item->id."-object-".$this->id, $new_value);
|
|
$item->setValue($new_value);
|
|
$this->workflowitems[$item->name] = $item;
|
|
}
|
|
|
|
|
|
// get values
|
|
$values = WorkflowvalueModel::search(["object_id" => $this->id, "object_type" => "termination"]);
|
|
|
|
foreach($values as $value) {
|
|
$this->workflowitems[$value->item->name]->setValue($value);
|
|
mfValuecache::singleton()->set("wfItemvalue-item-".$value->item_id."-object-".$this->id, $value);
|
|
}
|
|
}
|
|
|
|
public function getWorkflowvalue($itemname, $type = false) {
|
|
if(!is_array($this->workflowitems)) {
|
|
$this->loadWorkflowItems();
|
|
}
|
|
|
|
$item = mfValuecache::singleton()->get("wfTerm-name-".$itemname);
|
|
if(!$item) {
|
|
$item = WorkflowitemModel::getFirst(['name' => $itemname]);
|
|
if(!$item || !$item->id) {
|
|
return null;
|
|
}
|
|
mfValuecache::singleton()->set("wfTerm-name-".$itemname, $item);
|
|
mfValuecache::singleton()->set("wfTerm-id-".$item->id, $item);
|
|
}
|
|
$item->setObjectId($this->id);
|
|
|
|
switch($item->type) {
|
|
case "string":
|
|
$value_type = "string";
|
|
break;
|
|
case "enum":
|
|
$value_type = "string";
|
|
break;
|
|
case "gps":
|
|
$value_type = "string";
|
|
break;
|
|
case "color":
|
|
$value_type = "string";
|
|
break;
|
|
case "date":
|
|
$value_type = "string";
|
|
break;
|
|
case "int":
|
|
$value_type = "int";
|
|
break;
|
|
case "bool":
|
|
$value_type = "int";
|
|
break;
|
|
case "file":
|
|
$value_type = "int";
|
|
break;
|
|
case "text":
|
|
$value_type = "text";
|
|
break;
|
|
default:
|
|
$value_type = "string";
|
|
}
|
|
|
|
if(array_key_exists($itemname, $this->workflowitems)) {
|
|
return $this->workflowitems[$itemname]->value->{"value_$value_type"};
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function isWorkflowPatchingDone() {
|
|
$item_names = [
|
|
'pop_id',
|
|
'schrank',
|
|
'baugruppe',
|
|
'modul',
|
|
'ports',
|
|
'abschlusstyp',
|
|
'bb_kabel',
|
|
'bb_kabel_steps',
|
|
'bb_fasern',
|
|
'kundenkabel_typ',
|
|
'kundenkabel_fasern'
|
|
];
|
|
|
|
$done = true;
|
|
|
|
foreach($item_names as $name) {
|
|
if(!strlen($this->getWorkflowvalue($name)) && !strlen($this->getWorkflowvalue("ist_".$name))) {
|
|
$done = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return $done;
|
|
}
|
|
|
|
public function getPop() {
|
|
$pop_id = $this->getWorkflowvalue('ist_pop_id');
|
|
if(!$pop_id) {
|
|
$pop_id = $this->getWorkflowvalue('pop_id');
|
|
}
|
|
|
|
if(!$pop_id) {
|
|
return null;
|
|
}
|
|
|
|
return new Pop($pop_id);
|
|
}
|
|
|
|
public function getNewObjectCode() {
|
|
if(!$this->building_id) {
|
|
return false;
|
|
}
|
|
|
|
$bcode = $this->getProperty("building")->code;
|
|
var_dump($bcode);
|
|
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;
|
|
}
|
|
} else {
|
|
return $bcode.".001";
|
|
}
|
|
|
|
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 getLineworkportPairs() {
|
|
$ports = $this->getProperty("workflowitems")["ports"]->value->value_string;
|
|
$ist_port = $this->getProperty("workflowitems")["ist_ports"]->value->value_string;
|
|
if(strlen($ist_port)) {
|
|
$ports = $ist_port;
|
|
}
|
|
|
|
if(!$ports) {
|
|
return [];
|
|
}
|
|
|
|
$return = [];
|
|
$return["range"] = [];
|
|
$return["pairs"] = [];
|
|
|
|
$ports = preg_replace('/[^0-9-]+/', "", $ports);
|
|
if(strpos($ports, "-") !== false) {
|
|
// port range
|
|
$this->log->debug("is range");
|
|
$port_parts = explode("-", $ports);
|
|
if(is_array($port_parts) && count($port_parts) == 2) {
|
|
$from = $port_parts[0];
|
|
$to = $port_parts[1];
|
|
|
|
if($port_parts[0] > $port_parts[1]) {
|
|
$from = $port_parts[1];
|
|
$to = $port_parts[0];
|
|
}
|
|
|
|
$range = [];
|
|
$pairs = [];
|
|
|
|
|
|
|
|
for($i = $from; $i <= $to; $i++) {
|
|
$range[] = intval($i);
|
|
if($i + 1 <= $to) {
|
|
$pairs[] = $i."-".($i+1);
|
|
}
|
|
}
|
|
|
|
$return["range"] = $range;
|
|
$return["pairs"] = $pairs;
|
|
}
|
|
} else {
|
|
// single port
|
|
$this->log->debug("not a range");
|
|
$return["range"][] = $ports;
|
|
}
|
|
|
|
//var_dump($return);exit;
|
|
return $return;
|
|
|
|
}
|
|
|
|
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 = mfValuecache::singleton()->get("wfStatus-".$this->status_id);
|
|
if($this->status === null) {
|
|
$this->status = TerminationstatusModel::getOne($this->status_id);
|
|
if($this->status->id) {
|
|
mfValuecache::singleton()->set("wfStatus-".$this->status_id, $this->status);
|
|
}
|
|
}
|
|
return $this->status;
|
|
}
|
|
|
|
if($name == "workflowitems") {
|
|
$this->loadWorkflowItems();
|
|
/*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 == "lineworker") {
|
|
$lineworker_id = $this->getProperty("building")->lineworker_id;
|
|
$this->lineworker = mfValuecache::singleton()->get("mfObjectmodel-Address-$lineworker_id");
|
|
if($this->lineworker === null) {
|
|
$this->lineworker = new Address($this->getProperty("building")->lineworker_id);
|
|
if($this->lineworker->id) {
|
|
mfValuecache::singleton()->set("mfObjectmodel-Address-$lineworker_id", $this->lineworker);
|
|
}
|
|
}
|
|
return $this->lineworker;
|
|
}
|
|
|
|
if($name == "files") {
|
|
$this->files = TerminationFileModel::search(["termination_id" => $this->id]);
|
|
return $this->files;
|
|
}
|
|
|
|
if($name == "patching") {
|
|
$this->patching = PatchingModel::getFirst(["termination_id" => $this->id]);
|
|
return $this->patching;
|
|
}
|
|
|
|
if($name == "Cpeprovisioning") {
|
|
$this->cpeprovisioning = CpeprovisioningModel::getFirst(["termination_id" => $this->id]);
|
|
return $this->cpeprovisioning;
|
|
}
|
|
|
|
if($name == "linework_enabler") {
|
|
$this->linework_enabler = mfValuecache::singleton()->get("Worker-id-".$this->linework_enabled_by);
|
|
if(!$this->linework_enabler) {
|
|
$this->linework_enabler = new User($this->linework_enabled_by);
|
|
if($this->linework_enabler->id) {
|
|
mfValuecache::singleton()->set("Worker-id-".$this->linework_enabled_by, $this->linework_enabler);
|
|
}
|
|
}
|
|
return $this->linework_enabler;
|
|
}
|
|
|
|
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 === null) {
|
|
$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;
|
|
}
|
|
|
|
}
|