diff --git a/src/includes/class/class.LSattr_html_image.php b/src/includes/class/class.LSattr_html_image.php
index 35848bea..f7f8fa32 100644
--- a/src/includes/class/class.LSattr_html_image.php
+++ b/src/includes/class/class.LSattr_html_image.php
@@ -47,14 +47,8 @@ class LSattr_html_image extends LSattr_html {
LSerror :: addErrorCode('LSattr_html_03','password');
}
- if ($data) {
- if(is_array($data)) {
- $element -> setValue($data[0]);
- }
- else {
- $element -> setValue($data);
- }
- }
+ if ($data)
+ $element -> setValue(ensureIsArray($data)[0]);
return $element;
}
diff --git a/src/includes/class/class.LSattr_html_password.php b/src/includes/class/class.LSattr_html_password.php
index b6875a23..c3d08054 100644
--- a/src/includes/class/class.LSattr_html_password.php
+++ b/src/includes/class/class.LSattr_html_password.php
@@ -44,14 +44,10 @@ class LSattr_html_password extends LSattr_html {
}
if ($data) {
- if(is_array($data)) {
- if (count($data)>1)
- LSerror :: addErrorCode('LSattr_html_03','password');
- $element -> setValue($data[0]);
- }
- else {
- $element -> setValue($data);
- }
+ $data = ensureIsArray($data);
+ if (count($data) > 1)
+ LSerror :: addErrorCode('LSattr_html_03', 'password');
+ $element -> setValue($data[0]);
}
return $element;
}
diff --git a/src/includes/class/class.LSattr_html_select_list.php b/src/includes/class/class.LSattr_html_select_list.php
index d17df156..aa75398a 100644
--- a/src/includes/class/class.LSattr_html_select_list.php
+++ b/src/includes/class/class.LSattr_html_select_list.php
@@ -283,8 +283,7 @@ class LSattr_html_select_list extends LSattr_html{
$list = $LSsearch -> getSearchEntries();
foreach($list as $entry) {
$keys = $entry -> get($conf['values_attribute']);
- if (!is_array($keys)) $keys=array($keys);
- foreach ($keys as $key) {
+ foreach (ensureIsArray($keys) as $key) {
$retInfos[$key]=$key;
}
}
@@ -312,11 +311,7 @@ class LSattr_html_select_list extends LSattr_html{
$retInfos=array();
if (is_string($attr)) {
if (isset($ldapObject->attrs[$attr]) && $ldapObject->attrs[$attr] instanceof LSattribute) {
- $attr_values = $ldapObject->attrs[$attr]->getValue();
- if (!$attr_values)
- $attr_values = array();
- elseif (!is_array($attr_values))
- $attr_values = array($attr_values);
+ $attr_values = ensureIsArray($ldapObject->attrs[$attr]->getValue());
if (isset($options['translate_labels']) && !$options['translate_labels']) {
foreach($attr_values as $attr_value)
$retInfos[$attr_value] = $attr_value;
@@ -334,11 +329,7 @@ class LSattr_html_select_list extends LSattr_html{
if (isset($ldapObject->attrs[$attr['attr']]) && $ldapObject->attrs[$attr['attr']] instanceof LSattribute) {
if (isset($attr['json_component_key'])) {
if (get_class($ldapObject->attrs[$attr['attr']]->html) == 'LSattr_html_jsonCompositeAttribute') {
- $attr_values = $ldapObject->attrs[$attr['attr']]->getValue();
- if (!$attr_values)
- $attr_values = array();
- elseif (!is_array($attr_values))
- $attr_values = array($attr_values);
+ $attr_values = ensureIsArray($ldapObject->attrs[$attr['attr']]->getValue());
foreach($attr_values as $attr_value) {
$value_data = @json_decode($attr_value, true);
if (!isset($value_data[$attr['json_component_key']])) {
diff --git a/src/includes/class/class.LSattr_html_select_object.php b/src/includes/class/class.LSattr_html_select_object.php
index 66489a56..4af509bb 100644
--- a/src/includes/class/class.LSattr_html_select_object.php
+++ b/src/includes/class/class.LSattr_html_select_object.php
@@ -46,10 +46,7 @@ class LSattr_html_select_object extends LSattr_html{
return;
}
if ($data) {
- if (!is_array($data)) {
- $data=array($data);
- }
- $values=$this -> getFormValues($data);
+ $values = $this -> getFormValues(ensureIsArray($data));
if ($values) {
$element -> setValue($values);
}
diff --git a/src/includes/class/class.LSattribute.php b/src/includes/class/class.LSattribute.php
index 2c917503..261268b2 100644
--- a/src/includes/class/class.LSattribute.php
+++ b/src/includes/class/class.LSattribute.php
@@ -184,10 +184,8 @@ class LSattribute extends LSlog_staticLoggerClass {
$onDisplay = $this -> getConfig('onDisplay');
if ($onDisplay) {
- if (!is_array($onDisplay))
- $onDisplay = array($onDisplay);
$result = $data;
- foreach($onDisplay as $func) {
+ foreach(ensureIsArray($onDisplay) as $func) {
if (function_exists($func)) {
$result = call_user_func($func, $result);
}
@@ -615,8 +613,7 @@ class LSattribute extends LSlog_staticLoggerClass {
self :: log_debug(strval($this)." -> fireEvent($event)");
$return = true;
if(isset($this -> config[$event])) {
- $funcs = (!is_array($this -> config[$event])?array($this -> config[$event]):$this -> config[$event]);
- foreach($funcs as $func) {
+ foreach(ensureIsArray($this -> config[$event]) as $func) {
if(function_exists($func)) {
self :: log_debug(strval($this)." -> fireEvent($event): run ".format_callable($func));
if(!call_user_func_array($func, array(&$this -> ldapObject))) {
diff --git a/src/includes/class/class.LSformElement.php b/src/includes/class/class.LSformElement.php
index 0b2e0356..5f52c490 100644
--- a/src/includes/class/class.LSformElement.php
+++ b/src/includes/class/class.LSformElement.php
@@ -87,11 +87,7 @@ class LSformElement extends LSlog_staticLoggerClass {
* @retval boolean Retourne True
*/
public function setValue($data) {
- if (!is_array($data)) {
- $data=array($data);
- }
-
- $this -> values = $data;
+ $this -> values = ensureIsArray($data);
return true;
}
@@ -109,10 +105,7 @@ class LSformElement extends LSlog_staticLoggerClass {
* @retval boolean Retourne True
*/
public function setValueFromPostData($data) {
- if (!is_array($data)) {
- $data=array($data);
- }
- $this -> values = $data;
+ $this -> values = ensureIsArray($data);
return true;
}
@@ -137,12 +130,7 @@ class LSformElement extends LSlog_staticLoggerClass {
* @retval void
*/
public function addValue($data) {
- if (is_array($data)) {
- $this -> values = array_merge($this -> values, $data);
- }
- else {
- $this -> values[] = $data;
- }
+ $this -> values = array_merge($this -> values, ensureIsArray($data));
}
/**
@@ -253,10 +241,8 @@ class LSformElement extends LSlog_staticLoggerClass {
*/
protected static function getData(&$post, $name) {
if (isset($post[$name])) {
- $return=array();
- if(!is_array($post[$name])) {
- $post[$name] = array($post[$name]);
- }
+ $return = array();
+ $post[$name] = ensureIsArray($post[$name]);
foreach($post[$name] as $key => $val) {
if (!is_empty($val)) {
$return[$key] = $val;
diff --git a/src/includes/class/class.LSformElement_date.php b/src/includes/class/class.LSformElement_date.php
index 01406b54..b2a7a921 100644
--- a/src/includes/class/class.LSformElement_date.php
+++ b/src/includes/class/class.LSformElement_date.php
@@ -74,12 +74,9 @@ class LSformElement_date extends LSformElement {
* @retval boolean Retourne True
*/
public function setValue($data) {
- if (!is_array($data)) {
- $data=array($data);
- }
$special_values = $this -> getSpecialValues();
$values = array();
- foreach ($data as $value) {
+ foreach (ensureIsArray($data) as $value) {
if(is_numeric($value)) {
if (array_key_exists($value, $special_values)) {
$values[] = $special_values[$value];
@@ -239,11 +236,7 @@ class LSformElement_date extends LSformElement {
}
}
else {
- if(!is_array($values))
- $values = array();
- if(!is_array($special_values))
- $special_values = array();
- $return[$this -> name] = $special_values + $values;
+ $return[$this -> name] = ensureIsArray($special_values) + ensureIsArray($values);
self :: log_trace($this." -> merged values=".varDump($return[$this -> name]));
}
return true;
diff --git a/src/includes/class/class.LSformElement_jsonCompositeAttribute.php b/src/includes/class/class.LSformElement_jsonCompositeAttribute.php
index 2fcdf036..24b5102b 100644
--- a/src/includes/class/class.LSformElement_jsonCompositeAttribute.php
+++ b/src/includes/class/class.LSformElement_jsonCompositeAttribute.php
@@ -151,9 +151,7 @@ class LSformElement_jsonCompositeAttribute extends LSformElement {
protected function translateComponentValue($c,$value,$inLoop=false) {
if (!$inLoop && isset($this -> components[$c]['multiple']) && $this -> components[$c]['multiple']) {
$retval = array();
- if (!is_array($value))
- $value = array($value);
- foreach($value as $val)
+ foreach(ensureIsArray($value) as $val)
$retval[] = $this -> translateComponentValue($c, $val, true);
}
else {
diff --git a/src/includes/class/class.LSformElement_labeledValue.php b/src/includes/class/class.LSformElement_labeledValue.php
index cc03dcc4..0ebed417 100644
--- a/src/includes/class/class.LSformElement_labeledValue.php
+++ b/src/includes/class/class.LSformElement_labeledValue.php
@@ -121,15 +121,11 @@ class LSformElement_labeledValue extends LSformElement {
return true;
}
if (isset($_POST[$this -> name."_labels"]) && isset($_POST[$this -> name."_values"])) {
- $return[$this -> name]=array();
- if(!is_array($_POST[$this -> name."_labels"])) {
- $_POST[$this -> name."_labels"] = array($_POST[$this -> name."_labels"]);
- }
- if(!is_array($_POST[$this -> name."_values"])) {
- $_POST[$this -> name."_values"] = array($_POST[$this -> name."_values"]);
- }
+ $return[$this -> name] = array();
+ $_POST[$this -> name."_labels"] = ensureIsArray($_POST[$this -> name."_labels"]);
+ $_POST[$this -> name."_values"] = ensureIsArray($_POST[$this -> name."_values"]);
foreach($_POST[$this -> name."_labels"] as $key => $label) {
- $val=$_POST[$this -> name."_values"][$key];
+ $val = $_POST[$this -> name."_values"][$key];
if (!empty($label) && !is_empty($val)) {
$return[$this -> name][$key] = "[$label]$val";
}
diff --git a/src/includes/class/class.LSformElement_mail.php b/src/includes/class/class.LSformElement_mail.php
index 55484a3b..66547ce7 100644
--- a/src/includes/class/class.LSformElement_mail.php
+++ b/src/includes/class/class.LSformElement_mail.php
@@ -85,8 +85,7 @@ class LSformElement_mail extends LSformElement_text {
public function autocomplete($pattern) {
$ret = array();
if ($this -> getParam('html_options.autocomplete')) {
- $mail_attributes = $this -> getParam('html_options.autocomplete.mail_attributes', array('mail'));
- if (!is_array($mail_attributes)) $mail_attributes = array($mail_attributes);
+ $mail_attributes = ensureIsArray($this -> getParam('html_options.autocomplete.mail_attributes', array('mail')));
$obj_type = $this -> getParam('html_options.autocomplete.object_type');
if ($obj_type) {
@@ -124,9 +123,8 @@ class LSformElement_mail extends LSformElement_text {
$search -> run();
foreach($search -> getSearchEntries() as $e) {
foreach($mail_attributes as $attr) {
- $mails = $e->get($attr);
+ $mails = ensureIsArray($e->get($attr));
if (!$mails) continue;
- if (!is_array($mails)) $mails = array($mails);
foreach($mails as $mail)
$ret[$mail] = $e->displayName;
}
@@ -170,8 +168,7 @@ class LSformElement_mail extends LSformElement_text {
$displayName = ($displayNameFormat?getFData($displayNameFormat, $object['attrs']):null);
foreach($mail_attributes as $attr) {
if (!isset($object['attrs'][$attr])) continue;
- $mails = $object['attrs'][$attr];
- if (!is_array($mails)) $mails = array($mails);
+ $mails = ensureIsArray($object['attrs'][$attr]);
foreach($mails as $mail)
$ret[$mail] = ($displayName?$displayName:$mail);
}
diff --git a/src/includes/class/class.LSformElement_mailQuota.php b/src/includes/class/class.LSformElement_mailQuota.php
index f3868579..0d60ae73 100644
--- a/src/includes/class/class.LSformElement_mailQuota.php
+++ b/src/includes/class/class.LSformElement_mailQuota.php
@@ -139,9 +139,7 @@ class LSformElement_mailQuota extends LSformElement {
}
if (isset($_POST[$this -> name.'_size'])) {
$return[$this -> name]=array();
- if(!is_array($_POST[$this -> name.'_size'])) {
- $_POST[$this -> name.'_size'] = array($_POST[$this -> name.'_size']);
- }
+ $_POST[$this -> name.'_size'] = ensureIsArray($_POST[$this -> name.'_size']);
if(isset($_POST[$this -> name.'_sizeFact']) && !is_array($_POST[$this -> name.'_sizeFact'])) {
$_POST[$this -> name.'_sizeFact'] = array($_POST[$this -> name.'_sizeFact']);
}
diff --git a/src/includes/class/class.LSformElement_password.php b/src/includes/class/class.LSformElement_password.php
index 8c41b777..393f4996 100644
--- a/src/includes/class/class.LSformElement_password.php
+++ b/src/includes/class/class.LSformElement_password.php
@@ -278,19 +278,14 @@ class LSformElement_password extends LSformElement {
$mail = (String)$this -> sendMail['mail'];
self :: log_debug("send(): mail from params: '$mail'");
if (!$mail) {
- $mail_attrs = $this -> getMailAttrs();
- if (!is_array($mail_attrs)) {
- $mail_attrs=array($mail_attrs);
- }
+ $mail_attrs = ensureIsArray($this -> getMailAttrs());
self :: log_debug('send(): mail attrs: '.varDump($mail_attrs));
$checkDomainsList = $this -> getParam('html_options.mail.domain');
$checkDomain = $this -> getParam('html_options.mail.checkDomain', true, 'bool');
foreach($mail_attrs as $attr) {
$mail_attr = $this -> attr_html -> attribute -> ldapObject -> attrs[$attr];
if ($mail_attr instanceOf LSattribute) {
- $mail_values = $mail_attr -> getValue();
- if (!is_array($mail_values))
- $mail_values = array($mail_values);
+ $mail_values = ensureIsArray($mail_attr -> getValue());
foreach($mail_values as $mail_value) {
if ($mail_value && checkEmail($mail_value, $checkDomainsList, $checkDomain)) {
$mail = $mail_value;
diff --git a/src/includes/class/class.LSformElement_quota.php b/src/includes/class/class.LSformElement_quota.php
index e4c68ccc..66d5bf99 100644
--- a/src/includes/class/class.LSformElement_quota.php
+++ b/src/includes/class/class.LSformElement_quota.php
@@ -130,9 +130,7 @@ class LSformElement_quota extends LSformElement {
}
if (isset($_POST[$this -> name.'_size'])) {
$return[$this -> name]=array();
- if(!is_array($_POST[$this -> name.'_size'])) {
- $_POST[$this -> name.'_size'] = array($_POST[$this -> name.'_size']);
- }
+ $_POST[$this -> name.'_size'] = ensureIsArray($_POST[$this -> name.'_size']);
if(isset($_POST[$this -> name.'_sizeFact']) && !is_array($_POST[$this -> name.'_sizeFact'])) {
$_POST[$this -> name.'_sizeFact'] = array($_POST[$this -> name.'_sizeFact']);
}
diff --git a/src/includes/class/class.LSformElement_valueWithUnit.php b/src/includes/class/class.LSformElement_valueWithUnit.php
index d8fd0d72..c80337f3 100644
--- a/src/includes/class/class.LSformElement_valueWithUnit.php
+++ b/src/includes/class/class.LSformElement_valueWithUnit.php
@@ -159,9 +159,7 @@ class LSformElement_valueWithUnit extends LSformElement {
}
$return[$this -> name]=array();
if (isset($_POST[$this -> name.'_valueWithUnit'])) {
- if(!is_array($_POST[$this -> name.'_valueWithUnit'])) {
- $_POST[$this -> name.'_valueWithUnit'] = array($_POST[$this -> name.'_valueWithUnit']);
- }
+ $_POST[$this -> name.'_valueWithUnit'] = ensureIsArray($_POST[$this -> name.'_valueWithUnit']);
if(isset($_POST[$this -> name.'_unitFact']) && !is_array($_POST[$this -> name.'_unitFact'])) {
$_POST[$this -> name.'_unitFact'] = array($_POST[$this -> name.'_unitFact']);
}
@@ -186,16 +184,12 @@ class LSformElement_valueWithUnit extends LSformElement {
}
}
if (isset($_POST[$this -> name])) {
- if(!is_array($_POST[$this -> name])) {
- $_POST[$this -> name] = array($_POST[$this -> name]);
- }
- $return[$this -> name]=array_merge($return[$this -> name],$_POST[$this -> name]);
+ $_POST[$this -> name] = ensureIsArray($_POST[$this -> name]);
+ $return[$this -> name] = array_merge($return[$this -> name], $_POST[$this -> name]);
}
if (isset($_POST[$this -> name.'_value'])) {
- if (!is_array($_POST[$this -> name.'_value'])) {
- $_POST[$this -> name.'_value']=array($_POST[$this -> name.'_value']);
- }
- $return[$this -> name]=array_merge($return[$this -> name],$_POST[$this -> name.'_value']);
+ $_POST[$this -> name.'_value'] = ensureIsArray($_POST[$this -> name.'_value']);
+ $return[$this -> name] = array_merge($return[$this -> name], $_POST[$this -> name.'_value']);
}
return true;
}
diff --git a/src/includes/class/class.LSformRule_differentPassword.php b/src/includes/class/class.LSformRule_differentPassword.php
index c7f5e891..c1a1adc6 100644
--- a/src/includes/class/class.LSformRule_differentPassword.php
+++ b/src/includes/class/class.LSformRule_differentPassword.php
@@ -40,10 +40,6 @@ class LSformRule_differentPassword extends LSformRule {
public static function validate($value, $options=array(), &$formElement) {
$otherPasswordAttributes = LSconfig :: get('params.otherPasswordAttributes', null, null, $options);
if (!is_null($otherPasswordAttributes)) {
- // Make sure otherPasswordAttributes is an array
- if (!is_array($otherPasswordAttributes))
- $otherPasswordAttributes = array($otherPasswordAttributes);
-
// Load LSattr_ldap_password
if (!LSsession :: loadLSclass("LSattr_ldap_password")) {
LSerror :: addErrorCode('LSformRule_differentPassword_02');
@@ -51,7 +47,7 @@ class LSformRule_differentPassword extends LSformRule {
}
// Iter on otherPasswordAttributes to check password does not match
- foreach($otherPasswordAttributes as $attr) {
+ foreach(ensureIsArray($otherPasswordAttributes) as $attr) {
// Check attribute exist
if (!isset($formElement -> attr_html -> attribute -> ldapObject -> attrs[$attr])) {
LSerror :: addErrorCode('LSformRule_differentPassword_03', $attr);
diff --git a/src/includes/class/class.LSformRule_mimetype.php b/src/includes/class/class.LSformRule_mimetype.php
index 855682e3..417eb9ac 100644
--- a/src/includes/class/class.LSformRule_mimetype.php
+++ b/src/includes/class/class.LSformRule_mimetype.php
@@ -42,17 +42,9 @@ class LSformRule_mimetype extends LSformRule {
$file = LSsession :: getTmpFile($value);
$real_mimetype = mime_content_type($file);
- $mimetype = LSconfig :: get('params.mimeType', null, null, $options);
- if (!is_null($mimetype)) {
- if (is_array($mimetype)) {
- if (!in_array($real_mimetype, $mimetype))
- return;
- }
- else {
- if ($real_mimetype != $mimetype)
- return;
- }
- }
+ $mimetypes = ensureIsArray(LSconfig :: get('params.mimeType', null, null, $options));
+ if ($mimetypes && !in_array($real_mimetype, $mimetypes))
+ return false;
$mimeTypeRegEx = LSconfig :: get('params.mimeTypeRegEx', null, 'string', $options);
if (is_string($mimeTypeRegEx) && !preg_match($mimeTypeRegEx, $real_mimetype))
diff --git a/src/includes/class/class.LSformRule_password.php b/src/includes/class/class.LSformRule_password.php
index eacf8082..9942ef7e 100644
--- a/src/includes/class/class.LSformRule_password.php
+++ b/src/includes/class/class.LSformRule_password.php
@@ -56,11 +56,8 @@ class LSformRule_password extends LSformRule {
return;
}
- $regex = LSconfig :: get('params.regex', null, null, $options);
- if(!is_null($regex)) {
- if (!is_array($regex))
- $regex = array($regex);
-
+ $regex = ensureIsArray(LSconfig :: get('params.regex', null, null, $options));
+ if($regex) {
$minValidRegex = LSconfig :: get('params.minValidRegex', count($regex), 'int', $options);
if ($minValidRegex == 0 || $minValidRegex > count($regex))
$minValidRegex = count($regex);
@@ -85,8 +82,8 @@ class LSformRule_password extends LSformRule {
}
}
- $prohibitedValues = LSconfig :: get('params.prohibitedValues', null, null, $options);
- if(is_array($prohibitedValues) && in_array($value, $prohibitedValues)) {
+ $prohibitedValues = ensureIsArray(LSconfig :: get('params.prohibitedValues', null, null, $options));
+ if(in_array($value, $prohibitedValues)) {
self :: log_debug("this password is prohibited");
return;
}
diff --git a/src/includes/class/class.LSldapObject.php b/src/includes/class/class.LSldapObject.php
index 773043bb..ddbb3ec6 100644
--- a/src/includes/class/class.LSldapObject.php
+++ b/src/includes/class/class.LSldapObject.php
@@ -1354,25 +1354,24 @@ class LSldapObject extends LSlog_staticLoggerClass {
*
* @retval Mixed La valeur clef d'un objet en relation
**/
- public static function getObjectKeyValueInRelation($object,$objectType,$attrValues='dn') {
+ public static function getObjectKeyValueInRelation($object, $objectType, $attrValues='dn') {
if (!$objectType) {
LSerror :: addErrorCode('LSrelation_05','getObjectKeyValueInRelation');
return;
}
- if (!is_array($attrValues)) $attrValues=array($attrValues);
- $keyValues=array();
- foreach ($attrValues as $attrValue) {
- if ($attrValue=='dn') {
+ $keyValues = array();
+ foreach (ensureIsArray($attrValues) as $attrValue) {
+ if ($attrValue == 'dn') {
$dn=$object -> getDn();
- if (!in_array($dn,$keyValues))
+ if (!in_array($dn, $keyValues))
$keyValues[] = $dn;
}
else {
- $values=$object -> getValue($attrValue);
+ $values = $object -> getValue($attrValue);
if (is_array($values))
foreach ($values as $keyValue)
- if (!in_array($keyValue,$keyValues))
- $keyValues[]=$keyValue;
+ if (!in_array($keyValue, $keyValues))
+ $keyValues[] = $keyValue;
}
}
return $keyValues;
@@ -1396,20 +1395,28 @@ class LSldapObject extends LSlog_staticLoggerClass {
*
* @retval Array of $objectType Les objets en relations
**/
- public function listObjectsInRelation($object,$attr,$objectType,$attrValues='dn') {
+ public function listObjectsInRelation($object, $attr, $objectType, $attrValues='dn') {
if ((!$attr)||(!$objectType)) {
LSerror :: addErrorCode('LSrelation_05','listObjectsInRelation');
return;
}
- if (!is_array($attrValues)) $attrValues=array($attrValues);
- $keyValues=self :: getObjectKeyValueInRelation($object,$objectType,$attrValues);
+ $keyValues = self :: getObjectKeyValueInRelation($object, $objectType, $attrValues);
if (!empty($keyValues)) {
- $keyValuesFilters=array();
+ $keyValuesFilters = array();
foreach($keyValues as $keyValue) {
$keyValuesFilters[] = Net_LDAP2_Filter::create($attr,'equals',$keyValue);
}
$filter = LSldap::combineFilters('or', $keyValuesFilters);
- return $this -> listObjects($filter,LSsession :: getRootDn(),array('scope' => 'sub','recursive' => true,'withoutCache'=>true, 'onlyAccessible' => false));
+ return $this -> listObjects(
+ $filter,
+ LSsession :: getRootDn(),
+ array(
+ 'scope' => 'sub',
+ 'recursive' => true,
+ 'withoutCache'=>true,
+ 'onlyAccessible' => false
+ )
+ );
}
return array();
@@ -1511,17 +1518,13 @@ class LSldapObject extends LSlog_staticLoggerClass {
return;
}
if ($this -> attrs[$attr] instanceof LSattribute) {
- if (!is_array($attrValues)) $attrValues=array($attrValue);
- $keyValues=self :: getObjectKeyValueInRelation($object,$objectType,$attrValues);
- $values = $this -> attrs[$attr] -> getValue();
- if ((!is_array($values)) && (!empty($values))) {
- $values = array($values);
- }
- if (is_array($values)) {
- $updateData=array();
+ $keyValues = self :: getObjectKeyValueInRelation($object, $objectType, $attrValues);
+ $values = ensureIsArray($this -> attrs[$attr] -> getValue());
+ if ($values) {
+ $updateData = array();
foreach($values as $value) {
- if (!in_array($value,$keyValues)) {
- $updateData[]=$value;
+ if (!in_array($value, $keyValues)) {
+ $updateData[] = $value;
}
}
return $this -> _updateData(array($attr => $updateData));
@@ -1545,40 +1548,36 @@ class LSldapObject extends LSlog_staticLoggerClass {
*
* @retval boolean True en cas de succès, False sinon
*/
- public function renameOneObjectInRelation($object,$oldValues,$attr,$objectType,$attrValue='dn') {
+ public function renameOneObjectInRelation($object, $oldValues, $attr, $objectType, $attrValue='dn') {
if ((!$attr)||(!$objectType)) {
LSerror :: addErrorCode('LSrelation_05','renameOneObjectInRelation');
return;
}
- if (!is_array($oldValues)) $oldValues=array($oldValues);
- if ($object instanceof $objectType) {
- if ($this -> attrs[$attr] instanceof LSattribute) {
- $values = $this -> attrs[$attr] -> getValue();
- if ((!is_array($values)) && (!empty($values))) {
- $values = array($values);
+ if (!($object instanceof $objectType))
+ return;
+ if (!($this -> attrs[$attr] instanceof LSattribute))
+ return;
+ $values = ensureIsArray($this -> attrs[$attr] -> getValue());
+ if (!$values)
+ return;
+ $updateData = array();
+ $oldValues = ensureIsArray($oldValues);
+ foreach($values as $value) {
+ if (!in_array($value, $oldValues)) {
+ $updateData[] = $value;
+ }
+ else {
+ if ($attrValue == 'dn') {
+ $val = $object -> getDn();
}
- if (is_array($values)) {
- $updateData=array();
- foreach($values as $value) {
- if (!in_array($value,$oldValues)) {
- $updateData[] = $value;
- }
- else {
- if ($attrValue=='dn') {
- $val = $object -> getDn();
- }
- else {
- $val = $object -> getValue($attrValue);
- $val = $val[0];
- }
- $updateData[] = $val;
- }
- }
- return $this -> _updateData(array($attr => $updateData));
+ else {
+ $val = $object -> getValue($attrValue);
+ $val = $val[0];
}
+ $updateData[] = $val;
}
}
- return;
+ return $this -> _updateData(array($attr => $updateData));
}
/**
@@ -1606,29 +1605,28 @@ class LSldapObject extends LSlog_staticLoggerClass {
LSerror :: addErrorCode('LSrelation_05','updateObjectsInRelation');
return;
}
- if (!is_array($attrValues)) $attrValues=array($attrValue);
- $currentDns=array();
- $currentObjects = $this -> listObjectsInRelation($object,$attr,$objectType,$attrValues);
- if(is_array($currentObjects)) {
- for ($i=0;$i getDn();
- }
+ $currentDns = array();
+ $currentObjects = $this -> listObjectsInRelation($object, $attr, $objectType, $attrValues);
+ if(!is_array($currentObjects))
+ return;
+ for ($i=0; $i getDn();
}
- $dontTouch=array_intersect($listDns,$currentDns);
+ $dontTouch = array_intersect($listDns, $currentDns);
- for($i=0;$i getDn(),$dontTouch)) continue;
- if (!$currentObjects[$i] -> deleteOneObjectInRelation($object,$attr,$objectType,$attrValue,$canEditFunction,$attrValues)) {
+ for($i=0; $i getDn(), $dontTouch)) continue;
+ if (!$currentObjects[$i] -> deleteOneObjectInRelation($object, $attr, $objectType, $attrValue, $canEditFunction, $attrValues)) {
return;
}
}
- $type=$this -> getType();
+ $type = $this -> getType();
foreach($listDns as $dn) {
- if (in_array($dn,$dontTouch)) continue;
+ if (in_array($dn, $dontTouch)) continue;
$obj = new $type();
if ($obj -> loadData($dn)) {
- if (!$obj -> addOneObjectInRelation($object,$attr,$objectType,$attrValue,$canEditFunction)) {
+ if (!$obj -> addOneObjectInRelation($object, $attr, $objectType, $attrValue, $canEditFunction)) {
return;
}
}
@@ -1863,7 +1861,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
* @retval mixed Array of valid IOformats of this object type
**/
public function listValidIOformats() {
- $ret=array();
+ $ret = array();
$ioFormats = $this -> getConfig('ioFormat');
if (is_array($ioFormats)) {
foreach($ioFormats as $name => $conf) {
@@ -2109,7 +2107,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
if (empty($values)) {
return $return." empty\n";
}
- if (!is_array($values)) $values = array($values);
+ $values = ensureIsArray($values);
// Truncate values if too long
for ($i=0; $i < count($values); $i++)
diff --git a/src/includes/class/class.LSrelation.php b/src/includes/class/class.LSrelation.php
index d8243268..bd9e6dbb 100644
--- a/src/includes/class/class.LSrelation.php
+++ b/src/includes/class/class.LSrelation.php
@@ -112,7 +112,7 @@ class LSrelation extends LSlog_staticLoggerClass {
case 'canEdit_attribute':
return $this -> getConfig($key);
case 'linkAttributeValues':
- $linkAttributeValues = (is_array($this -> linkAttributeOtherValues)?$this -> linkAttributeOtherValues:array());
+ $linkAttributeValues = ensureIsArray($this -> linkAttributeOtherValues);
if ($this -> linkAttributeValue)
$linkAttributeValues[] = $this -> linkAttributeValue;
return $linkAttributeValues;
@@ -761,9 +761,7 @@ class LSrelation extends LSlog_staticLoggerClass {
// Check additional required parameters
if ($additional_required_parameters) {
- if (!is_array($additional_required_parameters))
- $additional_required_parameters = array($additional_required_parameters);
- foreach($additional_required_parameters as $p) {
+ foreach(ensureIsArray($additional_required_parameters) as $p) {
if (!isset($_REQUEST[$p])) {
self :: log_warning("Parameter '$p' is missing.");
LSerror :: addErrorCode('LSsession_12');