public function getRows($limit, $offset, $orderBy = null, $sord = null, array $filters = array(), $nodeId = null, $nodeLevel = null, $exporting)
{
$orderByRaw = null;
if (!is_null($orderBy) || !is_null($sord)) {
$found = false;
$pos = strpos($orderBy, 'desc');
if ($pos !== false) {
$found = true;
} else {
$pos = strpos($orderBy, 'asc');
if ($pos !== false) {
$found = true;
}
}
if ($found) {
$orderBy = rtrim($orderBy);
if (substr($orderBy, -1) == ',') {
$orderBy = substr($orderBy, 0, -1);
} else {
$orderBy .= " {$sord}";
}
$orderByRaw = $orderBy;
} else {
$this->orderBy = array(array($orderBy, $sord));
}
}
if ($limit == 0) {
$limit = 1;
}
if (empty($orderByRaw)) {
$orderByRaw = array();
foreach ($this->orderBy as $orderBy) {
array_push($orderByRaw, implode(' ', $orderBy));
}
$orderByRaw = implode(',', $orderByRaw);
}
$rows = $this->Database->whereNested(function ($query) use($filters, $nodeId, $exporting) {
foreach ($filters as $filter) {
if ($filter['op'] == 'is in') {
$query->whereIn($filter['field'], explode(',', $filter['data']));
continue;
}
if ($filter['op'] == 'is not in') {
$query->whereNotIn($filter['field'], explode(',', $filter['data']));
continue;
}
if ($filter['op'] == 'is null') {
$query->whereNull($filter['field']);
continue;
}
if ($filter['op'] == 'is not null') {
$query->whereNotNull($filter['field']);
continue;
}
if ($filter['op'] == 'between') {
if (strpos($filter['data'], ' - ') !== false) {
list($from, $to) = explode(' - ', $filter['data'], 2);
if (!$from or !$to) {
throw new \Exception('Invalid between format');
}
} else {
throw new \Exception('Invalid between format');
}
if ($from == $to) {
$query->where($filter['field'], $from);
} else {
//$query->whereBetween($filter['field'], array($from, $to));
$query->where($filter['field'], '>=', $from);
$query->where($filter['field'], '<=', $to);
}
continue;
}
$query->where($filter['field'], $filter['op'], $filter['data']);
}
if ($this->treeGrid && !$exporting) {
if (empty($nodeId)) {
$query->whereNull($this->parentColumn);
} else {
$query->where($this->parentColumn, '=', $nodeId);
}
}
})->take($limit)->skip($offset)->orderByRaw($orderByRaw)->get($this->visibleColumns);
if (!is_array($rows)) {
$rows = $rows->toArray();
}
foreach ($rows as &$row) {
$row = (array) $row;
if ($this->treeGrid && !$exporting) {
if (is_null($nodeLevel)) {
$row['level'] = 0;
} else {
$row['level'] = $nodeLevel + 1;
}
if ($row[$this->leafColumn] == 0) {
$row[$this->leafColumn] = false;
} else {
$row[$this->leafColumn] = true;
}
}
}
return $rows;
}