From b78dc34d360152106da5e6fc40587c664190a9d1 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 5 Jul 2017 17:44:18 +0200 Subject: [PATCH] allow types to define their custom icon --- lam/lib/baseType.inc | 22 +++++++++++++++++- lam/lib/types.inc | 11 +++++++++ lam/templates/config/confmodules.php | 2 +- lam/templates/config/conftypes.php | 32 +++++++++++++++----------- lam/templates/main_header.php | 2 +- lam/templates/pdfedit/pdfmain.php | 3 ++- lam/templates/profedit/profilemain.php | 3 ++- 7 files changed, 57 insertions(+), 18 deletions(-) diff --git a/lam/lib/baseType.inc b/lam/lib/baseType.inc index b8f3a834..fda44d90 100644 --- a/lam/lib/baseType.inc +++ b/lam/lib/baseType.inc @@ -5,7 +5,7 @@ use LAM\TYPES\ConfiguredType; $Id$ This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) - Copyright (C) 2005 - 2016 Roland Gruber + Copyright (C) 2005 - 2017 Roland Gruber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -201,6 +201,26 @@ class baseType { return $this->type; } + /** + * Returns the file name of the type icon. + * It needs to be 16x16px and located in graphics folder. + * By default this is "{type name}.png" + * + * @return string file name + */ + public function getIcon() { + return get_class($this) . '.png'; + } + + /** + * Returns the scope name. + * + * @return string scope + */ + public function getScope() { + return get_class($this); + } + } ?> \ No newline at end of file diff --git a/lam/lib/types.inc b/lam/lib/types.inc index acf068bc..4eabd4df 100644 --- a/lam/lib/types.inc +++ b/lam/lib/types.inc @@ -297,6 +297,17 @@ class ConfiguredType { return explode(',', $modules); } + /** + * Returns the file name of the type icon. + * It is 16x16px and located in graphics folder. + * + * @return string file name + */ + public function getIcon() { + $baseType = $this->getBaseType(); + return $baseType->getIcon(); + } + } /** diff --git a/lam/templates/config/confmodules.php b/lam/templates/config/confmodules.php index 0f2284c9..f821e674 100644 --- a/lam/templates/config/confmodules.php +++ b/lam/templates/config/confmodules.php @@ -306,7 +306,7 @@ function config_showAccountModules($type, &$container) { } // add account module selection - $container->addElement(new htmlSubTitle($type->getAlias(), '../../graphics/' . $type->getScope() . '.png'), true); + $container->addElement(new htmlSubTitle($type->getAlias(), '../../graphics/' . $type->getIcon()), true); $container->addElement(new htmlOutputText(_("Selected modules"))); $container->addElement(new htmlOutputText('')); $container->addElement(new htmlOutputText(_("Available modules")), true); diff --git a/lam/templates/config/conftypes.php b/lam/templates/config/conftypes.php index 270e0405..13b33948 100644 --- a/lam/templates/config/conftypes.php +++ b/lam/templates/config/conftypes.php @@ -15,7 +15,7 @@ use \htmlTableExtendedInputCheckbox; $Id$ This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) - Copyright (C) 2004 - 2016 Roland Gruber + Copyright (C) 2004 - 2017 Roland Gruber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -129,10 +129,10 @@ $availableScopes = array(); foreach ($allScopes as $scope) { $scopeObj = new $scope(null); if (!in_array($scope, $activeScopes) || $scopeObj->supportsMultipleConfigs()) { - $availableScopes[$scope] = $scopeObj->getAlias(); + $availableScopes[] = $scopeObj; } } -natcasesort($availableScopes); +usort($availableScopes, '\LAM\CONFIG\compareTypesByAlias'); echo $_SESSION['header']; @@ -246,12 +246,12 @@ $container = new htmlTable(); if (sizeof($availableScopes) > 0) { $container->addElement(new htmlSubTitle(_("Available account types")), true); $availableContainer = new htmlTable(); - foreach ($availableScopes as $key => $value) { - $availableContainer->addElement(new htmlImage('../../graphics/' . $key . '.png')); - $availableContainer->addElement(new htmlOutputText($value)); + foreach ($availableScopes as $availableScope) { + $availableContainer->addElement(new htmlImage('../../graphics/' . $availableScope->getIcon())); + $availableContainer->addElement(new htmlOutputText($availableScope->getAlias())); $availableContainer->addElement(new htmlSpacer('10px', null)); - $availableContainer->addElement(new htmlOutputText(\LAM\TYPES\getTypeDescription($key))); - $button = new htmlButton('add_' . $key, 'add.png', true); + $availableContainer->addElement(new htmlOutputText($availableScope->getDescription())); + $button = new htmlButton('add_' . $availableScope->getScope(), 'add.png', true); $button->setTitle(_("Add")); $availableContainer->addElement($button, true); } @@ -268,7 +268,7 @@ if (sizeof($activeTypes) > 0) { // title $titleGroup = new htmlGroup(); $titleGroup->colspan = 6; - $titleGroup->addElement(new htmlImage('../../graphics/' . $activeType->getScope() . '.png')); + $titleGroup->addElement(new htmlImage('../../graphics/' . $activeType->getIcon())); $titleText = new htmlOutputText($activeType->getAlias()); $titleText->setIsBold(true); $titleGroup->addElement($titleText); @@ -490,8 +490,14 @@ function checkInput() { return $errors; } +/** + * Compares types by alias for sorting. + * + * @param \baseType $a first type + * @param \baseType $b second type + */ +function compareTypesByAlias($a, $b) { + return strnatcasecmp($a->getAlias(), $b->getAlias()); +} + ?> - - - - diff --git a/lam/templates/main_header.php b/lam/templates/main_header.php index 069aedac..6183cb78 100644 --- a/lam/templates/main_header.php +++ b/lam/templates/main_header.php @@ -214,7 +214,7 @@ function printTypeTabs($headerPrefix) { } $link = '' . - '' . $type->getId() . ' ' . + '' . $type->getId() . ' ' . $type->getAlias() . ''; echo '
  • '; echo $link; diff --git a/lam/templates/pdfedit/pdfmain.php b/lam/templates/pdfedit/pdfmain.php index 70cbdc45..cb7b2aa1 100644 --- a/lam/templates/pdfedit/pdfmain.php +++ b/lam/templates/pdfedit/pdfmain.php @@ -194,6 +194,7 @@ foreach ($sortedTypes as $typeId => $title) { 'typeId' => $type->getId(), 'scope' => $type->getScope(), 'title' => $title, + 'icon' => $type->getIcon(), 'templates' => ""); $availableTypes[$title] = $type->getId(); } @@ -250,7 +251,7 @@ include '../main_header.php'; $existingContainer->addElement(new htmlSpacer(null, '10px'), true); } - $existingContainer->addElement(new htmlImage('../../graphics/' . $templateClasses[$i]['scope'] . '.png')); + $existingContainer->addElement(new htmlImage('../../graphics/' . $templateClasses[$i]['icon'])); $existingContainer->addElement(new htmlSpacer('3px', null)); $existingContainer->addElement(new htmlOutputText($templateClasses[$i]['title'])); $existingContainer->addElement(new htmlSpacer('3px', null)); diff --git a/lam/templates/profedit/profilemain.php b/lam/templates/profedit/profilemain.php index c425e5a4..46a1e81e 100644 --- a/lam/templates/profedit/profilemain.php +++ b/lam/templates/profedit/profilemain.php @@ -79,6 +79,7 @@ foreach ($types as $type) { 'typeId' => $type->getId(), 'scope' => $type->getScope(), 'title' => $type->getAlias(), + 'icon' => $type->getIcon(), 'profiles' => ""); } $profileClassesKeys = array_keys($profileClassesTemp); @@ -229,7 +230,7 @@ for ($i = 0; $i < sizeof($profileClasses); $i++) { $existingContainer->addElement(new htmlSpacer(null, '10px'), true); } - $existingContainer->addElement(new htmlImage('../../graphics/' . \LAM\TYPES\getScopeFromTypeId($profileClasses[$i]['typeId']) . '.png')); + $existingContainer->addElement(new htmlImage('../../graphics/' . $profileClasses[$i]['icon'])); $existingContainer->addElement(new htmlSpacer('3px', null)); $existingContainer->addElement(new htmlOutputText($profileClasses[$i]['title'])); $existingContainer->addElement(new htmlSpacer('3px', null));