new type API

This commit is contained in:
Roland Gruber 2017-04-25 20:03:38 +02:00
parent b4248bc898
commit cd4cc1ae26
6 changed files with 36 additions and 54 deletions

View File

@ -16,6 +16,7 @@
@ -65,8 +66,14 @@ This is a list of API changes for all LAM releases.
<li>getManagedObjectClasses()</li>
<li>getManagedAttributes()</li>
<li>getLDAPAliases() <br>
</li>
</li>
</ul>
<li>Removed global functions:</li>
<ul>
<li>getListClassName() -&gt; use ConfiguredType-&gt;getBaseType()-&gt;getListClassName() </li>
<li>getTypeAlias() -&gt; ConfiguredType-&gt;getBaseType()-&gt;getAlias()</li>
</ul>
</ul>

View File

@ -1,5 +1,6 @@
<?php
namespace LAM\HELP;
use \LAM\TYPES\TypeManager;
/*
$Id$
@ -34,19 +35,22 @@ $Id$
*/
// generate help entry for translated list attributes
$types = \LAM\TYPES\getTypes();
$entry206Example = "";
for ($i = 0; $i < sizeof($types); $i++) {
$entry206Example .= "<b>" . \LAM\TYPES\getTypeAlias($types[$i]) . ":</b><br>\n";
$descriptions = \LAM\TYPES\getListAttributeDescriptions($types[$i]);
$attributes = array_keys($descriptions);
for ($a = 0; $a < sizeof($attributes); $a++) {
$entry206Example .= "#" . $attributes[$a] . ": " . $descriptions[$attributes[$a]];
if ($a < (sizeof($attributes) - 1)) {
$entry206Example .= ", ";
if (isset($_SESSION['conf_config'])) {
$typeManager = new TypeManager($_SESSION['conf_config']);
$types = $typeManager->getConfiguredTypes();
foreach ($types as $type) {
$entry206Example .= "<b>" . $type->getAlias() . ":</b><br>\n";
$descriptions = $type->getBaseType()->getListAttributeDescriptions();
$attributes = array_keys($descriptions);
for ($a = 0; $a < sizeof($attributes); $a++) {
$entry206Example .= "#" . $attributes[$a] . ": " . $descriptions[$attributes[$a]];
if ($a < (sizeof($attributes) - 1)) {
$entry206Example .= ", ";
}
}
$entry206Example .= "<br><br>";
}
$entry206Example .= "<br><br>";
}
$helpArray = array (

View File

@ -69,28 +69,6 @@ function getTypes() {
return $return;
}
/**
* Returns the alias name of an account type.
*
* @param string $type type name
* @param \LAMConfig $config config (optional, uses $_SESSION['config'] by default)
* @return string type alias
*/
function getTypeAlias($type, $config = null) {
if (($config == null) && !empty($_SESSION['config'])) {
$config = $_SESSION['config'];
}
if ($config != null) {
$typeSettings = $config->get_typeSettings();
if (!empty($typeSettings['customLabel_' . $type])) {
return $typeSettings['customLabel_' . $type];
}
}
$scope = getScopeFromTypeId($type);
$obj = new $scope();
return $obj->getAlias();
}
/**
* Returns the description of an account type.
*
@ -98,21 +76,10 @@ function getTypeAlias($type, $config = null) {
* @return string type description
*/
function getTypeDescription($type) {
$obj = new $type();
$obj = new $type(null);
return $obj->getDescription();
}
/**
* Returns the class name for the list object.
*
* @param string $type account type
* @return string class name
*/
function getListClassName($type) {
$obj = new $type();
return $obj->getListClassName();
}
/**
* Returns the default attribute list for an account type.
* It is used as default value for the configuration editor.
@ -255,8 +222,11 @@ class ConfiguredType {
if ($this->alias !== null) {
return $this->alias;
}
$this->alias = getTypeAlias($this->id, $this->typeManager->getConfig());
return $this->alias;
$typeSettings = $this->typeManager->getConfig()->get_typeSettings();
if (!empty($typeSettings['customLabel_' . $this->id])) {
return $typeSettings['customLabel_' . $this->id];
}
return $this->getBaseType()->getAlias();
}
/**

View File

@ -427,17 +427,17 @@ function checkInput() {
// set suffixes
elseif (substr($key, 0, 7) == "suffix_") {
$typeSettings[$key] = trim($_POST[$key]);
$type = substr($postKeys[$i], 7);
$type = $typeManager->getConfiguredType(substr($postKeys[$i], 7));
if (strlen($_POST[$key]) < 1) {
$errors[] = array("ERROR", _("LDAP Suffix is invalid!"), \LAM\TYPES\getTypeAlias($type));
$errors[] = array("ERROR", _("LDAP Suffix is invalid!"), $type->getAlias());
}
}
// set attributes
elseif (substr($key, 0, 5) == "attr_") {
$typeSettings[$key] = $_POST[$key];
$type = substr($postKeys[$i], 5);
$type = $typeManager->getConfiguredType(substr($postKeys[$i], 5));
if (!is_string($_POST[$key]) || !preg_match("/^((#[^:;]+)|([^:;]*:[^:;]+))(;((#[^:;]+)|([^:;]*:[^:;]+)))*$/", $_POST[$key])) {
$errors[] = array("ERROR", _("List attributes are invalid!"), \LAM\TYPES\getTypeAlias($type));
$errors[] = array("ERROR", _("List attributes are invalid!"), $type->getAlias());
}
}
// set filter

View File

@ -52,7 +52,7 @@ if ($type->isHidden()) {
}
// create list object if needed
$listClass = LAM\TYPES\getListClassName($type->getScope());
$listClass = $type->getBaseType()->getListClassName();
if (!isset($_SESSION['list_' . $type->getId()])) {
$list = new $listClass($type);
$_SESSION['list_' . $type->getId()] = $list;

View File

@ -105,14 +105,15 @@ $container = new htmlTable();
$container->addElement(new htmlTitle(_('PDF editor')), true);
if (isset($_POST['deleteProfile']) && ($_POST['deleteProfile'] == 'true')) {
$typeToDelete = $typeManager->getConfiguredType($_POST['profileDeleteType']);
// delete structure
if (\LAM\PDF\deletePDFStructure($_POST['profileDeleteType'], $_POST['profileDeleteName'])) {
$message = new htmlStatusMessage('INFO', _('Deleted PDF structure.'), \LAM\TYPES\getTypeAlias($_POST['profileDeleteType']) . ': ' . htmlspecialchars($_POST['profileDeleteName']));
$message = new htmlStatusMessage('INFO', _('Deleted PDF structure.'), $typeToDelete->getAlias() . ': ' . htmlspecialchars($_POST['profileDeleteName']));
$message->colspan = 10;
$container->addElement($message, true);
}
else {
$message = new htmlStatusMessage('ERROR', _('Unable to delete PDF structure!'), \LAM\TYPES\getTypeAlias($_POST['profileDeleteType']) . ': ' . htmlspecialchars($_POST['profileDeleteName']));
$message = new htmlStatusMessage('ERROR', _('Unable to delete PDF structure!'), $typeToDelete->getAlias() . ': ' . htmlspecialchars($_POST['profileDeleteName']));
$message->colspan = 10;
$container->addElement($message, true);
}