public function lettersUsage(Entity $entity, array $filters = []) { $collumn = $entity->letterCollumn(); $query = $entity->newQuery()->selectRaw("{$collumn}, count(id) as count"); foreach ($filters as $filter) { if ($filter != $this) { $query = $filter->applyFilterToQuery($query); } } $fetched = $query->groupBy($collumn)->orderBy($collumn)->lists('count', $collumn); $result = []; foreach ($fetched as $letter => $count) { preg_match('/(.)/iu', $letter, $match); $letter = mb_strtoupper($match[1]); $result[$letter] = (isset($result[$letter]) ? $result[$letter] : 0) + $count; } return $result; }
public function applyOrdering(Entity $entity) { $entity->underlyingQuery()->orderBy($this->collumn, $this->direction); }
public function applyFilter(Entity $entity) { $entity->underlyingQuery($this->applyFilterToQuery($entity->underlyingQuery())); }