Last active
December 19, 2015 14:59
-
-
Save asagajda/5973304 to your computer and use it in GitHub Desktop.
Add this to repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function getFilteredCount(array $get) | |
{ | |
/* DB table to use */ | |
$tableObjectName = 'YourBundle:Entity'; | |
$cb = $this->getEntityManager() | |
->getRepository($tableObjectName) | |
->createQueryBuilder($alias) | |
->select("count(a.id)"); | |
/* | |
* Filtering | |
* NOTE this does not match the built-in DataTables filtering which does it | |
* word by word on any field. It's possible to do here, but concerned about efficiency | |
* on very large tables, and MySQL's regex functionality is very limited | |
*/ | |
if ( isset($get['sSearch']) && $get['sSearch'] != '' ){ | |
$aLike = array(); | |
for ( $i=0 ; $i<count($aColumns) ; $i++ ){ | |
if ( isset($get['bSearchable_'.$i]) && $get['bSearchable_'.$i] == "true" ){ | |
$aLike[] = $cb->expr()->like($aColumns[$i], '\'%'. $get['sSearch'] .'%\''); | |
} | |
} | |
if(count($aLike) > 0) $cb->andWhere(new Expr\Orx($aLike)); | |
else unset($aLike); | |
} | |
/* | |
* SQL queries | |
* Get data to display | |
*/ | |
$query = $cb->getQuery(); | |
$aResultTotal = $query->getResult(); | |
return $aResultTotal[0][1]; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment