Clean code

This commit is contained in:
Laurent Destailleur 2019-11-02 11:36:48 +01:00
parent 68c971a2b5
commit f9031cdbfd
9 changed files with 52 additions and 47 deletions

View File

@ -431,10 +431,10 @@ class Subscription extends CommonObject
/** /**
* Renvoi le libelle d'un statut donne * Renvoi le libelle d'un statut donne
* *
* @param int $statut Id statut * @param int $status Id status
* @return string Label * @return string Label
*/ */
public function LibStatut($statut) public function LibStatut($status)
{ {
// phpcs:enable // phpcs:enable
global $langs; global $langs;

View File

@ -54,7 +54,7 @@ if (! isset($cotis))
$sql = "SELECT d.login, d.pass, d.datefin"; $sql = "SELECT d.login, d.pass, d.datefin";
$sql .= " FROM ".MAIN_DB_PREFIX."adherent as d "; $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d ";
$sql .= " WHERE d.statut = $statut "; $sql .= " WHERE d.statut = ".$statut;
if ($cotis==1) if ($cotis==1)
{ {
$sql .= " AND datefin > '".$db->idate($now)."'"; $sql .= " AND datefin > '".$db->idate($now)."'";

View File

@ -2068,10 +2068,10 @@ class Contrat extends CommonObject
/** /**
* Return list of line rowid * Return list of line rowid
* *
* @param int $statut Status of lines to get * @param int $status Status of lines to get
* @return array|int Array of line's rowid or <0 if error * @return array|int Array of line's rowid or <0 if error
*/ */
public function array_detail($statut = -1) public function array_detail($status = -1)
{ {
// phpcs:enable // phpcs:enable
$tab=array(); $tab=array();
@ -2079,7 +2079,7 @@ class Contrat extends CommonObject
$sql = "SELECT cd.rowid"; $sql = "SELECT cd.rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."contratdet as cd"; $sql.= " FROM ".MAIN_DB_PREFIX."contratdet as cd";
$sql.= " WHERE fk_contrat =".$this->id; $sql.= " WHERE fk_contrat =".$this->id;
if ($statut >= 0) $sql.= " AND statut = '$statut'"; if ($status >= 0) $sql.= " AND statut = ".$status;
dol_syslog(get_class($this)."::array_detail()", LOG_DEBUG); dol_syslog(get_class($this)."::array_detail()", LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);

View File

@ -1057,13 +1057,13 @@ abstract class CommonObject
/** /**
* Get array of all contacts for an object * Get array of all contacts for an object
* *
* @param int $statut Status of links to get (-1=all) * @param int $status Status of links to get (-1=all)
* @param string $source Source of contact: external or thirdparty (llx_socpeople) or internal (llx_user) * @param string $source Source of contact: external or thirdparty (llx_socpeople) or internal (llx_user)
* @param int $list 0:Return array contains all properties, 1:Return array contains just id * @param int $list 0:Return array contains all properties, 1:Return array contains just id
* @param string $code Filter on this code of contact type ('SHIPPING', 'BILLING', ...) * @param string $code Filter on this code of contact type ('SHIPPING', 'BILLING', ...)
* @return array|int Array of contacts, -1 if error * @return array|int Array of contacts, -1 if error
*/ */
public function liste_contact($statut = -1, $source = 'external', $list = 0, $code = '') public function liste_contact($status = -1, $source = 'external', $list = 0, $code = '')
{ {
// phpcs:enable // phpcs:enable
global $langs; global $langs;
@ -1086,7 +1086,7 @@ abstract class CommonObject
if ($source == 'internal') $sql.= " AND tc.source = 'internal'"; if ($source == 'internal') $sql.= " AND tc.source = 'internal'";
if ($source == 'external' || $source == 'thirdparty') $sql.= " AND tc.source = 'external'"; if ($source == 'external' || $source == 'thirdparty') $sql.= " AND tc.source = 'external'";
$sql.= " AND tc.active=1"; $sql.= " AND tc.active=1";
if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'"; if ($status >= 0) $sql.= " AND ec.statut = ".$status;
$sql.=" ORDER BY t.lastname ASC"; $sql.=" ORDER BY t.lastname ASC";
dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG); dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG);

View File

@ -3765,7 +3765,7 @@ class Form
* *
* @param string $selected Id account pre-selected * @param string $selected Id account pre-selected
* @param string $htmlname Name of select zone * @param string $htmlname Name of select zone
* @param int $statut Status of searched accounts (0=open, 1=closed, 2=both) * @param int $status Status of searched accounts (0=open, 1=closed, 2=both)
* @param string $filtre To filter list * @param string $filtre To filter list
* @param int $useempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. * @param int $useempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries.
* @param string $moreattrib To add more attribute on select * @param string $moreattrib To add more attribute on select
@ -3773,7 +3773,7 @@ class Form
* @param string $morecss More CSS * @param string $morecss More CSS
* @return int <0 if error, Num of bank account found if OK (0, 1, 2, ...) * @return int <0 if error, Num of bank account found if OK (0, 1, 2, ...)
*/ */
public function select_comptes($selected = '', $htmlname = 'accountid', $statut = 0, $filtre = '', $useempty = 0, $moreattrib = '', $showcurrency = 0, $morecss = '') public function select_comptes($selected = '', $htmlname = 'accountid', $status = 0, $filtre = '', $useempty = 0, $moreattrib = '', $showcurrency = 0, $morecss = '')
{ {
// phpcs:enable // phpcs:enable
global $langs, $conf; global $langs, $conf;
@ -3784,7 +3784,7 @@ class Form
$sql = "SELECT rowid, label, bank, clos as status, currency_code"; $sql = "SELECT rowid, label, bank, clos as status, currency_code";
$sql.= " FROM ".MAIN_DB_PREFIX."bank_account"; $sql.= " FROM ".MAIN_DB_PREFIX."bank_account";
$sql.= " WHERE entity IN (".getEntity('bank_account').")"; $sql.= " WHERE entity IN (".getEntity('bank_account').")";
if ($statut != 2) $sql.= " AND clos = '".$statut."'"; if ($status != 2) $sql.= " AND clos = ".(int) $status;
if ($filtre) $sql.=" AND ".$filtre; if ($filtre) $sql.=" AND ".$filtre;
$sql.= " ORDER BY label"; $sql.= " ORDER BY label";
@ -3815,7 +3815,7 @@ class Form
} }
print trim($obj->label); print trim($obj->label);
if ($showcurrency) print ' ('.$obj->currency_code.')'; if ($showcurrency) print ' ('.$obj->currency_code.')';
if ($statut == 2 && $obj->status == 1) print ' ('.$langs->trans("Closed").')'; if ($status == 2 && $obj->status == 1) print ' ('.$langs->trans("Closed").')';
print '</option>'; print '</option>';
$i++; $i++;
} }
@ -3823,7 +3823,7 @@ class Form
} }
else else
{ {
if ($statut == 0) print '<span class="opacitymedium">'.$langs->trans("NoActiveBankAccountDefined").'</span>'; if ($status == 0) print '<span class="opacitymedium">'.$langs->trans("NoActiveBankAccountDefined").'</span>';
else print '<span class="opacitymedium">'.$langs->trans("NoBankAccountFound").'</span>'; else print '<span class="opacitymedium">'.$langs->trans("NoBankAccountFound").'</span>';
} }
} }
@ -3839,13 +3839,13 @@ class Form
* *
* @param string $selected Id establishment pre-selected * @param string $selected Id establishment pre-selected
* @param string $htmlname Name of select zone * @param string $htmlname Name of select zone
* @param int $statut Status of searched establishment (0=open, 1=closed, 2=both) * @param int $status Status of searched establishment (0=open, 1=closed, 2=both)
* @param string $filtre To filter list * @param string $filtre To filter list
* @param int $useempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. * @param int $useempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries.
* @param string $moreattrib To add more attribute on select * @param string $moreattrib To add more attribute on select
* @return int <0 if error, Num of establishment found if OK (0, 1, 2, ...) * @return int <0 if error, Num of establishment found if OK (0, 1, 2, ...)
*/ */
public function selectEstablishments($selected = '', $htmlname = 'entity', $statut = 0, $filtre = '', $useempty = 0, $moreattrib = '') public function selectEstablishments($selected = '', $htmlname = 'entity', $status = 0, $filtre = '', $useempty = 0, $moreattrib = '')
{ {
// phpcs:enable // phpcs:enable
global $langs, $conf; global $langs, $conf;
@ -3856,7 +3856,7 @@ class Form
$sql = "SELECT rowid, name, fk_country, status, entity"; $sql = "SELECT rowid, name, fk_country, status, entity";
$sql.= " FROM ".MAIN_DB_PREFIX."establishment"; $sql.= " FROM ".MAIN_DB_PREFIX."establishment";
$sql.= " WHERE 1=1"; $sql.= " WHERE 1=1";
if ($statut != 2) $sql.= " AND status = '".$statut."'"; if ($status != 2) $sql.= " AND status = ".(int) $status;
if ($filtre) $sql.=" AND ".$filtre; if ($filtre) $sql.=" AND ".$filtre;
$sql.= " ORDER BY name"; $sql.= " ORDER BY name";
@ -3886,7 +3886,7 @@ class Form
print '<option value="'.$obj->rowid.'">'; print '<option value="'.$obj->rowid.'">';
} }
print trim($obj->name); print trim($obj->name);
if ($statut == 2 && $obj->status == 1) print ' ('.$langs->trans("Closed").')'; if ($status == 2 && $obj->status == 1) print ' ('.$langs->trans("Closed").')';
print '</option>'; print '</option>';
$i++; $i++;
} }
@ -3894,7 +3894,7 @@ class Form
} }
else else
{ {
if ($statut == 0) print '<span class="opacitymedium">'.$langs->trans("NoActiveEstablishmentDefined").'</span>'; if ($status == 0) print '<span class="opacitymedium">'.$langs->trans("NoActiveEstablishmentDefined").'</span>';
else print '<span class="opacitymedium">'.$langs->trans("NoEstablishmentFound").'</span>'; else print '<span class="opacitymedium">'.$langs->trans("NoEstablishmentFound").'</span>';
} }
} }

