From 009a5aa11bda606233408cf0bd0c73ea3a731fcb Mon Sep 17 00:00:00 2001 From: BlackbitNeueMedien Date: Tue, 25 Aug 2020 10:24:21 +0200 Subject: [PATCH] Implement Countable interface for all Listings (#6962) * implement Countable interface for all Listings * implement Countable interface for all Listings * implement Countable interface for all Listings * implement Countable interface for all Listings * implement Countable interface for all Listings --- .../CartManager/Cart/Listing/Dao.php | 8 +++++--- .../CartManager/CartCheckoutData/Listing/Dao.php | 8 +++++--- .../CartManager/CartItem/Listing/Dao.php | 8 +++++--- .../PricingManager/Rule/Listing/Dao.php | 9 +++++++++ .../VoucherService/Token/Listing/Dao.php | 9 +++++---- lib/Model/Listing/AbstractListing.php | 15 ++++++++++++++- .../ClassDefinition/CustomLayout/Listing/Dao.php | 9 ++------- models/DataObject/ClassDefinition/Listing/Dao.php | 7 ++----- .../CollectionConfig/Listing/Dao.php | 7 ++----- .../CollectionGroupRelation/Listing/Dao.php | 7 ++----- .../GroupConfig/Listing/Dao.php | 7 ++----- .../Classificationstore/KeyConfig/Listing/Dao.php | 7 ++----- .../KeyGroupRelation/Listing/Dao.php | 7 ++----- .../StoreConfig/Listing/Dao.php | 7 ++----- .../DataObject/QuantityValue/Unit/Listing/Dao.php | 10 ++++++---- models/Element/Note/Listing/Dao.php | 9 ++------- models/Element/Recyclebin/Item/Listing/Dao.php | 7 ++----- models/Element/Tag/Listing/Dao.php | 9 ++------- models/Element/WorkflowState/Listing/Dao.php | 7 ++----- models/Glossary/Listing/Dao.php | 7 ++----- models/GridConfig/Listing/Dao.php | 7 ++----- models/GridConfigFavourite/Listing/Dao.php | 7 ++----- models/GridConfigShare/Listing/Dao.php | 7 ++----- models/ImportConfig/Listing/Dao.php | 7 ++----- models/ImportConfigShare/Listing/Dao.php | 7 ++----- models/Notification/Listing/Dao.php | 5 +++++ models/Redirect/Listing/Dao.php | 7 ++----- models/Schedule/Task/Listing/Dao.php | 9 +++++++++ models/Search/Backend/Data/Listing/Dao.php | 4 +--- models/Site/Listing/Dao.php | 12 ++++++++++++ models/Tool/Email/Blacklist/Listing/Dao.php | 9 ++------- models/Tool/Email/Log/Listing/Dao.php | 7 ++----- models/Tool/Targeting/Rule/Listing/Dao.php | 9 +++++++++ models/Tool/Targeting/TargetGroup/Listing/Dao.php | 12 ++++++++++++ models/Tool/UUID/Listing/Dao.php | 7 ++----- models/User/Listing/AbstractListing/Dao.php | 12 ++++++++++++ models/User/Permission/Definition/Listing/Dao.php | 12 ++++++++++++ models/Version/Listing/Dao.php | 7 ++----- 38 files changed, 167 insertions(+), 144 deletions(-) diff --git a/bundles/EcommerceFrameworkBundle/CartManager/Cart/Listing/Dao.php b/bundles/EcommerceFrameworkBundle/CartManager/Cart/Listing/Dao.php index 515a8b4370d..b0b3cb4948d 100644 --- a/bundles/EcommerceFrameworkBundle/CartManager/Cart/Listing/Dao.php +++ b/bundles/EcommerceFrameworkBundle/CartManager/Cart/Listing/Dao.php @@ -38,9 +38,11 @@ public function load() public function getTotalCount() { - $amount = $this->db->fetchRow('SELECT COUNT(*) as amount FROM `' . \Pimcore\Bundle\EcommerceFrameworkBundle\CartManager\Cart\Dao::TABLE_NAME . '`' . $this->getCondition()); - - return $amount['amount']; + try { + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM `' . \Pimcore\Bundle\EcommerceFrameworkBundle\CartManager\Cart\Dao::TABLE_NAME . '`' . $this->getCondition()); + } catch (\Exception $e) { + return 0; + } } public function setCartClass($cartClass) diff --git a/bundles/EcommerceFrameworkBundle/CartManager/CartCheckoutData/Listing/Dao.php b/bundles/EcommerceFrameworkBundle/CartManager/CartCheckoutData/Listing/Dao.php index 2cbc4ee9418..6291064b03e 100644 --- a/bundles/EcommerceFrameworkBundle/CartManager/CartCheckoutData/Listing/Dao.php +++ b/bundles/EcommerceFrameworkBundle/CartManager/CartCheckoutData/Listing/Dao.php @@ -36,8 +36,10 @@ public function load() public function getTotalCount() { - $amount = $this->db->fetchRow('SELECT COUNT(*) as amount FROM `' . \Pimcore\Bundle\EcommerceFrameworkBundle\CartManager\CartCheckoutData\Dao::TABLE_NAME . '`' . $this->getCondition()); - - return $amount['amount']; + try { + return (int)$this->db->fetchOne('SELECT COUNT(*) FROM `' . \Pimcore\Bundle\EcommerceFrameworkBundle\CartManager\CartCheckoutData\Dao::TABLE_NAME . '`' . $this->getCondition()); + } catch(\Exception $e) { + return 0; + } } } diff --git a/bundles/EcommerceFrameworkBundle/CartManager/CartItem/Listing/Dao.php b/bundles/EcommerceFrameworkBundle/CartManager/CartItem/Listing/Dao.php index 44b75603961..bdbd11b8ada 100644 --- a/bundles/EcommerceFrameworkBundle/CartManager/CartItem/Listing/Dao.php +++ b/bundles/EcommerceFrameworkBundle/CartManager/CartItem/Listing/Dao.php @@ -40,9 +40,11 @@ public function load() public function getTotalCount() { - $amount = $this->db->fetchRow('SELECT COUNT(*) as amount FROM `' . \Pimcore\Bundle\EcommerceFrameworkBundle\CartManager\CartItem\Dao::TABLE_NAME . '`' . $this->getCondition()); - - return $amount['amount']; + try { + return (int)$this->db->fetchOne('SELECT COUNT(*) FROM `' . \Pimcore\Bundle\EcommerceFrameworkBundle\CartManager\CartItem\Dao::TABLE_NAME . '`' . $this->getCondition()); + } catch(\Exception $e) { + return 0; + } } public function getTotalAmount() diff --git a/bundles/EcommerceFrameworkBundle/PricingManager/Rule/Listing/Dao.php b/bundles/EcommerceFrameworkBundle/PricingManager/Rule/Listing/Dao.php index 04a373ba7ca..b90fdd6896a 100644 --- a/bundles/EcommerceFrameworkBundle/PricingManager/Rule/Listing/Dao.php +++ b/bundles/EcommerceFrameworkBundle/PricingManager/Rule/Listing/Dao.php @@ -55,4 +55,13 @@ public function getRuleClass() { return $this->ruleClass; } + + public function getTotalCount() + { + try { + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM `' . \Pimcore\Bundle\EcommerceFrameworkBundle\PricingManager\Rule\Dao::TABLE_NAME . '`' . $this->getCondition()); + } catch (\Exception $e) { + return 0; + } + } } diff --git a/bundles/EcommerceFrameworkBundle/VoucherService/Token/Listing/Dao.php b/bundles/EcommerceFrameworkBundle/VoucherService/Token/Listing/Dao.php index a23d77020d1..48118a11e9e 100644 --- a/bundles/EcommerceFrameworkBundle/VoucherService/Token/Listing/Dao.php +++ b/bundles/EcommerceFrameworkBundle/VoucherService/Token/Listing/Dao.php @@ -42,19 +42,20 @@ public function load() return $tokens; } + /** + * @return int + */ public function getTotalCount() { try { - $amount = (int)$this->db->fetchOne( + return (int)$this->db->fetchOne( 'SELECT COUNT(*) as amount FROM ' . \Pimcore\Bundle\EcommerceFrameworkBundle\VoucherService\Token\Dao::TABLE_NAME . $this->getCondition(), $this->model->getConditionVariables() ); } catch (\Exception $e) { - return false; + return 0; } - - return $amount; } } diff --git a/lib/Model/Listing/AbstractListing.php b/lib/Model/Listing/AbstractListing.php index 0dc93c61094..75caa73612c 100644 --- a/lib/Model/Listing/AbstractListing.php +++ b/lib/Model/Listing/AbstractListing.php @@ -24,7 +24,7 @@ * * @method \Pimcore\Db\ZendCompatibility\QueryBuilder getQuery() */ -abstract class AbstractListing extends AbstractModel implements \Iterator +abstract class AbstractListing extends AbstractModel implements \Iterator, \Countable { /** * @var array @@ -582,4 +582,17 @@ public function rewind() $this->getData(); reset($this->data); } + + /** + * @return int + */ + public function count() + { + $dao = $this->getDao(); + if(!\method_exists($dao, 'getTotalCount')) { + @trigger_error('Listings should implement Countable interface', E_USER_DEPRECATED); + return 0; + } + return $dao->getTotalCount(); + } } diff --git a/models/DataObject/ClassDefinition/CustomLayout/Listing/Dao.php b/models/DataObject/ClassDefinition/CustomLayout/Listing/Dao.php index 983955cb560..b8adca1d57d 100644 --- a/models/DataObject/ClassDefinition/CustomLayout/Listing/Dao.php +++ b/models/DataObject/ClassDefinition/CustomLayout/Listing/Dao.php @@ -45,18 +45,13 @@ public function load() /** * @return int - * - * @todo: $amount could not be defined, so this could cause an issue */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM custom_layouts ' . $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM custom_layouts ' . $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } } diff --git a/models/DataObject/ClassDefinition/Listing/Dao.php b/models/DataObject/ClassDefinition/Listing/Dao.php index 42e0532ced6..3c3ff1c38db 100644 --- a/models/DataObject/ClassDefinition/Listing/Dao.php +++ b/models/DataObject/ClassDefinition/Listing/Dao.php @@ -51,13 +51,10 @@ public function load() */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM classes ' . $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM classes ' . $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } } diff --git a/models/DataObject/Classificationstore/CollectionConfig/Listing/Dao.php b/models/DataObject/Classificationstore/CollectionConfig/Listing/Dao.php index fc47daf4dc3..a52b73c6efd 100644 --- a/models/DataObject/Classificationstore/CollectionConfig/Listing/Dao.php +++ b/models/DataObject/Classificationstore/CollectionConfig/Listing/Dao.php @@ -60,13 +60,10 @@ public function getDataArray() */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM ' . DataObject\Classificationstore\CollectionConfig\Dao::TABLE_NAME_COLLECTIONS . ' '. $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM ' . DataObject\Classificationstore\CollectionConfig\Dao::TABLE_NAME_COLLECTIONS . ' '. $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } } diff --git a/models/DataObject/Classificationstore/CollectionGroupRelation/Listing/Dao.php b/models/DataObject/Classificationstore/CollectionGroupRelation/Listing/Dao.php index f808be1d1b8..e270ed7c5b4 100644 --- a/models/DataObject/Classificationstore/CollectionGroupRelation/Listing/Dao.php +++ b/models/DataObject/Classificationstore/CollectionGroupRelation/Listing/Dao.php @@ -76,13 +76,10 @@ public function getDataArray() */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM ' . DataObject\Classificationstore\CollectionGroupRelation\Dao::TABLE_NAME_RELATIONS . ' '. $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM ' . DataObject\Classificationstore\CollectionGroupRelation\Dao::TABLE_NAME_RELATIONS . ' '. $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } } diff --git a/models/DataObject/Classificationstore/GroupConfig/Listing/Dao.php b/models/DataObject/Classificationstore/GroupConfig/Listing/Dao.php index 6b5cf157c2e..3f6b7182288 100644 --- a/models/DataObject/Classificationstore/GroupConfig/Listing/Dao.php +++ b/models/DataObject/Classificationstore/GroupConfig/Listing/Dao.php @@ -62,13 +62,10 @@ public function getDataArray() */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM ' . DataObject\Classificationstore\GroupConfig\Dao::TABLE_NAME_GROUPS . ' '. $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM ' . DataObject\Classificationstore\GroupConfig\Dao::TABLE_NAME_GROUPS . ' '. $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } } diff --git a/models/DataObject/Classificationstore/KeyConfig/Listing/Dao.php b/models/DataObject/Classificationstore/KeyConfig/Listing/Dao.php index eee01680597..0499b800f8b 100644 --- a/models/DataObject/Classificationstore/KeyConfig/Listing/Dao.php +++ b/models/DataObject/Classificationstore/KeyConfig/Listing/Dao.php @@ -62,14 +62,11 @@ public function getDataArray() */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM ' . DataObject\Classificationstore\KeyConfig\Dao::TABLE_NAME_KEYS . ' '. $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM ' . DataObject\Classificationstore\KeyConfig\Dao::TABLE_NAME_KEYS . ' '. $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } /** diff --git a/models/DataObject/Classificationstore/KeyGroupRelation/Listing/Dao.php b/models/DataObject/Classificationstore/KeyGroupRelation/Listing/Dao.php index 46e8d7c8fa2..3301f701ff1 100644 --- a/models/DataObject/Classificationstore/KeyGroupRelation/Listing/Dao.php +++ b/models/DataObject/Classificationstore/KeyGroupRelation/Listing/Dao.php @@ -95,13 +95,10 @@ public function getDataArray() */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM ' . DataObject\Classificationstore\KeyGroupRelation\Dao::TABLE_NAME_RELATIONS . ' '. $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM ' . DataObject\Classificationstore\KeyGroupRelation\Dao::TABLE_NAME_RELATIONS . ' '. $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } } diff --git a/models/DataObject/Classificationstore/StoreConfig/Listing/Dao.php b/models/DataObject/Classificationstore/StoreConfig/Listing/Dao.php index 99642d6e92f..8f9f15d5687 100644 --- a/models/DataObject/Classificationstore/StoreConfig/Listing/Dao.php +++ b/models/DataObject/Classificationstore/StoreConfig/Listing/Dao.php @@ -60,13 +60,10 @@ public function getDataArray() */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM ' . DataObject\Classificationstore\StoreConfig\Dao::TABLE_NAME_STORES . ' '. $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM ' . DataObject\Classificationstore\StoreConfig\Dao::TABLE_NAME_STORES . ' '. $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } } diff --git a/models/DataObject/QuantityValue/Unit/Listing/Dao.php b/models/DataObject/QuantityValue/Unit/Listing/Dao.php index bdcaa1a6449..534cd13aac5 100644 --- a/models/DataObject/QuantityValue/Unit/Listing/Dao.php +++ b/models/DataObject/QuantityValue/Unit/Listing/Dao.php @@ -47,12 +47,14 @@ public function load() } /** - * @return mixed + * @return int */ public function getTotalCount() { - $amount = $this->db->fetchRow('SELECT COUNT(*) as amount FROM `' . DataObject\QuantityValue\Unit\Dao::TABLE_NAME . '`' . $this->getCondition()); - - return $amount['amount']; + try { + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM '.DataObject\QuantityValue\Unit\Dao::TABLE_NAME.' ' . $this->getCondition(), $this->model->getConditionVariables()); + } catch (\Exception $e) { + return 0; + } } } diff --git a/models/Element/Note/Listing/Dao.php b/models/Element/Note/Listing/Dao.php index 4c464b11419..f45c1195d0f 100644 --- a/models/Element/Note/Listing/Dao.php +++ b/models/Element/Note/Listing/Dao.php @@ -57,18 +57,13 @@ public function loadIdList() /** * @return int - * - * @todo: $amount could not be defined, so this could cause an issue */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM notes ' . $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM notes ' . $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } } diff --git a/models/Element/Recyclebin/Item/Listing/Dao.php b/models/Element/Recyclebin/Item/Listing/Dao.php index 9b8d781aae8..fde3e6205a6 100644 --- a/models/Element/Recyclebin/Item/Listing/Dao.php +++ b/models/Element/Recyclebin/Item/Listing/Dao.php @@ -50,13 +50,10 @@ public function load() */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM recyclebin ' . $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM recyclebin ' . $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } } diff --git a/models/Element/Tag/Listing/Dao.php b/models/Element/Tag/Listing/Dao.php index d655ef8c370..1695bc4b226 100644 --- a/models/Element/Tag/Listing/Dao.php +++ b/models/Element/Tag/Listing/Dao.php @@ -57,18 +57,13 @@ public function loadIdList() /** * @return int - * - * @todo: $amount could not be defined, so this could cause an issue */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM tags ' . $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM tags ' . $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } } diff --git a/models/Element/WorkflowState/Listing/Dao.php b/models/Element/WorkflowState/Listing/Dao.php index ac06b309b9c..579ff13fe38 100644 --- a/models/Element/WorkflowState/Listing/Dao.php +++ b/models/Element/WorkflowState/Listing/Dao.php @@ -50,13 +50,10 @@ public function load() */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM element_workflow_state ' . $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM element_workflow_state ' . $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } } diff --git a/models/Glossary/Listing/Dao.php b/models/Glossary/Listing/Dao.php index 68608a31275..f4b311657ff 100644 --- a/models/Glossary/Listing/Dao.php +++ b/models/Glossary/Listing/Dao.php @@ -60,13 +60,10 @@ public function getDataArray() */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM glossary ' . $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM glossary ' . $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } } diff --git a/models/GridConfig/Listing/Dao.php b/models/GridConfig/Listing/Dao.php index 2f508d64590..8663928e581 100644 --- a/models/GridConfig/Listing/Dao.php +++ b/models/GridConfig/Listing/Dao.php @@ -50,13 +50,10 @@ public function load() */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM gridconfigs ' . $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM gridconfigs ' . $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } } diff --git a/models/GridConfigFavourite/Listing/Dao.php b/models/GridConfigFavourite/Listing/Dao.php index d6ba1166d87..6f08090a403 100644 --- a/models/GridConfigFavourite/Listing/Dao.php +++ b/models/GridConfigFavourite/Listing/Dao.php @@ -51,13 +51,10 @@ public function load() */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM gridconfig_favourites ' . $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM gridconfig_favourites ' . $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } } diff --git a/models/GridConfigShare/Listing/Dao.php b/models/GridConfigShare/Listing/Dao.php index 65a4f596e6d..a431c97d5ae 100644 --- a/models/GridConfigShare/Listing/Dao.php +++ b/models/GridConfigShare/Listing/Dao.php @@ -50,13 +50,10 @@ public function load() */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM gridconfig_shares ' . $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM gridconfig_shares ' . $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } } diff --git a/models/ImportConfig/Listing/Dao.php b/models/ImportConfig/Listing/Dao.php index c5150f0416a..458a6b947a2 100644 --- a/models/ImportConfig/Listing/Dao.php +++ b/models/ImportConfig/Listing/Dao.php @@ -50,13 +50,10 @@ public function load() */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM importconfigs ' . $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM importconfigs ' . $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } } diff --git a/models/ImportConfigShare/Listing/Dao.php b/models/ImportConfigShare/Listing/Dao.php index 7b58857a51e..bd8694f0e61 100644 --- a/models/ImportConfigShare/Listing/Dao.php +++ b/models/ImportConfigShare/Listing/Dao.php @@ -50,13 +50,10 @@ public function load() */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM importconfig_shares ' . $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM importconfig_shares ' . $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } } diff --git a/models/Notification/Listing/Dao.php b/models/Notification/Listing/Dao.php index db20e34800c..6938992f727 100644 --- a/models/Notification/Listing/Dao.php +++ b/models/Notification/Listing/Dao.php @@ -42,6 +42,11 @@ public function count(): int return $count; } + public function getTotalCount() + { + return $this->count(); + } + /** * @return array * diff --git a/models/Redirect/Listing/Dao.php b/models/Redirect/Listing/Dao.php index 79a5879654e..d98f990f2a2 100644 --- a/models/Redirect/Listing/Dao.php +++ b/models/Redirect/Listing/Dao.php @@ -48,13 +48,10 @@ public function load() */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM redirects ' . $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM redirects ' . $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } } diff --git a/models/Schedule/Task/Listing/Dao.php b/models/Schedule/Task/Listing/Dao.php index 33e36a31fce..524b90c57e8 100644 --- a/models/Schedule/Task/Listing/Dao.php +++ b/models/Schedule/Task/Listing/Dao.php @@ -42,4 +42,13 @@ public function load() return $tasks; } + + public function getTotalCount() + { + try { + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM schedule_tasks ' . $this->getCondition(), $this->model->getConditionVariables()); + } catch (\Exception $e) { + return 0; + } + } } diff --git a/models/Search/Backend/Data/Listing/Dao.php b/models/Search/Backend/Data/Listing/Dao.php index f742bead135..67e138428c4 100644 --- a/models/Search/Backend/Data/Listing/Dao.php +++ b/models/Search/Backend/Data/Listing/Dao.php @@ -64,9 +64,7 @@ public function load() */ public function getTotalCount() { - $amount = (int)$this->db->fetchOne('SELECT COUNT(*) as amount FROM search_backend_data' . $this->getCondition() . $this->getGroupBy(), $this->model->getConditionVariables()); - - return $amount; + return (int)$this->db->fetchOne('SELECT COUNT(*) FROM search_backend_data' . $this->getCondition() . $this->getGroupBy(), $this->model->getConditionVariables()); } /** diff --git a/models/Site/Listing/Dao.php b/models/Site/Listing/Dao.php index ea42614e27a..b864ec9938d 100644 --- a/models/Site/Listing/Dao.php +++ b/models/Site/Listing/Dao.php @@ -42,4 +42,16 @@ public function load() return $sites; } + + /** + * @return int + */ + public function getTotalCount() + { + try { + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM sites ' . $this->getCondition(), $this->model->getConditionVariables()); + } catch (\Exception $e) { + return 0; + } + } } diff --git a/models/Tool/Email/Blacklist/Listing/Dao.php b/models/Tool/Email/Blacklist/Listing/Dao.php index 688b4d8ec31..8bfe1ba82e6 100644 --- a/models/Tool/Email/Blacklist/Listing/Dao.php +++ b/models/Tool/Email/Blacklist/Listing/Dao.php @@ -47,18 +47,13 @@ public function load() /** * @return int - * - * @todo: $amount could not be defined, so this could cause an issue */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM email_blacklist ' . $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM email_blacklist ' . $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } } diff --git a/models/Tool/Email/Log/Listing/Dao.php b/models/Tool/Email/Log/Listing/Dao.php index 745d2c33647..75c9874bfd3 100644 --- a/models/Tool/Email/Log/Listing/Dao.php +++ b/models/Tool/Email/Log/Listing/Dao.php @@ -61,13 +61,10 @@ public function getDataArray() */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM email_log ' . $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM email_log ' . $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } } diff --git a/models/Tool/Targeting/Rule/Listing/Dao.php b/models/Tool/Targeting/Rule/Listing/Dao.php index 6b5c8189433..e2f7fd079f0 100644 --- a/models/Tool/Targeting/Rule/Listing/Dao.php +++ b/models/Tool/Targeting/Rule/Listing/Dao.php @@ -41,4 +41,13 @@ public function load() return $targets; } + + public function getTotalCount() + { + try { + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM targeting_rules ' . $this->getCondition(), $this->model->getConditionVariables()); + } catch (\Exception $e) { + return 0; + } + } } diff --git a/models/Tool/Targeting/TargetGroup/Listing/Dao.php b/models/Tool/Targeting/TargetGroup/Listing/Dao.php index ab3dd76587e..c38ce558844 100644 --- a/models/Tool/Targeting/TargetGroup/Listing/Dao.php +++ b/models/Tool/Targeting/TargetGroup/Listing/Dao.php @@ -41,4 +41,16 @@ public function load() return $targetGroups; } + + /** + * @return int + */ + public function getTotalCount() + { + try { + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM targeting_target_groups ' . $this->getCondition(), $this->model->getConditionVariables()); + } catch (\Exception $e) { + return 0; + } + } } diff --git a/models/Tool/UUID/Listing/Dao.php b/models/Tool/UUID/Listing/Dao.php index c400f338c0e..39679822d40 100644 --- a/models/Tool/UUID/Listing/Dao.php +++ b/models/Tool/UUID/Listing/Dao.php @@ -48,13 +48,10 @@ public function load() */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM ' . UUID\Dao::TABLE_NAME .' ' . $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM ' . UUID\Dao::TABLE_NAME .' ' . $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } } diff --git a/models/User/Listing/AbstractListing/Dao.php b/models/User/Listing/AbstractListing/Dao.php index 87537a09a63..31dbdd42adf 100644 --- a/models/User/Listing/AbstractListing/Dao.php +++ b/models/User/Listing/AbstractListing/Dao.php @@ -64,4 +64,16 @@ protected function getCondition() return $condition; } + + /** + * @return int + */ + public function getTotalCount() + { + try { + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM users ' . $this->getCondition(), $this->model->getConditionVariables()); + } catch (\Exception $e) { + return 0; + } + } } diff --git a/models/User/Permission/Definition/Listing/Dao.php b/models/User/Permission/Definition/Listing/Dao.php index be96875c0d2..5f7879e1164 100644 --- a/models/User/Permission/Definition/Listing/Dao.php +++ b/models/User/Permission/Definition/Listing/Dao.php @@ -43,4 +43,16 @@ public function load() return $definitions; } + + /** + * @return int + */ + public function getTotalCount() + { + try { + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM users_permission_definitions ' . $this->getCondition(), $this->model->getConditionVariables()); + } catch (\Exception $e) { + return 0; + } + } } diff --git a/models/Version/Listing/Dao.php b/models/Version/Listing/Dao.php index 3b88e0ef9ee..88ddf2243dc 100644 --- a/models/Version/Listing/Dao.php +++ b/models/Version/Listing/Dao.php @@ -48,13 +48,10 @@ public function load() */ public function getTotalCount() { - $amount = 0; - try { - $amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM versions ' . $this->getCondition(), $this->model->getConditionVariables()); + return (int) $this->db->fetchOne('SELECT COUNT(*) FROM versions ' . $this->getCondition(), $this->model->getConditionVariables()); } catch (\Exception $e) { + return 0; } - - return $amount; } }