LSformElement::select_object : display unrecognized values and detect value corresponding to more than one object.

This commit is contained in:
Benjamin Renard 2012-10-03 12:23:49 +02:00
parent 38183ece71
commit 6ebfc6a20b
6 changed files with 1687 additions and 1655 deletions

View file

@ -27,6 +27,8 @@
*/ */
class LSattr_html_select_object extends LSattr_html{ class LSattr_html_select_object extends LSattr_html{
var $unrecognizedValues=false;
/** /**
* Ajoute l'attribut au formualaire passer en paramètre * Ajoute l'attribut au formualaire passer en paramètre
* *
@ -145,9 +147,9 @@ class LSattr_html_select_object extends LSattr_html{
} }
if (is_array($values)) { if (is_array($values)) {
$obj = new $conf['object_type']();
if(($conf['value_attribute']=='dn')||($conf['value_attribute']=='%{dn}')||$fromDNs) { if(($conf['value_attribute']=='dn')||($conf['value_attribute']=='%{dn}')||$fromDNs) {
$DNs=$values; $DNs=$values;
$obj = new $conf['object_type']();
foreach($DNs as $dn) { foreach($DNs as $dn) {
if($obj -> loadData($dn)) { if($obj -> loadData($dn)) {
$retInfos[$dn] = $obj -> getDisplayName($conf['display_name_format']); $retInfos[$dn] = $obj -> getDisplayName($conf['display_name_format']);
@ -159,25 +161,28 @@ class LSattr_html_select_object extends LSattr_html{
LSerror :: addErrorCode('LSattr_html_select_object_02',$this -> name); LSerror :: addErrorCode('LSattr_html_select_object_02',$this -> name);
return; return;
} }
$filters=array(); $unrecognizedValues=array();
foreach($values as $val) { foreach($values as $val) {
if (!empty($val)) { if (!empty($val)) {
$filters[]=Net_LDAP2_Filter::create($conf['value_attribute'],'equals',$val); $filter=Net_LDAP2_Filter::create($conf['value_attribute'],'equals',$val);
}
}
if (!empty($filters)) {
$filter=LSldap::combineFilters('or',$filters);
if ($filter) {
$obj = new $conf['object_type']();
$listobj = $obj -> listObjectsName($filter,NULL,array(),$conf['display_name_format']); $listobj = $obj -> listObjectsName($filter,NULL,array(),$conf['display_name_format']);
if (count($listobj)==1) {
foreach($listobj as $dn => $name) { foreach($listobj as $dn => $name) {
$DNs[]=$dn; $DNs[]=$dn;
$retInfos[$dn] = $name; $retInfos[$dn] = $name;
} }
} }
else {
$unrecognizedValues[]=$val;
if(count($listobj)>1) {
LSerror :: addErrorCode('LSattr_html_select_object_03',array('val' => $val, 'attribute' => $this -> name));
} }
} }
} }
}
$this -> unrecognizedValues=$unrecognizedValues;
}
}
else { else {
return false; return false;
} }
@ -225,5 +230,8 @@ _("LSattr_html_select_object : LSobject type is undefined (attribute : %{attr}).
LSerror :: defineError('LSattr_html_select_object_02', LSerror :: defineError('LSattr_html_select_object_02',
_("LSattr_html_select_object : the value of the parameter value_attribute in the configuration of the attribute %{attrs} is incorrect. This attribute does not exists.") _("LSattr_html_select_object : the value of the parameter value_attribute in the configuration of the attribute %{attrs} is incorrect. This attribute does not exists.")
); );
LSerror :: defineError('LSattr_html_select_object_03',
_("LSattr_html_select_object : more than one object returned corresponding to value %{val} of attribute %{attr}.")
);
?> ?>

View file

@ -88,7 +88,11 @@ class LSformElement_select_object extends LSformElement {
LSselect :: loadDependenciesDisplay(); LSselect :: loadDependenciesDisplay();
} }
} }
$return['html'] = $this -> fetchTemplate(NULL,array('selectableObject' => $this -> selectableObject)); $return['html'] = $this -> fetchTemplate(NULL,array(
'selectableObject' => $this -> selectableObject,
'unrecognizedValues' => $this -> attr_html -> unrecognizedValues,
'unrecognizedValueLabel' => _("%{value} (unrecognized value)")
));
return $return; return $return;
} }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -18,3 +18,10 @@
</tr> </tr>
</table> </table>
{/if} {/if}
{if !empty($unrecognizedValues)}
<ul class="LSform">
{foreach from=$unrecognizedValues item=v}
<li class="LSform-errors">{getFData format=$unrecognizedValueLabel data=$v}</li>
{/foreach}
<ul>
{/if}