Use more Extbase in feeds plugin
This commit is contained in:
parent
a5be68bc6e
commit
3d35f69684
|
@ -25,8 +25,6 @@ class FeedsController extends AbstractController
|
|||
*/
|
||||
protected $libraryRepository;
|
||||
|
||||
protected $documentRepository;
|
||||
|
||||
/**
|
||||
* @param LibraryRepository $libraryRepository
|
||||
*/
|
||||
|
@ -35,6 +33,11 @@ class FeedsController extends AbstractController
|
|||
$this->libraryRepository = $libraryRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var DocumentRepository
|
||||
*/
|
||||
protected $documentRepository;
|
||||
|
||||
/**
|
||||
* @param DocumentRepository $documentRepository
|
||||
*/
|
||||
|
@ -81,49 +84,44 @@ class FeedsController extends AbstractController
|
|||
|| GeneralUtility::inList($this->settings['collections'], $requestData['collection'])
|
||||
) {
|
||||
|
||||
$result = $this->documentRepository->getDocumentsForFeeds($this->settings, $requestData['collection']);
|
||||
$documents = $this->documentRepository->findAllByCollectionsLimited(GeneralUtility::intExplode(',', $requestData['collection'], true), $this->settings['limit']);
|
||||
|
||||
$rows = $result->fetchAll();
|
||||
|
||||
foreach ($rows as $resArray) {
|
||||
foreach ($documents as $document) {
|
||||
|
||||
$title = '';
|
||||
// Get title of superior document.
|
||||
if ((empty($resArray['title']) || !empty($this->settings['prependSuperiorTitle']))
|
||||
&& !empty($resArray['partof'])
|
||||
if ((empty($document->getTitle()) || !empty($this->settings['prependSuperiorTitle']))
|
||||
&& !empty($document->getPartof())
|
||||
) {
|
||||
$superiorTitle = Document::getTitle($resArray['partof'], true);
|
||||
$superiorTitle = Document::getTitle($document->getPartof(), true);
|
||||
if (!empty($superiorTitle)) {
|
||||
$title .= '[' . $superiorTitle . ']';
|
||||
}
|
||||
}
|
||||
// Get title of document.
|
||||
if (!empty($resArray['title'])) {
|
||||
$title .= ' ' . $resArray['title'];
|
||||
if (!empty($document->getTitle())) {
|
||||
$title .= ' ' . $document->getTitle();
|
||||
}
|
||||
// Set default title if empty.
|
||||
if (empty($title)) {
|
||||
$title = LocalizationUtility::translate('noTitle', 'dlf');
|
||||
}
|
||||
// Append volume information.
|
||||
if (!empty($resArray['volume'])) {
|
||||
$title .= ', ' . LocalizationUtility::translate('volume', 'dlf') . ' ' . $resArray['volume'];
|
||||
if (!empty($document->getVolume())) {
|
||||
$title .= ', ' . LocalizationUtility::translate('volume', 'dlf') . ' ' . $document->getVolume();
|
||||
}
|
||||
// Is this document new or updated?
|
||||
if ($resArray['crdate'] == $resArray['tstamp']) {
|
||||
if ($document->getCrdate() == $document->getTstamp()) {
|
||||
$title = LocalizationUtility::translate('plugins.feeds.new', 'dlf') . ' ' . trim($title);
|
||||
} else {
|
||||
$title = LocalizationUtility::translate('plugins.feeds.update', 'dlf') . ' ' . trim($title);
|
||||
}
|
||||
|
||||
$resArray['title'] = $title;
|
||||
$documents[] = $resArray;
|
||||
$document->setTitle($title);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->view->assign('documents', $documents);
|
||||
$this->view->assign('feedMeta', $feedMeta);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,11 @@ namespace Kitodo\Dlf\Domain\Model;
|
|||
|
||||
class Document extends \TYPO3\CMS\Extbase\DomainObject\AbstractValueObject
|
||||
{
|
||||
/**
|
||||
* @var \DateTime
|
||||
*/
|
||||
protected $crdate;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
*/
|
||||
|
@ -690,4 +695,24 @@ class Document extends \TYPO3\CMS\Extbase\DomainObject\AbstractValueObject
|
|||
$this->tstamp = $tstamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the creation date
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getCrdate(): \DateTime
|
||||
{
|
||||
return $this->crdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the creation date
|
||||
*
|
||||
* @param \DateTime $crdate
|
||||
*/
|
||||
public function setCrdate($crdate): void
|
||||
{
|
||||
$this->crdate = $crdate;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -66,7 +66,8 @@ class DocumentRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
|
|||
return $query->execute();
|
||||
}
|
||||
|
||||
public function getDocumentsFromDocumentset($documentSet, $pages) {
|
||||
public function getDocumentsFromDocumentset($documentSet, $pages)
|
||||
{
|
||||
$query = $this->createQuery();
|
||||
|
||||
$query->matching($query->equals('pid', $pages));
|
||||
|
@ -75,59 +76,42 @@ class DocumentRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
|
|||
return $query->execute();
|
||||
}
|
||||
|
||||
public function getDocumentsForFeeds($settings, $collectionUid) {
|
||||
$additionalWhere = '';
|
||||
// Check for pre-selected collections.
|
||||
if (!empty($collectionUid)) {
|
||||
$additionalWhere = 'tx_dlf_collections.uid=' . intval($collectionUid);
|
||||
} elseif (!empty($settings['collections'])) {
|
||||
$additionalWhere = 'tx_dlf_collections.uid IN (' . implode(',', GeneralUtility::intExplode(',', $settings['collections'])) . ')';
|
||||
/**
|
||||
* Finds all documents for the given collections
|
||||
*
|
||||
* @param array $collections separated by comma
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
|
||||
*/
|
||||
public function findAllByCollectionsLimited($collections, $limit = 50)
|
||||
{
|
||||
$query = $this->createQuery();
|
||||
|
||||
// order by start_date -> start_time...
|
||||
$query->setOrderings(
|
||||
['tstamp' => QueryInterface::ORDER_DESCENDING]
|
||||
);
|
||||
|
||||
$constraints = [];
|
||||
if ($collections) {
|
||||
$constraints[] = $query->in('collections.uid', $collections);
|
||||
}
|
||||
|
||||
// get documents
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_dlf_documents');
|
||||
|
||||
$result = $queryBuilder
|
||||
->select(
|
||||
'tx_dlf_documents.uid AS uid',
|
||||
'tx_dlf_documents.partof AS partof',
|
||||
'tx_dlf_documents.title AS title',
|
||||
'tx_dlf_documents.volume AS volume',
|
||||
'tx_dlf_documents.author AS author',
|
||||
'tx_dlf_documents.record_id AS record_id',
|
||||
'tx_dlf_documents.tstamp AS tstamp',
|
||||
'tx_dlf_documents.crdate AS crdate'
|
||||
)
|
||||
->from('tx_dlf_documents')
|
||||
->join(
|
||||
'tx_dlf_documents',
|
||||
'tx_dlf_relations',
|
||||
'tx_dlf_documents_collections_mm',
|
||||
$queryBuilder->expr()->eq('tx_dlf_documents.uid', $queryBuilder->quoteIdentifier('tx_dlf_documents_collections_mm.uid_local'))
|
||||
)
|
||||
->join(
|
||||
'tx_dlf_documents_collections_mm',
|
||||
'tx_dlf_collections',
|
||||
'tx_dlf_collections',
|
||||
$queryBuilder->expr()->eq('tx_dlf_collections.uid', $queryBuilder->quoteIdentifier('tx_dlf_documents_collections_mm.uid_foreign'))
|
||||
)
|
||||
->where(
|
||||
$queryBuilder->expr()->eq('tx_dlf_documents.pid', $queryBuilder->createNamedParameter((int) $settings['pages'])),
|
||||
$queryBuilder->expr()->eq('tx_dlf_documents_collections_mm.ident', $queryBuilder->createNamedParameter('docs_colls')),
|
||||
$queryBuilder->expr()->eq('tx_dlf_collections.pid', $queryBuilder->createNamedParameter((int) $settings['pages'])),
|
||||
$additionalWhere
|
||||
)
|
||||
->groupBy('tx_dlf_documents.uid')
|
||||
->orderBy('tx_dlf_documents.tstamp', 'DESC')
|
||||
->setMaxResults((int) $settings['limit'])
|
||||
->execute();
|
||||
|
||||
return $result;
|
||||
if (count($constraints)) {
|
||||
$query->matching(
|
||||
$query->logicalAnd($constraints)
|
||||
);
|
||||
}
|
||||
$query->setLimit((int) $limit);
|
||||
|
||||
return $query->execute();
|
||||
}
|
||||
|
||||
public function getStatisticsForCollection($settings) {
|
||||
|
||||
|
||||
public function getStatisticsForCollection($settings)
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_dlf_documents');
|
||||
|
||||
|
@ -170,7 +154,8 @@ class DocumentRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
|
|||
return ['titles' => $countTitles, 'volumes' => $countVolumes];
|
||||
}
|
||||
|
||||
public function getStatisticsForSelectedCollection($settings) {
|
||||
public function getStatisticsForSelectedCollection($settings)
|
||||
{
|
||||
// Include only selected collections.
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_dlf_documents');
|
||||
|
@ -260,7 +245,8 @@ class DocumentRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
|
|||
return ['titles' => $countTitles, 'volumes' => $countVolumes];
|
||||
}
|
||||
|
||||
public function getTableOfContentsFromDb($uid, $pid, $settings) {
|
||||
public function getTableOfContentsFromDb($uid, $pid, $settings)
|
||||
{
|
||||
// Build table of contents from database.
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tx_dlf_documents');
|
||||
|
|
|
@ -20,27 +20,6 @@
|
|||
</TCEforms>
|
||||
<type>array</type>
|
||||
<el>
|
||||
<settings.pages>
|
||||
<TCEforms>
|
||||
<onChange>reload</onChange>
|
||||
<exclude>1</exclude>
|
||||
<label>LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.startingpoint</label>
|
||||
<config>
|
||||
<type>group</type>
|
||||
<internal_type>db</internal_type>
|
||||
<allowed>pages</allowed>
|
||||
<size>1</size>
|
||||
<maxitems>1</maxitems>
|
||||
<minitems>1</minitems>
|
||||
<show_thumbs>1</show_thumbs>
|
||||
<wizards>
|
||||
<suggest>
|
||||
<type>suggest</type>
|
||||
</suggest>
|
||||
</wizards>
|
||||
</config>
|
||||
</TCEforms>
|
||||
</settings.pages>
|
||||
<settings.collections>
|
||||
<TCEforms>
|
||||
<displayCond>FIELD:settings.pages:REQ:true</displayCond>
|
||||
|
|
|
@ -54,6 +54,14 @@ return [
|
|||
'eval' => 'datetime',
|
||||
]
|
||||
],
|
||||
'crdate' => [
|
||||
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.creationDate',
|
||||
'config' => [
|
||||
'type' => 'input',
|
||||
'renderType' => 'inputDateTime',
|
||||
'eval' => 'datetime',
|
||||
]
|
||||
],
|
||||
'starttime' => [
|
||||
'exclude' => 1,
|
||||
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.starttime',
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<author>{document.author}</author>
|
||||
</f:if>
|
||||
<pubDate><f:format.date format="r">{document.crdate}</f:format.date></pubDate>
|
||||
<guid>{document.record_id}</guid>
|
||||
<guid>{document.recordId}</guid>
|
||||
</item>
|
||||
</f:for>
|
||||
</channel>
|
||||
|
|
Loading…
Reference in New Issue