95 lines
2.2 KiB
PHP
95 lines
2.2 KiB
PHP
<?php
|
|
|
|
class Network extends mfBaseModel {
|
|
private $owner;
|
|
private $pops;
|
|
private $addresstypes;
|
|
private $roles;
|
|
private $sections;
|
|
private $buildings;
|
|
|
|
|
|
public function getTypeAddresses($search_type) {
|
|
if(!$this->id) {
|
|
return false;
|
|
}
|
|
$addresses = [];
|
|
|
|
$addresstypes = $this->getProperty("addresstypes");
|
|
//var_dump($addresstypes);exit;
|
|
foreach($addresstypes as $address_id => $atypes) {
|
|
//var_dump($atypes);
|
|
foreach($atypes as $atype) {
|
|
//var_dump($atype);
|
|
if($atype->type == $search_type && !array_key_exists($address_id, $addresses)) {
|
|
$addresses[$address_id] = new Address($address_id);
|
|
}
|
|
}
|
|
}
|
|
|
|
return $addresses;
|
|
}
|
|
|
|
public function loadAddresstypes() {
|
|
if(!$this->id) {
|
|
return false;
|
|
}
|
|
|
|
//$this->loadRoles();
|
|
|
|
$types = NetworkAddressModel::search(['network_id' => $this->id]);
|
|
|
|
foreach($types as $type) {
|
|
$this->addresstypes[$type->address_id][] = $type;
|
|
}
|
|
|
|
//var_dump($this->addresstypes);exit;
|
|
}
|
|
|
|
public function getProperty($name) {
|
|
if($this->$name == null) {
|
|
|
|
if(!$this->id) {
|
|
return null;
|
|
}
|
|
|
|
if($name == "owner") {
|
|
$this->owner = new Address($this->owner_id);
|
|
return $this->owner;
|
|
}
|
|
|
|
if($name == "pops") {
|
|
$pops = PopModel::search(['network_id' => $this->id]);
|
|
$this->pops = $pops;
|
|
return $this->pops;
|
|
}
|
|
|
|
if($name == "addresstypes") {
|
|
$this->loadAddresstypes();
|
|
return $this->addresstypes;
|
|
}
|
|
|
|
if($name == "sections") {
|
|
$this->sections = NetworksectionModel::search(['network_id' => $this->id]);
|
|
return $this->sections;
|
|
}
|
|
|
|
if($name == "buildings") {
|
|
$this->buildings = BuildingModel::search(["network_id" => $this->id]);
|
|
return $this->buildings;
|
|
}
|
|
|
|
$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;
|
|
}
|
|
} |