Skip to content

Commit

Permalink
Merge pull request #2 from Intracto/feature/mongo-odm-2.0
Browse files Browse the repository at this point in the history
Make bundle compatible with doctrine/mongodb-odm 2.0
  • Loading branch information
wimme002 authored Jan 31, 2020
2 parents f343a09 + cea2878 commit 4716ebc
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Doctrine/ODM/DataTablesRepositoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Doctrine\ODM\MongoDB\Query\Builder;
use Intracto\DataTables\Columns;
use Intracto\DataTables\Parameters;
use MongoDB\BSON\Regex;

trait DataTablesRepositoryTrait
{
Expand All @@ -22,15 +23,15 @@ trait DataTablesRepositoryTrait
*/
public function getDataTablesTotalRecordsCount(Parameters $parameters, Columns $columns)
{
return $this->createQueryBuilder()->getQuery()->execute()->count();
return iterator_count($this->createQueryBuilder()->getQuery()->execute());
}

/**
* {@inheritdoc}
*/
public function getDataTablesFilteredRecordsCount(Parameters $parameters, Columns $columns)
{
return $this->getFilteredDataTablesQb($parameters, $columns)->getQuery()->execute()->count();
return iterator_count($this->getFilteredDataTablesQb($parameters, $columns)->getQuery()->execute());
}

/**
Expand Down Expand Up @@ -85,7 +86,7 @@ private function addFilters(Parameters $parameters, Builder $qb)
if (is_callable($value)) {
$value($qb);
} else {
$qb->field($field)->equals(new \MongoRegex(sprintf('/%s/i', $value)));
$qb->field($field)->equals(new Regex($value, 'i'));
}
}
}
Expand All @@ -108,7 +109,7 @@ private function addSearch(Parameters $parameters, Columns $columns, Builder $qb
$expression = $qb->expr();

foreach ($columns->getSearchableFields() as $field) {
$searchExpr = $qb->expr()->field($field)->equals(new \MongoRegex(sprintf('/%s/i', $searchString)));
$searchExpr = $qb->expr()->field($field)->equals(new Regex($searchString, 'i'));
$expression->addOr($searchExpr);
}

Expand Down

0 comments on commit 4716ebc

Please sign in to comment.