Bring back itemsProcFunc for listing search facets

This commit is contained in:
Alexander Bigga 2022-02-08 23:38:58 +01:00
parent a5cb77c090
commit 4a0ef0a14a
4 changed files with 84 additions and 7 deletions

View File

@ -13,7 +13,12 @@
namespace Kitodo\Dlf\Hooks;
use Kitodo\Dlf\Common\Helper;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Backend\View\PageLayoutContext;
/**
* Helper for Flexform's custom "itemsProcFunc"
@ -25,6 +30,11 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
*/
class ItemsProcFunc
{
/**
* @var int
*/
protected $storagePid;
/**
* Helper to get flexform's items array for plugin "Toolbox"
*
@ -40,4 +50,75 @@ class ItemsProcFunc
$params['items'][] = [Helper::getLanguageService()->getLL($label), $class];
}
}
/**
* The constructor to access TypoScript configuration
*
* @access public
*
* @return void
*/
public function __construct()
{
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$configurationManager = $objectManager->get(ConfigurationManager::class);
// we must get the storagePid from full TypoScript setup at this point.
$fullTyposcriptSetup = $configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
$this->storagePid = $fullTyposcriptSetup["plugin."]["tx_dlf."]["persistence."]["storagePid"];
}
/**
* Helper to get flexform's items array for plugin "Search"
*
* @access public
*
* @param array &$params: An array with parameters
*/
public function getFacetsList(array &$params): void
{
$this->generateList(
$params,
'label,index_name',
'tx_dlf_metadata',
'sorting',
'is_facet=1'
);
}
/**
* Get list items from database
*
* @access protected
*
* @param array &$params: An array with parameters
* @param string $fields: Comma-separated list of fields to fetch
* @param string $table: Table name to fetch the items from
* @param string $sorting: Field to sort items by (optionally appended by 'ASC' or 'DESC')
* @param string $andWhere: Additional AND WHERE clause
*
* @return void
*/
protected function generateList(&$params, $fields, $table, $sorting, $andWhere = '')
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable($table);
// Get $fields from $table on given pid.
$result = $queryBuilder
->select(...explode(',', $fields))
->from($table)
->where(
$queryBuilder->expr()->eq($table . '.pid', intval($this->storagePid)),
$queryBuilder->expr()->in($table . '.sys_language_uid', [-1, 0]),
$andWhere
)
->orderBy($sorting)
->execute();
while ($resArray = $result->fetch(\PDO::FETCH_NUM)) {
if ($resArray) {
$params['items'][] = $resArray;
}
}
}
}

View File

@ -146,11 +146,8 @@
<config>
<type>select</type>
<renderType>selectMultipleSideBySide</renderType>
<foreign_table>tx_dlf_metadata</foreign_table>
<foreign_table_where>AND tx_dlf_metadata.hidden = 0 AND tx_dlf_metadata.sys_language_uid IN (-1,0)
AND tx_dlf_metadata.is_facet = 1
ORDER BY tx_dlf_metadata.label ASC
</foreign_table_where>
<items type="array"></items>
<itemsProcFunc>Kitodo\Dlf\Hooks\ItemsProcFunc->getFacetsList</itemsProcFunc>
<size>5</size>
<autoSizeMax>15</autoSizeMax>
<maxitems>1024</maxitems>

View File

@ -318,7 +318,6 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'][\Kitodo\Dlf\U
1 = {$module.tx_dlf.view.layoutRootPath}
}
}
persistence < plugin.tx_dlf.persistence
}'
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScriptConstants(

View File

@ -198,7 +198,7 @@ CREATE TABLE tx_dlf_collections (
index_search text NOT NULL,
oai_name varchar(255) DEFAULT '' NOT NULL,
description text NOT NULL,
thumbnail text NOT NULL,
thumbnail varchar(255) DEFAULT '' NOT NULL,
priority smallint(6) DEFAULT '3' NOT NULL,
documents int(11) DEFAULT '0' NOT NULL,
owner int(11) DEFAULT '0' NOT NULL,