Added Role view to Network
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -1,5 +1,22 @@
|
||||
<?php
|
||||
|
||||
class Addresstype extends mfBaseModel {
|
||||
private $address;
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$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;
|
||||
}
|
||||
}
|
||||
@@ -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'";
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
class NetworkAddress extends mfBaseModel {
|
||||
private $network;
|
||||
private $address;
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
class NetworkAddressModel {
|
||||
public $network_id = null;
|
||||
public $address_id = null;
|
||||
public $type = null;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new NetworkAddress();
|
||||
|
||||
foreach($data as $field => $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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user