public function getData(array $p_params, array $p_cols)
{
$qb = $this->createQueryBuilder('e');
$qb->from('Newscoop\\Entity\\Comment\\Commenter', 'c')->from('Newscoop\\Entity\\Article', 'a');
$andx = $qb->expr()->andx();
$andx->add($qb->expr()->eq('e.language', new Expr\Literal('a.language')));
$andx->add($qb->expr()->eq('e.thread', new Expr\Literal('a.number')));
$andx->add($qb->expr()->eq('e.commenter', new Expr\Literal('c.id')));
if (!empty($p_params['sSearch'])) {
$this->buildWhere($p_cols, $p_params['sSearch'], $qb, $andx);
}
if (!empty($p_params['sFilter'])) {
$this->buildFilter($p_cols, $p_params['sFilter'], $qb, $andx);
}
// sort
if (isset($p_params["iSortCol_0"])) {
$cols = array_keys($p_cols);
$sortId = $p_params["iSortCol_0"];
$sortBy = $cols[$sortId];
$dir = $p_params["sSortDir_0"] ?: 'asc';
switch ($sortBy) {
case 'commenter':
$qb->orderBy("c.name", $dir);
break;
case 'thread':
$qb->orderBy("a.name", $dir);
break;
case 'threadorder':
$qb->orderBy("e.thread_order", $dir);
break;
case 'comment':
case 'index':
$qb->orderBy("e.time_created", $dir);
break;
default:
$qb->orderBy("e." . $sortBy, $dir);
}
}
$qb->where($andx);
// limit
if (isset($p_params['iDisplayLength'])) {
$qb->setFirstResult((int) $p_params['iDisplayStart'])->setMaxResults((int) $p_params['iDisplayLength']);
}
return $qb->getQuery()->getResult();
}