get my_networks from parent address if exists
This commit is contained in:
@@ -16,7 +16,22 @@ class BuildingController extends mfBaseController {
|
||||
|
||||
protected function indexAction() {
|
||||
$this->layout()->setTemplate("Building/Index");
|
||||
$this->layout()->set("buildings", BuildingModel::getAll());
|
||||
|
||||
if($this->me->is("Admin")) {
|
||||
$this->layout()->set("buildings", BuildingModel::getAll());
|
||||
} else {
|
||||
$buildings = [];
|
||||
foreach($this->me->my_networks as $network) {
|
||||
foreach(BuildingModel::search(["network_id" => $network->id]) as $b) {
|
||||
if(!array_key_exists($b->id, $buildings)) {
|
||||
$buildings[$b->id] = $b;
|
||||
}
|
||||
}
|
||||
}
|
||||
//var_dump($buildings);exit;
|
||||
$this->layout()->set("buildings", $buildings);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
|
||||
@@ -93,7 +93,7 @@ class BuildingModel {
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Address($data);
|
||||
$items[] = new Building($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
@@ -102,9 +102,14 @@ class BuildingModel {
|
||||
private function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
/*
|
||||
* Address Type
|
||||
*/
|
||||
|
||||
if(array_key_exists("network_id", $filter)) {
|
||||
$network_id = $filter['network_id'];
|
||||
if(is_numeric($network_id)) {
|
||||
$where .= " AND Building.network_id=$network_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(is_array($filter['type']) && count($filter['type'])) {
|
||||
$ot = $filter['type'];
|
||||
$in = [];
|
||||
|
||||
@@ -6,6 +6,7 @@ class Network extends mfBaseModel {
|
||||
private $addresstypes;
|
||||
private $roles;
|
||||
private $sections;
|
||||
private $buildings;
|
||||
|
||||
|
||||
public function getTypeAddresses($search_type) {
|
||||
@@ -48,41 +49,34 @@ class Network extends mfBaseModel {
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if($name == "owner") {
|
||||
if($this->id) {
|
||||
$this->owner = new Address($this->owner_id);
|
||||
return $this->owner;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
$this->owner = new Address($this->owner_id);
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
if($name == "pops") {
|
||||
if($this->id) {
|
||||
$pops = PopModel::search(['network_id' => $this->id]);
|
||||
$this->pops = $pops;
|
||||
return $this->pops;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
$pops = PopModel::search(['network_id' => $this->id]);
|
||||
$this->pops = $pops;
|
||||
return $this->pops;
|
||||
}
|
||||
|
||||
if($name == "addresstypes") {
|
||||
if($this->id) {
|
||||
$this->loadAddresstypes();
|
||||
return $this->addresstypes;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
$this->loadAddresstypes();
|
||||
return $this->addresstypes;
|
||||
}
|
||||
|
||||
if($name == "sections") {
|
||||
if($this->id) {
|
||||
$this->sections = NetworksectionModel::search(['network_id' => $this->id]);
|
||||
return $this->sections;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
$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);
|
||||
|
||||
@@ -149,7 +149,13 @@ class User extends mfBaseModel {
|
||||
|
||||
$my_networks = [];
|
||||
|
||||
$network_list = NetworkAddressModel::search(['address_id' => $this->address_id]);
|
||||
$address_id = $this->address_id;
|
||||
|
||||
if($this->getProperty("address")->parent_id) {
|
||||
$address_id = $this->getProperty("address")->parent_id;
|
||||
}
|
||||
//var_dump($address_id);exit;
|
||||
$network_list = NetworkAddressModel::search(['address_id' => $address_id]);
|
||||
foreach($network_list as $n) {
|
||||
if(!array_key_exists($n->network_id, $my_networks)) {
|
||||
$my_networks[$n->network_id] = new Network($n->network_id);
|
||||
|
||||
Reference in New Issue
Block a user