-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5a8d5a8
Showing
29 changed files
with
1,905 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GAYA\ContentUsage\Configuration; | ||
|
||
use GAYA\ContentUsage\Domain\Model\Ctype; | ||
use GAYA\ContentUsage\Domain\Model\Doktype; | ||
use GAYA\ContentUsage\Domain\Model\Plugin; | ||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility; | ||
|
||
class TcaConfiguration | ||
{ | ||
/** | ||
* @var mixed[] | ||
*/ | ||
private array $tca; | ||
|
||
public function __construct() | ||
{ | ||
$this->tca = $GLOBALS['TCA']; | ||
} | ||
|
||
/** | ||
* @return Doktype[] | ||
*/ | ||
public function getDoktypes(): array | ||
{ | ||
$doktypes = []; | ||
|
||
foreach ($this->tca['pages']['columns']['doktype']['config']['items'] as $doktypeItem) { | ||
if ($doktypeItem[1] === '--div--') { | ||
continue; | ||
} | ||
|
||
$doktype = new Doktype(); | ||
$doktype->setId((int)$doktypeItem[1]); | ||
$doktype->setLabel($this->getTranslation($doktypeItem[0])); | ||
$doktype->setIcon($doktypeItem[2] ?? ''); | ||
|
||
$doktypes[] = $doktype; | ||
} | ||
|
||
return $doktypes; | ||
} | ||
|
||
/** | ||
* @return Ctype[] | ||
*/ | ||
public function getCtypes(): array | ||
{ | ||
$ctypes = []; | ||
|
||
foreach ($this->tca['tt_content']['columns']['CType']['config']['items'] as $ctypeItem) { | ||
if ($ctypeItem[1] === '--div--') { | ||
continue; | ||
} | ||
|
||
$ctype = new Ctype(); | ||
$ctype->setId($ctypeItem[1]); | ||
$ctype->setLabel($this->getTranslation($ctypeItem[0])); | ||
$ctype->setIcon($ctypeItem[2] ?? ''); | ||
|
||
$ctypes[] = $ctype; | ||
} | ||
|
||
return $ctypes; | ||
} | ||
|
||
/** | ||
* @return Plugin[] | ||
*/ | ||
public function getPlugins(): array | ||
{ | ||
$plugins = []; | ||
|
||
foreach ($this->tca['tt_content']['columns']['list_type']['config']['items'] as $pluginItem) { | ||
if ($pluginItem[1] === '') { | ||
continue; | ||
} | ||
|
||
$plugin = new Plugin(); | ||
$plugin->setId($pluginItem[1]); | ||
$plugin->setLabel($this->getTranslation($pluginItem[0])); | ||
$plugin->setIcon($pluginItem[2] ?? ''); | ||
|
||
$plugins[] = $plugin; | ||
} | ||
|
||
return $plugins; | ||
} | ||
|
||
private function getTranslation(string $key): string | ||
{ | ||
if (str_starts_with($key, 'LLL:')) { | ||
return LocalizationUtility::translate($key); | ||
} else { | ||
return $key; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GAYA\ContentUsage\Controller; | ||
|
||
use GAYA\ContentUsage\Domain\Model\Ctype; | ||
use GAYA\ContentUsage\Domain\Model\Doktype; | ||
use GAYA\ContentUsage\Configuration\TcaConfiguration; | ||
use GAYA\ContentUsage\Domain\Model\Plugin; | ||
use GAYA\ContentUsage\Domain\Repository\ContentRepository; | ||
use GAYA\ContentUsage\Domain\Repository\PageRepository; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use TYPO3\CMS\Backend\Routing\UriBuilder; | ||
use TYPO3\CMS\Backend\Template\ModuleTemplate; | ||
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory; | ||
use TYPO3\CMS\Beuser\Domain\Model\ModuleData; | ||
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; | ||
use TYPO3\CMS\Core\Http\HtmlResponse; | ||
use TYPO3\CMS\Core\Http\RedirectResponse; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Fluid\View\StandaloneView; | ||
use TYPO3Fluid\Fluid\View\ViewInterface; | ||
|
||
class ReportController | ||
{ | ||
protected ServerRequestInterface $request; | ||
|
||
protected ViewInterface $view; | ||
|
||
protected ?ModuleData $moduleData = null; | ||
protected ?ModuleTemplate $moduleTemplate = null; | ||
|
||
public function __construct( | ||
protected readonly ModuleTemplateFactory $moduleTemplateFactory, | ||
protected readonly UriBuilder $uriBuilder, | ||
private TcaConfiguration $tcaConfiguration, | ||
private PageRepository $pageRepository, | ||
private ContentRepository $contentRepository | ||
) { | ||
|
||
} | ||
|
||
public function processRequest(ServerRequestInterface $request): ResponseInterface | ||
{ | ||
$this->request = $request; | ||
$this->moduleTemplate = $this->moduleTemplateFactory->create($request); | ||
|
||
|
||
$action = $request->getQueryParams()['action'] ?? 'main'; | ||
|
||
$this->initializeView($action); | ||
|
||
switch ($action) { | ||
case 'doktypes': | ||
return $this->doktypesAction(); | ||
break; | ||
case 'ctypes': | ||
return $this->ctypesAction(); | ||
break; | ||
case 'listTypes': | ||
return $this->listTypesAction(); | ||
break; | ||
case 'doktypeDetail': | ||
foreach ($this->tcaConfiguration->getDoktypes() as $doktype) { | ||
if ($doktype->getId() === (int)$request->getQueryParams()['doktype']) { | ||
return $this->doktypeDetailAction($doktype, $request->getQueryParams()['status']); | ||
} | ||
} | ||
break; | ||
case 'ctypeDetail': | ||
foreach ($this->tcaConfiguration->getCtypes() as $ctype) { | ||
if ($ctype->getId() === $request->getQueryParams()['ctype']) { | ||
return $this->ctypeDetailAction($ctype, $request->getQueryParams()['status']); | ||
} | ||
} | ||
break; | ||
case 'listTypeDetail': | ||
foreach ($this->tcaConfiguration->getPlugins() as $plugin) { | ||
if ($plugin->getId() === $request->getQueryParams()['listType']) { | ||
return $this->listTypeDetailAction($plugin, $request->getQueryParams()['status']); | ||
} | ||
} | ||
break; | ||
default: | ||
return $this->mainAction(); | ||
} | ||
|
||
// If we are here, there was a problem | ||
return new RedirectResponse((string)$this->uriBuilder->buildUriFromRoute('tools_ContentUsage')); | ||
} | ||
|
||
/** | ||
* Sets up the Fluid View. | ||
* | ||
* @param string $templateName | ||
*/ | ||
protected function initializeView(string $templateName): void | ||
{ | ||
$this->view = GeneralUtility::makeInstance(StandaloneView::class); | ||
$this->view->setTemplate($templateName); | ||
$this->view->setTemplateRootPaths(['EXT:content_usage/Resources/Private/Templates']); | ||
$this->view->setPartialRootPaths(['EXT:content_usage/Resources/Private/Partials']); | ||
$this->view->setLayoutRootPaths(['EXT:content_usage/Resources/Private/Layouts']); | ||
} | ||
|
||
public function mainAction(): ResponseInterface | ||
{ | ||
$this->moduleTemplate->setContent($this->view->render()); | ||
|
||
return new HtmlResponse($this->moduleTemplate->renderContent()); | ||
} | ||
|
||
public function doktypesAction(): ResponseInterface | ||
{ | ||
$doktypes = $this->tcaConfiguration->getDoktypes(); | ||
foreach ($doktypes as $doktype) { | ||
$doktype->setTotalActivePages($this->pageRepository->countActiveByDoktype($doktype)); | ||
$doktype->setTotalDisabledPages($this->pageRepository->countDisabledByDoktype($doktype)); | ||
$doktype->setTotalDeletedPages($this->pageRepository->countDeletedByDoktype($doktype)); | ||
} | ||
|
||
$this->view->assign('doktypes', $doktypes); | ||
|
||
$this->moduleTemplate->setContent($this->view->render()); | ||
|
||
return new HtmlResponse($this->moduleTemplate->renderContent()); | ||
} | ||
|
||
public function ctypesAction(): ResponseInterface | ||
{ | ||
$ctypes = $this->tcaConfiguration->getCtypes(); | ||
foreach ($ctypes as $ctype) { | ||
$ctype->setTotalActiveContents($this->contentRepository->countActiveByCtype($ctype)); | ||
$ctype->setTotalDisabledContents($this->contentRepository->countDisabledByCtype($ctype)); | ||
$ctype->setTotalDeletedContents($this->contentRepository->countDeletedByCtype($ctype)); | ||
} | ||
|
||
$this->view->assign('ctypes', $ctypes); | ||
|
||
$this->moduleTemplate->setContent($this->view->render()); | ||
|
||
return new HtmlResponse($this->moduleTemplate->renderContent()); | ||
} | ||
|
||
public function listTypesAction(): ResponseInterface | ||
{ | ||
$plugins = $this->tcaConfiguration->getPlugins(); | ||
foreach ($plugins as $plugin) { | ||
$plugin->setTotalActiveContents($this->contentRepository->countActiveByPlugin($plugin)); | ||
$plugin->setTotalDisabledContents($this->contentRepository->countDisabledByPlugin($plugin)); | ||
$plugin->setTotalDeletedContents($this->contentRepository->countDeletedByPlugin($plugin)); | ||
} | ||
|
||
$this->view->assign('plugins', $plugins); | ||
|
||
$this->moduleTemplate->setContent($this->view->render()); | ||
|
||
return new HtmlResponse($this->moduleTemplate->renderContent()); | ||
} | ||
|
||
public function doktypeDetailAction(Doktype $doktype, string $status): ResponseInterface | ||
{ | ||
match ($status) { | ||
'active' => $doktype->setActivePages($this->pageRepository->findActiveByDoktype($doktype)), | ||
'disabled' => $doktype->setDisabledPages($this->pageRepository->findDisabledByDoktype($doktype)), | ||
'deleted' => $doktype->setDeletedPages($this->pageRepository->findDeletedByDoktype($doktype)), | ||
}; | ||
|
||
$this->view->assign('doktype', $doktype); | ||
$this->view->assign('status', $status); | ||
|
||
$this->moduleTemplate->setContent($this->view->render()); | ||
|
||
return new HtmlResponse($this->moduleTemplate->renderContent()); | ||
} | ||
|
||
public function ctypeDetailAction(Ctype $ctype, string $status): ResponseInterface | ||
{ | ||
match ($status) { | ||
'active' => $ctype->setActiveContents($this->contentRepository->findActiveByCtype($ctype)), | ||
'disabled' => $ctype->setDisabledContents($this->contentRepository->findDisabledByCtype($ctype)), | ||
'deleted' => $ctype->setDeletedContents($this->contentRepository->findDeletedByCtype($ctype)), | ||
}; | ||
|
||
$this->view->assign('ctype', $ctype); | ||
$this->view->assign('status', $status); | ||
|
||
$this->moduleTemplate->setContent($this->view->render()); | ||
|
||
return new HtmlResponse($this->moduleTemplate->renderContent()); | ||
} | ||
|
||
public function listTypeDetailAction(Plugin $plugin, string $status): ResponseInterface | ||
{ | ||
match ($status) { | ||
'active' => $plugin->setActiveContents($this->contentRepository->findActiveByPlugin($plugin)), | ||
'disabled' => $plugin->setDisabledContents($this->contentRepository->findDisabledByPlugin($plugin)), | ||
'deleted' => $plugin->setDeletedContents($this->contentRepository->findDeletedByPlugin($plugin)), | ||
}; | ||
|
||
$this->view->assign('plugin', $plugin); | ||
$this->view->assign('status', $status); | ||
|
||
$this->moduleTemplate->setContent($this->view->render()); | ||
|
||
return new HtmlResponse($this->moduleTemplate->renderContent()); | ||
} | ||
|
||
/** | ||
* @return BackendUserAuthentication | ||
*/ | ||
protected function getBackendUser(): BackendUserAuthentication | ||
{ | ||
return $GLOBALS['BE_USER']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GAYA\ContentUsage\Domain\Model; | ||
|
||
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; | ||
|
||
class Content extends AbstractEntity | ||
{ | ||
protected string $header; | ||
|
||
protected string $ctype; | ||
|
||
protected string $listType; | ||
|
||
protected int $sysLanguageUid = 0; | ||
|
||
protected int $t3verWsid = 0; | ||
|
||
public function getHeader(): string | ||
{ | ||
return $this->header; | ||
} | ||
|
||
public function setHeader(string $header): void | ||
{ | ||
$this->header = $header; | ||
} | ||
|
||
public function getCtype(): string | ||
{ | ||
return $this->ctype; | ||
} | ||
|
||
public function setCtype(string $ctype): void | ||
{ | ||
$this->ctype = $ctype; | ||
} | ||
|
||
public function getListType(): string | ||
{ | ||
return $this->listType; | ||
} | ||
|
||
public function setListType(string $listType): void | ||
{ | ||
$this->listType = $listType; | ||
} | ||
|
||
public function getSysLanguageUid(): int | ||
{ | ||
return $this->sysLanguageUid; | ||
} | ||
|
||
public function setSysLanguageUid(int $sysLanguageUid): void | ||
{ | ||
$this->sysLanguageUid = $sysLanguageUid; | ||
} | ||
|
||
public function getT3verWsid(): int | ||
{ | ||
return $this->t3verWsid; | ||
} | ||
|
||
public function setT3verWsid(int $t3verWsid): void | ||
{ | ||
$this->t3verWsid = $t3verWsid; | ||
} | ||
} |
Oops, something went wrong.