From 6fa6dbbd870ada17f53e25879f739a7227933fb5 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 30 Nov 2021 22:05:03 +0100 Subject: [PATCH] added filter to Address --- Layout/default/Address/Index.php | 174 +++++++++++++++++++++- application/Address/AddressController.php | 50 +++++++ application/Address/AddressModel.php | 118 ++++++++++++++- application/Building/BuildingModel.php | 2 +- 4 files changed, 332 insertions(+), 12 deletions(-) diff --git a/Layout/default/Address/Index.php b/Layout/default/Address/Index.php index 3697760e6..2b792858d 100644 --- a/Layout/default/Address/Index.php +++ b/Layout/default/Address/Index.php @@ -27,16 +27,120 @@
+
+
+

Filter

+ +
"> +
+ is("Admin")): ?> +
+ + +
+ + +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + + +
+
+
+ + ">Filter zurücksetzen +
+
+
+ +
+
+ +

Liste aller Personen & Firmen

- - Zeige nur Personen und Firmen ohne Zugehörigkeit an. array_merge($filter, ["parents_only" => 0])])?>">Alle anzeigen
- + Zeige alle Personen und Firmen
+ + Zeige nur Personen und Firmen ohne Zugehörigkeit an. array_merge($filter, ["parents_only" => 0])])?>">Alle anzeigen
Gefiltert nach Rolle:
@@ -48,6 +152,35 @@ "> Neue Person/Firma anlegen

