Commit 015832d4 authored by Dainis Abols's avatar Dainis Abols
Browse files

TYPO3 v10 compatability

v2.7.3
parent 48057387
......@@ -267,7 +267,7 @@ class LuisLibrary
file_put_contents($imagePath, $imageData);
// Check what storage to use
$resourceFactory = ResourceFactory::getInstance();
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
if ($this->conf['extraImagesStorage'] > 0) {
$storage = $resourceFactory->getStorageObject(4);
} else {
......@@ -330,7 +330,7 @@ class LuisLibrary
// @TODO: Add log here
$resourceFactory = ResourceFactory::getInstance();
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
if ($this->conf['extraImagesStorage'] > 0) {
$storage = $resourceFactory->getStorageObject($this->conf['extraImagesStorage']);
} else {
......@@ -343,7 +343,7 @@ class LuisLibrary
// Get user object
$user = $UserModel->getUserData($this->username);
$resourceFactory = ResourceFactory::getInstance();
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
$fileObject = $resourceFactory->getFileObject($newFile->getUid());
$contentElement = BackendUtility::getRecord(
'be_users',
......
......@@ -15,7 +15,6 @@ use Lu\LuApi\Models\Namedays;
use Lu\LuApi\Models\Programs;
use Lu\LuApi\Models\ProgramsContinue;
use Lu\LuApi\Models\Purchases;
use Lu\LuApi\Models\Search;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
......@@ -113,12 +112,10 @@ class ExchangeController extends ActionController
break;
/* SELF ENDING ROUTES */
case "download": FileDownloader::fetch(); break; // Direct file download from type and id
case "qrcode": QRCodeGenerator::create(); break; // QR Code generator from URL
/* BASIC ROUTES */
case "course": $data = Courses::fetch(); break; // Study catalogue course
case "course-continue": $data = CoursesContinue::fetch(); break; // Study catalogue course continue
case "program": $data = Programs::fetch(); break; // Study catalogue program
......@@ -129,13 +126,11 @@ class ExchangeController extends ActionController
case "naba-store": $data = NabaStore::fetch(); $view = $data['view']; break; // Call live song storage
/* VIEWABLE ROUTES */
case "tornkalns-lessons":
case "dabas-maja": $data = Lessons::fetch(1859); $view = $data['view']; break; // Dabas maja's lessons and auditoriums
case "zinatnu-maja": $data = Lessons::fetch(2219); $view = $data['view']; break; // Zinatnu maja's lessons and auditoriums
/* EMAIL CHECK ROUTE */
case "email": $data = Email::fetch(); $view = $data['view']; break; // Detect show gmail or webmail
}
......@@ -148,4 +143,4 @@ class ExchangeController extends ActionController
}
}
}
}
\ No newline at end of file
}
......@@ -124,6 +124,13 @@ class SolrLibrary
*/
private $sort_field;
/**
* Advanced sort fields
*
* @var array
*/
private $sort = [];
/**
* Default sort order
*
......@@ -460,6 +467,21 @@ class SolrLibrary
return $this;
}
/**
* Set advanced sort
*
* @param $sortField
* @param $sortOrder
*
* @return $this
*/
public function sort($sortField, $sortOrder)
{
$this->sort[$sortField] = $sortOrder;
return $this;
}
/**
* Build and execute the Solr query
*
......@@ -590,12 +612,18 @@ class SolrLibrary
// @TODO: Add 'hl.q='.$this->hlQuery'`to this
}
// Add sort
if ($this->sort_field) {
$SolrQuery->addSortField($this->sort_field, $this->sort_order);
}
// Add complex sort
if ($this->sort) {
foreach($this->sort as $sortField => $sortOrder) {
$SolrQuery->addSortField($sortField, 'asc' ? \SolrQuery::ORDER_ASC : \SolrQuery::ORDER_DESC);
}
}
return $SolrQuery;
}
......
......@@ -28,6 +28,20 @@ class SolrNames
*/
private $filters = [];
/**
* Set sort
*
* @var array
*/
private $sort = [];
/**
* Facet filters
*
* @var array
*/
private $facet_field = [];
/**
* Types request
*
......@@ -75,6 +89,29 @@ class SolrNames
$this->filters = $filters;
}
/**
* Sets sort
*
* @param string $sortField
* @param string $sortOrder
*/
public function sort(string $sortField, string $sortOrder)
{
if (!empty($sortField)) {
$this->sort[$sortField] = $sortOrder;
}
}
/**
* Sets filters
*
* @param array $filters
*/
public function setFacetFilter($key, $value)
{
$this->facet_field[$key] = $value;
}
/**
* Set limit
*
......@@ -154,6 +191,40 @@ class SolrNames
$SolrLibrary->limit($this->limit);
$SolrLibrary->offset($this->offset);
// Check facet request
if ($this->facet) {
// Set facet usage
$SolrLibrary->facet([
'field' => [
'gender',
'family_status',
'region',
'place_of_birth',
'place_of_death',
'prewar_residence',
'war_residence',
'occupation',
],
'limit' => -1,
]);
}
// Add facet where
if (!empty($this->facet_field)) {
foreach ($this->facet_field as $field=>$value) {
$value = array_map(function($field) { return $field.$value; }, $value);
$value = $field.':'.implode(' AND '.$field.':', $value);
$SolrLibrary->fq($value);
}
}
// Set sort
if ($this->sort) {
foreach($this->sort as $sortField => $sortOrder) {
$SolrLibrary->sort($sortField, $sortOrder);
}
}
// Fetch results
$result = $SolrLibrary->execute($fullReponse);
$data = !empty($result['data']) ? $result['data'] : [];
......
......@@ -50,6 +50,20 @@ class SolrSearch
*/
private $facet = false;
/**
* Facet filters
*
* @var array
*/
private $facet_field = [];
/**
* Order type
*
* @var string
*/
private $order = 'default';
/**
* Highlist status
*
......@@ -154,6 +168,26 @@ class SolrSearch
$this->facet = $facet;
}
/**
* Sets filters
*
* @param array $filters
*/
public function setFacetFilter($key, $value)
{
$this->facet_field[$key] = $value;
}
/**
* Sets order
*
* @param string $order
*/
public function setOrder($order)
{
$this->order = $order;
}
/**
* Set highlight options diveded by |
* If non provided default <em>|</em> is used
......@@ -189,13 +223,16 @@ class SolrSearch
$SolrLibrary = new SolrLibrary();
// Execute request
// $SolrLibrary->select(['*'])
$SolrLibrary->select(['*'])
->from($this->solrCore)
->where('*', '*')
// ->orderBy('date_published', 'desc')
->limit($SolrLibrary::MAXINT);
// Check sorting request
if ($this->order != 'default') {
$SolrLibrary->orderBy('date_published', $this->order == 'asc' ? 'asc' : 'desc');
}
// Build request with filters and types
if (!empty($this->filters) && !empty($this->types)) {
$SolrLibrary->whereStr("(".implode(" OR ", $this->filters).")");
......@@ -207,45 +244,53 @@ class SolrSearch
$SolrLibrary->whereStr("parent_id:(".implode(" OR ", $this->parentIDs).")");
}
// // Filter acceptance date
// if (!empty($this->filters['accepted_date_from']) || !empty($this->filters['accepted_date_till'])) {
// $dateFilter = '[';
// if (!empty($this->filters['accepted_date_from'])) {
// $dateFrom = new \DateTime($this->filters['accepted_date_from']);
// $dateFilter .= $dateFrom->format('Y-m-d').'T00:00:00Z';
// } else {
// $dateFilter .= '*';
// }
// $dateFilter .= ' TO ';
// if (!empty($this->filters['accepted_date_till'])) {
// $dateTill = new \DateTime($this->filters['accepted_date_till']);
// $dateFilter .= $dateTill->format('Y-m-d').'T23:59:59Z';
// } else {
// $dateFilter .= '*';
// }
// $dateFilter .= ']';
// $SolrLibrary->where('date_accepted', $dateFilter);
// }
// // Check facet request
// if ($this->facet) {
// // Set facet usage
// $SolrLibrary->facet([
// 'field' => [
// 'rikojuma_dokum',
// 'document_type',
// 'issuer',
// ],
// 'limit' => -1,
// ]);
// }
//
// // Add facet where
// if (!empty($this->filters['facet_field'])) {
// foreach ($this->filters['facet_field'] as $field=>$value) {
// $SolrLibrary->fq($field.':"'.$value.'"');
// }
// }
// Filter acceptance date
if (!empty($this->filters['published_date_from']) || !empty($this->filters['published_date_till'])) {
$dateFilter = '[';
if (!empty($this->filters['published_date_from'])) {
$dateFrom = new \DateTime($this->filters['published_date_from']);
$dateFilter .= $dateFrom->format('Y-m-d').'T00:00:00Z';
} else {
$dateFilter .= '*';
}
$dateFilter .= ' TO ';
if (!empty($this->filters['published_date_till'])) {
$dateTill = new \DateTime($this->filters['published_date_till']);
$dateFilter .= $dateTill->format('Y-m-d').'T23:59:59Z';
} else {
$dateFilter .= '*';
}
$dateFilter .= ']';
$SolrLibrary->where('date_published', $dateFilter);
}
// Check facet request
if ($this->facet) {
// Set facet usage
$SolrLibrary->facet([
'field' => [
'type',
'tag',
'category',
],
'limit' => -1,
]);
}
// Add facet where
if (!empty($this->facet_field)) {
foreach ($this->facet_field as $field=>$value) {
// Required for facets with multiple words and special characters
foreach($value as &$val) {
$val = '"'.$val.'"';
}
// Maps array to single values
$value = array_map(function($field) { return $field.$value; }, $value);
$value = $field.':'.implode(' AND '.$field.':', $value);
$SolrLibrary->fq($value);
}
}
// Set highlights
if ($this->highlight == "on") {
......
......@@ -33,10 +33,11 @@ class Courses implements RestModel
{
// Set language data
$languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
$iso = $GLOBALS['TYPO3_REQUEST']->getAttribute('language')->getTwoLetterIsoCode();
$this->language = [
'id' => $languageAspect->getId(),
'iso' => $GLOBALS['TSFE']->sys_language_isocode,
'code' => $GLOBALS['TSFE']->sys_language_isocode == 'lv' ? 'lat' : 'eng',
'iso' => $iso,
'code' => $iso == 'lv' ? 'lat' : 'eng',
];
}
......
......@@ -33,10 +33,11 @@ class CoursesContinue implements RestModel
{
// Set language data
$languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
$iso = $GLOBALS['TYPO3_REQUEST']->getAttribute('language')->getTwoLetterIsoCode();
$this->language = [
'id' => $languageAspect->getId(),
'iso' => $GLOBALS['TSFE']->sys_language_isocode,
'code' => $GLOBALS['TSFE']->sys_language_isocode == 'lv' ? 'lat' : 'eng',
'iso' => $iso,
'code' => $iso == 'lv' ? 'lat' : 'eng',
];
}
......
......@@ -49,10 +49,11 @@ class Email implements RestModel
{
// Set language data
$languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
$iso = $GLOBALS['TYPO3_REQUEST']->getAttribute('language')->getTwoLetterIsoCode();
$this->language = [
'id' => $languageAspect->getId(),
'iso' => $GLOBALS['TSFE']->sys_language_isocode,
'code' => $GLOBALS['TSFE']->sys_language_isocode == 'lv' ? 'lat' : 'eng',
'iso' => $iso,
'code' => $iso == 'lv' ? 'lat' : 'eng',
];
}
......
......@@ -35,10 +35,11 @@ class Lessons implements RestModel
{
// Set language data
$languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
$iso = $GLOBALS['TYPO3_REQUEST']->getAttribute('language')->getTwoLetterIsoCode();
$this->language = [
'id' => $languageAspect->getId(),
'iso' => $GLOBALS['TSFE']->sys_language_isocode,
'code' => $GLOBALS['TSFE']->sys_language_isocode == 'lv' ? 'lat' : 'eng',
'iso' => $iso,
'code' => $iso == 'lv' ? 'lat' : 'eng',
];
}
......
......@@ -34,10 +34,11 @@ class NabaLive implements RestModel
{
// Set language data
$languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
$iso = $GLOBALS['TYPO3_REQUEST']->getAttribute('language')->getTwoLetterIsoCode();
$this->language = [
'id' => $languageAspect->getId(),
'iso' => $GLOBALS['TSFE']->sys_language_isocode,
'code' => $GLOBALS['TSFE']->sys_language_isocode == 'lv' ? 'lat' : 'eng',
'iso' => $iso,
'code' => $iso == 'lv' ? 'lat' : 'eng',
];
}
......
......@@ -34,10 +34,11 @@ class NabaStore implements RestModel
{
// Set language data
$languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
$iso = $GLOBALS['TYPO3_REQUEST']->getAttribute('language')->getTwoLetterIsoCode();
$this->language = [
'id' => $languageAspect->getId(),
'iso' => $GLOBALS['TSFE']->sys_language_isocode,
'code' => $GLOBALS['TSFE']->sys_language_isocode == 'lv' ? 'lat' : 'eng',
'iso' => $iso,
'code' => $iso == 'lv' ? 'lat' : 'eng',
];
}
......
......@@ -35,10 +35,11 @@ class Namedays implements RestModel
{
// Set language data
$languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
$iso = $GLOBALS['TYPO3_REQUEST']->getAttribute('language')->getTwoLetterIsoCode();
$this->language = [
'id' => $languageAspect->getId(),
'iso' => $GLOBALS['TSFE']->sys_language_isocode,
'code' => $GLOBALS['TSFE']->sys_language_isocode == 'lv' ? 'lat' : 'eng',
'iso' => $iso,
'code' => $iso == 'lv' ? 'lat' : 'eng',
];
}
......
......@@ -33,10 +33,11 @@ class Programs implements RestModel
{
// Set language data
$languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
$iso = $GLOBALS['TYPO3_REQUEST']->getAttribute('language')->getTwoLetterIsoCode();
$this->language = [
'id' => $languageAspect->getId(),
'iso' => $GLOBALS['TSFE']->sys_language_isocode,
'code' => $GLOBALS['TSFE']->sys_language_isocode == 'lv' ? 'lat' : 'eng',
'iso' => $iso,
'code' => $iso == 'lv' ? 'lat' : 'eng',
];
}
......
......@@ -33,10 +33,11 @@ class ProgramsContinue implements RestModel
{
// Set language data
$languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
$iso = $GLOBALS['TYPO3_REQUEST']->getAttribute('language')->getTwoLetterIsoCode();
$this->language = [
'id' => $languageAspect->getId(),
'iso' => $GLOBALS['TSFE']->sys_language_isocode,
'code' => $GLOBALS['TSFE']->sys_language_isocode == 'lv' ? 'lat' : 'eng',
'iso' => $iso,
'code' => $iso == 'lv' ? 'lat' : 'eng',
];
}
......
......@@ -34,10 +34,11 @@ class Purchases implements RestModel
{
// Set language data
$languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
$iso = $GLOBALS['TYPO3_REQUEST']->getAttribute('language')->getTwoLetterIsoCode();
$this->language = [
'id' => $languageAspect->getId(),
'iso' => $GLOBALS['TSFE']->sys_language_isocode,
'code' => $GLOBALS['TSFE']->sys_language_isocode == 'lv' ? 'lat' : 'eng',
'iso' => $iso,
'code' => $iso == 'lv' ? 'lat' : 'eng',
];
}
......
{
"name": "luitd/lu-api",
"version": "2.6.9",
"description": "REST API Integration for TYPO3",
"type": "typo3-cms-extension",
"keywords": [
"TYPO3",
"extension"
],
"authors": [
{
"name": "Dainis Abols",
"email": "dainis@dainisabols.lv",
"role": "Developer"
}
],
"license": "GPL-3.0-or-later",
"require": {
"typo3/cms-core": "^9.5 || ^10",
"fluidtypo3/vhs": "^6"
},
"autoload": {
"psr-4": {
"Lu\\LuApi\\": "Classes"
}
},
"replace": {
"typo3-ter/lu_api": "self.version"
},
"config": {
"vendor-dir": ".Build/vendor",
"bin-dir": ".Build/bin"
},
"scripts": {
"post-autoload-dump": [
"mkdir -p .Build/Web/typo3conf/ext/",
"[ -L .Build/Web/typo3conf/ext/lu_api ] || ln -snvf ../../../../. .Build/Web/typo3conf/ext/lu_api"
]
},
"extra": {
"typo3/cms": {
"extension-key": "lu_api",
"cms-package-dir": "{$vendor-dir}/typo3/cms",
"web-dir": ".Build/Web"
}
}
}
{
"name": "luitd/lu-api",
"version": "2.7.3",
"description": "REST API Integration for TYPO3",
"type": "typo3-cms-extension",
"keywords": [
"TYPO3",
"extension"
],
"authors": [
{
"name": "Dainis Abols",
"email": "dainis@dainisabols.lv",
"role": "Developer"
}
],
"license": "GPL-3.0-or-later",
"require": {
"typo3/cms-core": "^9.5 || ^10",
"fluidtypo3/vhs": "^6"
},
"autoload": {
"psr-4": {
"Lu\\LuApi\\": "Classes"
}
},
"replace": {
"typo3-ter/lu_api": "self.version"
},
"config": {
"vendor-dir": ".Build/vendor",
"bin-dir": ".Build/bin"
},
"scripts": {
"post-autoload-dump": [