Added Network
This commit is contained in:
31
application/Network/Network.php
Normal file
31
application/Network/Network.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
class Network extends mfBaseModel {
|
||||
private $owner;
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if($name == "owner") {
|
||||
if($this->id) {
|
||||
$this->owner = new Address($this->owner_id);
|
||||
return $this->owner;
|
||||
} else {
|
||||
return 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;
|
||||
}
|
||||
}
|
||||
95
application/Network/NetworkController.php
Normal file
95
application/Network/NetworkController.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
class NetworkController extends mfBaseController {
|
||||
|
||||
protected function init() {
|
||||
$this->needlogin=true;
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
/*
|
||||
if(!$me->isAdmin()) {
|
||||
$this->redirect("Dashboard");
|
||||
}*/
|
||||
}
|
||||
|
||||
protected function indexAction() {
|
||||
$this->layout()->set("owners", AddressModel::search(['addresstype' => ["netowner"]]));
|
||||
$this->layout()->set("networks", NetworkModel::getAll());
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
$this->layout()->setTemplate("Network/Form");
|
||||
$this->layout()->set("owners", AddressModel::search(['addresstype' => ["netowner"]]));
|
||||
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
$id = $this->request->id;
|
||||
if(!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Netzgebiet nicht gefunden", "error");
|
||||
$this->redirect("Network");
|
||||
}
|
||||
|
||||
$network = new Network($id);
|
||||
if($network->id != $id) {
|
||||
$this->layout()->setFlash("Netzgebiet nicht gefunden", "error");
|
||||
$this->redirect("Network");
|
||||
}
|
||||
|
||||
$this->layout()->set("network", $network);
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
$id = $r->id;
|
||||
//var_dump($r);
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$network = new Network($id);
|
||||
if(!$network->id) {
|
||||
$this->layout()->setFlash("Netzgebie tnicht gefunden", "error");
|
||||
$this->redirect("Network");
|
||||
}
|
||||
} else {
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
//var_dump($r->addresstypes);exit;
|
||||
|
||||
if(!$r->owner_id || !$r->name) {
|
||||
$this->layout()->setFlash("Bitte Name und Besitzer eintragen", "error");
|
||||
$this->layout()->set("network", $network);
|
||||
return $this->add();
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['owner_id'] = $r->owner_id;
|
||||
$data['name'] = $r->name;
|
||||
$data['note'] = $r->note;
|
||||
|
||||
$data['edit_by'] = 1;
|
||||
|
||||
if($mode == "add") {
|
||||
$data['create_by'] = 1;
|
||||
$network = NetworkModel::create($data);
|
||||
} else {
|
||||
$network->update($data);
|
||||
}
|
||||
|
||||
//var_dump($address);exit;
|
||||
|
||||
$new_id = $network->save();
|
||||
if(!$new_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
$this->layout()->set("network", $network);
|
||||
return $this->add();
|
||||
}
|
||||
|
||||
|
||||
$this->layout()->setFlash("Netzgebiet erfolgreich gespeichert.", "success");
|
||||
$this->redirect("Network", "Edit", ['id' => $new_id]);
|
||||
}
|
||||
}
|
||||
105
application/Network/NetworkModel.php
Normal file
105
application/Network/NetworkModel.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
class NetworkModel {
|
||||
public $name = null;
|
||||
public $owner_id = null;
|
||||
public $note = null;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
public static function find($data) {
|
||||
|
||||
}
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new Network();
|
||||
|
||||
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("Network", "*", "id=$id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Network($data);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Network", "*");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Network($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Network", "*". "$where ORDER BY name, owner_id");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Network($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("Network", "*". "$where ORDER BY name, owner_id");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Network($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if(array_key_exists("owner_id", $filter)) {
|
||||
$ownerid= $filter['owner_id'];
|
||||
if(is_numeric($ownerid)) {
|
||||
$where .= " AND owner_id=$ownerid";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user