Skip to content

Commit

Permalink
Implement Countable interface for all Listings (#6962)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
BlackbitDevs committed Aug 25, 2020
1 parent 4182af0 commit 009a5aa
Show file tree
Hide file tree
Showing 38 changed files with 167 additions and 144 deletions.
Expand Up @@ -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)
Expand Down
Expand Up @@ -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;
}
}
}
Expand Up @@ -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()
Expand Down
Expand Up @@ -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;
}
}
}
Expand Up @@ -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;
}
}
15 changes: 14 additions & 1 deletion lib/Model/Listing/AbstractListing.php
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
}
Expand Up @@ -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;
}
}
7 changes: 2 additions & 5 deletions models/DataObject/ClassDefinition/Listing/Dao.php
Expand Up @@ -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;
}
}
Expand Up @@ -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;
}
}
Expand Up @@ -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;
}
}
Expand Up @@ -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;
}
}
Expand Up @@ -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;
}

/**
Expand Down
Expand Up @@ -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;
}
}
Expand Up @@ -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;
}
}
10 changes: 6 additions & 4 deletions models/DataObject/QuantityValue/Unit/Listing/Dao.php
Expand Up @@ -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;
}
}
}
9 changes: 2 additions & 7 deletions models/Element/Note/Listing/Dao.php
Expand Up @@ -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;
}
}
7 changes: 2 additions & 5 deletions models/Element/Recyclebin/Item/Listing/Dao.php
Expand Up @@ -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;
}
}
9 changes: 2 additions & 7 deletions models/Element/Tag/Listing/Dao.php
Expand Up @@ -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;
}
}
7 changes: 2 additions & 5 deletions models/Element/WorkflowState/Listing/Dao.php
Expand Up @@ -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;
}
}
7 changes: 2 additions & 5 deletions models/Glossary/Listing/Dao.php
Expand Up @@ -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;
}
}
7 changes: 2 additions & 5 deletions models/GridConfig/Listing/Dao.php
Expand Up @@ -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;
}
}
7 changes: 2 additions & 5 deletions models/GridConfigFavourite/Listing/Dao.php
Expand Up @@ -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;
}
}

0 comments on commit 009a5aa

Please sign in to comment.