Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Countable interface for all Listings #6962

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 $this->db->fetchOne('SELECT COUNT(*) FROM `' . \Pimcore\Bundle\EcommerceFrameworkBundle\CartManager\CartCheckoutData\Dao::TABLE_NAME . '`' . $this->getCondition());
BlackbitDevs marked this conversation as resolved.
Show resolved Hide resolved
} 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 $this->db->fetchOne('SELECT COUNT(*) FROM `' . \Pimcore\Bundle\EcommerceFrameworkBundle\CartManager\CartItem\Dao::TABLE_NAME . '`' . $this->getCondition());
BlackbitDevs marked this conversation as resolved.
Show resolved Hide resolved
} 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;
}
}
12 changes: 11 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 @@ -571,4 +571,14 @@ public function rewind()
$this->getData();
reset($this->data);
}

public function count()
dvesh3 marked this conversation as resolved.
Show resolved Hide resolved
{
$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;
}
}
}
2 changes: 1 addition & 1 deletion models/Dependency.php
Expand Up @@ -118,7 +118,7 @@ public function getRequires($offset = null, $limit = null)
* @param int|null $offset
* @param int|null $limit
*
* @return array
* @return array{type: string, id: int}
BlackbitDevs marked this conversation as resolved.
Show resolved Hide resolved
*/
public function getRequiredBy($offset = null, $limit = null)
{
Expand Down
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;
}
}
2 changes: 1 addition & 1 deletion models/GridConfigShare/Listing/Dao.php
Expand Up @@ -53,7 +53,7 @@ public function getTotalCount()
$amount = 0;

try {
$amount = (int) $this->db->fetchOne('SELECT COUNT(*) as amount FROM gridconfig_shares ' . $this->getCondition(), $this->model->getConditionVariables());
$amount = (int) $this->db->fetchOne('SELECT COUNT(*) FROM gridconfig_shares ' . $this->getCondition(), $this->model->getConditionVariables());
BlackbitDevs marked this conversation as resolved.
Show resolved Hide resolved
} catch (\Exception $e) {
}

Expand Down