+ $pagination['count']): ?> + + + + @@ -93,10 +226,45 @@
Typ
+ + $pagination['count']): ?> + + + + +
+ + \ No newline at end of file diff --git a/application/Address/AddressController.php b/application/Address/AddressController.php index e7ce3497f..82147aecc 100644 --- a/application/Address/AddressController.php +++ b/application/Address/AddressController.php @@ -16,6 +16,39 @@ class AddressController extends mfBaseController { } protected function indexAction() { + $rfilter = $this->request->filter; + iF(!is_array($rfilter)) { + $rfilter = []; + } + if(!array_key_exists("addresstype", $rfilter)) { + $rfilter["addresstype"] = []; + } + + $this->layout->set("filter", $rfilter); + + $filter = $this->getPreparedFilter($rfilter); + + // pagination defaults + $pagination = []; + $pagination['start'] = 0; + $pagination['count'] = 25; + $pagination['maxItems'] = 0; + + if(is_numeric($this->request->s)) { + $pagination['start'] = intval($this->request->s); + } + //var_dump($filter);exit; + $pagination['maxItems'] = AddressModel::count($filter); + $addresses = AddressModel::search($filter, $pagination); + + $this->layout()->set("addresses", $addresses); + $this->layout()->set("request", $this->request); + $this->layout()->set("pagination", $pagination); + + return true; + + + //var_dump($this->request->filter); $default_filter = ['parents_only' => 1]; if(is_array($this->request->filter) && count($this->request->filter)) { @@ -31,6 +64,23 @@ class AddressController extends mfBaseController { $this->layout()->set("request", $this->request); } + + private function getPreparedFilter($filter) { + $new_filter = []; + + if(is_array($filter) && count($filter)) { + if(!array_key_exists("parents_only", $filter)) { + $new_filter["parents_only"] = 1; + } + + foreach($filter as $name => $value) { + $new_filter[$name] = $value; + } + } + + return $new_filter; + } + protected function addAction() { $this->layout()->setTemplate("Address/Form"); diff --git a/application/Address/AddressModel.php b/application/Address/AddressModel.php index bdd2227a4..968a52a94 100644 --- a/application/Address/AddressModel.php +++ b/application/Address/AddressModel.php @@ -119,25 +119,63 @@ class AddressModel { return $addresses; } - public static function search($filter) { + public static function count($filter) { + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $sql = "SELECT COUNT(*) as cnt FROM ( + SELECT Address.id as address_id + FROM Address + LEFT JOIN Addresstype ON (Addresstype.address_id = Address.id) + WHERE $where + GROUP BY Address.id + ) as tbl"; + mfLoghandler::singleton()->debug($sql); + + $res = $db->query($sql); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + return $data->cnt; + } + return 0; + } + + public static function search($filter, $limit = false) { + //var_dump($filter);exit; $items = []; $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); $have = []; - $sql = "SELECT Address.* FROM Address, Addresstype + /*$sql = "SELECT Address.* FROM Address, Addresstype WHERE Addresstype.address_id = Address.id AND $where GROUP BY Addresstype.address_id - ORDER BY Address.id"; + ORDER BY Address.id";*/ + $sql = "SELECT Address.* FROM Address + LEFT JOIN Addresstype ON (Addresstype.address_id = Address.id) + WHERE $where + GROUP BY Address.id + ORDER BY company, lastname, firstname, zip, city, Address.id"; + + if(is_array($limit) && count($limit)) { + if(is_numeric($limit['start']) && is_numeric($limit['count'])) { + $sql .= " LIMIT ".$limit['start'].", ".$limit['count']; + } elseif(is_numeric($count)) { + $sql .= " LIMIT ".$limit['count']; + } + } + + mfLoghandler::singleton()->debug($sql); + $res = $db->query($sql); if($db->num_rows($res)) { while($data = $db->fetch_object($res)) { $items[] = new Address($data); - $have[] = $data->id; + //$have[] = $data->id; } } - + /* if(!array_key_exists("addresstype", $filter)) { if($have) { $res = $db->select("Address", "*", "$where AND id NOT IN (".implode(",", $have).")"); @@ -149,7 +187,7 @@ class AddressModel { $items[] = new Address($data); } } - } + }*/ return $items; } @@ -157,7 +195,7 @@ class AddressModel { private function getSqlFilter($filter) { $where = "1=1 "; - + //var_dump($filter);exit; if(array_key_exists("customer_number", $filter)) { $cn = $filter["customer_number"]; if(is_numeric($cn)) { @@ -171,6 +209,70 @@ class AddressModel { $where .= " AND spin='$spin'"; } } + + if(array_key_exists("company", $filter)) { + $company = FronkDB::singleton()->escape($filter["company"]); + if($company) { + $where .= " AND company like '%$company%'"; + } + } + + if(array_key_exists("firstname", $filter)) { + $firstname = FronkDB::singleton()->escape($filter["firstname"]); + if($firstname) { + $where .= " AND firstname like '%$firstname%'"; + } + } + + if(array_key_exists("lastname", $filter)) { + $lastname = FronkDB::singleton()->escape($filter["lastname"]); + if($lastname) { + $where .= " AND lastname like '%$lastname%'"; + } + } + + if(array_key_exists("street", $filter)) { + $street = FronkDB::singleton()->escape($filter["street"]); + if($street) { + $where .= " AND street like '%$street%'"; + } + } + + if(array_key_exists("zip", $filter)) { + $zip = FronkDB::singleton()->escape($filter["zip"]); + if($zip) { + $where .= " AND zip like '%$zip%'"; + } + } + + if(array_key_exists("city", $filter)) { + $city = FronkDB::singleton()->escape($filter["city"]); + if($city) { + $where .= " AND city like '%$city%'"; + } + } + + if(array_key_exists("country", $filter)) { + $country = FronkDB::singleton()->escape($filter["country"]); + if($country) { + $where .= " AND country like '%$country%'"; + } + } + + if(array_key_exists("email", $filter)) { + $email = FronkDB::singleton()->escape($filter["email"]); + if($email) { + $where .= " AND email like '%$email%'"; + } + } + + if(array_key_exists("pfm", $filter)) { + $pfm = FronkDB::singleton()->escape($filter["pfm"]); + if($pfm) { + $where .= " AND (phone like '%$pfm%' OR fax like '%$pfm%' OR mobile like '%$pfm%' )"; + } + } + /* * Address Type */ @@ -211,7 +313,7 @@ class AddressModel { if(array_key_exists("parents_only", $filter)) { $po = $filter['parents_only']; - if($po == 1) { + if($po) { $where .= " AND parent_id IS NULL"; } } diff --git a/application/Building/BuildingModel.php b/application/Building/BuildingModel.php index 734b4937c..cda045cb8 100644 --- a/application/Building/BuildingModel.php +++ b/application/Building/BuildingModel.php @@ -131,7 +131,7 @@ class BuildingModel { private function getSqlFilter($filter) { $where = "1=1 "; - + if(array_key_exists("network_id", $filter)) { $network_id = $filter['network_id']; if(is_numeric($network_id)) {