From 4120d0f92cc1fc5f6f7db3f2c8a2b80af27f836c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 16 Sep 2018 13:49:22 +0200 Subject: [PATCH] reduce complexity of user class --- htdocs/user/class/user.class.php | 43 +++++++++++++++----------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 3f3e217dc04..bc26f3ebc07 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -2169,9 +2169,7 @@ class User extends CommonObject */ function getPhotoUrl($width, $height, $cssclass='', $imagesize='') { - $result=''; - - $result.=''; + $result =''; $result.=Form::showphoto('userphoto', $this, $width, $height, 0, $cssclass, $imagesize); $result.=''; @@ -2199,7 +2197,7 @@ class User extends CommonObject global $dolibarr_main_authentication, $dolibarr_main_demo; global $menumanager; - if(!$user->rights->user->user->lire && $user->id !=$this->id) $option='nolink'; + if(!$user->rights->user->user->lire && $user->id !=$this->id) $option='nolink'; if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) $withpictoimg=0; @@ -2348,7 +2346,7 @@ class User extends CommonObject $linkend=''; } - if ($option == 'nolink') + if ($option == 'nolink') { $linkstart = ''; $linkend=''; @@ -2388,34 +2386,33 @@ class User extends CommonObject if ($mode == 0) { - $prefix=''; if ($statut == 1) return $langs->trans('Enabled'); - if ($statut == 0) return $langs->trans('Disabled'); + elseif ($statut == 0) return $langs->trans('Disabled'); } - if ($mode == 1) + elseif ($mode == 1) { if ($statut == 1) return $langs->trans('Enabled'); - if ($statut == 0) return $langs->trans('Disabled'); + elseif ($statut == 0) return $langs->trans('Disabled'); } - if ($mode == 2) + elseif ($mode == 2) { if ($statut == 1) return img_picto($langs->trans('Enabled'),'statut4','class="pictostatus"').' '.$langs->trans('Enabled'); - if ($statut == 0) return img_picto($langs->trans('Disabled'),'statut5','class="pictostatus"').' '.$langs->trans('Disabled'); + elseif ($statut == 0) return img_picto($langs->trans('Disabled'),'statut5','class="pictostatus"').' '.$langs->trans('Disabled'); } - if ($mode == 3) + elseif ($mode == 3) { if ($statut == 1) return img_picto($langs->trans('Enabled'),'statut4','class="pictostatus"'); - if ($statut == 0) return img_picto($langs->trans('Disabled'),'statut5','class="pictostatus"'); + elseif ($statut == 0) return img_picto($langs->trans('Disabled'),'statut5','class="pictostatus"'); } - if ($mode == 4) + elseif ($mode == 4) { if ($statut == 1) return img_picto($langs->trans('Enabled'),'statut4','class="pictostatus"').' '.$langs->trans('Enabled'); - if ($statut == 0) return img_picto($langs->trans('Disabled'),'statut5','class="pictostatus"').' '.$langs->trans('Disabled'); + elseif ($statut == 0) return img_picto($langs->trans('Disabled'),'statut5','class="pictostatus"').' '.$langs->trans('Disabled'); } - if ($mode == 5) + elseif ($mode == 5) { if ($statut == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4','class="pictostatus"'); - if ($statut == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5','class="pictostatus"'); + elseif ($statut == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5','class="pictostatus"'); } } @@ -2436,8 +2433,8 @@ class User extends CommonObject global $conf; $dn=''; if ($mode==0) $dn=$conf->global->LDAP_KEY_USERS."=".$info[$conf->global->LDAP_KEY_USERS].",".$conf->global->LDAP_USER_DN; - if ($mode==1) $dn=$conf->global->LDAP_USER_DN; - if ($mode==2) $dn=$conf->global->LDAP_KEY_USERS."=".$info[$conf->global->LDAP_KEY_USERS]; + elseif ($mode==1) $dn=$conf->global->LDAP_USER_DN; + elseif ($mode==2) $dn=$conf->global->LDAP_KEY_USERS."=".$info[$conf->global->LDAP_KEY_USERS]; return $dn; } @@ -2511,7 +2508,7 @@ class User extends CommonObject if (! empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass, 4); // Create OpenLDAP MD5 password (TODO add type of encryption) } // Set LDAP password if possible - else if ($conf->global->LDAP_SERVER_PROTOCOLVERSION !== '3') // If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password + elseif ($conf->global->LDAP_SERVER_PROTOCOLVERSION !== '3') // If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password { if (! empty($conf->global->DATABASE_PWD_ENCRYPTED)) { @@ -2524,7 +2521,7 @@ class User extends CommonObject } } // Use $this->pass_indatabase value if exists - else if (! empty($this->pass_indatabase)) + elseif (! empty($this->pass_indatabase)) { if (! empty($conf->global->LDAP_FIELD_PASSWORD)) $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass_indatabase; // $this->pass_indatabase = mot de passe non crypte if (! empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass_indatabase, 4); // md5 for OpenLdap TODO add type of encryption @@ -3020,7 +3017,7 @@ class User extends CommonObject public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id) { $tables = array( - 'user' + 'user', ); return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); @@ -3077,7 +3074,7 @@ class User extends CommonObject */ public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null) { - global $conf,$user,$langs; + global $conf, $user, $langs; $langs->load("user");