Merge pull request #3078 from Icinga/translation/de-de
Translation updates de_DE fixes #3067
This commit is contained in:
commit
5042fdab54
|
@ -215,7 +215,7 @@ class NavigationConfigForm extends ConfigForm
|
||||||
foreach ($this->getShareConfig($type) as $sectionName => $sectionConfig) {
|
foreach ($this->getShareConfig($type) as $sectionName => $sectionConfig) {
|
||||||
if ($sectionName !== $this->itemToLoad
|
if ($sectionName !== $this->itemToLoad
|
||||||
&& $sectionConfig->owner === ($owner ?: $this->getUser()->getUsername())
|
&& $sectionConfig->owner === ($owner ?: $this->getUser()->getUsername())
|
||||||
&& !in_array($sectionName, $children, true)
|
&& ! in_array($sectionName, $children, true)
|
||||||
) {
|
) {
|
||||||
$names[] = $sectionName;
|
$names[] = $sectionName;
|
||||||
}
|
}
|
||||||
|
@ -223,7 +223,7 @@ class NavigationConfigForm extends ConfigForm
|
||||||
|
|
||||||
foreach ($this->getUserConfig($type) as $sectionName => $sectionConfig) {
|
foreach ($this->getUserConfig($type) as $sectionName => $sectionConfig) {
|
||||||
if ($sectionName !== $this->itemToLoad
|
if ($sectionName !== $this->itemToLoad
|
||||||
&& !in_array($sectionName, $children, true)
|
&& ! in_array($sectionName, $children, true)
|
||||||
) {
|
) {
|
||||||
$names[] = $sectionName;
|
$names[] = $sectionName;
|
||||||
}
|
}
|
||||||
|
@ -363,8 +363,8 @@ class NavigationConfigForm extends ConfigForm
|
||||||
$shared = false;
|
$shared = false;
|
||||||
if ($this->hasBeenShared($name)) {
|
if ($this->hasBeenShared($name)) {
|
||||||
if (isset($data['parent']) && $data['parent']
|
if (isset($data['parent']) && $data['parent']
|
||||||
? !$this->hasBeenShared($data['parent'])
|
? ! $this->hasBeenShared($data['parent'])
|
||||||
: ((! isset($data['users']) || !$data['users']) && (! isset($data['groups']) || !$data['groups']))
|
: ((! isset($data['users']) || ! $data['users']) && (! isset($data['groups']) || ! $data['groups']))
|
||||||
) {
|
) {
|
||||||
// It is shared but shouldn't anymore
|
// It is shared but shouldn't anymore
|
||||||
$config = $this->unshare($name, isset($data['parent']) ? $data['parent'] : null);
|
$config = $this->unshare($name, isset($data['parent']) ? $data['parent'] : null);
|
||||||
|
@ -579,7 +579,7 @@ class NavigationConfigForm extends ConfigForm
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if ((! $itemForm->requiresParentSelection() || !isset($formData['parent']) || !$formData['parent'])
|
if ((! $itemForm->requiresParentSelection() || ! isset($formData['parent']) || ! $formData['parent'])
|
||||||
&& $this->getUser()->can('application/share/navigation')
|
&& $this->getUser()->can('application/share/navigation')
|
||||||
) {
|
) {
|
||||||
$checked = isset($formData['shared']) ? null : (isset($formData['users']) || isset($formData['groups']));
|
$checked = isset($formData['shared']) ? null : (isset($formData['users']) || isset($formData['groups']));
|
||||||
|
@ -719,10 +719,12 @@ class NavigationConfigForm extends ConfigForm
|
||||||
if (! empty($forbiddenUsers)) {
|
if (! empty($forbiddenUsers)) {
|
||||||
$valid = false;
|
$valid = false;
|
||||||
$this->getElement('users')->addError(
|
$this->getElement('users')->addError(
|
||||||
$this->translate(sprintf(
|
sprintf(
|
||||||
'You are not permitted to share this navigation item with the following users: %s',
|
$this->translate(
|
||||||
|
'You are not permitted to share this navigation item with the following users: %s'
|
||||||
|
),
|
||||||
implode(', ', $forbiddenUsers)
|
implode(', ', $forbiddenUsers)
|
||||||
))
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -741,10 +743,12 @@ class NavigationConfigForm extends ConfigForm
|
||||||
if (! empty($forbiddenGroups)) {
|
if (! empty($forbiddenGroups)) {
|
||||||
$valid = false;
|
$valid = false;
|
||||||
$this->getElement('groups')->addError(
|
$this->getElement('groups')->addError(
|
||||||
$this->translate(sprintf(
|
sprintf(
|
||||||
'You are not permitted to share this navigation item with the following groups: %s',
|
$this->translate(
|
||||||
|
'You are not permitted to share this navigation item with the following groups: %s'
|
||||||
|
),
|
||||||
implode(', ', $forbiddenGroups)
|
implode(', ', $forbiddenGroups)
|
||||||
))
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
@ -332,7 +332,7 @@ EOT;
|
||||||
$caption = t('Content');
|
$caption = t('Content');
|
||||||
}
|
}
|
||||||
|
|
||||||
$label = t(sprintf('Refresh the %s', $caption));
|
$label = sprintf(t('Refresh the %s'), $caption);
|
||||||
$title = $label;
|
$title = $label;
|
||||||
|
|
||||||
$tpl = str_replace(
|
$tpl = str_replace(
|
||||||
|
|
Binary file not shown.
|
@ -0,0 +1,155 @@
|
||||||
|
# Icinga Web 2 - Head for multiple monitoring backends.
|
||||||
|
# Copyright (C) 2017 Icinga Development Team
|
||||||
|
# This file is distributed under the same license as Doc Module.
|
||||||
|
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||||
|
#
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: Doc Module (2.4.2)\n"
|
||||||
|
"Report-Msgid-Bugs-To: dev@icinga.com\n"
|
||||||
|
"POT-Creation-Date: 2017-11-09 13:18+0000\n"
|
||||||
|
"PO-Revision-Date: 2017-11-09 14:34+0100\n"
|
||||||
|
"Language: de_DE\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Poedit-Basepath: .\n"
|
||||||
|
"Last-Translator: Markus Frosch <markus.frosch@icinga.com>\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"X-Generator: Poedit 1.8.11\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/library/Doc/DocController.php:79
|
||||||
|
#: ../../../../modules/doc/library/Doc/DocController.php:107
|
||||||
|
#, php-format
|
||||||
|
msgid "%s Documentation"
|
||||||
|
msgstr "%s Dokumentation"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/application/views/scripts/style/guide.phtml:101
|
||||||
|
msgid "Blockquote"
|
||||||
|
msgstr "Zitat"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/library/Doc/Renderer/DocSectionRenderer.php:68
|
||||||
|
#, php-format
|
||||||
|
msgid "Chapter %s not found"
|
||||||
|
msgstr "Kapitel %s nicht gefunden"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/application/views/scripts/style/guide.phtml:69
|
||||||
|
msgid "Comment List"
|
||||||
|
msgstr "Kommentar Liste"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/configuration.php:19
|
||||||
|
msgid "Developer - Style"
|
||||||
|
msgstr "Entwickler - Style"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/configuration.php:24
|
||||||
|
msgid "Doc"
|
||||||
|
msgstr "Doku"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/configuration.php:6
|
||||||
|
msgid "Documentation"
|
||||||
|
msgstr "Dokumentation"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/application/controllers/IndexController.php:23
|
||||||
|
msgctxt "Tab title"
|
||||||
|
msgid "Documentation"
|
||||||
|
msgstr "Dokumentation"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/library/Doc/DocParser.php:60
|
||||||
|
#, php-format
|
||||||
|
msgid "Documentation directory '%s' is not readable"
|
||||||
|
msgstr "Dokumentations Verzeichnis '%s' ist nicht lesbar"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/application/controllers/SearchController.php:95
|
||||||
|
#: ../../../../modules/doc/application/controllers/IcingawebController.php:29
|
||||||
|
msgid "Documentation for Icinga Web 2 is not available"
|
||||||
|
msgstr "Dokumentation für Icinga Web 2 ist nicht verfügbar"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/application/controllers/ModuleController.php:42
|
||||||
|
#, php-format
|
||||||
|
msgid "Documentation for module '%s' is not available"
|
||||||
|
msgstr "Dokumentation für Modul '%s' ist nicht verfügbar"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/library/Doc/Renderer/DocTocRenderer.php:88
|
||||||
|
msgid "Documentation is empty."
|
||||||
|
msgstr "Dokumentation ist leer"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/application/controllers/StyleController.php:35
|
||||||
|
msgid "Icons"
|
||||||
|
msgstr "Icons"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/application/controllers/StyleController.php:36
|
||||||
|
msgid "List all available icons"
|
||||||
|
msgstr "Liste alles verfügbaren Icons"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/application/views/scripts/index/index.phtml:16
|
||||||
|
msgid "List all modules for which documentation is available"
|
||||||
|
msgstr "Liste aller Module für die Dokumentation verfügbar ist"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/application/controllers/ModuleController.php:77
|
||||||
|
#, php-format
|
||||||
|
msgid "Module '%s' is not installed"
|
||||||
|
msgstr "Modul '%s' ist nicht installiert"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/application/controllers/ModuleController.php:61
|
||||||
|
msgctxt "Tab title"
|
||||||
|
msgid "Module Documentation"
|
||||||
|
msgstr "Modul Dokumentation"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/application/views/scripts/index/index.phtml:13
|
||||||
|
msgid "Module documentations"
|
||||||
|
msgstr "Modul Dokumentationen"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/application/views/scripts/search/index.phtml:5
|
||||||
|
msgid "No documentation found matching the filter"
|
||||||
|
msgstr "Keine Dokumentation gefunden die auf diesen Filter passt"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/library/Doc/Renderer/DocSearchRenderer.php:115
|
||||||
|
#, php-format
|
||||||
|
msgctxt "search.render.section.link"
|
||||||
|
msgid "Show all matches of \"%s\" in the chapter \"%s\""
|
||||||
|
msgstr "Alle Treffer von \"%s\" in Kapitel \"%s\" anzeigen"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/library/Doc/Renderer/DocSearchRenderer.php:123
|
||||||
|
#, php-format
|
||||||
|
msgctxt "search.render.section.link"
|
||||||
|
msgid "Show all matches of \"%s\" in the section \"%s\" of the chapter \"%s\""
|
||||||
|
msgstr "Alle Treffer von \"%s\" in Abschnitt \"%s\" von Kapitel \"%s\" anzeigen"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/library/Doc/Renderer/DocTocRenderer.php:113
|
||||||
|
#, php-format
|
||||||
|
msgctxt "toc.render.section.link"
|
||||||
|
msgid "Show the chapter \"%s\""
|
||||||
|
msgstr "Kapitel \"%s\" anzeigen"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/application/views/scripts/index/index.phtml:10
|
||||||
|
msgid "Show the documentation's table of contents for Icinga Web 2"
|
||||||
|
msgstr "Inhaltsübersicht der Dokumentation von Icinga Web 2 anzeigen"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/application/views/scripts/module/index.phtml:13
|
||||||
|
#, php-format
|
||||||
|
msgid "Show the documentation's table of contents for the %s"
|
||||||
|
msgstr "Inhaltsübersicht der Dokumentation von %s anzeigen"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/library/Doc/Renderer/DocTocRenderer.php:117
|
||||||
|
#, php-format
|
||||||
|
msgctxt "toc.render.section.link"
|
||||||
|
msgid "Show the section \"%s\" of the chapter \"%s\""
|
||||||
|
msgstr "Abschnitt \"%s\" von Kapitel \"%s\" anzeigen"
|
||||||
|
|
||||||
|
#: ../../../../modules/doc/application/controllers/StyleController.php:29
|
||||||
|
msgid "Style Guide"
|
||||||
|
msgstr "Style Guide"
|
||||||
|
|
||||||
|
# Nur aus Beispiel
|
||||||
|
#: ../../../../modules/doc/application/views/scripts/style/guide.phtml:74
|
||||||
|
#: ../../../../modules/doc/application/views/scripts/style/guide.phtml:87
|
||||||
|
msgid "commented"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
# Nur aus Beispiel
|
||||||
|
#: ../../../../modules/doc/application/views/scripts/style/guide.phtml:75
|
||||||
|
#: ../../../../modules/doc/application/views/scripts/style/guide.phtml:88
|
||||||
|
msgid "some time ago"
|
||||||
|
msgstr ""
|
|
@ -158,11 +158,11 @@ class IdoResourcePage extends Form
|
||||||
$db = new DbTool($this->getValues());
|
$db = new DbTool($this->getValues());
|
||||||
$version = $db->connectToDb()->getServerVersion();
|
$version = $db->connectToDb()->getServerVersion();
|
||||||
if (version_compare($version, '9.1', '<')) {
|
if (version_compare($version, '9.1', '<')) {
|
||||||
$this->error($this->translate(sprintf(
|
$this->error(sprintf(
|
||||||
'The server\'s version %s is too old. The minimum required version is %s.',
|
$this->translate('The server\'s version %s is too old. The minimum required version is %s.'),
|
||||||
$version,
|
$version,
|
||||||
'9.1'
|
'9.1'
|
||||||
)));
|
));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
@ -141,22 +141,22 @@ class DbResourcePage extends Form
|
||||||
|
|
||||||
if ($this->getValue('db') === 'pgsql') {
|
if ($this->getValue('db') === 'pgsql') {
|
||||||
if ($connectionError !== null) {
|
if ($connectionError !== null) {
|
||||||
$this->warning($this->translate(sprintf(
|
$this->warning(sprintf(
|
||||||
'Unable to check the server\'s version. This is usually not a critical error as there is'
|
$this->translate('Unable to check the server\'s version. This is usually not a critical error'
|
||||||
. ' probably only access to the database permitted which does not exist yet. If you are'
|
. ' as there is probably only access to the database permitted which does not exist yet. If you are'
|
||||||
. ' absolutely sure you are running PostgreSQL in a version equal to or newer than 9.1,'
|
. ' absolutely sure you are running PostgreSQL in a version equal to or newer than 9.1,'
|
||||||
. ' you can skip the validation and safely proceed to the next step. The error was: %s',
|
. ' you can skip the validation and safely proceed to the next step. The error was: %s'),
|
||||||
$connectionError->getMessage()
|
$connectionError->getMessage()
|
||||||
)));
|
));
|
||||||
$state = false;
|
$state = false;
|
||||||
} else {
|
} else {
|
||||||
$version = $db->getServerVersion();
|
$version = $db->getServerVersion();
|
||||||
if (version_compare($version, '9.1', '<')) {
|
if (version_compare($version, '9.1', '<')) {
|
||||||
$this->error($this->translate(sprintf(
|
$this->error(sprintf(
|
||||||
'The server\'s version %s is too old. The minimum required version is %s.',
|
$this->translate('The server\'s version %s is too old. The minimum required version is %s.'),
|
||||||
$version,
|
$version,
|
||||||
'9.1'
|
'9.1'
|
||||||
)));
|
));
|
||||||
$state = false;
|
$state = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,132 @@
|
||||||
|
<?php
|
||||||
|
/* Icinga Web 2 | (c) 2017 Icinga Development Team | GPLv2+ */
|
||||||
|
|
||||||
|
namespace Icinga\Module\Translation\Clicommands;
|
||||||
|
|
||||||
|
use Icinga\Date\DateFormatter;
|
||||||
|
use Icinga\Module\Translation\Cli\ArrayToTextTableHelper;
|
||||||
|
use Icinga\Module\Translation\Cli\TranslationCommand;
|
||||||
|
use Icinga\Util\Translator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Timestamp test helper
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class TestCommand extends TranslationCommand
|
||||||
|
{
|
||||||
|
protected $locales = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get translation examples for DateFormatter
|
||||||
|
*
|
||||||
|
* To help you check if the values got translated correctly
|
||||||
|
*
|
||||||
|
* USAGE:
|
||||||
|
*
|
||||||
|
* icingacli translation test dateformatter <locale>
|
||||||
|
*
|
||||||
|
* EXAMPLES:
|
||||||
|
*
|
||||||
|
* icingacli translation test dateformatter de_DE
|
||||||
|
* icingacli translation test dateformatter fr_FR
|
||||||
|
*/
|
||||||
|
public function dateformatterAction()
|
||||||
|
{
|
||||||
|
$time = time();
|
||||||
|
|
||||||
|
/** @uses DateFormatter::timeAgo */
|
||||||
|
$this->printTable($this->getMultiTranslated(
|
||||||
|
'Time Ago',
|
||||||
|
array('Icinga\Date\DateFormatter', 'timeAgo'),
|
||||||
|
array(
|
||||||
|
"15 sec" => $time - 15,
|
||||||
|
"62 sec" => $time - 62,
|
||||||
|
"10 min" => $time - 600,
|
||||||
|
"1h" => $time - 1 * 3600,
|
||||||
|
"3h" => $time - 3 * 3600,
|
||||||
|
"25h" => $time - 25 * 3600,
|
||||||
|
"31d" => $time - 31 * 24 * 3600,
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->printTable($this->getMultiTranslated(
|
||||||
|
'Time Since',
|
||||||
|
array('Icinga\Date\DateFormatter', 'timeSince'),
|
||||||
|
array(
|
||||||
|
"15 sec" => $time - 15,
|
||||||
|
"62 sec" => $time - 62,
|
||||||
|
"10 min" => $time - 600,
|
||||||
|
"1h" => $time - 1 * 3600,
|
||||||
|
"3h" => $time - 3 * 3600,
|
||||||
|
"25h" => $time - 25 * 3600,
|
||||||
|
"31d" => $time - 31 * 24 * 3600,
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->printTable($this->getMultiTranslated(
|
||||||
|
'Time Until',
|
||||||
|
array('Icinga\Date\DateFormatter', 'timeUntil'),
|
||||||
|
array(
|
||||||
|
"15 sec" => $time + 15,
|
||||||
|
"62 sec" => $time + 62,
|
||||||
|
"10 min" => $time + 600,
|
||||||
|
"1h" => $time + 1 * 3600,
|
||||||
|
"3h" => $time + 3 * 3600,
|
||||||
|
"25h" => $time + 25 * 3600,
|
||||||
|
"31d" => $time + 31 * 24 * 3600,
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function defaultAction()
|
||||||
|
{
|
||||||
|
$this->dateformatterAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
foreach ($this->params->getAllStandalone() as $l) {
|
||||||
|
$this->locales[] = $l;
|
||||||
|
}
|
||||||
|
// TODO: get from to environment by default?
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function callTranslated($callback, $arguments, $locale = 'C')
|
||||||
|
{
|
||||||
|
Translator::setupLocale($locale);
|
||||||
|
return call_user_func_array($callback, $arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getMultiTranslated($name, $callback, $arguments, $locales = null)
|
||||||
|
{
|
||||||
|
if ($locales === null) {
|
||||||
|
$locales = $this->locales;
|
||||||
|
}
|
||||||
|
array_unshift($locales, 'C');
|
||||||
|
|
||||||
|
$rows = array();
|
||||||
|
|
||||||
|
foreach ($arguments as $k => $args) {
|
||||||
|
$row = array($name => $k);
|
||||||
|
|
||||||
|
if (! is_array($args)) {
|
||||||
|
$args = array($args);
|
||||||
|
}
|
||||||
|
foreach ($locales as $locale) {
|
||||||
|
$row[$locale] = $this->callTranslated($callback, $args, $locale);
|
||||||
|
}
|
||||||
|
$rows[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function printTable($rows)
|
||||||
|
{
|
||||||
|
$tt = new ArrayToTextTableHelper($rows);
|
||||||
|
$tt->showHeaders(true);
|
||||||
|
$tt->render();
|
||||||
|
echo "\n\n";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,233 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Icinga\Module\Translation\Cli;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array to Text Table Generation Class
|
||||||
|
*
|
||||||
|
* @author Tony Landis <tony@tonylandis.com>
|
||||||
|
* @link http://www.tonylandis.com/
|
||||||
|
* @copyright Copyright (C) 2006-2009 Tony Landis
|
||||||
|
* @license http://www.opensource.org/licenses/bsd-license.php
|
||||||
|
*/
|
||||||
|
class ArrayToTextTableHelper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var array The array for processing
|
||||||
|
*/
|
||||||
|
protected $rows;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int The column width settings
|
||||||
|
*/
|
||||||
|
protected $cs = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int The Row lines settings
|
||||||
|
*/
|
||||||
|
protected $rs = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int The Column index of keys
|
||||||
|
*/
|
||||||
|
protected $keys = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int Max Column Height (returns)
|
||||||
|
*/
|
||||||
|
protected $mH = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int Max Row Width (chars)
|
||||||
|
*/
|
||||||
|
protected $mW = 30;
|
||||||
|
|
||||||
|
protected $head = false;
|
||||||
|
protected $pcen = "+";
|
||||||
|
protected $prow = "-";
|
||||||
|
protected $pcol = "|";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare array into textual format
|
||||||
|
*
|
||||||
|
* @param array $rows The input array
|
||||||
|
* @param bool $head Show heading
|
||||||
|
* @param int $maxWidth Max Column Height (returns)
|
||||||
|
* @param int $maxHeight Max Row Width (chars)
|
||||||
|
*/
|
||||||
|
public function __construct($rows)
|
||||||
|
{
|
||||||
|
$this->rows =& $rows;
|
||||||
|
$this->cs = array();
|
||||||
|
$this->rs = array();
|
||||||
|
|
||||||
|
if (! $xc = count($this->rows)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->keys = array_keys($this->rows[0]);
|
||||||
|
$columns = count($this->keys);
|
||||||
|
|
||||||
|
for ($x = 0; $x < $xc; $x++) {
|
||||||
|
for ($y = 0; $y < $columns; $y++) {
|
||||||
|
$this->setMax($x, $y, $this->rows[$x][$this->keys[$y]]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the headers using the key values of the array for the titles
|
||||||
|
*
|
||||||
|
* @param bool $bool
|
||||||
|
*/
|
||||||
|
public function showHeaders($bool)
|
||||||
|
{
|
||||||
|
if ($bool) {
|
||||||
|
$this->setHeading();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the maximum width (number of characters) per column before truncating
|
||||||
|
*
|
||||||
|
* @param int $maxWidth
|
||||||
|
*/
|
||||||
|
public function setMaxWidth($maxWidth)
|
||||||
|
{
|
||||||
|
$this->mW = (int) $maxWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the maximum height (number of lines) per row before truncating
|
||||||
|
*
|
||||||
|
* @param int $maxHeight
|
||||||
|
*/
|
||||||
|
public function setMaxHeight($maxHeight)
|
||||||
|
{
|
||||||
|
$this->mH = (int) $maxHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints the data to a text table
|
||||||
|
*
|
||||||
|
* @param bool $return Set to 'true' to return text rather than printing
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function render($return = false)
|
||||||
|
{
|
||||||
|
if ($return) {
|
||||||
|
ob_start(null, 0, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->printLine();
|
||||||
|
$this->printHeading();
|
||||||
|
|
||||||
|
$rc = count($this->rows);
|
||||||
|
for ($i = 0; $i < $rc;
|
||||||
|
$i++) {
|
||||||
|
$this->printRow($i);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->printLine(false);
|
||||||
|
|
||||||
|
if ($return) {
|
||||||
|
$contents = ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
return $contents;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setHeading()
|
||||||
|
{
|
||||||
|
$data = array();
|
||||||
|
foreach ($this->keys as $colKey => $value) {
|
||||||
|
$this->setMax(false, $colKey, $value);
|
||||||
|
$data[$colKey] = strtoupper($value);
|
||||||
|
}
|
||||||
|
if (! is_array($data)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$this->head = $data;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function printLine($nl = true)
|
||||||
|
{
|
||||||
|
print $this->pcen;
|
||||||
|
foreach ($this->cs as $key => $val) {
|
||||||
|
print $this->prow .
|
||||||
|
str_pad('', $val, $this->prow, STR_PAD_RIGHT) .
|
||||||
|
$this->prow .
|
||||||
|
$this->pcen;
|
||||||
|
}
|
||||||
|
if ($nl) {
|
||||||
|
print "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function printHeading()
|
||||||
|
{
|
||||||
|
if (! is_array($this->head)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
print $this->pcol;
|
||||||
|
foreach ($this->cs as $key => $val) {
|
||||||
|
print ' ' .
|
||||||
|
str_pad($this->head[$key], $val, ' ', STR_PAD_BOTH) .
|
||||||
|
' ' .
|
||||||
|
$this->pcol;
|
||||||
|
}
|
||||||
|
|
||||||
|
print "\n";
|
||||||
|
$this->printLine();
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function printRow($rowKey)
|
||||||
|
{
|
||||||
|
// loop through each line
|
||||||
|
for ($line = 1; $line <= $this->rs[$rowKey]; $line++) {
|
||||||
|
print $this->pcol;
|
||||||
|
for ($colKey = 0; $colKey < count($this->keys); $colKey++) {
|
||||||
|
print " ";
|
||||||
|
print str_pad(
|
||||||
|
substr($this->rows[$rowKey][$this->keys[$colKey]], ($this->mW * ($line - 1)), $this->mW),
|
||||||
|
$this->cs[$colKey],
|
||||||
|
' ',
|
||||||
|
STR_PAD_RIGHT
|
||||||
|
);
|
||||||
|
print " " . $this->pcol;
|
||||||
|
}
|
||||||
|
print "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setMax($rowKey, $colKey, &$colVal)
|
||||||
|
{
|
||||||
|
$w = mb_strlen($colVal);
|
||||||
|
$h = 1;
|
||||||
|
if ($w > $this->mW) {
|
||||||
|
$h = ceil($w % $this->mW);
|
||||||
|
if ($h > $this->mH) {
|
||||||
|
$h = $this->mH;
|
||||||
|
}
|
||||||
|
$w = $this->mW;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! isset($this->cs[$colKey]) || $this->cs[$colKey] < $w) {
|
||||||
|
$this->cs[$colKey] = $w;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($rowKey !== false && (! isset($this->rs[$rowKey]) || $this->rs[$rowKey] < $h)) {
|
||||||
|
$this->rs[$rowKey] = $h;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue