Programme.php 1.65 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
53
<?php

namespace Lu\LuSearch\Domain\Model;

use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Frontend\Page\PageRepository;

/**
 * Class Programme
 *
 * @package Lu\LuSearch\Domain\Model
 */
class Programme
{
    /**
     * Rebuild search preview
     *
     * @param $item
     *
     * @return array
     */
    static public function buildSearchResult($item)
    {
        // Fetch site ID from config
        $siteId = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('lu_search', 'programme_page_id');
        $item['parent_id'] = $siteId;
        $item['uid'] = str_replace(['program_lv_', 'program_en_'], null, $item['uid']);
        
        // Reassign author and site name
        $pageRepository = GeneralUtility::makeInstance(PageRepository::class);
        $page           = $pageRepository->getPage($siteId, false);
        $item['author'] = $item['siteName'] = $page['title'];

        // Reset date published to now
        $item['date_published'] = date("Y-m-d H:i", $page['crdate']);

        // Change body back to original
        $item['body'] = $item['body_original'];

        // Build url
        $objectManager   = GeneralUtility::makeInstance(ObjectManager::class);
        $uriBuilder      = $objectManager->get(UriBuilder::class);
        $item['siteUrl'] = $uriBuilder
            ->reset()
            ->setTargetPageUid($siteId)
            ->uriFor('detail', ['program' => $item['uid']], 'Course', 'lustudycatalogue', 'pi1');

        return $item;
    }
}