Clean code

This commit is contained in:
Laurent Destailleur
2017-10-28 16:00:07 +02:00
parent 9e382a7f1b
commit 00db7e16ec
4 changed files with 8 additions and 3 deletions

View File

@@ -4424,7 +4424,7 @@ abstract class CommonObject
//Eliminate copied source object extra_fields that do not exist in target object //Eliminate copied source object extra_fields that do not exist in target object
$new_array_options=array(); $new_array_options=array();
foreach ($this->array_options as $key => $value) { foreach ($this->array_options as $key => $value) {
if (in_array(substr($key,8), array_keys($target_extrafields))) if (in_array(substr($key,8), array_keys($target_extrafields))) // We remove the 'options_' from $key
$new_array_options[$key] = $value; $new_array_options[$key] = $value;
} }
@@ -4510,6 +4510,7 @@ abstract class CommonObject
$sql.=",".$attributeKey; $sql.=",".$attributeKey;
} }
$sql .= ") VALUES (".$this->id; $sql .= ") VALUES (".$this->id;
foreach($new_array_options as $key => $value) foreach($new_array_options as $key => $value)
{ {
$attributeKey = substr($key,8); // Remove 'options_' prefix $attributeKey = substr($key,8); // Remove 'options_' prefix

View File

@@ -1336,7 +1336,7 @@ class ExtraFields
$list=$this->attribute_list[$key]; $list=$this->attribute_list[$key];
$hidden=(abs($list)!=1 ? 1 : 0); $hidden=(abs($list)!=1 ? 1 : 0);
if ($hidden) return ''; if ($hidden) return ''; // This is a protection. If field is hidden, we should just not call this method.
// If field is a computed field, value must become result of compute // If field is a computed field, value must become result of compute
if ($computed) if ($computed)

View File

@@ -42,6 +42,9 @@ if (empty($reshook) && ! empty($extrafields->attributes[$object->table_element][
{ {
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label)
{ {
// Discard if extrafield is a hidden field
if (abs($extrafields->attributes[$object->table_element]['list'][$key]) != 1) continue;
// Load language if required // Load language if required
if (! empty($extrafields->attributes[$object->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$object->table_element]['langfile'][$key]); if (! empty($extrafields->attributes[$object->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);

View File

@@ -163,7 +163,8 @@ class User extends CommonObject
} }
/** /**
* Load a user from database with its id or ref (login) * Load a user from database with its id or ref (login).
* This function does not load permissions, only user properties. Use getrights() for this just after the fetch.
* *
* @param int $id If defined, id to used for search * @param int $id If defined, id to used for search
* @param string $login If defined, login to used for search * @param string $login If defined, login to used for search