new type API

This commit is contained in:
Roland Gruber 2017-04-25 20:14:59 +02:00
parent cd4cc1ae26
commit 394faed7eb
3 changed files with 10 additions and 32 deletions

View File

@ -71,7 +71,9 @@ This is a list of API changes for all LAM releases.
<li>Removed global functions:</li> <li>Removed global functions:</li>
<ul> <ul>
<li>getListClassName() -&gt; use ConfiguredType-&gt;getBaseType()-&gt;getListClassName() </li> <li>getListClassName() -&gt; use ConfiguredType-&gt;getBaseType()-&gt;getListClassName() </li>
<li>getTypeAlias() -&gt; ConfiguredType-&gt;getBaseType()-&gt;getAlias()</li> <li>getTypeAlias() -&gt; use ConfiguredType-&gt;getBaseType()-&gt;getAlias()</li>
<li>getDefaultListAttributes() -&gt; use ConfiguredType-&gt;getBaseType()-&gt;getDefaultListAttributes()</li>
<li>getListAttributeDescriptions() -&gt; use ConfiguredType-&gt;getBaseType()-&gt;getListAttributeDescriptions()</li>
</ul> </ul>

View File

@ -80,30 +80,6 @@ function getTypeDescription($type) {
return $obj->getDescription(); return $obj->getDescription();
} }
/**
* Returns the default attribute list for an account type.
* It is used as default value for the configuration editor.
*
* @param string $type account type
* @return string attribute list
*/
function getDefaultListAttributes($type) {
$obj = new $type();
return $obj->getDefaultListAttributes();
}
/**
* Returns a list of attributes which have a translated description.
* This is used for the head row in the list view.
*
* @param string $type account type
* @return array list of descriptions
*/
function getListAttributeDescriptions($type) {
$obj = new $type();
return $obj->getListAttributeDescriptions();
}
/** /**
* Returns the account type for a given type id. * Returns the account type for a given type id.
* *
@ -207,7 +183,7 @@ class ConfiguredType {
$attributeSpecs = explode(';', $attributeString); $attributeSpecs = explode(';', $attributeString);
$attributes = array(); $attributes = array();
foreach ($attributeSpecs as $attributeSpec) { foreach ($attributeSpecs as $attributeSpec) {
$attributes[] = new ListAttribute($attributeSpec, $this->scope); $attributes[] = new ListAttribute($attributeSpec, $this);
} }
$this->attributes = $attributes; $this->attributes = $attributes;
return $this->attributes; return $this->attributes;
@ -333,17 +309,17 @@ class ListAttribute {
private $attributeSpec; private $attributeSpec;
private $scope; private $type;
/** /**
* Constructor. * Constructor.
* *
* @param string $attributeSpec spec of attribute (e.g. '#uid' or 'uid:User') * @param string $attributeSpec spec of attribute (e.g. '#uid' or 'uid:User')
* @param string $scope account type (e.g. 'user') * @param ConfiguredType $type account type (e.g. 'user')
*/ */
public function __construct($attributeSpec, $scope) { public function __construct($attributeSpec, $type) {
$this->attributeSpec = $attributeSpec; $this->attributeSpec = $attributeSpec;
$this->scope = $scope; $this->type = $type;
} }
/** /**
* Returns the name of the LDAP attribute. * Returns the name of the LDAP attribute.
@ -366,7 +342,7 @@ class ListAttribute {
public function getAlias() { public function getAlias() {
if ($this->isPredefined()) { if ($this->isPredefined()) {
$name = strtolower(substr($this->attributeSpec, 1)); $name = strtolower(substr($this->attributeSpec, 1));
$hash_table = getListAttributeDescriptions($this->scope); $hash_table = $this->type->getBaseType()->getListAttributeDescriptions();
$hash_table = array_change_key_case($hash_table, CASE_LOWER); $hash_table = array_change_key_case($hash_table, CASE_LOWER);
if (isset($hash_table[$name])) { if (isset($hash_table[$name])) {
return $hash_table[$name]; return $hash_table[$name];

View File

@ -291,7 +291,7 @@ if (sizeof($activeTypes) > 0) {
$attributes = $typeSettings['attr_' . $activeType->getId()]; $attributes = $typeSettings['attr_' . $activeType->getId()];
} }
else { else {
$attributes = \LAM\TYPES\getDefaultListAttributes($activeType->getScope()); $attributes = $activeType->getBaseType()->getDefaultListAttributes();
} }
$attrsInput = new htmlTableExtendedInputField(_("List attributes"), 'attr_' . $activeType->getId(), $attributes, '206'); $attrsInput = new htmlTableExtendedInputField(_("List attributes"), 'attr_' . $activeType->getId(), $attributes, '206');
$attrsInput->setFieldSize(40); $attrsInput->setFieldSize(40);