Skip to content
Snippets Groups Projects
Commit 730704ad authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] Adding service function to read all categories for a siteroot id

parent 3149f056
No related branches found
No related tags found
1 merge request!2Feature be module
......@@ -70,10 +70,13 @@ class BackendController extends ActionController {
$backendUser = $GLOBALS['BE_USER'];
$pageInfo = BackendUtility::readPageAccess($pageUid, $backendUser->getPagePermsClause(1));
$this->docHeaderComponent = GeneralUtility::makeInstance(DocHeaderComponent::class);
$this->docHeaderComponent->setMetaInformation($pageInfo);
Utility::makeButtons($this->docHeaderComponent, $this->request);
// retrieve next site root id
$siteRootId = Utility::getSiteRoot((int) GeneralUtility::_GP('id'));
Utility::getCategoriesForSiteRoot($siteRootId);
$this->view->assign('docHeader', $this->docHeaderComponent->docHeaderContent());
$this->view->assign('pageUid', $pageUid);
}
......
......@@ -28,6 +28,9 @@ namespace SGalinski\SgNews\Service\Backend;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Database\QueryGenerator;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -38,6 +41,7 @@ use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
* Class Utility
*/
class Utility {
const CATEGORY_DOKTYPE = 117;
/**
* create buttons for the backend module header
......@@ -75,4 +79,49 @@ class Utility {
$buttonBar->addButton($shortcutButton, ButtonBar::BUTTON_POSITION_RIGHT);
$docHeaderComponent->getButtonBar();
}
/**
* Retrieves the next site root in the page hierarchy from the current page
*
* @param int $currentPid
* @return int
*/
public static function getSiteRoot($currentPid) {
$rootLine = BackendUtility::BEgetRootLine((int) $currentPid);
$siteRoot = ['uid' => 0];
foreach ($rootLine as $page) {
if ($page['is_siteroot'] === '1') {
$siteRoot = $page;
break;
}
}
return $siteRoot['uid'];
}
/**
* Get an array of all category titles below the given site root id
*
* @param $siteRootPid
* @throws \InvalidArgumentException
* @return array
*/
public static function getCategoriesForSiteRoot($siteRootPid) {
// get all pageids below the given siteroot
$queryGenerator = GeneralUtility::makeInstance(QueryGenerator::class);
$childPids = $queryGenerator->getTreeList($siteRootPid, PHP_INT_MAX, 0, 1);
// if doktype = 117 (category) then get the category name (page title)
/** @var DatabaseConnection $databaseConnection */
$databaseConnection = $GLOBALS['TYPO3_DB'];
$where = 'doktype = ' . self::CATEGORY_DOKTYPE . ' AND uid in (' . $childPids . ')';
$result = $databaseConnection->exec_SELECTquery('title', 'pages', $where)->fetch_all();
$categories = [];
foreach($result as $item) {
$categories[] = $item[0];
}
return $categories;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment