Commit 2a488736 authored by Georg Ringer's avatar Georg Ringer Committed by Christian Kuhn
Browse files

[TASK] Improve sys_note code

Code of sys_note can be highly improved:
* Use fluid
* Move xlf files to Resources
* Add kind-of repository

Change-Id: Ia89acb29ddbc0919901570f6bdd1575376863c4a
Resolves: #39221
Releases: 6.0
Reviewed-on: http://review.typo3.org/13021
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
parent 56e6927f
<?php
/***************************************************************
* Copyright notice
*
* (c) 2012 Georg Ringer <typo3@ringerge.org>
* 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
* (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!
***************************************************************/
/**
* Sys_note repository
*
* @package TYPO3
* @subpackage sys_note
* @author Georg Ringer <typo3@ringerge.org>
*/
class Tx_SysNote_Domain_Repository_SysNoteRepository {
/**
* Find all sys_notes by a given pidlist
*
* @param string $pidlist comma separated list of pids
* @return array records
*/
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']) . ')' .
t3lib_BEfunc::deleteClause('sys_note'),
'',
'sorting'
);
foreach ($records as $key => $record) {
$records[$key]['tstamp'] = new DateTime('@' . $record['tstamp']);
$records[$key]['author'] = t3lib_BEfunc::getRecord('be_users', $record['cruser']);
}
return $records;
}
}
?>
\ No newline at end of file
......@@ -38,78 +38,38 @@ class Tx_SysNote_SysNote {
* @return string
*/
public function renderByPid($pidList) {
// Create query for selecting the notes:
$rows = $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']) . ')' .
t3lib_BEfunc::deleteClause('sys_note'),
'',
'sorting'
);
/** @var $repository Tx_SysNote_Domain_Repository_SysNoteRepository */
$repository = t3lib_div::makeInstance('Tx_SysNote_Domain_Repository_SysNoteRepository');
$out = '';
if (count($rows) > 0) {
$categories = array();
// Load full table description:
t3lib_div::loadTCA('sys_note');
// Traverse categories
if ($GLOBALS['TCA']['sys_note'] && $GLOBALS['TCA']['sys_note']['columns']['category']
&& is_array($GLOBALS['TCA']['sys_note']['columns']['category']['config']['items'])
) {
foreach ($GLOBALS['TCA']['sys_note']['columns']['category']['config']['items'] as $el) {
$categories[$el[1]] = $GLOBALS['LANG']->sL($el[0]);
}
}
$notes = $repository->findAllByPidList($pidList);
// For each note found, make rendering:
foreach ($rows as $row) {
if ($row['personal'] == 1 && (int) $row['cruser'] !== (int) $GLOBALS['BE_USER']->user['uid'] && $GLOBALS['BE_USER']->isAdmin() === FALSE) {
continue;
}
$author = t3lib_BEfunc::getRecord('be_users', $row['cruser']);
$authorInformation = $author['realName'];
if (empty($authorInformation)) {
$authorInformation = $author['username'];
}
$title = !(empty($categories[$row['category']])) ? $categories[$row['category']] . ': ' : '';
$headerParts = array();
if (!empty($authorInformation)) {
$headerParts[] = '<span>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.author', TRUE) . '</span> ' . $authorInformation;
}
$headerParts[] = '<span>' . $GLOBALS['LANG']->sL('LLL:EXT:sys_note/locallang.xlf:date', TRUE) . ':</span> ' . t3lib_BEfunc::date($row['tstamp']);
if ($row['personal'] == 1) {
$headerParts[] = '<span>' . rtrim($GLOBALS['LANG']->sL('LLL:EXT:sys_note/locallang_tca.xlf:sys_note.personal', TRUE), ':') . '</span>';
}
// Compile content:
$out .= '
<div class="single-note category-' . $row['category'] . '">
<div class="header">
' . implode(' &middot; ', $headerParts) . '
<div class="right">
<a href="#" onclick="' . htmlspecialchars(t3lib_BEfunc::editOnClick('&edit[sys_note][' . $row['uid'] . ']=edit', $GLOBALS['BACK_PATH'])) . '">' .
t3lib_iconWorks::getSpriteIcon('actions-document-open') .
'</a>
</div>
</div>
<div class="content">
<div class="title">' . htmlspecialchars($title) . htmlspecialchars($row['subject']) . '</div>
' . nl2br(htmlspecialchars($row['message'])) . '
</div>
</div>';
}
$out = '';
if ($this->notesAvailable($notes)) {
/** @var $fluidView Tx_Fluid_View_StandaloneView */
$fluidView = t3lib_div::makeInstance('Tx_Fluid_View_StandaloneView');
$templatePathAndFilename = t3lib_extMgm::extPath('sys_note', 'Resources/Private/Template/List.html');
$out = '<div id="typo3-dblist-sysnotes">' . $out . '</div>';
$fluidView->setTemplatePathAndFilename($templatePathAndFilename);
$fluidView->assign('notes', $notes);
$out = $fluidView->render();
}
return $out;
}
/**
* Check if notes are available
*
* @param array $notes All notes returned from repository
* @return boolean TRUE if there are one or more notes
*/
protected function notesAvailable(array $notes) {
$notesAvailable = FALSE;
if (count($notes) > 0) {
$notesAvailable = TRUE;
}
return $notesAvailable;
}
}
?>
\ No newline at end of file
<?php
/***************************************************************
* Copyright notice
*
* (c) 2012 Georg Ringer <typo3@ringerge.org>
* 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
* (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!
***************************************************************/
/**
* ViewHelper to create a link to edit a note
*
* @package TYPO3
* @subpackage sys_note
* @author Georg Ringer <typo3@ringerge.org>
*/
class Tx_SysNote_ViewHelpers_EditLinkViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
/**
* @param integer $id
* @return string
*/
public function render($id) {
$returnUrl = t3lib_div::getIndpEnv('REQUEST_URI');
return $GLOBALS['BACK_PATH'] . 'alt_doc.php?&edit[sys_note][' . $id . ']=edit&returnUrl=' . rawurlencode($returnUrl);
}
}
?>
\ No newline at end of file
......@@ -16,16 +16,16 @@ $TCA['sys_note'] = array(
'type' => 'select',
'items' => array(
array('', '0'),
array('LLL:EXT:sys_note/locallang_tca.xlf:sys_note.category.I.1', '1', 'sysext/t3skin/icons/ext/sys_note/icon-instruction.png'),
array('LLL:EXT:sys_note/locallang_tca.xlf:sys_note.category.I.2', '3', 'sysext/t3skin/icons/ext/sys_note/icon-note.png'),
array('LLL:EXT:sys_note/locallang_tca.xlf:sys_note.category.I.3', '4', 'sysext/t3skin/icons/ext/sys_note/icon-todo.png'),
array('LLL:EXT:sys_note/locallang_tca.xlf:sys_note.category.I.4', '2', 'sysext/t3skin/icons/ext/sys_note/icon-template.png')
array('LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.category.I.1', '1', 'sysext/t3skin/icons/ext/sys_note/icon-instruction.png'),
array('LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.category.I.2', '3', 'sysext/t3skin/icons/ext/sys_note/icon-note.png'),
array('LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.category.I.3', '4', 'sysext/t3skin/icons/ext/sys_note/icon-todo.png'),
array('LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.category.I.4', '2', 'sysext/t3skin/icons/ext/sys_note/icon-template.png')
),
'default' => '0'
)
),
'subject' => array(
'label' => 'LLL:EXT:sys_note/locallang_tca.xlf:sys_note.subject',
'label' => 'LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.subject',
'config' => array(
'type' => 'input',
'size' => '40',
......@@ -33,7 +33,7 @@ $TCA['sys_note'] = array(
)
),
'message' => array(
'label' => 'LLL:EXT:sys_note/locallang_tca.xlf:sys_note.message',
'label' => 'LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.message',
'config' => array(
'type' => 'text',
'cols' => '40',
......@@ -41,7 +41,7 @@ $TCA['sys_note'] = array(
)
),
'personal' => array(
'label' => 'LLL:EXT:sys_note/locallang_tca.xlf:sys_note.personal',
'label' => 'LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.personal',
'config' => array(
'type' => 'check'
)
......
{namespace notes=Tx_SysNote_ViewHelpers}
<div id="typo3-dblist-sysnotes" xmlns:f="http://www.w3.org/1999/html">
<f:for each="{notes}" as="note">
<div class="single-note category-{note.category}">
<div class="header">
<span><f:translate key="LLL:EXT:lang/locallang_core.xlf:labels.author" /></span>
<f:if condition="{note.author.realName}">
<f:then>{note.author.realName}</f:then>
<f:else>{note.author.username}</f:else>
</f:if>
&middot;
<span><f:translate key="LLL:EXT:sys_note/Resources/Private/Language/locallang.xlf:date" />:</span>
<f:format.date>{note.tstamp}</f:format.date>
<f:if condition="{note.personal}">
&middot;
<span><f:translate key="LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.personal" /></span>
</f:if>
<div class="right">
<f:be.buttons.icon uri="{notes:editLink(id:note.uid)}" icon="actions-document-open" />
</div>
</div>
<div class="content">
<div class="title">
<f:if condition="{note.category}"><f:translate key="LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.category.I.{note.category}" />:</f:if>
{note.subject}</div>
<f:format.nl2br>{note.message}</f:format.nl2br>
</div>
</div>
</f:for>
</div>
\ No newline at end of file
......@@ -12,7 +12,7 @@ $TCA['sys_note'] = array(
'cruser_id' => 'cruser',
'prependAtCopy' => 'LLL:EXT:lang/locallang_general.xlf:LGL.prependAtCopy',
'delete' => 'deleted',
'title' => 'LLL:EXT:sys_note/locallang_tca.xlf:sys_note',
'title' => 'LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note',
'iconfile' => t3lib_extMgm::extRelPath($_EXTKEY) . 'ext_icon.gif',
'sortby' => 'sorting',
'dynamicConfigFile' => t3lib_extMgm::extPath($_EXTKEY) . 'Configuration/Tca/SysNote.php',
......@@ -20,6 +20,6 @@ $TCA['sys_note'] = array(
);
t3lib_extMgm::allowTableOnStandardPages('sys_note');
t3lib_extMgm::addLLrefForTCAdescr('sys_note', 'EXT:sys_note/locallang_csh_sysnote.xlf');
t3lib_extMgm::addLLrefForTCAdescr('sys_note', 'EXT:sys_note/Resources/Private/Language/locallang_csh_sysnote.xlf');
?>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment