Commit a9a09422 authored by Kai Vogel's avatar Kai Vogel Committed by Christian Kuhn
Browse files

[FEATURE] Rebuild sys_note to match extbase scheme

This patch extends the sys_note extension and adds a controller and
model. Additionally it rewrites the repository to use the extbase
persistance layer. And it provides the possibility to modify the view
configuration via TypoScript.

Resolves: #43495
Releases: 6.1

Change-Id: I372e9fe0761875cd8967e920417d89cd5ad379b9
Reviewed-on: https://review.typo3.org/16909
Reviewed-by: Kai Vogel
Tested-by: Kai Vogel
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
parent e5d2ba5e
<?php
namespace TYPO3\CMS\SysNote;
namespace TYPO3\CMS\SysNote\Controller;
/***************************************************************
* Copyright notice
*
* (c) 2012 Georg Ringer <typo3@ringerge.org>
* (c) 2013 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
......@@ -23,50 +24,41 @@ namespace TYPO3\CMS\SysNote;
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Render sys_notes
* Note controller
*
* @author Georg Ringer <typo3@ringerge.org>
* @author Kai Vogel <kai.vogel@speedprogs.de>
*/
class SysNoteRenderer {
class NoteController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
/**
* Render sys_notes by pid
*
* @param string $pidList comma separated list of page ids
* @return string
* @var \TYPO3\CMS\SysNote\Domain\Repository\SysNoteRepository
* @inject
*/
public function renderByPid($pidList) {
/** @var $repository \TYPO3\CMS\SysNote\Domain\Repository\SysNoteRepository */
$repository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\SysNote\\Domain\\Repository\\SysNoteRepository');
$notes = $repository->findAllByPidList($pidList);
$out = '';
if ($this->notesAvailable($notes)) {
/** @var $fluidView \TYPO3\CMS\Fluid\View\StandaloneView */
$fluidView = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
$templatePathAndFilename = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('sys_note', 'Resources/Private/Template/List.html');
$fluidView->setTemplatePathAndFilename($templatePathAndFilename);
$fluidView->assign('notes', $notes);
$out = $fluidView->render();
}
return $out;
}
protected $sysNoteRepository;
/**
* Check if notes are available
* @var \TYPO3\CMS\Extbase\Domain\Repository\BackendUserRepository
* @inject
*/
protected $backendUserRepository;
/**
* Render notes by single PID or PID list
*
* @param array $notes All notes returned from repository
* @return boolean TRUE if there are one or more notes
* @param mixed $pids Single PID or comma separated list of PIDs
* @return string
* @dontvalidate $pids
*/
protected function notesAvailable(array $notes) {
$notesAvailable = FALSE;
if (count($notes) > 0) {
$notesAvailable = TRUE;
public function listAction($pids) {
if (empty($pids) || empty($GLOBALS['BE_USER']->user['uid'])) {
return '';
}
return $notesAvailable;
$author = $this->backendUserRepository->findByUid($GLOBALS['BE_USER']->user['uid']);
$notes = $this->sysNoteRepository->findByPidsAndAuthor($pids, $author);
$this->view->assign('notes', $notes);
}
}
?>
\ No newline at end of file
<?php
namespace TYPO3\CMS\SysNote\Core;
/***************************************************************
* Copyright notice
*
* (c) 2013 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Bootstrap for note module
*
* @author Kai Vogel <kai.vogel@speedprogs.de>
*/
class Bootstrap {
/**
* Do not touch if you are not sure what you are doing!
* @var array
*/
protected $extbaseConfiguration = array(
'vendorName' => 'TYPO3\CMS',
'extensionName' => 'SysNote',
'pluginName' => 'Note',
);
/**
* @var array
*/
protected $currentGetArguments;
/**
* Bootstrap extbase and execute controller
*
* @param string $controllerName Controller to execute
* @param string $actionName Action to run
* @param array $arguments Arguments to pass to the controller action
* @return string
*/
public function run($controllerName, $actionName, array $arguments = array()) {
$arguments['controller'] = ucfirst(trim($controllerName));
$arguments['action'] = lcfirst(trim($actionName));
$this->overrideGetArguments($arguments);
/** @var $extbaseBootstrap \TYPO3\CMS\Extbase\Core\Bootstrap */
$extbaseBootstrap = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Core\\Bootstrap');
$content = $extbaseBootstrap->run('', $this->extbaseConfiguration);
$this->revertGetArguments();
return $content;
}
/**
* Modify $_GET to force specific controller, action and arguments in
* extbase bootstrap process
*
* Note: Overwriting $_GET was the most simple solution here until extbase
* provides a clean way to force a controller and action in backend mode.
*
* @param array $arguments The arguments to set
* @return void
*/
protected function overrideGetArguments(array $arguments) {
$this->currentGetArguments = $_GET;
$_GET['tx_sysnote_note'] = $arguments;
}
/**
* Revert previously backuped get arguments
*
* @return void
*/
protected function revertGetArguments() {
if (is_array($this->currentGetArguments)) {
$_GET = $this->currentGetArguments;
}
}
}
?>
\ No newline at end of file
<?php
namespace TYPO3\CMS\SysNote\Domain\Model;
/***************************************************************
* Copyright notice
*
* (c) 2013 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* SysNote model
*
* @author Kai Vogel <kai.vogel@speedprogs.de>
*/
class SysNote extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
/**
* @var \DateTime
*/
protected $creationDate;
/**
* @var \DateTime
*/
protected $modificationDate;
/**
* @var \TYPO3\CMS\Extbase\Domain\Model\BackendUser
*/
protected $author;
/**
* @var string
*/
protected $subject;
/**
* @var string
*/
protected $message;
/**
* @var boolean
*/
protected $personal;
/**
* @var integer
*/
protected $category;
/**
* @return \DateTime $creationDate
*/
public function getCreationDate() {
return $this->creationDate;
}
/**
* @param \DateTime $creationDate
* @return void
*/
public function setCreationDate($creationDate) {
$this->creationDate = $creationDate;
}
/**
* @return \DateTime $modificationDate
*/
public function getModificationDate() {
return $this->modificationDate;
}
/**
* @param \DateTime $modificationDate
* @return void
*/
public function setModificationDate($modificationDate) {
$this->modificationDate = $modificationDate;
}
/**
* @return \TYPO3\CMS\Extbase\Domain\Model\BackendUser $author
*/
public function getAuthor() {
return $this->author;
}
/**
* @param \TYPO3\CMS\Extbase\Domain\Model\BackendUser $author
* @return void
*/
public function setAuthor(\TYPO3\CMS\Extbase\Domain\Model\BackendUser $author) {
$this->author = $author;
}
/**
* @return string $subject
*/
public function getSubject() {
return $this->subject;
}
/**
* @param string $subject
* @return void
*/
public function setSubject($subject) {
$this->subject = $subject;
}
/**
* @return string $message
*/
public function getMessage() {
return $this->message;
}
/**
* @param string $message
* @return void
*/
public function setMessage($message) {
$this->message = $message;
}
/**
* @return boolean $personal
*/
public function getPersonal() {
return $this->personal;
}
/**
* @param boolean $personal
* @return void
*/
public function setPersonal($personal) {
$this->personal = $personal;
}
/**
* @return integer $category
*/
public function getCategory() {
return $this->category;
}
/**
* @param integer $category
* @return void
*/
public function setCategory($category) {
$this->category = $category;
}
}
?>
\ No newline at end of file
......@@ -23,35 +23,51 @@ namespace TYPO3\CMS\SysNote\Domain\Repository;
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Sys_note repository
*
* @author Georg Ringer <typo3@ringerge.org>
* @author Kai Vogel <kai.vogel@speedprogs.de>
*/
class SysNoteRepository {
class SysNoteRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
/**
* Find all sys_notes by a given pidlist
* Initialize the repository
*
* @param string $pidlist comma separated list of pids
* @return array records
* @return void
*/
public function findAllByPidList($pidlist) {
$records = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_note', 'pid IN (' . $GLOBALS['TYPO3_DB']->cleanIntList($pidlist) . ')
AND (personal=0 OR cruser=' . intval($GLOBALS['BE_USER']->user['uid']) . ')' . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('sys_note'), '', 'sorting');
// exec_SELECTgetRows can return NULL if the query failed. This is
// transformed here to an empty array instead.
if ($records === NULL) {
$records = array();
}
foreach ($records as $key => $record) {
$records[$key]['tstamp'] = new \DateTime('@' . $record['tstamp']);
$records[$key]['author'] = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('be_users', $record['cruser']);
}
return $records;
public function initializeObject() {
$querySettings = $this->objectManager->create('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings');
$querySettings->setRespectStoragePage(FALSE);
$this->setDefaultQuerySettings($querySettings);
}
}
/**
* Find notes by given pids and author
*
* @param mixed $pids Single PID or comma separated list of PIDs
* @param \TYPO3\CMS\Extbase\Domain\Model\BackendUser $author The author
* @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface
*/
public function findByPidsAndAuthor($pids, \TYPO3\CMS\Extbase\Domain\Model\BackendUser $author) {
$pids = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', (string) $pids);
$query = $this->createQuery();
$query->setOrderings(array(
'sorting' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
'creationDate' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
));
$query->matching(
$query->logicalAnd(
$query->in('pid', $pids),
$query->logicalOr(
$query->equals('personal', 0),
$query->equals('author', $author)
)
)
);
return $query->execute();
}
}
?>
\ No newline at end of file
......@@ -23,24 +23,26 @@ namespace TYPO3\CMS\SysNote\Hook;
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Hook for the info module
*
* @author Georg Ringer <typo3@ringerge.org>
* @author Kai Vogel <kai.vogel@speedprogs.de>
*/
class InfoModuleHook {
/**
* Add sys_notes as additional content to the footer of the page module
* Add sys_notes as additional content to the footer of the info module
*
* @param array $params
* @param \TYPO3\CMS\Backend\Controller\PageLayoutController $parentObject
* @param \TYPO3\CMS\Frontend\Controller\PageInformationController $parentObject
* @return string
*/
public function render(array $params = array(), \TYPO3\CMS\Frontend\Controller\PageInformationController $parentObject) {
$sysNote = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\SysNote\\SysNoteRenderer');
$content = $sysNote->renderByPid($parentObject->pObj->id);
return $content;
/** @var $noteBootstrap \TYPO3\CMS\SysNote\Core\Bootstrap */
$noteBootstrap = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\SysNote\\Core\\Bootstrap');
return $noteBootstrap->run('Note', 'list', array('pids' => $parentObject->pObj->id));
}
}
......
......@@ -23,10 +23,12 @@ namespace TYPO3\CMS\SysNote\Hook;
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Hook for the page module
*
* @author Georg Ringer <typo3@ringerge.org>
* @author Kai Vogel <kai.vogel@speedprogs.de>
*/
class PageHook {
......@@ -38,9 +40,9 @@ class PageHook {
* @return string
*/
public function render(array $params = array(), \TYPO3\CMS\Backend\Controller\PageLayoutController $parentObject) {
$sysNote = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\SysNote\\SysNoteRenderer');
$content = $sysNote->renderByPid($parentObject->id);
return $content;
/** @var $noteBootstrap \TYPO3\CMS\SysNote\Core\Bootstrap */
$noteBootstrap = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\SysNote\\Core\\Bootstrap');
return $noteBootstrap->run('Note', 'list', array('pids' => $parentObject->id));
}
}
......
......@@ -23,10 +23,12 @@ namespace TYPO3\CMS\SysNote\Hook;
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Hook for the list module
*
* @author Georg Ringer <typo3@ringerge.org>
* @author Kai Vogel <kai.vogel@speedprogs.de>
*/
class RecordListHook {
......@@ -38,9 +40,9 @@ class RecordListHook {
* @return string
*/
public function render(array $params = array(), \TYPO3\CMS\Recordlist\RecordList $parentObject) {
$renderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\SysNote\\SysNoteRenderer');
$sysNotes = $renderer->renderByPid($parentObject->id);
return $sysNotes;
/** @var $noteBootstrap \TYPO3\CMS\SysNote\Core\Bootstrap */
$noteBootstrap = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\SysNote\\Core\\Bootstrap');
return $noteBootstrap->run('Note', 'list', array('pids' => $parentObject->id));
}
}
......
......@@ -23,6 +23,7 @@ namespace TYPO3\CMS\SysNote\ViewHelpers;
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* ViewHelper to create a link to edit a note
*
......
# ======================================================================
# Module constants
# ======================================================================
module.tx_sysnote {
view {
# cat=Internal Notes/general/1000; type=string; label=Layout Root Path: Path to layouts
layoutRootPath = EXT:sys_note/Resources/Private/Layouts/
# cat=Internal Notes/general/1010; type=string; label=Partial Root Path: Path to partials
partialRootPath = EXT:sys_note/Resources/Private/Partials/
# cat=Internal Notes/general/1020; type=string; label=Template Root Path: Path to templates
templateRootPath = EXT:sys_note/Resources/Private/Templates/
}
}
\ No newline at end of file
# ======================================================================
# Module setup
# ======================================================================
module.tx_sysnote {
view {
layoutRootPath = {$module.tx_sysnote.view.layoutRootPath}
templateRootPath = {$module.tx_sysnote.view.templateRootPath}
partialRootPath = {$module.tx_sysnote.view.partialRootPath}
}
}
# ======================================================================
# Extbase mapping
# ======================================================================
config.tx_extbase.persistence.classes {
TYPO3\CMS\SysNote\Domain\Model\SysNote.mapping {
tableName = sys_note
recordType =
columns {
crdate.mapOnProperty = creationDate
tstamp.mapOnProperty = modificationDate
cruser.mapOnProperty = author
}
}
}
\ No newline at end of file
......@@ -3,8 +3,29 @@
<file source-language="en" datatype="plaintext" original="messages" date="2011-10-17T20:22:37Z" product-name="sys_note">
<header/>
<body>
<trans-unit id="author" xml:space="preserve">
<source>Author:</source>
</trans-unit>
<trans-unit id="date" xml:space="preserve">
<source>Date</source>
<source>Date:</source>
</trans-unit>
<trans-unit id="personal" xml:space="preserve">
<source>Personal:</source>
</trans-unit>
<trans-unit id="category.1" xml:space="preserve">
<source>Instructions</source>
</trans-unit>
<trans-unit id="category.2" xml:space="preserve">
<source>Template</source>
</trans-unit>