Commit 17edd62b authored by Dainis Abols's avatar Dainis Abols
Browse files

Major search changed, additonal language selects. Needs migrations!

parent fb5ad638
...@@ -44,6 +44,18 @@ class FrontController extends ActionController ...@@ -44,6 +44,18 @@ class FrontController extends ActionController
{ {
$this->sourceRepository = $sourceRepository; $this->sourceRepository = $sourceRepository;
} }
/**
* SearchController constructor.
*
* Assign page ID
*/
public function __construct()
{
// Set language data
$this->language = [
'file' => 'LLL:EXT:lu_names/Resources/Private/Language/en_locallang.xlf',
];
}
/** /**
* Detail action * Detail action
...@@ -63,7 +75,13 @@ class FrontController extends ActionController ...@@ -63,7 +75,13 @@ class FrontController extends ActionController
$pageRenderer->addCssFile("EXT:lu_names/Resources/Public/Css/names_style.css"); $pageRenderer->addCssFile("EXT:lu_names/Resources/Public/Css/names_style.css");
// Change language file
if (!empty($this->settings['pluginLanguage'])) {
$this->language['file'] = 'LLL:EXT:lu_names/Resources/Private/Language/'.$this->settings['pluginLanguage'].'_locallang.xlf';
}
$this->view->assignMultiple($assign); $this->view->assignMultiple($assign);
$this->view->assign('language', $this->language);
} }
public function listSourcesAction() public function listSourcesAction()
...@@ -81,7 +99,13 @@ class FrontController extends ActionController ...@@ -81,7 +99,13 @@ class FrontController extends ActionController
$sources = $this->sourceRepository->findAll(); $sources = $this->sourceRepository->findAll();
// Change language file
if (!empty($this->settings['pluginLanguage'])) {
$this->language['file'] = 'LLL:EXT:lu_names/Resources/Private/Language/'.$this->settings['pluginLanguage'].'_locallang.xlf';
}
$this->view->assign('sources', $sources); $this->view->assign('sources', $sources);
$this->view->assign('language', $this->language);
} }
/** /**
......
...@@ -4,6 +4,7 @@ namespace Lu\LuNames\Controller; ...@@ -4,6 +4,7 @@ namespace Lu\LuNames\Controller;
use Lu\LuApi\DataSources\SolrNames; use Lu\LuApi\DataSources\SolrNames;
use Lu\LuApi\Helpers\DataHelper; use Lu\LuApi\Helpers\DataHelper;
use Lu\LuNames\Domain\Model\Location;
use Lu\LuNames\Domain\Model\Person; use Lu\LuNames\Domain\Model\Person;
use Lu\LuNames\Domain\Repository\PersonRepository; use Lu\LuNames\Domain\Repository\PersonRepository;
use Lu\LuNames\Helpers\CacheHelper; use Lu\LuNames\Helpers\CacheHelper;
...@@ -109,7 +110,7 @@ class SearchController extends ActionController ...@@ -109,7 +110,7 @@ class SearchController extends ActionController
private PersonRepository $personRepository; private PersonRepository $personRepository;
/** /**
* MusicController constructor. * SearchController constructor.
* *
* Assign page ID * Assign page ID
*/ */
...@@ -122,6 +123,7 @@ class SearchController extends ActionController ...@@ -122,6 +123,7 @@ class SearchController extends ActionController
'id' => $languageAspect->getId(), 'id' => $languageAspect->getId(),
'iso' => $iso, 'iso' => $iso,
'code' => $iso == 'lv' ? 'lat' : 'eng', 'code' => $iso == 'lv' ? 'lat' : 'eng',
'file' => 'LLL:EXT:lu_names/Resources/Private/Language/en_locallang.xlf',
]; ];
// Set uri builder // Set uri builder
...@@ -148,7 +150,7 @@ class SearchController extends ActionController ...@@ -148,7 +150,7 @@ class SearchController extends ActionController
$cacheHelper = new CacheHelper(); $cacheHelper = new CacheHelper();
if (empty($request['query'])) { if (empty($request['query'])) {
$request = $this->request->getArguments(); $request += $this->request->getArguments();
} }
// Generate letter list // Generate letter list
...@@ -207,6 +209,11 @@ class SearchController extends ActionController ...@@ -207,6 +209,11 @@ class SearchController extends ActionController
// Add custom JS // Add custom JS
$this->renderJs(); $this->renderJs();
// Change language file
if (!empty($this->settings['pluginLanguage'])) {
$this->language['file'] = 'LLL:EXT:lu_names/Resources/Private/Language/'.$this->settings['pluginLanguage'].'_locallang.xlf';
}
// Assign variables // Assign variables
$this->view->assign('query', $cleanQuery); $this->view->assign('query', $cleanQuery);
$this->view->assign('letter', $request['letter'] ?? ''); $this->view->assign('letter', $request['letter'] ?? '');
...@@ -221,6 +228,7 @@ class SearchController extends ActionController ...@@ -221,6 +228,7 @@ class SearchController extends ActionController
$this->view->assign('facets', $facets); $this->view->assign('facets', $facets);
$this->view->assign('letters', $letters); $this->view->assign('letters', $letters);
$this->view->assign('sort', $this->sort); $this->view->assign('sort', $this->sort);
$this->view->assign('language', $this->language);
} }
/** /**
...@@ -439,11 +447,11 @@ class SearchController extends ActionController ...@@ -439,11 +447,11 @@ class SearchController extends ActionController
'maiden_name' => @$item['maiden_name'], 'maiden_name' => @$item['maiden_name'],
], ],
'birth' => [ 'birth' => [
'date' => ($item['year_of_birth'] ?? '').($item['month_of_birth'] ? '-'.sprintf("%02d", $item['month_of_birth']) : '').($item['day_of_birth'] ? '-'.sprintf("%02d", $item['day_of_birth']) : ''), 'date' => (new Person())->makeDater($item['year_of_birth'], $item['month_of_birth'], $item['day_of_birth']),
'day' => @$item['day_of_birth'], 'day' => @$item['day_of_birth'],
'month' => @$item['month_of_birth'], 'month' => @$item['month_of_birth'],
'year' => @$item['year_of_birth'], 'year' => @$item['year_of_birth'],
'location' => @$item['place_of_birth'], 'location' => (new Location())->getTitleByIds(@$item['place_of_birth']),
], ],
'life' => [ 'life' => [
'location' => trim( 'location' => trim(
...@@ -451,16 +459,16 @@ class SearchController extends ActionController ...@@ -451,16 +459,16 @@ class SearchController extends ActionController
($item['prewar_residence'] ? "Pre-war residence: ".$item['prewar_residence'].". " : ''). ($item['prewar_residence'] ? "Pre-war residence: ".$item['prewar_residence'].". " : '').
($item['war_residence'] ? "War residence: ".$item['war_residence'].". " : ''), ". " ($item['war_residence'] ? "War residence: ".$item['war_residence'].". " : ''), ". "
), ),
'region' => @$item['region'], 'region' => (new Location())->getTitleByIds(@$item['region']),
'prewar' => @$item['prewar_residence'], 'prewar' => (new Location())->getTitleByIds(@$item['prewar_residence']),
'war' => @$item['war_residence'], 'war' => (new Location())->getTitleByIds(@$item['war_residence']),
], ],
'death' => [ 'death' => [
'date' => ($item['year_of_death'] ?? '').($item['month_of_death'] ? '-'.sprintf("%02d", $item['month_of_death']) : '').($item['day_of_death'] ? '-'.sprintf("%02d", $item['day_of_death']) : ''), 'date' => (new Person())->makeDater($item['year_of_death'], $item['month_of_death'], $item['day_of_death']),
'day' => @$item['day_of_death'], 'day' => @$item['day_of_death'],
'month' => @$item['month_of_death'], 'month' => @$item['month_of_death'],
'year' => @$item['year_of_death'], 'year' => @$item['year_of_death'],
'location' => @$item['place_of_death'], 'location' => (new Location())->getTitleByIds(@$item['place_of_death']),
], ],
'gender' => @$item['gender'], 'gender' => @$item['gender'],
'family' => [ 'family' => [
......
...@@ -13,6 +13,13 @@ use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; ...@@ -13,6 +13,13 @@ use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
*/ */
class FamilyStatus extends AbstractEntity class FamilyStatus extends AbstractEntity
{ {
/**
* Table name
*
* @var string
*/
protected $table = 'tx_lunames_domain_model_familystatus';
/** /**
* The name of the person * The name of the person
* *
...@@ -37,14 +44,52 @@ class FamilyStatus extends AbstractEntity ...@@ -37,14 +44,52 @@ class FamilyStatus extends AbstractEntity
*/ */
public function getTitleById($uid) public function getTitleById($uid)
{ {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_lunames_domain_model_familystatus'); $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
$queryBuilder->getRestrictions()->removeAll(); $queryBuilder->getRestrictions()->removeAll();
$queryBuilder->select('title') $queryBuilder->select('title')
->from('tx_lunames_domain_model_familystatus') ->from($this->table)
->where('uid = '.$uid); ->where('uid = '.$uid);
// Read and load data // Read and load data
$result = $queryBuilder->execute()->fetch(); $result = $queryBuilder->execute()->fetch();
return $result['title'] ?? ''; return $result['title'] ?? '';
} }
/**
* Fetch all titles title by ids
*
* @param $uid
*
* @return mixed|string
*/
public function getTitleByIds($uid = '')
{
// Return empty, if nothing provided
if (!$uid) {
return '';
}
// Fetch
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
$queryBuilder->getRestrictions()->removeAll();
$queryBuilder->select('title')
->from($this->table)
->where($queryBuilder->expr()->in('uid',$uid));
// Read and load data
$statement = $queryBuilder->execute();
$titles = [];
while ($row = $statement->fetch()) {
$titles[] = $row['title'];
}
// Return back same value if nothing found in database
if (empty($titles)) {
return $uid;
}
// Return implided string version
return implode(', ', $titles);
}
} }
...@@ -7,12 +7,19 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; ...@@ -7,12 +7,19 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
/** /**
* Class Region * Class Location
* *
* @package Lu\LuNames\Domain\Model * @package Lu\LuNames\Domain\Model
*/ */
class Location extends AbstractEntity class Location extends AbstractEntity
{ {
/**
* Table name
*
* @var string
*/
protected $table = 'tx_lunames_domain_model_location';
/** /**
* @var string * @var string
*/ */
...@@ -43,14 +50,51 @@ class Location extends AbstractEntity ...@@ -43,14 +50,51 @@ class Location extends AbstractEntity
*/ */
public function getTitleById($uid) public function getTitleById($uid)
{ {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_lunames_domain_model_location'); $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
$queryBuilder->getRestrictions()->removeAll(); $queryBuilder->getRestrictions()->removeAll();
$queryBuilder->select('title') $queryBuilder->select('title')
->from('tx_lunames_domain_model_location') ->from($this->table)
->where('uid = '.$uid); ->where('uid = '.$uid);
// Read and load data // Read and load data
$result = $queryBuilder->execute()->fetch(); $result = $queryBuilder->execute()->fetch();
return $result['title'] ?? ''; return $result['title'] ?? '';
} }
/**
* Fetch all titles title by ids
*
* @param $uid
*
* @return mixed|string
*/
public function getTitleByIds($uid = '')
{
// Return empty, if nothing provided
if (!$uid) {
return '';
}
// Fetch
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
$queryBuilder->getRestrictions()->removeAll();
$queryBuilder->select('title')
->from($this->table)
->where($queryBuilder->expr()->in('uid', explode(',', $uid)));
// Read and load data
$statement = $queryBuilder->execute();
$titles = [];
while ($row = $statement->fetch()) {
$titles[] = $row['title'];
}
// Return back same value if nothing found in database
if (empty($titles)) {
return $uid;
}
// Return implided string version
return implode(', ', $titles);
}
} }
...@@ -13,6 +13,13 @@ use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; ...@@ -13,6 +13,13 @@ use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
*/ */
class Occupation extends AbstractEntity class Occupation extends AbstractEntity
{ {
/**
* Table name
*
* @var string
*/
protected $table = 'tx_lunames_domain_model_occupation';
/** /**
* The name of the person * The name of the person
* *
...@@ -37,14 +44,51 @@ class Occupation extends AbstractEntity ...@@ -37,14 +44,51 @@ class Occupation extends AbstractEntity
*/ */
public function getTitleById($uid) public function getTitleById($uid)
{ {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_lunames_domain_model_occupation'); $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
$queryBuilder->getRestrictions()->removeAll(); $queryBuilder->getRestrictions()->removeAll();
$queryBuilder->select('title') $queryBuilder->select('title')
->from('tx_lunames_domain_model_location') ->from($this->table)
->where('uid = '.$uid); ->where('uid = '.$uid);
// Read and load data // Read and load data
$result = $queryBuilder->execute()->fetch(); $result = $queryBuilder->execute()->fetch();
return $result['title'] ?? ''; return $result['title'] ?? '';
} }
/**
* Fetch all titles title by ids
*
* @param $uid
*
* @return mixed|string
*/
public function getTitleByIds($uid = '')
{
// Return empty, if nothing provided
if (!$uid) {
return '';
}
// Fetch
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
$queryBuilder->getRestrictions()->removeAll();
$queryBuilder->select('title')
->from($this->table)
->where($queryBuilder->expr()->in('uid',$uid));
// Read and load data
$statement = $queryBuilder->execute();
$titles = [];
while ($row = $statement->fetch()) {
$titles[] = $row['title'];
}
// Return back same value if nothing found in database
if (empty($titles)) {
return $uid;
}
// Return implided string version
return implode(', ', $titles);
}
} }
...@@ -439,9 +439,7 @@ class Person extends AbstractEntity ...@@ -439,9 +439,7 @@ class Person extends AbstractEntity
// Check if ID set // Check if ID set
$name = $items[$k]; $name = $items[$k];
if (is_numeric($name)) { $name = $this->getTitleByFacet($field, $name);
$name = $this->getTitleByFacet($field, $name);
}
$item[] = [ $item[] = [
'uid' => $items[$k], 'uid' => $items[$k],
...@@ -487,16 +485,17 @@ class Person extends AbstractEntity ...@@ -487,16 +485,17 @@ class Person extends AbstractEntity
case 'place_of_death': case 'place_of_death':
case 'prewar_residence': case 'prewar_residence':
case 'war_residence': case 'war_residence':
case 'region':
$myLocation = new Location(); $myLocation = new Location();
$name = $myLocation->getTitleById($uid); $name = $myLocation->getTitleByIds($uid);
break; break;
case 'occupation': case 'occupation':
$myLocation = new Occupation(); $myOccupation = new Occupation();
$name = $myLocation->getTitleById($uid); $name = $myOccupation->getTitleByIds($uid);
break; break;
case 'family_status': case 'family_status':
$myLocation = new FamilyStatus(); $myFamilyStatus = new FamilyStatus();
$name = $myLocation->getTitleById($uid); $name = $myFamilyStatus->getTitleByIds($uid);
break; break;
} }
...@@ -549,4 +548,34 @@ class Person extends AbstractEntity ...@@ -549,4 +548,34 @@ class Person extends AbstractEntity
// Return finalized url // Return finalized url
return $uri['path'].$uri['query']; return $uri['path'].$uri['query'];
} }
/**
* Create visual date output
*
* @param $year
* @param null $mopnth
* @param null $day
*
* @return string
*/
public function makeDater($year, $month = null, $day = null)
{
$date = [];
// Add day
if ($day) {
$date[0] = sprintf("%02d", $day);
}
// Add monthy
if ($day) {
$date[1] = sprintf("%02d", $month);
}
// Add year
$date[2] = $year;
// Return imploded version
return implode('.', $date);
}
} }
...@@ -12,29 +12,28 @@ ...@@ -12,29 +12,28 @@
<el> <el>
<switchableControllerActions> <switchableControllerActions>
<TCEforms> <TCEforms>
<label>LLL:EXT:lu_names/Resources/Private/Language/locallang.xlf:plugin.mode.label</label> <label>LLL:EXT:lu_names/Resources/Private/Language/en_locallang.xlf:plugin.mode.label</label>
<onChange>reload</onChange> <onChange>reload</onChange>
<config> <config>
<type>select</type> <type>select</type>
<renderType>selectSingle</renderType> <renderType>selectSingle</renderType>
<items> <items>
<numIndex index="1"> <numIndex index="1">
<numIndex index="0">LLL:EXT:lu_names/Resources/Private/Language/locallang.xlf:plugin.mode.searchResults</numIndex> <numIndex index="0">LLL:EXT:lu_names/Resources/Private/Language/en_locallang.xlf:plugin.mode.searchResults</numIndex>
<numIndex index="1">Search->list</numIndex> <numIndex index="1">Search->list</numIndex>
</numIndex> </numIndex>
<numIndex index="2"> <numIndex index="2">
<numIndex index="0">LLL:EXT:lu_names/Resources/Private/Language/locallang.xlf:plugin.mode.sources</numIndex> <numIndex index="0">LLL:EXT:lu_names/Resources/Private/Language/en_locallang.xlf:plugin.mode.sources</numIndex>
<numIndex index="1">Front->listSources</numIndex> <numIndex index="1">Front->listSources</numIndex>
</numIndex> </numIndex>
<numIndex index="3"> <numIndex index="3">
<numIndex index="0">LLL:EXT:lu_names/Resources/Private/Language/locallang.xlf:plugin.mode.detail</numIndex> <numIndex index="0">LLL:EXT:lu_names/Resources/Private/Language/en_locallang.xlf:plugin.mode.detail</numIndex>
<numIndex index="1">Front->detail</numIndex> <numIndex index="1">Front->detail</numIndex>
</numIndex> </numIndex>
</items> </items>
</config> </config>
</TCEforms> </TCEforms>
</switchableControllerActions> </switchableControllerActions>
<settings.detailPageId> <settings.detailPageId>
<TCEforms> <TCEforms>
<label>Detail page id</label> <label>Detail page id</label>
...@@ -48,6 +47,29 @@ ...@@ -48,6 +47,29 @@
</config> </config>
</TCEforms> </TCEforms>
</settings.detailPageId> </settings.detailPageId>
<settings.pluginLanguage>
<TCEforms>
<label>LLL:EXT:lu_names/Resources/Private/Language/en_locallang.xlf:plugin.language.label</label>
<config>
<type>select</type>
<renderType>selectSingle</renderType>
<items>
<numIndex index="1">
<numIndex index="0">English</numIndex>