View File

@ -1749,12 +1749,12 @@ function searchTaskInChild(&$inc, $parent, &$lines, &$taskrole)
* @param int $socid Id thirdparty * @param int $socid Id thirdparty
* @param int $projectsListId Id of project I have permission on * @param int $projectsListId Id of project I have permission on
* @param int $mytasks Limited to task I am contact to * @param int $mytasks Limited to task I am contact to
* @param int $statut -1=No filter on statut, 0 or 1 = Filter on status * @param int $status -1=No filter on statut, 0 or 1 = Filter on status
* @param array $listofoppstatus List of opportunity status * @param array $listofoppstatus List of opportunity status
* @param array $hiddenfields List of info to not show ('projectlabel', 'declaredprogress', '...', ) * @param array $hiddenfields List of info to not show ('projectlabel', 'declaredprogress', '...', )
* @return void * @return void
*/ */
function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks = 0, $statut = -1, $listofoppstatus = array(), $hiddenfields = array()) function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks = 0, $status = -1, $listofoppstatus = array(), $hiddenfields = array())
{ {
global $langs,$conf,$user,$bc; global $langs,$conf,$user,$bc;
@ -1768,7 +1768,7 @@ function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks
$project_year_filter=0; $project_year_filter=0;
$title=$langs->trans("Projects"); $title=$langs->trans("Projects");
if (strcmp($statut, '') && $statut >= 0) $title=$langs->trans("Projects").' '.$langs->trans($projectstatic->statuts_long[$statut]); if (strcmp($status, '') && $status >= 0) $title=$langs->trans("Projects").' '.$langs->trans($projectstatic->statuts_long[$status]);
$arrayidtypeofcontact=array(); $arrayidtypeofcontact=array();
@ -1797,9 +1797,9 @@ function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks
$sql.= " AND ec.fk_c_type_contact = ctc.rowid"; // Replace the 2 lines with ec.fk_c_type_contact in $arrayidtypeofcontact $sql.= " AND ec.fk_c_type_contact = ctc.rowid"; // Replace the 2 lines with ec.fk_c_type_contact in $arrayidtypeofcontact
$sql.= " AND ctc.element = 'project_task'"; $sql.= " AND ctc.element = 'project_task'";
} }
if ($statut >= 0) if ($status >= 0)
{ {
$sql.= " AND p.fk_statut = ".$statut; $sql.= " AND p.fk_statut = ".(int) $status;
} }
if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE)) if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE))
{ {

View File

@ -43,7 +43,7 @@ $pagenext = $page + 1;
if (! $sortorder) $sortorder="DESC"; if (! $sortorder) $sortorder="DESC";
if (! $sortfield) $sortfield="d.datedon"; if (! $sortfield) $sortfield="d.datedon";
$statut=(GETPOST("statut", 'intcomma')!='')?GETPOST("statut", 'intcomma'):"-1"; $search_status=(GETPOST("search_status", 'intcomma') != '') ? GETPOST("search_status", 'intcomma') : "-1";
$search_all=trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml')); $search_all=trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml'));
$search_ref=GETPOST('search_ref', 'alpha'); $search_ref=GETPOST('search_ref', 'alpha');
$search_company=GETPOST('search_company', 'alpha'); $search_company=GETPOST('search_company', 'alpha');
@ -87,13 +87,13 @@ $donationstatic=new Don($db);
// Genere requete de liste des dons // Genere requete de liste des dons
$sql = "SELECT d.rowid, d.datedon, d.fk_soc as socid, d.firstname, d.lastname, d.societe,"; $sql = "SELECT d.rowid, d.datedon, d.fk_soc as socid, d.firstname, d.lastname, d.societe,";
$sql.= " d.amount, d.fk_statut as statut, "; $sql.= " d.amount, d.fk_statut as status,";
$sql.= " p.rowid as pid, p.ref, p.title, p.public"; $sql.= " p.rowid as pid, p.ref, p.title, p.public";
$sql.= " FROM ".MAIN_DB_PREFIX."don as d LEFT JOIN ".MAIN_DB_PREFIX."projet AS p"; $sql.= " FROM ".MAIN_DB_PREFIX."don as d LEFT JOIN ".MAIN_DB_PREFIX."projet AS p";
$sql.= " ON p.rowid = d.fk_projet WHERE d.entity IN (".getEntity('donation').")"; $sql.= " ON p.rowid = d.fk_projet WHERE d.entity IN (".getEntity('donation').")";
if ($statut != '' && $statut != '-1') if ($search_status != '' && $search_status != '-1')
{ {
$sql .= " AND d.fk_statut IN (".$db->escape($statut).")"; $sql .= " AND d.fk_statut IN (".$db->escape($search_status).")";
} }
if (trim($search_ref) != '') if (trim($search_ref) != '')
{ {
@ -135,9 +135,13 @@ if ($resql)
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$i = 0; $i = 0;
$param = '&statut='.$statut; $param = '';
//if ($page > 0) $param.= '&page='.$page; if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss);
if ($optioncss != '') $param.='&optioncss='.$optioncss; if ($search_status && $search_status != -1) $param .= '&search_status='.urlencode($search_status);
if ($search_ref) $param .= '&search_ref='.urlencode($search_ref);
if ($search_company) $param .= '&search_company='.urlencode($search_company);
if ($search_name) $param .= '&search_name='.urlencode($search_name);
if ($search_amount) $param .= '&search_amount='.urlencode($search_amount);
$newcardbutton=''; $newcardbutton='';
if ($user->rights->don->creer) if ($user->rights->don->creer)
@ -257,7 +261,7 @@ if ($resql)
print "</td>\n"; print "</td>\n";
} }
print '<td class="right">'.price($objp->amount).'</td>'; print '<td class="right">'.price($objp->amount).'</td>';
print '<td class="right">'.$donationstatic->LibStatut($objp->statut, 5).'</td>'; print '<td class="right">'.$donationstatic->LibStatut($objp->status, 5).'</td>';
print '<td></td>'; print '<td></td>';
print "</tr>"; print "</tr>";
$i++; $i++;

