Standardize code

This commit is contained in:
Laurent Destailleur 2020-08-16 23:33:50 +02:00
parent 816aeadcba
commit 99809b487e
2 changed files with 81 additions and 3 deletions

View File

@ -79,6 +79,7 @@ $object = new Fiscalyear($db);
$max = 100;
$form = new Form($db);
$fiscalyearstatic = new Fiscalyear($db);
$title = $langs->trans('AccountingPeriods');
$helpurl = "";
@ -132,13 +133,15 @@ if ($result)
print '</tr>';
if ($num) {
$fiscalyearstatic = new Fiscalyear($db);
while ($i < $num && $i < $max) {
$obj = $db->fetch_object($result);
$fiscalyearstatic->id = $obj->rowid;
print '<tr class="oddeven">';
print '<td><a href="fiscalyear_card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowFiscalYear"), "technic").' '.$obj->rowid.'</a></td>';
print '<td>';
print $fiscalyearstatic->getNomUrl(1);
print '</td>';
print '<td class="left">'.$obj->label.'</td>';
print '<td class="left">'.dol_print_date($db->jdate($obj->date_start), 'day').'</td>';
print '<td class="left">'.dol_print_date($db->jdate($obj->date_end), 'day').'</td>';

View File

@ -35,6 +35,8 @@ class Fiscalyear extends CommonObject
*/
public $element = 'fiscalyear';
public $picto = 'technic';
/**
* @var string Name of table without prefix where object is stored
*/
@ -97,6 +99,7 @@ class Fiscalyear extends CommonObject
public $statuts = array();
public $statuts_short = array();
/**
* Constructor
*
@ -267,6 +270,78 @@ class Fiscalyear extends CommonObject
}
}
/**
* Return clicable link of object (with eventually picto)
*
* @param int $withpicto Add picto into link
* @param int $notooltip 1=Disable tooltip
* @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
* @return string String with URL
*/
public function getNomUrl($withpicto = 0, $notooltip = 0, $save_lastsearch_value = -1)
{
global $conf, $langs, $user;
if (empty($this->ref)) $this->ref = $this->id;
if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
$result = '';
$url = DOL_URL_ROOT.'/accountancy/admin/fiscalyear_card.php?id='.$this->id;
if (!$user->rights->accounting->fiscalyear->write)
$option = 'nolink';
if ($option !== 'nolink')
{
// Add param to save lastsearch_values or not
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
}
if ($short) return $url;
$label = '';
if ($user->rights->accounting->fiscalyear->write) {
$label = '<u>'.$langs->trans("FiscalPeriod").'</u>';
$label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->id;
if (isset($this->statut)) {
$label .= '<br><b>'.$langs->trans("Status").":</b> ".$this->getLibStatut(5);
}
}
$linkclose = '';
if (empty($notooltip) && $user->rights->accounting->fiscalyear->write)
{
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
{
$label = $langs->trans("FiscalYear");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
}
$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose .= ' class="classfortooltip"';
}
$linkstart = '<a href="'.$url.'"';
$linkstart .= $linkclose.'>';
$linkend = '</a>';
if ($option === 'nolink') {
$linkstart = '';
$linkend = '';
}
$result .= $linkstart;
if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
if ($withpicto != 2) $result .= $this->ref;
$result .= $linkend;
return $result;
}
/**
* Give a label from a status
*