Bolt\Controller\Async\General::popularTags PHP Method

popularTags() public method

Fetch a JSON encoded set of the most popular taxonomy specific tags.
public popularTags ( Request $request, string $taxonomytype ) : Symfony\Component\HttpFoundation\JsonResponse
$request Symfony\Component\HttpFoundation\Request
$taxonomytype string
return Symfony\Component\HttpFoundation\JsonResponse
    public function popularTags(Request $request, $taxonomytype)
    {
        $table = $this->getOption('general/database/prefix');
        $table .= 'taxonomy';
        $query = $this->createQueryBuilder()->select('name, COUNT(slug) AS count')->from($table)->where('taxonomytype = :taxonomytype')->groupBy('name')->orderBy('count', 'DESC')->setMaxResults($request->query->getInt('limit', 20))->setParameters([':taxonomytype' => $taxonomytype]);
        $results = $query->execute()->fetchAll();
        usort($results, function ($a, $b) {
            if ($a['name'] == $b['name']) {
                return 0;
            }
            return $a['name'] < $b['name'] ? -1 : 1;
        });
        return $this->json($results);
    }