View File

@ -1698,22 +1698,22 @@ class SupplierProposal extends CommonObject
* Close the askprice * Close the askprice
* *
* @param User $user Object user that close * @param User $user Object user that close
* @param int $statut Statut * @param int $status Status
* @param string $note Comment * @param string $note Comment
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
public function cloture($user, $statut, $note) public function cloture($user, $status, $note)
{ {
global $langs,$conf; global $langs,$conf;
$this->statut = $statut; $this->statut = $status;
$error=0; $error=0;
$now=dol_now(); $now=dol_now();
$this->db->begin(); $this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal"; $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal";
$sql.= " SET fk_statut = ".$statut.", note_private = '".$this->db->escape($note)."', date_cloture='".$this->db->idate($now)."', fk_user_cloture=".$user->id; $sql.= " SET fk_statut = ".$status.", note_private = '".$this->db->escape($note)."', date_cloture='".$this->db->idate($now)."', fk_user_cloture=".$user->id;
$sql.= " WHERE rowid = ".$this->id; $sql.= " WHERE rowid = ".$this->id;
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
@ -1722,7 +1722,7 @@ class SupplierProposal extends CommonObject
$modelpdf=$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED?$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED:$this->modelpdf; $modelpdf=$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED?$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED:$this->modelpdf;
$trigger_name='SUPPLIER_PROPOSAL_CLOSE_REFUSED'; $trigger_name='SUPPLIER_PROPOSAL_CLOSE_REFUSED';
if ($statut == 2) if ($status == 2)
{ {
$trigger_name='SUPPLIER_PROPOSAL_CLOSE_SIGNED'; $trigger_name='SUPPLIER_PROPOSAL_CLOSE_SIGNED';
$modelpdf=$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL?$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL:$this->modelpdf; $modelpdf=$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL?$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL:$this->modelpdf;
@ -1732,7 +1732,7 @@ class SupplierProposal extends CommonObject
$result = $this->updateOrCreatePriceFournisseur($user); $result = $this->updateOrCreatePriceFournisseur($user);
} }
} }
if ($statut == 4) if ($status == 4)
{ {
$trigger_name='SUPPLIER_PROPOSAL_CLASSIFY_BILLED'; $trigger_name='SUPPLIER_PROPOSAL_CLASSIFY_BILLED';
} }
@ -2258,15 +2258,16 @@ class SupplierProposal extends CommonObject
if ($resql) if ($resql)
{ {
$label = $labelShort = ''; $label = $labelShort = '';
$status = '';
if ($mode == 'opened') { if ($mode == 'opened') {
$delay_warning=$conf->supplier_proposal->cloture->warning_delay; $delay_warning=$conf->supplier_proposal->cloture->warning_delay;
$statut = self::STATUS_VALIDATED; $status = self::STATUS_VALIDATED;
$label = $langs->trans("SupplierProposalsToClose"); $label = $langs->trans("SupplierProposalsToClose");
$labelShort = $langs->trans("ToAcceptRefuse"); $labelShort = $langs->trans("ToAcceptRefuse");
} }
if ($mode == 'signed') { if ($mode == 'signed') {
$delay_warning=$conf->supplier_proposal->facturation->warning_delay; $delay_warning=$conf->supplier_proposal->facturation->warning_delay;
$statut = self::STATUS_SIGNED; $status = self::STATUS_SIGNED;
$label = $langs->trans("SupplierProposalsToProcess"); // May be billed or ordered $label = $langs->trans("SupplierProposalsToProcess"); // May be billed or ordered
$labelShort = $langs->trans("ToClose"); $labelShort = $langs->trans("ToClose");
} }
@ -2275,7 +2276,7 @@ class SupplierProposal extends CommonObject
$response->warning_delay = $delay_warning/60/60/24; $response->warning_delay = $delay_warning/60/60/24;
$response->label = $label; $response->label = $label;
$response->labelShort = $labelShort; $response->labelShort = $labelShort;
$response->url = DOL_URL_ROOT.'/supplier_proposal/list.php?viewstatut='.$statut; $response->url = DOL_URL_ROOT.'/supplier_proposal/list.php?viewstatut='.$status;
$response->img = img_object('', "propal"); $response->img = img_object('', "propal");
// This assignment in condition is not a bug. It allows walking the results. // This assignment in condition is not a bug. It allows walking the results.

View File

@ -954,22 +954,22 @@ class User extends CommonObject
/** /**
* Change status of a user * Change status of a user
* *
* @param int $statut Status to set * @param int $status Status to set
* @return int <0 if KO, 0 if nothing is done, >0 if OK * @return int <0 if KO, 0 if nothing is done, >0 if OK
*/ */
public function setstatus($statut) public function setstatus($status)
{ {
global $conf,$langs,$user; global $conf,$langs,$user;
$error=0; $error=0;
// Check parameters // Check parameters
if ($this->statut == $statut) return 0; if ($this->statut == $status) return 0;
else $this->statut = $statut; else $this->statut = $status;
$this->db->begin(); $this->db->begin();
// Deactivate user // Save in database
$sql = "UPDATE ".MAIN_DB_PREFIX."user"; $sql = "UPDATE ".MAIN_DB_PREFIX."user";
$sql.= " SET statut = ".$this->statut; $sql.= " SET statut = ".$this->statut;
$sql.= " WHERE rowid = ".$this->id; $sql.= " WHERE rowid = ".$this->id;