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>getManagedObjectClasses()</li>
<li>getManagedAttributes()</li> <li>getManagedAttributes()</li>
<li>getLDAPAliases() <br> <li>getLDAPAliases() <br>
</li> </li>
</ul> </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> </ul>

View File

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

View File

@ -69,28 +69,6 @@ function getTypes() {
return $return; 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. * Returns the description of an account type.
* *
@ -98,21 +76,10 @@ function getTypeAlias($type, $config = null) {
* @return string type description * @return string type description
*/ */
function getTypeDescription($type) { function getTypeDescription($type) {
$obj = new $type(); $obj = new $type(null);
return $obj->getDescription(); 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. * Returns the default attribute list for an account type.
* It is used as default value for the configuration editor. * It is used as default value for the configuration editor.
@ -255,8 +222,11 @@ class ConfiguredType {
if ($this->alias !== null) { if ($this->alias !== null) {
return $this->alias; return $this->alias;
} }
$this->alias = getTypeAlias($this->id, $this->typeManager->getConfig()); $typeSettings = $this->typeManager->getConfig()->get_typeSettings();
return $this->alias; 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 // set suffixes
elseif (substr($key, 0, 7) == "suffix_") { elseif (substr($key, 0, 7) == "suffix_") {
$typeSettings[$key] = trim($_POST[$key]); $typeSettings[$key] = trim($_POST[$key]);
$type = substr($postKeys[$i], 7); $type = $typeManager->getConfiguredType(substr($postKeys[$i], 7));
if (strlen($_POST[$key]) < 1) { 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 // set attributes
elseif (substr($key, 0, 5) == "attr_") { elseif (substr($key, 0, 5) == "attr_") {
$typeSettings[$key] = $_POST[$key]; $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])) { 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 // set filter

View File

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

View File

@ -105,14 +105,15 @@ $container = new htmlTable();
$container->addElement(new htmlTitle(_('PDF editor')), true); $container->addElement(new htmlTitle(_('PDF editor')), true);
if (isset($_POST['deleteProfile']) && ($_POST['deleteProfile'] == 'true')) { if (isset($_POST['deleteProfile']) && ($_POST['deleteProfile'] == 'true')) {
$typeToDelete = $typeManager->getConfiguredType($_POST['profileDeleteType']);
// delete structure // delete structure
if (\LAM\PDF\deletePDFStructure($_POST['profileDeleteType'], $_POST['profileDeleteName'])) { 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; $message->colspan = 10;
$container->addElement($message, true); $container->addElement($message, true);
} }
else { 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; $message->colspan = 10;
$container->addElement($message, true); $container->addElement($message, true);
} }