Skip to content

Commit

Permalink
Merge pull request #8 from frederic34/devh
Browse files Browse the repository at this point in the history
fix duration units
  • Loading branch information
frederic34 authored Oct 27, 2024
2 parents 59ef690 + 1cd3dd6 commit 9d692e0
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 33 deletions.
53 changes: 29 additions & 24 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true

[*.php]
indent_style = tab
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
[*.js]
indent_style = tab
[*.css]
indent_style = tab
[*.xml]
indent_style = tab
[*.md]
trim_trailing_whitespace = false
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true

[*.php]
indent_style = tab
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
[*.js]
indent_style = tab
[*.css]
indent_style = tab
[*.xml]
indent_style = tab
insert_final_newline = false
[*.md]
trim_trailing_whitespace = false
[*.sql]
indent_style = tab
trim_trailing_whitespace = true
indent_size = 4
2 changes: 1 addition & 1 deletion admin/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
$tooltiphelp = (($langs->trans($key . 'Tooltip') != $key . 'Tooltip') ? $langs->trans($key . 'Tooltip') : '');
print $form->textwithpicto($langs->trans($key), $tooltiphelp);
print '</td><td>';
$value = $conf->global->$key;
$value = $conf->global->$key ?? '';
if (isset($val['type']) && $val['type'] == 'password') {
$value = preg_replace('/./i', '*', $value);
}
Expand Down
25 changes: 17 additions & 8 deletions class/actions_easytooltip.class.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2023 Frédéric France <[email protected]>
/* Copyright (C) 2023-2024 Frédéric France <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -70,7 +70,6 @@ public function __construct($db)
$this->db = $db;
}


/**
* Overloading the getTooltipContent function : replacing the parent's function with the one below
*
Expand All @@ -84,7 +83,6 @@ public function getTooltipContent($parameters, &$object, &$action, $hookmanager)
{
global $conf, $user, $langs;

// var_dump($parameters);
$langs->load('easytooltip@easytooltip');
$contexts = explode(':', $parameters['context']);
$found = false;
Expand All @@ -103,13 +101,21 @@ public function getTooltipContent($parameters, &$object, &$action, $hookmanager)
// ADDING DURATION IF NOT PRESENT
if ($object->type == Product::TYPE_SERVICE && empty($parameters['tooltipcontentarray']['duration']) && !empty($object->duration_value)) {
// Duration
$tooltip = '<br><b>' . $langs->trans("Duration") . ':</b> ' . $object->duration_value;
require_once DOL_DOCUMENT_ROOT . '/core/class/cunits.class.php';
$measuringUnits = new CUnits($this->db);
$durations = [];
$plural = '';
if ($object->duration_value > 1) {
$dur = ["i" => $langs->trans("Minutes"), "h" => $langs->trans("Hours"), "d" => $langs->trans("Days"), "w" => $langs->trans("Weeks"), "m" => $langs->trans("Months"), "y" => $langs->trans("Years")];
} elseif ($object->duration_value > 0) {
$dur = ["i" => $langs->trans("Minute"), "h" => $langs->trans("Hour"), "d" => $langs->trans("Day"), "w" => $langs->trans("Week"), "m" => $langs->trans("Month"), "y" => $langs->trans("Year")];
$plural = 's';
}
$result = $measuringUnits->fetchAll('', 'scale', 0, 0, ['t.active' => 1, 't.unit_type' => 'time']);
if ($result !== -1) {
foreach ($measuringUnits->records as $record) {
$durations[$record->short_label] = dol_ucfirst($record->label) . $plural;
}
}
$tooltip .= (!empty($object->duration_unit) && isset($dur[$object->duration_unit]) ? "&nbsp;" . $langs->trans($dur[$object->duration_unit]) : '');
$tooltip = '<br><b>' . $langs->trans("Duration") . ':</b> ' . $object->duration_value;
$tooltip .= (!empty($object->duration_unit) && isset($durations[$object->duration_unit]) ? "&nbsp;" . $langs->trans($durations[$object->duration_unit]) : '');
self::arraySpliceAssoc($parameters['tooltipcontentarray'], 4, 0, ['duration' => $tooltip]);
}
// ADDING LAST CUSTOMER ORDER
Expand Down Expand Up @@ -264,6 +270,9 @@ public function getTooltipContent($parameters, &$object, &$action, $hookmanager)
} elseif (in_array('ticketdao', $contexts)) {
/** @var Ticket $object */
$found = true;
} elseif (in_array('opensurvey_sondagedao', $contexts)) {
/** @var Opensurveysondage $object */
$found = true;
} elseif (in_array('projectdao', $contexts)) {
/** @var Project $object */
$found = true;
Expand Down
1 change: 1 addition & 0 deletions core/modules/modEasyTooltip.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public function __construct($db)
// Set here all hooks context managed by module. To find available hook context, make a "grep -r '>initHooks(' *" on source code. You can also set hook context to 'all'
'hooks' => [
'data' => [
'globalcard',
'main',
'commandedao',
'contratdao',
Expand Down
1 change: 1 addition & 0 deletions langs/fr_FR/easytooltip.lang
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ PROJECT=Projet
PROPAL=Devis
SOCIETE=Tiers
TICKET=Ticket
OPENSURVEY_SONDAGE=Sondage

0 comments on commit 9d692e0

Please sign in to comment.