Added Buildings
This commit is contained in:
208
Layout/default/Building/Form.php
Normal file
208
Layout/default/Building/Form.php
Normal file
@@ -0,0 +1,208 @@
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/header.php"); ?>
|
||||
|
||||
<div class="wrapper">
|
||||
<div class="container-fluid">
|
||||
|
||||
<!-- start page title -->
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="page-title-box">
|
||||
<div class="page-title-right">
|
||||
<ol class="breadcrumb m-0">
|
||||
<li class="breadcrumb-item"><a href="<?=self::getUrl("Dashboard")?>">the-tool</a></li>
|
||||
<li class="breadcrumb-item"><a href="<?=self::getUrl("Building")?>">Objekte</a></li>
|
||||
<li class="breadcrumb-item active"><?=($building->id) ? "bearbeiten" : "Neu" ?></li>
|
||||
</ol>
|
||||
</div>
|
||||
<h4 class="page-title">Objekte</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end page title -->
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4 class="header-title mb-2"><?=($network->id) ? "Objekt bearbeiten" : "Neues Objekt"?></h4>
|
||||
|
||||
<form class="form-horizontal" method="post" action="<?=self::getUrl("Building", "save")?>">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
|
||||
<input type="hidden" name="id" value="<?=$building->id?>" />
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="network_id">Netzgebiet</label>
|
||||
<div class="col-lg-10">
|
||||
<select class="select2 form-control " name="network_id" id="building_id">
|
||||
<option></option>
|
||||
<?php foreach($networks as $network): ?>
|
||||
<option value="<?=$network->id?>" <?=($building->network_id == $network->id) ? "selected='selected'" : ""?>><?=($network->name)?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="pop_id">POP</label>
|
||||
<div class="col-lg-10">
|
||||
<select class="select2 form-control " name="pop_id" id="pop_id">
|
||||
<option></option>
|
||||
<?php foreach($networks as $network): ?>
|
||||
<?php foreach($network->pops as $pop): ?>
|
||||
<option value="<?=$pop->id?>" <?=($building->pop_id == $pop->id) ? "selected='selected'" : ""?>><?=$network->name?> - <?=($pop->name)?></option>
|
||||
<?php endforeach; ?>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="type_id">Objekttyp</label>
|
||||
<div class="col-lg-10">
|
||||
<select class="select2 form-control " name="type_id" id="type_id">
|
||||
<option></option>
|
||||
<?php foreach($types as $type): ?>
|
||||
<option value="<?=$type->id?>" <?=($building->type_id == $type->id) ? "selected='selected'" : ""?>><?=($type->name)?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="code">Objecktcode</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control" name="code" id="code" value="<?=$building->code?>" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="oan_id">OAN ID</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control" name="oan_id" id="oan_id" value="<?=$building->oan_id?>" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="street">Straße</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control" name="street" id="street" value="<?=$building->street?>" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="zip">PLZ</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control" name="zip" id="zip" value="<?=$building->zip?>" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="city">Ort</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control" name="city" id="city" value="<?=$building->city?>" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="gps_lat">GPS Länge (N)</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control" name="gps_lat" id="gps_lat" value="<?=$building->gps_lat?>" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="gps_long">GPS Breite (E)</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control" name="gps_long" id="gps_long" value="<?=$building->gps_long?>" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="contact">Kontakt</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control" name="contact" id="contact" value="<?=$building->contact?>" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="phone">Telefon</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control" name="phone" id="phone" value="<?=$building->phone?>" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="email">Email</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control" name="email" id="email" value="<?=$building->email?>" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="units">Wohneinheiten</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="number" class="form-control" name="units" id="units" value="<?=$building->units?>" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="description">Bauabschnitt</label>
|
||||
<div class="col-lg-10">
|
||||
<textarea id="description" class="form-control" name="description" rows="5"><?=$building->description?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="note">Interne Notiz</label>
|
||||
<div class="col-lg-10">
|
||||
<textarea id="note" class="form-control" name="note" rows="5"><?=$building->note?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2"></label>
|
||||
<div class="col-lg-10">
|
||||
<button type="submit" class="btn btn-primary">Speichern</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div> <!-- end container-fluid -->
|
||||
</div>
|
||||
<!-- end wrapper -->
|
||||
|
||||
<script type="text/javascript">
|
||||
$("#network_id").select2({placeholder: ""});
|
||||
$("#pop_id").select2({placeholder: ""});
|
||||
$("#type_id").select2({placeholder: ""});
|
||||
|
||||
// disable mousewheel on input number field when in focus
|
||||
$('form').on('focus', 'input[type=number]', function (e) {
|
||||
$(this).on('wheel.disableScroll', function (e) {
|
||||
e.preventDefault()
|
||||
})
|
||||
});
|
||||
$('form').on('blur', 'input[type=number]', function (e) {
|
||||
$(this).off('wheel.disableScroll')
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/footer.php"); ?>
|
||||
74
Layout/default/Building/Index.php
Normal file
74
Layout/default/Building/Index.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/header.php"); ?>
|
||||
|
||||
<div class="wrapper">
|
||||
<div class="container-fluid">
|
||||
|
||||
<!-- start page title -->
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="page-title-box">
|
||||
<div class="page-title-right">
|
||||
<ol class="breadcrumb m-0">
|
||||
<li class="breadcrumb-item"><a href="<?=self::getUrl("Dashboard")?>">the-tool</a></li>
|
||||
<li class="breadcrumb-item active">Objekte</li>
|
||||
</ol>
|
||||
</div>
|
||||
<h4 class="page-title">Objekte</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end page title -->
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body mb-3">
|
||||
<div class="float-left">
|
||||
<h4 class="header-title">Liste aller Objekte</h4>
|
||||
</div>
|
||||
<div class="float-right">
|
||||
<a class="btn btn-primary mb-2" href="<?=self::getUrl("Building", "add")?>"><i class="fas fa-plus"></i> Neues Objekt anlegen</a>
|
||||
</div>
|
||||
|
||||
<table class="table table-striped table-hover">
|
||||
<tr>
|
||||
<th>Netzgebiet</th>
|
||||
<th>POP</th>
|
||||
<th>Typ</th>
|
||||
<th>Objektcode</th>
|
||||
<th>OAN ID</th>
|
||||
<th>Adresse</th>
|
||||
<th>Einheiten</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
<?php foreach($buildings as $building): ?>
|
||||
<tr>
|
||||
<td><?=$building->network->name?></td>
|
||||
<td><?=$building->pop->name?></td>
|
||||
<td><?=$building->type->name?></td>
|
||||
<td><?=$building->code?></td>
|
||||
<td><?=$building->oan_id?></td>
|
||||
<td>
|
||||
<?=$building->street?><br />
|
||||
<?=$building->zip?> <?=$building->city?>
|
||||
</td>
|
||||
<td><?=$building->units?></td>
|
||||
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
|
||||
<a href="<?=self::getUrl("Building", "edit", ["id" => $building->id])?>"><i class="far fa-edit" title="Objekt Bearbeiten"></i></a>
|
||||
<a href="<?=self::getUrl("Building", "delete", ["id" => $building->id])?>" class="text-danger" onclick="if(!confirm('Objekt wirklich löschen?')) return false;" title="Objekt Löschen"><i class="fas fa-trash"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div> <!-- end container-fluid -->
|
||||
</div>
|
||||
<!-- end wrapper -->
|
||||
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/footer.php"); ?>
|
||||
@@ -30,6 +30,17 @@
|
||||
<li><a href="<?=self::getUrl("Network")?>">Netzgebiete</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="has-submenu">
|
||||
<a href="#">
|
||||
<i class="fas fa-hard-hat"></i>Netzbau <div class="arrow-down"></div>
|
||||
</a>
|
||||
<ul class="submenu">
|
||||
<li><a href="<?=self::getUrl("Building")?>">Objekte</a></li>
|
||||
<li><a href="<?=self::getUrl("Termination")?>">Anschlüsse</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
<!-- End navigation menu -->
|
||||
|
||||
|
||||
@@ -9,10 +9,10 @@ class AddressController extends mfBaseController {
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
/*
|
||||
|
||||
if(!$me->isAdmin()) {
|
||||
$this->redirect("Dashboard");
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
protected function indexAction() {
|
||||
|
||||
42
application/Building/Building.php
Normal file
42
application/Building/Building.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
class Building extends mfBaseModel {
|
||||
private $network;
|
||||
private $pop;
|
||||
private $type;
|
||||
private $status;
|
||||
private $pipeworker;
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if($name == "type") {
|
||||
$this->type = new Buildingtype($this->type_id);
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
if($name == "status") {
|
||||
$this->status = new Buildingstatus($this->status_id);
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
if($name == "pipeworker") {
|
||||
$this->pipeworker = new Address($this->pipeworker_id);
|
||||
return $this->pipeworker;
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
}
|
||||
112
application/Building/BuildingController.php
Normal file
112
application/Building/BuildingController.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
class BuildingController 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()->setTemplate("Building/Index");
|
||||
$this->layout()->set("buildings", BuildingModel::getAll());
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
$this->layout()->setTemplate("Building/Form");
|
||||
$this->layout()->set("networks", NetworkModel::getAll());
|
||||
$this->layout()->set("types", BuildingtypeModel::getAll());
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
$id = $this->request->id;
|
||||
if(!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Objekt nicht gefunden", "error");
|
||||
$this->redirect("Building");
|
||||
}
|
||||
|
||||
$building = new Building($id);
|
||||
if($building->id != $id) {
|
||||
$this->layout()->setFlash("Objekt nicht gefunden", "error");
|
||||
$this->redirect("Building");
|
||||
}
|
||||
|
||||
$this->layout()->set("building", $building);
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
$id = $r->id;
|
||||
//var_dump($r);exit;
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$building = new Building($id);
|
||||
if(!$building->id) {
|
||||
$this->layout()->setFlash("Objekt nicht gefunden", "error");
|
||||
$this->redirect("Objekt");
|
||||
}
|
||||
} else {
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
if(!$r->network_id || !$r->type_id) {
|
||||
$this->layout()->setFlash("Bitte Netzgebiet und Typ auswählen", "error");
|
||||
$this->layout()->set("building", $building);
|
||||
return $this->add();
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['network_id'] = $r->network_id;
|
||||
$data['pop_id'] = ($r->pop_id) ? $r->pop_id : null;
|
||||
$data['type_id'] = $r->type_id;
|
||||
$data['status_id'] = ($r->status_id) ? $r->status_id : null;
|
||||
$data['pipeworker_id'] = ($r->pipeworker_id) ? $r->pipeworker_id : null;
|
||||
$data['code'] = $r->code;
|
||||
$data['oan_id'] = $r->oan_id;
|
||||
$data['street'] = $r->street;
|
||||
$data['zip'] = $r->zip;
|
||||
$data['city'] = $r->city;
|
||||
$data['gps_lat'] = $r->gps_lat;
|
||||
$data['gps_long'] = $r->gps_long;
|
||||
$data['contact'] = $r->contact;
|
||||
$data['phone'] = $r->phone;
|
||||
$data['email'] = $r->email;
|
||||
$data['units'] = $r->units;
|
||||
$data['description'] = $r->description;
|
||||
$data['note'] = $r->note;
|
||||
|
||||
|
||||
$data['edit_by'] = 1;
|
||||
|
||||
if($mode == "add") {
|
||||
$data['status_id'] = 1;
|
||||
$data['create_by'] = 1;
|
||||
$building = BuildingModel::create($data);
|
||||
} else {
|
||||
$building->update($data);
|
||||
}
|
||||
|
||||
//var_dump($address);exit;
|
||||
|
||||
$new_id = $building->save();
|
||||
if(!$new_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
$this->layout()->set("building", $building);
|
||||
return $this->add();
|
||||
}
|
||||
|
||||
|
||||
$this->layout()->setFlash("Objekt erfolgreich gespeichert.", "success");
|
||||
$this->redirect("Building", "Edit", ['id' => $new_id]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
150
application/Building/BuildingModel.php
Normal file
150
application/Building/BuildingModel.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
class BuildingModel {
|
||||
public $network_id = null;
|
||||
public $pop_id = null;
|
||||
public $type_id = null;
|
||||
public $status_id = null;
|
||||
public $pipeworker_id = null;
|
||||
public $code = null;
|
||||
public $oan_id = null;
|
||||
public $street = null;
|
||||
public $zip = null;
|
||||
public $city = null;
|
||||
public $gps_lat = null;
|
||||
public $gps_long = null;
|
||||
public $contact = null;
|
||||
public $phone = null;
|
||||
public $email = null;
|
||||
public $units = null;
|
||||
public $description = null;
|
||||
public $note = null;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new Building();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
$model ->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if($model->create_by === null) {
|
||||
$model->create_by = $me->id;
|
||||
}
|
||||
if($model->edit_by === null) {
|
||||
$model->edit_by = $me->id;
|
||||
}
|
||||
|
||||
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("Building", "*", "id=$id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Building($data);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Building", "*", "1=1 ORDER BY network_id,pop_id,street,zip,city");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Building($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function search($filter) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT Building.* FROM Building
|
||||
LEFT JOIN Buildingtype ON (Buildingtype.id = Building.type_id)
|
||||
LEFT JOIN Buildingstatus ON (Buildingstatus.id = Building.status_id)
|
||||
WHERE $where
|
||||
ORDER BY network_id,pop_id,street,zip,city";
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Address($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
/*
|
||||
* Address Type
|
||||
*/
|
||||
if(is_array($filter['type']) && count($filter['type'])) {
|
||||
$ot = $filter['type'];
|
||||
$in = [];
|
||||
foreach($ot as $type) {
|
||||
$type = FronkDB::singleton()->escape($type);
|
||||
$in[] = "Buildingtype.name = '$type'";
|
||||
}
|
||||
|
||||
$or = "";
|
||||
if(count($in)) {
|
||||
$or = implode(" OR ", $in);
|
||||
$where .= " AND ( $or )";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("status", $filter)) {
|
||||
if(in_array(substr($filter['status'], 1, 2), ["<=", ">="])) {
|
||||
$op = substr($filter['status'], 1, 2);
|
||||
$status = substr($filter['status'], 3);
|
||||
} elseif(in_array(substr($filter['status'], 1, 1), ["<", ">"])) {
|
||||
$op = substr($filter['status'], 1, 1);
|
||||
$status = substr($filter['status'], 2);
|
||||
} else {
|
||||
$op = "=";
|
||||
$status = $filter['status'];
|
||||
}
|
||||
|
||||
if(is_numeric($status)) {
|
||||
$where .= " AND Buildingstatus.code $op $status";
|
||||
} else {
|
||||
// get code of statusname
|
||||
$code = Buildingstatus::getOne(["name" => $status]);
|
||||
if($code) {
|
||||
$status = FronkDB::singleton()->escape($status);
|
||||
$where .= " AND Buildingstatus.code $op '$status'";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
5
application/Buildingstatus/Buildingstatus.php
Normal file
5
application/Buildingstatus/Buildingstatus.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class Buildingstatus extends mfBaseModel {
|
||||
|
||||
}
|
||||
95
application/Buildingstatus/BuildingstatusModel.php
Normal file
95
application/Buildingstatus/BuildingstatusModel.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
class BuildingstatusModel {
|
||||
public $code = null;
|
||||
public $name = null;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new Buildingstatus();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
$model ->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if($model->create_by === null) {
|
||||
$model->create_by = $me->id;
|
||||
}
|
||||
if($model->edit_by === null) {
|
||||
$model->edit_by = $me->id;
|
||||
}
|
||||
|
||||
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("Buildingstatus", "*", "id=$id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Buildingstatus($data);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Buildingstatus", "*", "1=1 ORDER BY code,name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Buildingstatus($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function search($filter) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Buildingstatus", "*", $where);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Buildingstatus($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
if(array_key_exists("code", $filter)) {
|
||||
$code = FronkDB::singleton()->escape($filter['code']);
|
||||
$where .= " AND code='$code'";
|
||||
}
|
||||
|
||||
if(array_key_exists("name", $filter)) {
|
||||
$name = FronkDB::singleton()->escape($filter['name']);
|
||||
$where .= " AND name='$name'";
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
5
application/Buildingtype/Buildingtype.php
Normal file
5
application/Buildingtype/Buildingtype.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
class Buildingtype extends mfBaseModel {
|
||||
|
||||
}
|
||||
90
application/Buildingtype/BuildingtypeModel.php
Normal file
90
application/Buildingtype/BuildingtypeModel.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
class BuildingtypeModel {
|
||||
public $code = null;
|
||||
public $name = null;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new Buildingtype();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
$model ->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if($model->create_by === null) {
|
||||
$model->create_by = $me->id;
|
||||
}
|
||||
if($model->edit_by === null) {
|
||||
$model->edit_by = $me->id;
|
||||
}
|
||||
|
||||
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("Buildingtype", "*", "id=$id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Buildingtype($data);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("Buildingtype", "*", "1=1 ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Buildingtype($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function search($filter) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Buildingtype", "*", $where);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Buildingtype($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
if(array_key_exists("name", $filter)) {
|
||||
$name = FronkDB::singleton()->escape($filter['name']);
|
||||
$where .= " AND name='$name'";
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,10 +8,10 @@ class NetworkController extends mfBaseController {
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
/*
|
||||
|
||||
if(!$me->isAdmin()) {
|
||||
$this->redirect("Dashboard");
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
protected function indexAction() {
|
||||
|
||||
@@ -8,10 +8,10 @@ class NetworkAddressController extends mfBaseController {
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
/*
|
||||
|
||||
if(!$me->isAdmin()) {
|
||||
$this->redirect("Dashboard");
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
|
||||
@@ -8,10 +8,10 @@ class PopController extends mfBaseController {
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
/*
|
||||
|
||||
if(!$me->isAdmin()) {
|
||||
$this->redirect("Dashboard");
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
protected function indexAction() {
|
||||
|
||||
@@ -8,10 +8,10 @@ class ProductController extends mfBaseController {
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
/*
|
||||
|
||||
if(!$me->isAdmin()) {
|
||||
$this->redirect("Dashboard");
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
protected function indexAction() {
|
||||
|
||||
@@ -8,10 +8,10 @@ class ProductAttributeController extends mfBaseController {
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
/*
|
||||
|
||||
if(!$me->isAdmin()) {
|
||||
$this->redirect("Dashboard");
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@ class ProductgroupController extends mfBaseController {
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
/*
|
||||
|
||||
if(!$me->isAdmin()) {
|
||||
$this->redirect("Dashboard");
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
protected function indexAction() {
|
||||
|
||||
@@ -8,10 +8,10 @@ class ProducttechController extends mfBaseController {
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
/*
|
||||
|
||||
if(!$me->isAdmin()) {
|
||||
$this->redirect("Dashboard");
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
protected function indexAction() {
|
||||
|
||||
@@ -8,10 +8,10 @@ class ProducttechAttributeController extends mfBaseController {
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
/*
|
||||
|
||||
if(!$me->isAdmin()) {
|
||||
$this->redirect("Dashboard");
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
protected function deleteAction() {
|
||||
|
||||
@@ -74,9 +74,15 @@ class User extends mfBaseModel {
|
||||
}
|
||||
|
||||
public function is($what) {
|
||||
if(!$this->id) {
|
||||
return false;
|
||||
}
|
||||
if(is_object($this->permissions) && property_exists($this->permissions, "is$what")) {
|
||||
return $this->permissions->{"is$what"};
|
||||
}
|
||||
if(is_object($this->address) && property_exists($this->address, "types") && is_array($this->address->types)) {
|
||||
return ($this->address->types[$what]->id) ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
public function isAdmin() {
|
||||
|
||||
Reference in New Issue
Block a user