Newscoop\Entity\Repository\DatatableRepository::getData PHP Method

getData() public method

Get data for table
public getData ( array $params, array $cols ) : array
$params array
$cols array
return array
    public function getData(array $params, array $cols)
    {
        static $default_params = array('iDisplayStart' => 0, 'iDisplayLength' => 25);
        $params += $default_params;
        $qb = $this->repository->createQueryBuilder('e');
        if (!empty($params['sSearch'])) {
            $qb->where($this->buildWhere($cols, $params));
        }
        // sort
        foreach (array_keys($cols) as $id => $property) {
            if (!is_string($property)) {
                // not sortable
                continue;
            }
            if (isset($params["iSortCol_{$id}"])) {
                $dir = $params["sSortDir_{$id}"] ?: 'asc';
                $qb->orderBy("e.{$property}", $dir);
            }
        }
        // limit
        $qb->setFirstResult((int) $params['iDisplayStart'])->setMaxResults((int) $params['iDisplayLength']);
        return $qb->getQuery()->getResult();
    }