From 505d64aea79381485680c14eef6c4f3792efb0ac Mon Sep 17 00:00:00 2001 From: mruz Date: Wed, 2 Sep 2020 09:33:30 +0200 Subject: [PATCH 1/3] Model, get related record if field is null fix #275 --- ice/mvc/model.zep | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ice/mvc/model.zep b/ice/mvc/model.zep index 5dc0d329..001d404e 100644 --- a/ice/mvc/model.zep +++ b/ice/mvc/model.zep @@ -546,6 +546,16 @@ abstract class Model extends Arr implements \Serializable return this->loadOne(filters); } + /** + * Check whether model is loaded. + * + * @return boolean + */ + public function loaded() -> boolean + { + return this->isLoaded ? true : false; + } + /** * Get the last Db error. * @@ -707,7 +717,7 @@ abstract class Model extends Arr implements \Serializable let filters[referencedField] = this->{field}, result = create_instance_params(referenceModel, [filters, null, options]); - if !result->count() { + if !result->loaded() { return false; } From 40b1e78962346ab4ff624976d1004c09974e0788 Mon Sep 17 00:00:00 2001 From: mruz Date: Wed, 2 Sep 2020 09:54:37 +0200 Subject: [PATCH 2/3] Pagination, calculate if data is array or total is specified #273 --- ice/pagination.zep | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/ice/pagination.zep b/ice/pagination.zep index 35c8fc3b..94358e9b 100644 --- a/ice/pagination.zep +++ b/ice/pagination.zep @@ -39,24 +39,30 @@ class Pagination extends Arr */ public function calculate() -> { - var items, data; - int limit, page, pages, total, previous, next; + var items, data, total; + int limit, page, pages, previous, next; - let items = this->get("data", []); + let total = this->get("total"); - if typeof items != "array" && !(items instanceof Arr) { - throw new Exception("Invalid data for pagination"); - } + if typeof total == "null" { + // No total number specified, we need to count items in data + let data = this->get("data", []); - if items instanceof Arr { - let data = items->all(); - } else { - let data = items; + // Check if we can paginate the data + if typeof data == "object" && (data instanceof Arr) { + // Convert to array + let items = data->all(); + } elseif typeof data == "array" { + let items = data; + } else { + throw new Exception("Invalid data for pagination"); + } + + let total = count(items); } let limit = (int) this->get("limit", 10), page = (int) this->get("page", 1), - total = count(items), pages = (int) ceil(total / intval(limit ? limit : 1)); // Make sure page is >= 1 @@ -64,7 +70,10 @@ class Pagination extends Arr let page = 1; } - this->set("items", array_slice(data, limit * (page - 1), limit)); + if !this->has("items") && items { + // Set items on the current page only + this->set("items", array_slice(items, limit * (page - 1), limit)); + } if page < pages { let next = page + 1; From f8f9e09ce9c40175f99fc4309abc25f4927b112d Mon Sep 17 00:00:00 2001 From: mruz Date: Sat, 12 Sep 2020 08:14:24 +0200 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa5d47be..ea6da77a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +------------------------------------------------------------------- +Sat Sep 12 06:11:32 UTC 2020 + +- Ice 1.6.2 + * Model, get related record if field is null fix #275 + * Pagination, calculate if data is array or total is specified #273 + * Url, fixed getStatic() #193 + ------------------------------------------------------------------- Sun May 10 14:32:39 UTC 2020