Results.php 1.51 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php

namespace Lu\LuSearch\Domain\Model;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;

/**
 * Class Results
 *
 * @package Lu\LuSearch\Domain\Model
 */
class Results
{
    /**
     * Fetch title by uid and field
     *
     * @param $field
     * @param $uid
     *
     * @return mixed|string
     */
    public function getTitleByFacet($field, $uid)
    {
        // Fetch titles
        switch ($field) {
            case 'category':
                // Fetch category name
                $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_category')->createQueryBuilder();
                $row          = $queryBuilder
                    ->select('title')
                    ->from('sys_category')->where(
                        $queryBuilder->expr()->eq('uid', $uid)
                    )
                    ->execute()->fetch();
                break;
            case 'tag':
                // Fetch category name
                $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tx_news_domain_model_tag')->createQueryBuilder();
                $row          = $queryBuilder
                    ->select('title')
                    ->from('tx_news_domain_model_tag')->where(
                        $queryBuilder->expr()->eq('uid', $uid)
                    )
                    ->execute()->fetch();
                break;
        }

        // Return
        return $row['title'] ?? $uid;
    }
}