Added filters to Pipework
This commit is contained in:
@@ -25,7 +25,49 @@
|
||||
<div class="card-body mb-3">
|
||||
<h4 class="header-title mb-3">Filter</h4>
|
||||
|
||||
|
||||
<form method="get" action="<?=self::getUrl("Pipework")?>">
|
||||
<div class="row">
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_network_id">Netzgebiet</label>
|
||||
<select name="filter[network_id]" id="filter_network_id" class="form-control">
|
||||
<option></option>
|
||||
<?php foreach($mynetworks as $fnet): ?>
|
||||
<option value="<?=$fnet->id?>" <?=($filter['network_id'] == $fnet->id) ? "selected='selected'" : ""?>><?=$fnet->name?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_status_id">Objektstatus</label>
|
||||
<select name="filter[status_id]" id="filter_status_id" class="form-control">
|
||||
<option></option>
|
||||
<?php foreach(BuildingstatusModel::getAll() as $status): ?>
|
||||
<option value="<?=$status->id?>" <?=($filter['status_id'] == $status->id) ? "selected='selected'" : ""?>><?=$status->code?> - <?=$status->name?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_code">Code</label>
|
||||
<input type="text" class="form-control" name="filter[code]" id="filter_code" value="<?=$filter['code']?>" />
|
||||
</div>
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_street">Straße</label>
|
||||
<input type="text" class="form-control" name="filter[street]" id="filter_street" value="<?=$filter['street']?>" />
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div class="row mt-2">
|
||||
<div class="col">
|
||||
<button type="submit" class="btn btn-primary">Filter anwenden</button>
|
||||
<a class="btn btn-secondary" href="<?=self::getUrl("Pipework")?>">Filter zurücksetzen</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -110,6 +110,13 @@ class BuildingModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("status_id", $filter)) {
|
||||
$status_id = $filter['status_id'];
|
||||
if(is_numeric($status_id)) {
|
||||
$where .= " AND Building.status_id=$status_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(is_array($filter['type']) && count($filter['type'])) {
|
||||
$ot = $filter['type'];
|
||||
$in = [];
|
||||
@@ -153,28 +160,28 @@ class BuildingModel {
|
||||
if(array_key_exists("code", $filter)) {
|
||||
$code = FronkDB::singleton()->escape($filter['code']);
|
||||
if($code) {
|
||||
$where .= " AND Building.`code`='$code'";
|
||||
$where .= " AND Building.`code` like '%$code%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("street", $filter)) {
|
||||
$street = FronkDB::singleton()->escape($filter["street"]);
|
||||
if($street) {
|
||||
$where .= " AND street='$street'";
|
||||
$where .= " AND street like '%$street%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("zip", $filter)) {
|
||||
$zip = FronkDB::singleton()->escape($filter["zip"]);
|
||||
if($zip) {
|
||||
$where .= " AND zip='$zip'";
|
||||
$where .= " AND zip like '%$zip%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("city", $filter)) {
|
||||
$city = FronkDB::singleton()->escape($filter["city"]);
|
||||
if($city) {
|
||||
$where .= " AND city='$city'";
|
||||
$where .= " AND city like '%$city%'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -105,6 +105,8 @@ class NetworkModel {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
@@ -17,16 +17,42 @@ class PipeworkController extends mfBaseController {
|
||||
protected function indexAction() {
|
||||
$this->layout()->setTemplate("Pipework/Index");
|
||||
|
||||
$this->layout->set("filter", $this->request->filter);
|
||||
|
||||
if($this->request->filter) {
|
||||
$filter = $this->getPreparedFilter($this->request->filter);
|
||||
}
|
||||
|
||||
$my_networks = [];
|
||||
|
||||
// get allowed networks
|
||||
if($this->me->is("Admin")) {
|
||||
$my_networks = NetworkModel::getAll();
|
||||
if($filter['network_id']) {
|
||||
$my_networks[] = new Network($filter['network_id']);
|
||||
} else {
|
||||
$my_networks = NetworkModel::getAll();
|
||||
}
|
||||
$this->layout()->set("mynetworks", NetworkModel::getAll());
|
||||
} else {
|
||||
$use_filter_network = false;
|
||||
$my_networks = $this->me->my_networks;
|
||||
|
||||
foreach($my_networks as $mn) {
|
||||
if($mn->id == $filter['network_id']) {
|
||||
$use_filter_network = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if($use_filter_network) {
|
||||
$my_networks = [];
|
||||
$my_networks[] = new Network($filter['network_id']);
|
||||
}
|
||||
|
||||
$this->layout()->set("mynetworks", $this->me->my_networks);
|
||||
|
||||
}
|
||||
unset($filter['network_id']);
|
||||
|
||||
// get Buildings in networks
|
||||
$networks = [];
|
||||
@@ -39,13 +65,15 @@ class PipeworkController extends mfBaseController {
|
||||
"network_id" => $network->id,
|
||||
"workflow_finished" => 0
|
||||
];
|
||||
|
||||
if(is_array($filter) && count($filter)) {
|
||||
$building_search = array_merge($building_search, $filter);
|
||||
foreach($filter as $name => $value) {
|
||||
$building_search[$name] = $value;
|
||||
}
|
||||
//$building_search = array_merge($building_search, $filter);
|
||||
}
|
||||
|
||||
$this->log->debug(print_r($building_search, true));
|
||||
|
||||
|
||||
|
||||
foreach(BuildingModel::search($building_search) as $b) {
|
||||
if(!array_key_exists($b->id, $networks[$network->name])) {
|
||||
$networks[$network->name][$b->id] = $b;
|
||||
@@ -77,8 +105,17 @@ class PipeworkController extends mfBaseController {
|
||||
}
|
||||
|
||||
private function getPreparedFilter($filter) {
|
||||
$new_filter = [];
|
||||
|
||||
return $filter;
|
||||
foreach($filter as $name => $value) {
|
||||
/*if($name == 'network_id') {
|
||||
$new_filter['id'] = $value;
|
||||
continue;
|
||||
}*/
|
||||
$new_filter[$name] = $value;
|
||||
}
|
||||
|
||||
return $new_filter;
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
|
||||
Reference in New Issue
Block a user