From cd88c4f57c40300ad68cee21b83eeb32ef581d28 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Thu, 24 Mar 2022 16:46:11 +0100 Subject: [PATCH] Improved pagination --- Layout/default/Address/Index.php | 65 ++---------- Layout/default/Building/Index.php | 13 ++- Layout/default/Order/Index.php | 66 ++---------- Layout/default/Preorder/Index.php | 62 ++++++++++++ Layout/default/menu.php | 1 + Layout/default/tpl/pagination-summary.php | 7 ++ Layout/default/tpl/pagination.php | 88 ++++++++++++++++ application/Preorder/Preorder.php | 54 ++++++++++ application/Preorder/PreorderController.php | 24 +++++ application/Preorder/PreorderModel.php | 107 ++++++++++++++++++++ 10 files changed, 371 insertions(+), 116 deletions(-) create mode 100644 Layout/default/Preorder/Index.php create mode 100644 Layout/default/tpl/pagination-summary.php create mode 100644 Layout/default/tpl/pagination.php create mode 100644 application/Preorder/Preorder.php create mode 100644 application/Preorder/PreorderController.php create mode 100644 application/Preorder/PreorderModel.php diff --git a/Layout/default/Address/Index.php b/Layout/default/Address/Index.php index 338bc99b4..a95b15f5d 100644 --- a/Layout/default/Address/Index.php +++ b/Layout/default/Address/Index.php @@ -1,3 +1,8 @@ +getUrl($Mod,"Index"); + $pagination_baseurl_params = ["filter" => $filter]; + $pagination_entity_name = "Adressen"; +?> @@ -153,34 +158,8 @@ "> Neue Person/Firma anlegen - $pagination['count']): ?> - - - + + @@ -228,34 +207,8 @@
- $pagination['count']): ?> - - - + + diff --git a/Layout/default/Building/Index.php b/Layout/default/Building/Index.php index adcd70faf..56c8890e9 100644 --- a/Layout/default/Building/Index.php +++ b/Layout/default/Building/Index.php @@ -106,6 +106,9 @@ @@ -444,13 +447,17 @@ console.log(all_coords); // calculate center position - var center_pos = GetCenterFromDegrees(all_coords); - console.log(center_pos); - buildingMap.setView(center_pos, 12); + mapCenterPos = GetCenterFromDegrees(all_coords); + console.log(mapCenterPos); + buildingMap.setView(mapCenterPos, 12); return true; } + function centerMap() { + buildingMap.setView(mapCenterPos, 12); + } + // gets buildings and calls renderMap() function getMapdata() { filter = getFilter(); diff --git a/Layout/default/Order/Index.php b/Layout/default/Order/Index.php index 2af0c9839..f60739bcb 100644 --- a/Layout/default/Order/Index.php +++ b/Layout/default/Order/Index.php @@ -1,4 +1,8 @@ getUrl($Mod,"Index"); + $pagination_baseurl_params = ["filter" => $filter]; + $pagination_entity_name = "Bestellungen"; //var_dump($mynetworks); $sorted_networks = []; @@ -102,7 +106,7 @@ @@ -521,34 +525,8 @@ "> Neue Bestellung anlegen - $pagination['count']): ?> - - - + + @@ -966,34 +944,8 @@
- $pagination['count']): ?> - - - + + diff --git a/Layout/default/Preorder/Index.php b/Layout/default/Preorder/Index.php new file mode 100644 index 000000000..f3d17b4a0 --- /dev/null +++ b/Layout/default/Preorder/Index.php @@ -0,0 +1,62 @@ + + + +
+
+
+
+ +
+

Vorbestellkampagnen

+
+
+
+ + +
+
+ +
+
+
+

Liste aller Vorbestellkampagnen

