Commit ff53131d authored by Dainis Abols's avatar Dainis Abols
Browse files

Major functionality changes and additions. Check incremental git for details

v3.1.3
parent 7a93690c
......@@ -3,6 +3,10 @@
namespace Lu\LuSearch\Controller;
use Lu\LuApi\DataSources\SolrSearch;
use Lu\LuSearch\Domain\Model\Course;
use Lu\LuSearch\Domain\Model\CourseContinue;
use Lu\LuSearch\Domain\Model\Programme;
use Lu\LuSearch\Domain\Model\ProgrammeContinue;
use Lu\LuSearch\Domain\Model\Results;
use Lu\LuSearch\Helpers\DataHelper;
use TYPO3\CMS\Beuser\Domain\Model\BackendUser;
......@@ -86,12 +90,22 @@ class SearchController extends ActionController
*/
public function __construct()
{
global $GLOBALS;
// Set language data
$languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
$context = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Context\Context::class);
$currentLanguageId = $context->getPropertyFromAspect('language', 'id');
if (!empty($GLOBALS['TSFE']->site)) {
$currentLanguage = $GLOBALS['TSFE']->site->getLanguages()[$currentLanguageId];
} else {
$currentLanguage = $GLOBALS['TYPO3_REQUEST']->getAttribute('language');
}
$this->language = [
'id' => $languageAspect->getId(),
'iso' => $GLOBALS['TSFE']->sys_language_isocode,
'code' => $GLOBALS['TSFE']->sys_language_isocode == 'lv' ? 'lat' : 'eng',
'id' => $currentLanguageId,
'name' => $currentLanguage->getTitle(),
'iso' => strtolower($currentLanguage->getTwoLetterIsoCode()) ?? 'en',
'code' => strtolower($currentLanguage->getTwoLetterIsoCode()) ?? 'en',
];
// Set uri builder
......@@ -109,8 +123,8 @@ class SearchController extends ActionController
public function listAction()
{
// Pre-define variables
$data = [];
$request = $_REQUEST;
$data = [];
$request = $_REQUEST;
$currentPage = $request["tx_lusearch_pi1"]['@widget_0']['currentPage'];
// Check queries
......@@ -184,6 +198,8 @@ class SearchController extends ActionController
$this->view->assign('filters', $request['filter']);
$facets = $this->convertFacets($dataFacets['facet_fields'] ?? []);
$this->view->assign('facets', $facets);
$facets_names = $this->getFacetSlugs($facets);
$this->view->assign('facets_names', $facets_names);
$this->view->assign('data', $data);
}
......@@ -201,13 +217,14 @@ class SearchController extends ActionController
{
// Pre-set models and values
$dataHelper = new DataHelper();
$query = $request['query'];
$query = mb_strtolower($request['query']);
$orderBy = $request['orderBy'];
// Search in SOLR
$solr = new SolrSearch();
$solr->setLimit($this->limit);
$solr->setOffset(($this->currentPage - 1) * $this->limit);
$solr->setLanguage($this->language['iso']);
if ($withFacets) {
$solr->useFacets(true);
} else {
......@@ -222,7 +239,25 @@ class SearchController extends ActionController
}
// Set filters
$filters = ['title:"'.$query.'"', 'author:"'.$query.'"', 'body:"'.$query.'"'];
if ($query) {
// Save OR requests!
$query = str_replace(" or ", "||", $query);
$query = str_replace(" ", " AND ", $query);
$query = str_replace("||", " or ", $query);
// Title field CAN NOT be empty
$filters = [
'id:('.$query.')',
'uid:('.$query.')',
'parent_id:('.$query.')',
'title:('.$query.')',
'title_clean:('.$query.')',
'author:('.$query.')',
'author_clean:('.$query.')',
'body:('.$query.')',
'body_clean:('.$query.')',
];
}
$solr->setFilters($filters);
// Set parent IDs
......@@ -236,15 +271,25 @@ class SearchController extends ActionController
if ($this->settings['searchContent']) {
$types[] = 'type:content';
}
// if ($this->settings['searchContacts']) {
// $types[] = 'type:contact';
// }
// if ($this->settings['searchEvents']) {
// $types[] = 'type:event';
// }
if ($this->settings['searchPages']) {
$types[] = 'type:page';
if ($this->settings['searchContacts']) {
$types[] = 'type:contact';
}
if ($this->settings['searchEvents']) {
$types[] = 'type:event';
}
if ($this->settings['searchCourse']) {
$types[] = 'type:course';
}
if ($this->settings['searchCourseContinue']) {
$types[] = 'type:course_continue';
}
if ($this->settings['searchProgram']) {
$types[] = 'type:program';
}
if ($this->settings['searchProgramContinue']) {
$types[] = 'type:program_continue';
}
$solr->setTypes($types);
// Set order
......@@ -287,6 +332,7 @@ class SearchController extends ActionController
$siteData = $this->getParentSite($item['parent_id']);
// Fetch data
$id = $item['uid'];
$uid = str_replace($item['type'].'-', '', $item['id']);
$title = $highlight[$item['id']]['title'][0] ?? $this->clearAndHighlight($item['title'], $cleanQuery, false);
$siteUrl = !empty($siteData) ? 'https://'.$siteData->getBase()->getHost() : '';
......@@ -296,12 +342,13 @@ class SearchController extends ActionController
}
$image = !empty($siteData) ? $this->addNewsImage((int)$uid) : '';
if (empty($image)) {
// If still empty, check page images recursivly
// If still empty, check page images recursively
$image = $this->getParentImage($item['parent_id']);
}
// Add values to array
$result['data'][] = [
'id' => $id,
'uid' => $uid,
'parent_id' => $item['parent_id'],
'type' => $item['type'],
......@@ -309,6 +356,7 @@ class SearchController extends ActionController
'author' => $highlight[$item['id']]['author'][0] ?? $this->clearAndHighlight($item['author'], $cleanQuery),
'title' => $title,
'body' => $highlight[$item['id']]['body'][0] ?? $this->clearAndHighlight($item['body'], $cleanQuery),
'body_original' => $item['body'],
'siteName' => !empty($siteData) ? $this->getSiteName($siteData->getRootPageId()) : '',
'siteUrl' => $siteUrl,
'newsId' => !empty($siteData) ? $this->addNewsIds($siteData->getRootPageId()) : '',
......@@ -317,6 +365,28 @@ class SearchController extends ActionController
];
}
// Make type modifications
foreach ($result['data'] as &$res) {
switch ($res['type']) {
case "course":
$res = Course::buildSearchResult($res);
$res['imgUrl'] = $this->getParentImage($res['parent_id']);
break;
case "course_continue":
$res = CourseContinue::buildSearchResult($res);
$res['imgUrl'] = $this->getParentImage($res['parent_id']);
break;
case "program":
$res = Programme::buildSearchResult($res);
$res['imgUrl'] = $this->getParentImage($res['parent_id']);
break;
case "program_continue":
$res = ProgrammeContinue::buildSearchResult($res);
$res['imgUrl'] = $this->getParentImage($res['parent_id']);
break;
}
}
// Return result
return $result;
}
......@@ -370,7 +440,7 @@ class SearchController extends ActionController
*/
public function buildTree($startingPoint, $depth = 100)
{
GLOBAL $GLOBALS;
global $GLOBALS;
// Get page record for tree starting point
$pageRecord = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord(
......@@ -389,7 +459,7 @@ class SearchController extends ActionController
];
// Create the page tree, from the starting point, 2 levels deep with admin rights
$GLOBALS['BE_USER'] = new BackendUserAuthentication();
$GLOBALS['BE_USER'] = new BackendUserAuthentication();
$GLOBALS['BE_USER']->user['admin'] = 1;
$tree->getTree($startingPoint, $depth, '');
$GLOBALS['BE_USER'] = null;
......@@ -623,7 +693,7 @@ class SearchController extends ActionController
if ($items[$k + 1] > 0) {
$item[] = [
'name' => $items[$k],
'visual' => $myResults->getTitleByFacet($field, $items[$k]),
'visual' => ($items[$k] > 0) ? $myResults->getTitleByFacet($field, $items[$k]) : $items[$k],
'count' => $items[$k + 1],
'url' => $this->generateUrl($field, $items[$k]),
];
......@@ -713,4 +783,25 @@ class SearchController extends ActionController
return $visual;
}
/**
* Convert string to basic slug
*
* @param $facets
*
* @return array
*/
private function getFacetSlugs($facets)
{
$slugs = [];
foreach($facets as $facet) {
foreach($facet['items'] as $item) {
$delimiter = '_';
$str = $item['name'];
$slugs[$item['name']] = strtolower(trim(preg_replace('/[\s-]+/', $delimiter, preg_replace('/[^A-Za-z0-9-]+/', $delimiter, preg_replace('/[&]/', 'and', preg_replace('/[\']/', '', iconv('UTF-8', 'ASCII//TRANSLIT', $str))))), $delimiter));
}
}
return $slugs;
}
}
<?php
namespace Lu\LuSearch\Domain\Model;
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;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
/**
* Class Course
*
* @package Lu\LuSearch\Domain\Model
*/
class Course
{
/**
* 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', 'course_page_id');
$item['parent_id'] = $siteId;
// 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']);
// Build url
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$uriBuilder = $objectManager->get(UriBuilder::class);
$item['siteUrl'] = $uriBuilder
->reset()
->setTargetPageUid($siteId)
->uriFor('detail', ['course' => $item['id']], 'Course', 'lustudycatalogue', 'pi1');
return $item;
}
}
<?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 CourseContinue
*
* @package Lu\LuSearch\Domain\Model
*/
class CourseContinue
{
/**
* 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', 'course_continue_page_id');
$item['parent_id'] = $siteId;
// 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']);
// Build url
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$uriBuilder = $objectManager->get(UriBuilder::class);
$item['siteUrl'] = $uriBuilder
->reset()
->setTargetPageUid($siteId)
->uriFor('detail', ['course' => $item['id']], 'Course', 'lustudycatalogue', 'pi1');
return $item;
}
}
<?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;
}
}
<?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 ProgrammeContinue
*
* @package Lu\LuSearch\Domain\Model
*/
class ProgrammeContinue
{
/**
* 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_continue_page_id');
$item['parent_id'] = $siteId;
// 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['id']], 'Course', 'lustudycatalogue', 'pi1');
return $item;
}
}
......@@ -30,7 +30,7 @@ class Results
$row = $queryBuilder
->select('title')
->from('sys_category')->where(
$queryBuilder->expr()->eq('uid', $uid)
$queryBuilder->expr()->eq('uid', (int)$uid)
)
->execute()->fetch();
break;
......@@ -40,7 +40,7 @@ class Results
$row = $queryBuilder
->select('title')
->from('tx_news_domain_model_tag')->where(
$queryBuilder->expr()->eq('uid', $uid)
$queryBuilder->expr()->eq('uid', (int)$uid)
)
->execute()->fetch();
break;
......
......@@ -95,6 +95,18 @@ class NewContentElementPreviewRenderer implements PageLayoutViewDrawItemHookInte
if ($this->getFieldFromFlexform('settings.searchEvents') == 1) {
$itemContent .= $this->getLanguageService()->sL(self::LLPATH.'plugin.search_events').'<i class="fa fa-check" style="margin-left: 20px;"></i><br/>';
}
if ($this->getFieldFromFlexform('settings.searchCourse') == 1) {
$itemContent .= $this->getLanguageService()->sL(self::LLPATH.'plugin.search_course').'<i class="fa fa-check" style="margin-left: 20px;"></i><br/>';
}
if ($this->getFieldFromFlexform('settings.searchCourseContinue') == 1) {
$itemContent .= $this->getLanguageService()->sL(self::LLPATH.'plugin.search_course_continue').'<i class="fa fa-check" style="margin-left: 20px;"></i><br/>';
}
if ($this->getFieldFromFlexform('settings.searchProgram') == 1) {
$itemContent .= $this->getLanguageService()->sL(self::LLPATH.'plugin.search_program').'<i class="fa fa-check" style="margin-left: 20px;"></i><br/>';
}
if ($this->getFieldFromFlexform('settings.searchProgramContinue') == 1) {
$itemContent .= $this->getLanguageService()->sL(self::LLPATH.'plugin.search_program_continue').'<i class="fa fa-check" style="margin-left: 20px;"></i><br/>';
}
// Make pre format
$itemContent = '<span class="exampleContent"><pre style="white-space:normal; margin-top: 10px;">'.$itemContent.'</pre></span>';
......
......@@ -50,28 +50,58 @@
</config>
</TCEforms>
</settings.searchContent>
<settings.searchPages>
<settings.searchEvents>
<TCEforms>
<label>LLL:EXT:lu_search/Resources/Private/Language/locallang.xlf:plugin.search_pages</label>
<label>LLL:EXT:lu_search/Resources/Private/Language/locallang.xlf:plugin.search_events</label>
<config>
<type>check</type>
<renderType>checkboxToggle</renderType>
<eval>required</eval>
</config>
</TCEforms>
</settings.searchPages>
<settings.searchEvents>
</settings.searchEvents>
<settings.searchCourse>
<TCEforms>
<label>LLL:EXT:lu_search/Resources/Private/Language/locallang.xlf:plugin.search_events</label>
<label>LLL:EXT:lu_search/Resources/Private/Language/locallang.xlf:plugin.search_course</label>
<config>
<type>check</type>
<renderType>checkboxToggle</renderType>
<eval>required</eval>
</config>
</TCEforms>
</settings.searchEvents>
</settings.searchCourse>
<settings.searchCourseContinue>
<TCEforms>
<label>LLL:EXT:lu_search/Resources/Private/Language/locallang.xlf:plugin.search_course_continue</label>
<config>
<type>check</type>
<renderType>checkboxToggle</renderType>
<eval>required</eval>
</config>
</TCEforms>
</settings.searchCourseContinue>
<settings.searchProgram>
<TCEforms>
<label>LLL:EXT:lu_search/Resources/Private/Language/locallang.xlf:plugin.search_program</label>
<config>
<type>check</type>
<renderType>checkboxToggle</renderType>
<eval>required</eval>
</config>
</TCEforms>
</settings.searchProgram>
<settings.searchProgramContinue>
<TCEforms>
<label>LLL:EXT:lu_search/Resources/Private/Language/locallang.xlf:plugin.search_program_continue</label>
<config>
<type>check</type>
<renderType>checkboxToggle</renderType>
<eval>required</eval>
</config>
</TCEforms>
</settings.searchProgramContinue>
</el>
</ROOT>
</sDEF>
</sheets>
</T3DataStructure>
\ No newline at end of file
</T3DataStructure>
......@@ -41,8 +41,17 @@
<trans-unit id="plugin.search_news">
<source><![CDATA[Search in News]]></source>
</trans-unit>
<trans-unit id="plugin.search_pages">
<source><![CDATA[Search in Pages]]></source>
<trans-unit id="plugin.search_course">
<source><![CDATA[Search in Courses]]></source>
</trans-unit>
<trans-unit id="plugin.search_course_continue">
<source><![CDATA[Search in Courses (continuing education)]]></source>
</trans-unit>
<trans-unit id="plugin.search_program">
<source><![CDATA[Search in Programmes]]></source>
</trans-unit>
<trans-unit id="plugin.search_program_continue">
<source><![CDATA[Search in Programmes (continuing education)]]></source>
</trans-unit>
<trans-unit id="results.contacts">
<source><![CDATA[Contacts]]></source>
......@@ -56,8 +65,17 @@
<trans-unit id="results.news">
<source><![CDATA[News]]></source>
</trans-unit>
<trans-unit id="results.page">
<source><![CDATA[Page]]></source>
<trans-unit id="results.course">
<source><![CDATA[Course]]></source>
</trans-unit>
<trans-unit id="results.courseContinue">
<source><![CDATA[Course (continue)]]></source>
</trans-unit>
<trans-unit id="results.programme">
<source><![CDATA[Programme]]></source>
</trans-unit>
<trans-unit id="results.programmeContinue">
<source><![CDATA[Programme (continue)]]></source>
</trans-unit>
<!-- Filters -->
......@@ -79,8 +97,21 @@
<trans-unit id="facet.type.news">
<source><![CDATA[News]]></source>
</trans-unit>
<trans-unit id="facet.type.page">
<source><![CDATA[Page]]></source>
<trans-unit id="facet.type.course">
<source><![CDATA[Course]]></source>
<target><![CDATA[Kurss]]></target>
</trans-unit>