diff --git a/Layout/default/Address/Form.php b/Layout/default/Address/Form.php index 3405d689b..fa69a5f51 100644 --- a/Layout/default/Address/Form.php +++ b/Layout/default/Address/Form.php @@ -131,7 +131,6 @@ - diff --git a/Layout/default/Network/Index.php b/Layout/default/Network/Index.php index 70ce75732..51aa2d025 100644 --- a/Layout/default/Network/Index.php +++ b/Layout/default/Network/Index.php @@ -125,19 +125,34 @@
| Name | -GPS (Breite, Länge) | -Standortinfo | + +=__($role)?> | +||
|---|---|---|---|---|---|
| =$pop->name?> | -=$pop->gps_lat?>, =$pop->gps_long?> | -=nl2br($pop->location)?> | +=AddressModel::getOne($address_id)->getCompanyOrName()?> | + ++ $address_id, 'addresstype' => [$role]]) !== null): ?> + + type == $role): ?> + checked='checked' + + + /> + + | +$pop->id])?>"> $pop->id])?>" class="text-danger" title="Löschen"> diff --git a/application/Address/Address.php b/application/Address/Address.php index 46a98a5bc..1fe2f86f2 100644 --- a/application/Address/Address.php +++ b/application/Address/Address.php @@ -33,7 +33,7 @@ class Address extends mfBaseModel { return false; } - $this->types = AddresstypeModel::search(['address_id' => $this->id]); + $this->types = AddresstypeModel::search(['address_id' => $this->id], true); } public function getProperty($name) { diff --git a/application/Address/AddressModel.php b/application/Address/AddressModel.php index 0d49b44dc..7ac2e2fba 100644 --- a/application/Address/AddressModel.php +++ b/application/Address/AddressModel.php @@ -19,11 +19,7 @@ class AddressModel { public $edit_by = null; public $create = null; public $edit = null; - - public static function find($data) { - - } - + public static function create(Array $data) { $model = new Address(); diff --git a/application/Addresstype/Addresstype.php b/application/Addresstype/Addresstype.php index b20ec6b98..a3c1f1edd 100644 --- a/application/Addresstype/Addresstype.php +++ b/application/Addresstype/Addresstype.php @@ -1,5 +1,22 @@ $name == null) { + + $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; + } } \ No newline at end of file diff --git a/application/Addresstype/AddresstypeModel.php b/application/Addresstype/AddresstypeModel.php index 1bbf71de5..1bcb1bdf0 100644 --- a/application/Addresstype/AddresstypeModel.php +++ b/application/Addresstype/AddresstypeModel.php @@ -65,7 +65,29 @@ class AddresstypeModel { } - public static function search($filter) { + public static function getFirst($filter) { + $db = FronkDB::singleton(); + $log = mfLoghandler::singleton(); + $log->debug(print_r($filter,true)); + $where = self::getSqlFilter($filter); + $sql = "SELECT Addresstype.* FROM Addresstype + WHERE $where + ORDER BY address_id ASC, `primary` DESC, type ASC"; + $log->debug($sql); + $res = $db->query($sql); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new NetworkAddress($data); + if($item->id) { + return $item; + } else { + return null; + } + } + return null; + } + + public static function search($filter, $indexByType = false) { $items = []; $db = FronkDB::singleton(); @@ -73,11 +95,15 @@ class AddresstypeModel { $sql = "SELECT Addresstype.* FROM Addresstype WHERE $where ORDER BY address_id ASC, `primary` DESC, type ASC"; - //var_dump($sql); + //var_dump($sql);exit; $res = $db->query($sql); if($db->num_rows($res)) { - while($data = $db->fetch_object($res)) { - $items[$data->type] = new Addresstype($data); + while($data = $db->fetch_object($res)) { + if($indexByType) { + $items[$data->type] = new Addresstype($data); + } else { + $items[] = new Addresstype($data); + } } } return $items; @@ -99,7 +125,7 @@ class AddresstypeModel { $in[] = "Addresstype.type = 'netowner'"; } if(in_array("salespartner", $at)) { - $in[] = "Addresstype.type = 'Addresstype'"; + $in[] = "Addresstype.type = 'salespartner'"; } if(in_array("pipeworker", $at)) { $in[] = "Addresstype.type = 'pipeworker'"; @@ -107,6 +133,12 @@ class AddresstypeModel { if(in_array("lineworker", $at)) { $in[] = "Addresstype.type = 'lineworker'"; } + if(in_array("pipeplanner", $at)) { + $in[] = "Addresstype.type = 'pipeplanner'"; + } + if(in_array("lineplanner", $at)) { + $in[] = "Addresstype.type = 'lineplanner'"; + } if(in_array("netoperator", $at)) { $in[] = "Addresstype.type = 'netoperator'"; } diff --git a/application/Network/Network.php b/application/Network/Network.php index f1143c4c1..18b93f423 100644 --- a/application/Network/Network.php +++ b/application/Network/Network.php @@ -3,6 +3,36 @@ class Network extends mfBaseModel { private $owner; private $pops; + private $addresstypes; + private $roles; + + 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 loadRoles() { + if(!$this->id) { + return false; + } + + $types = AddresstypeModel::search(['addresstype' => TT_NETWORK_ROLES]); + var_dump($types);exit; + foreach($types as $type) { + + } + } public function getProperty($name) { if($this->$name == null) { @@ -26,6 +56,15 @@ class Network extends mfBaseModel { } } + if($name == "addresstypes") { + if($this->id) { + $this->loadAddresstypes(); + return $this->addresstypes; + } else { + return null; + } + } + $classname = ucfirst($name); $idfield = $name."_id"; $this->$name = new $classname($this->$idfield); diff --git a/application/Network/NetworkController.php b/application/Network/NetworkController.php index ceee1621a..c924590b8 100644 --- a/application/Network/NetworkController.php +++ b/application/Network/NetworkController.php @@ -17,6 +17,10 @@ class NetworkController extends mfBaseController { protected function indexAction() { $this->layout()->set("owners", AddressModel::search(['addresstype' => ["netowner"]])); $this->layout()->set("networks", NetworkModel::getAll()); + + /*$net = new Network(1); + $at = $net->addresstypes; //[1]->addresstype->address; + var_dump($at);exit;*/ } protected function addAction() { diff --git a/application/Network/NetworkModel.php b/application/Network/NetworkModel.php index 9a9652db4..eca10a807 100644 --- a/application/Network/NetworkModel.php +++ b/application/Network/NetworkModel.php @@ -10,10 +10,7 @@ class NetworkModel { public $create = null; public $edit = null; - public static function find($data) { - - } - + public static function create(Array $data) { $model = new Network(); @@ -60,7 +57,7 @@ class NetworkModel { $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); - $res = $db->select("Network", "*". "$where ORDER BY name, owner_id"); + $res = $db->select("Network", "*", "$where ORDER BY name, owner_id"); if($db->num_rows($res)) { $data = $db->fetch_object($res); $item = new Network($data); @@ -78,7 +75,7 @@ class NetworkModel { $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); - $res = $db->select("Network", "*". "$where ORDER BY name, owner_id"); + $res = $db->select("Network", "*", "$where ORDER BY name, owner_id"); if($db->num_rows($res)) { while($data = $db->fetch_object($res)) { $items[] = new Network($data); diff --git a/application/NetworkAddress/NetworkAddress.php b/application/NetworkAddress/NetworkAddress.php new file mode 100644 index 000000000..6bc2cf587 --- /dev/null +++ b/application/NetworkAddress/NetworkAddress.php @@ -0,0 +1,23 @@ +$name == null) { + + $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; + } +} \ No newline at end of file diff --git a/application/NetworkAddress/NetworkAddressModel.php b/application/NetworkAddress/NetworkAddressModel.php new file mode 100644 index 000000000..262b05228 --- /dev/null +++ b/application/NetworkAddress/NetworkAddressModel.php @@ -0,0 +1,108 @@ + $value) { + if(property_exists(get_called_class(), $field)) { + $model ->$field = $value; + } + } + + return $model; + } + + public static function getOne($id) { + if(!is_numeric($id) || !$id) { + throw new Exception("Invalid number", 400); + } + $item = []; + $db = FronkDB::singleton(); + + $res = $db->select("NetworkAddress", "*", "id=$id LIMIT 1"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new NetworkAddress($data); + } + return $item; + } + + public static function getAll() { + $items = []; + + $db = FronkDB::singleton(); + + $res = $db->select("NetworkAddress", "*"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new NetworkAddress($data); + } + } + return $items; + + } + + public static function getFirst($filter) { + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $res = $db->select("NetworkAddress", "*", "$where ORDER BY `type`"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new NetworkAddress($data); + if($item->id) { + return $item; + } else { + return null; + } + } + return null; + } + + public static function search($filter) { + $items = []; + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $res = $db->select("NetworkAddress", "*", "$where ORDER BY `type`"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[$data->id] = new NetworkAddress($data->id); + } + } + return $items; + } + + private function getSqlFilter($filter) { + $where = "1=1 "; + + //var_dump($filter);exit; + if(array_key_exists("network_id", $filter)) { + $network_id = $filter['network_id']; + if(is_numeric($network_id)) { + $where .= " AND network_id=$network_id"; + } + } + + if(array_key_exists("address_id", $filter)) { + $address_id = $filter['address_id']; + if(is_numeric($address_id)) { + $where .= " AND address_id=$address_id"; + } + } + + //var_dump($filter, $where);exit; + return $where; + } + +} \ No newline at end of file diff --git a/config/config.php b/config/config.php index a2e17082d..4c96aad4f 100644 --- a/config/config.php +++ b/config/config.php @@ -22,6 +22,9 @@ define("LOGFILENAME",BASEDIR."/var/log/".MFAPPNAME.".log"); * Application-specific settings */ +define("TT_ROLES", ['systemowner','netowner','salespartner','pipeworker','lineworker','pipeplanner','lineplanner','netoperator','support','billing','employee','customer','supplier','contact']); +define("TT_NETWORK_ROLES", ['netowner','salespartner','pipeworker','lineworker','pipeplanner','lineplanner','netoperator']); + // Upload settings define('MFUPLOAD_FILE_SAVE_PATH',BASEDIR.'/files'); // folder where files will be stored @@ -35,7 +38,6 @@ define('MFLOCALE_TIME', "de_AT.UTF-8"); define('MFLOCALE_MONETARY', "de_AT.UTF-8"); define('MFLOCALE_NUMERIC', "de_AT.UTF-8"); - /* * Maintainer / developer settings */ |