Little refactoring the statistics plugin

This commit is contained in:
Alexander Bigga 2021-11-20 13:48:07 +01:00
parent caa477b19d
commit 39b8f90fb1
9 changed files with 84 additions and 122 deletions

View File

@ -32,6 +32,9 @@ class CollectionController extends AbstractController
*/
protected $hookObjects = [];
/**
* @var CollectionRepository
*/
protected $collectionRepository;
/**
@ -42,6 +45,9 @@ class CollectionController extends AbstractController
$this->collectionRepository = $collectionRepository;
}
/**
* @var DocumentRepository
*/
protected $documentRepository;
/**

View File

@ -24,8 +24,9 @@ use Kitodo\Dlf\Domain\Repository\DocumentRepository;
*/
class StatisticsController extends AbstractController
{
protected $collectionRepository;
/**
* @var DocumentRepository
*/
protected $documentRepository;
/**
@ -43,21 +44,8 @@ class StatisticsController extends AbstractController
*/
public function mainAction()
{
// Quit without doing anything if required configuration variables are not set.
if (empty($this->settings['pages'])) {
$this->logger->warning('Incomplete plugin configuration');
}
// Check for selected collections.
if ($this->settings['collections']) {
// Include only selected collections.
$result = $this->documentRepository->getStatisticsForSelectedCollection($this->settings);
} else {
$result = $this->documentRepository->getStatisticsForCollection($this->settings);
}
$countTitles = $result['titles'];
$countVolumes = $result['volumes'];
$countTitles = $this->documentRepository->countAllTitles($this->settings);
$countVolumes = $this->documentRepository->countAllVolumes($this->settings);
// Set replacements.
$args['###TITLES###'] = $countTitles . ' ' . htmlspecialchars(

View File

@ -563,16 +563,19 @@ class Document extends \TYPO3\CMS\Extbase\DomainObject\AbstractValueObject
$this->rightsInfo = $rightsInfo;
}
/**
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
* Returns the collections
*
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Kitodo\Dlf\Domain\Model\Collection> $collections
*/
public function getCollections(): ?\TYPO3\CMS\Extbase\Persistence\ObjectStorage
public function getCollections()
{
return $this->collections;
}
/**
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $collections
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Kitodo\Dlf\Domain\Model\Collection> $collections
*/
public function setCollections(?\TYPO3\CMS\Extbase\Persistence\ObjectStorage $collections): void
{

View File

@ -10,7 +10,7 @@
* LICENSE.txt file that was distributed with this source code.
*/
namespace Kitodo\Dlf\Domain\Model;
namespace Kitodo\Dlf\Domain\Repository;
class ActionLogRepository extends \TYPO3\CMS\Extbase\DomainObject\AbstractValueObject
{

View File

@ -133,24 +133,60 @@ class DocumentRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
return $query->execute();
}
public function getStatisticsForCollection($settings)
/**
* Find all the titles
*
* documents with partof == 0
*
* @param array $settings
*
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
*/
public function findAllTitles($settings = [])
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tx_dlf_documents');
$query = $this->createQuery();
// Include all collections.
$countTitles = $queryBuilder
->count('tx_dlf_documents.uid')
->from('tx_dlf_documents')
->where(
$queryBuilder->expr()->eq('tx_dlf_documents.pid', intval($settings['pages'])),
$queryBuilder->expr()->eq('tx_dlf_documents.partof', 0),
Helper::whereExpression('tx_dlf_documents')
)
->execute()
->fetchColumn(0);
$constraints = [];
$constraints[] = $query->equals('partof', 0);
if ($settings['collections']) {
$constraints[] = $query->in('collections.uid', GeneralUtility::intExplode(',', $settings['collections']));
}
if (count($constraints)) {
$query->matching(
$query->logicalAnd($constraints)
);
}
return $query->execute();
}
/**
* Count the titles
*
* documents with partof == 0
*
* @param array $settings
*
* @return int
*/
public function countAllTitles($settings = [])
{
return $this->findAllTitles($settings)->count();
}
/**
* Count the volumes
*
* documents with partof != 0
*
* @param array $settings
*
* @return int
*/
public function countAllVolumes($settings = [])
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tx_dlf_documents');
$subQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
@ -175,7 +211,7 @@ class DocumentRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
->execute()
->fetchColumn(0);
return ['titles' => $countTitles, 'volumes' => $countVolumes];
return $countVolumes;
}
public function getStatisticsForSelectedCollection($settings)

View File

@ -22,13 +22,15 @@
<el>
<settings.collections>
<TCEforms>
<displayCond>FIELD:settings.pages:REQ:true</displayCond>
<exclude>1</exclude>
<label>LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.collection.flexform.collections</label>
<config>
<type>select</type>
<items type="array"/>
<itemsProcFunc>Kitodo\Dlf\Hooks\ItemsProcFunc->collectionList</itemsProcFunc>
<renderType>selectMultipleSideBySide</renderType>
<foreign_table>tx_dlf_collections</foreign_table>
<foreign_table_where>AND tx_dlf_collections.hidden = 0 AND tx_dlf_collections.sys_language_uid IN (-1,0)
ORDER BY tx_dlf_collections.label ASC
</foreign_table_where>
<size>5</size>
<autoSizeMax>15</autoSizeMax>
<maxitems>1024</maxitems>
@ -39,13 +41,15 @@
</settings.collections>
<settings.solrcore>
<TCEforms>
<displayCond>FIELD:settings.pages:REQ:true</displayCond>
<exclude>1</exclude>
<label>LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:flexform.solrcore</label>
<config>
<type>select</type>
<items type="array"></items>
<itemsProcFunc>Kitodo\Dlf\Hooks\ItemsProcFunc->solrList</itemsProcFunc>
<renderType>selectSingle</renderType>
<foreign_table>tx_dlf_solrcores</foreign_table>
<foreign_table_where>ORDER BY
tx_dlf_solrcores.label ASC
</foreign_table_where>
<size>1</size>
<maxitems>1</maxitems>
<minitems>1</minitems>

View File

@ -20,26 +20,6 @@
</TCEforms>
<type>array</type>
<el>
<settings.pages>
<TCEforms>
<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.features>
<TCEforms>
<exclude>1</exclude>

View File

@ -20,26 +20,6 @@
</TCEforms>
<type>array</type>
<el>
<settings.pages>
<TCEforms>
<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.paginate.itemsPerPage>
<TCEforms>
<exclude>1</exclude>
@ -85,21 +65,6 @@
</config>
</TCEforms>
</settings.targetPid>
<settings.templateFile>
<TCEforms>
<exclude>1</exclude>
<label>LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:flexform.templateFile</label>
<config>
<type>group</type>
<internal_type>file_reference</internal_type>
<allowed>tmpl,tpl,html,htm,txt</allowed>
<size>1</size>
<maxitems>1</maxitems>
<minitems>0</minitems>
<disable_controls>upload</disable_controls>
</config>
</TCEforms>
</settings.templateFile>
</el>
</ROOT>
</sDEF>

View File

@ -20,36 +20,16 @@
</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>
<exclude>1</exclude>
<label>LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:flexform.collections</label>
<config>
<type>select</type>
<items type="array"></items>
<itemsProcFunc>Kitodo\Dlf\Hooks\ItemsProcFunc->collectionList</itemsProcFunc>
<foreign_table>tx_dlf_collections</foreign_table>
<foreign_table_where>AND tx_dlf_collections.hidden = 0 AND tx_dlf_collections.sys_language_uid IN (-1,0)
ORDER BY tx_dlf_collections.label ASC
</foreign_table_where>
<size>5</size>
<autoSizeMax>15</autoSizeMax>
<maxitems>1024</maxitems>