+
+ + + + + + + + + + + + + + + + + + + + + + + +
NetzgebieteNameGebietVorbestellungenStartEnde
network->name?>name?>area?>preorders)?>start)?>end)?> + $camp->id])?>"> + $camp->id])?>" class="text-danger" onclick="if(!confirm('Vorbestellkampagne wirklich löschen?')) return false;" title="Vorbestellkampagne Löschen"> +
+
+
+ +
+
+ + diff --git a/Layout/default/menu.php b/Layout/default/menu.php index 47cefdeec..c62b1cfdb 100644 --- a/Layout/default/menu.php +++ b/Layout/default/menu.php @@ -83,6 +83,7 @@ Verkauf
diff --git a/Layout/default/tpl/pagination-summary.php b/Layout/default/tpl/pagination-summary.php new file mode 100644 index 000000000..620f9a84a --- /dev/null +++ b/Layout/default/tpl/pagination-summary.php @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/Layout/default/tpl/pagination.php b/Layout/default/tpl/pagination.php new file mode 100644 index 000000000..5e418a73a --- /dev/null +++ b/Layout/default/tpl/pagination.php @@ -0,0 +1,88 @@ + $pagination['count']): ?> + + $i * $pagination['count'], + 'url' => $pagination_baseurl."?".http_build_query($mfPagination_baseurl_params), + 'current' => ($pagination['start'] == $i*$pagination['count']), + ]; + $mfPagination_pages[$i] = $page; + } +} else { + $show_from = $mfPagination_currentpage - 4; + $show_to = $mfPagination_currentpage + 4; + + if($show_from < 1) { + $show_from = 1; + } + if($show_to > $mfPagination_pagecount) { + $show_to = $mfPagination_pagecount+1; + } + + for($i = 0; $i < $mfPagination_pagecount+1; $i++) { + if($show_from > 1 && $i == $show_from) { + $mfPagination_pages[$i] = "separator_before"; + continue; + } + if($i == $show_to && $show_to < $mfPagination_pagecount) { + $mfPagination_pages[$i] = "separator_after"; + continue; + } + + $mfPagination_baseurl_params['s'] = $i * $pagination['count']; + + if(($i == 0 || $i == $mfPagination_pagecount) || ($i >= $show_from && $i <= $show_to)) { + $log->debug("show_from: $show_from, show_to: $show_to"); + + $page = [ + 's' => $i * $pagination['count'], + 'url' => $pagination_baseurl."?".http_build_query($mfPagination_baseurl_params), + 'current' => ($pagination['start'] == $i*$pagination['count']), + ]; + $mfPagination_pages[$i] = $page; + } + } + +} + +?> + +
+ pagecount: + currentpage: + +
+ + + \ No newline at end of file diff --git a/application/Preorder/Preorder.php b/application/Preorder/Preorder.php new file mode 100644 index 000000000..2d17d346b --- /dev/null +++ b/application/Preorder/Preorder.php @@ -0,0 +1,54 @@ +$name == null) { + + if($name == "creator") { + $user = mfValuecache::singleton()->get("Worker-id-".$this->create_by); + if($user) { + $this->creator = $user; + return $this->creator; + } + $this->creator = new User($this->create_by); + if($this->creator->id) { + mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator); + } + return $this->creator; + } + + if($name == "editor") { + $user = mfValuecache::singleton()->get("Worker-id-".$this->edit_by); + if($user) { + $this->editor = $user; + return $this->editor; + } + $this->editor = new User($this->edit_by); + if($this->editor->id) { + mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor); + } + return $this->editor; + } + + $classname = ucfirst($name); + $idfield = $name."_id"; + $this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield); + if(!$this->$name) { + $this->$name = new $classname($this->$idfield); + } + + if($this->$name->id) { + mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name); + return $this->$name; + } else { + return null; + } + } + + return $this->$name; + } + +} \ No newline at end of file diff --git a/application/Preorder/PreorderController.php b/application/Preorder/PreorderController.php new file mode 100644 index 000000000..93524e86d --- /dev/null +++ b/application/Preorder/PreorderController.php @@ -0,0 +1,24 @@ +needlogin=true; + $me = new User(); + $me->loadMe(); + $this->me = $me; + $this->layout()->set("me",$me); + + if(!$me->is(["Admin"])) { + $this->redirect("Dashboard"); + } + } + + protected function indexAction() { + $this->layout()->setTemplate("Preorder/Index"); + + $campaigns = PreorderModel::getAll(); + $this->layout()->set("campaigns", $campaigns); + + } +} \ No newline at end of file diff --git a/application/Preorder/PreorderModel.php b/application/Preorder/PreorderModel.php new file mode 100644 index 000000000..0fef9c697 --- /dev/null +++ b/application/Preorder/PreorderModel.php @@ -0,0 +1,107 @@ + $value) { + if(property_exists(get_called_class(), $field)) { + $model->$field = $value; + } + } + + $me = mfValuecache::singleton()->get("me"); + if(!$me) { + $me = new User(); + $me->loadMe(); + mfValuecache::singleton()->set("me", $me); + } + + 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 getAll() { + $items = []; + + $db = FronkDB::singleton(); + + $res = $db->select("Preorder", "*", "ORDER BY `create`"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new Preorder($data); + } + } + return $items; + + } + + public static function getFirst() { + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $res = $db->select("Preorder", "*", "$where ORDER BY `create`"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new Preorder($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("Preorder", "*", "$where ORDER BY `create`"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new Preorder($data); + } + } + return $items; + } + + private function getSqlFilter($filter) { + $where = "1=1 "; + + //var_dump($filter);exit; + if(array_key_exists("network_id", $filter)) { + $networkid = $filter['network_id']; + if(is_numeric($networkid)) { + $where .= " AND network_id=$networkid"; + } + } + + //var_dump($filter, $where);exit; + return $where; + } + +}