Skip to content

Commit

Permalink
#535 [Hook] fix: separate duration time and calculated session time
Browse files Browse the repository at this point in the history
  • Loading branch information
evarisk-micka committed Feb 22, 2024
1 parent f50cac0 commit 98a5a15
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
34 changes: 29 additions & 5 deletions class/actions_dolimeet.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,11 +440,25 @@ function fillTable(data) {
foreach ($sessions as $session) {
$sessionDurations += $session->duration;
}
$out = '<tr class="trextrafields_collapse_' . $object->id . '"><td class="titlefield">' . $langs->transnoentities('TrainingSessionDurations') . '</td>';
$out .= '<td id="' . $object->element . '_extras_trainingsession_durations_' . $object->id . '" class="valuefield ' . $object->element . '_extras_trainingsession_durations">' . $picto . ($sessionDurations > 0 ? convertSecondToTime($sessionDurations, 'allhourmin') : '00:00') . '</td></tr>';
?>
if (GETPOST('action') == 'edit_extras' && GETPOST('attribute') == 'trainingsession_durations') {
$out = '<td id="' . $object->element . '_extras_trainingsession_durations_' . $object->id . '" class="valuefield ' . $object->element . '_extras_trainingsession_durations">' . $picto;
$out .= '<form enctype="multipart/form-data" action="'. $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post" name="formextra">';
$out .= '<input type="hidden" name="action" value="update_extras">';
$out .= '<input type="hidden" name="attribute" value="trainingsession_durations">';
$out .= '<input type="hidden" name="token" value="'.newToken().'">';
$out .= '<input type="hidden" name="confirm" value="yes">';
$out .= $form->select_duration('duration', $object->array_options['options_trainingsession_durations'], 0, 'text', 0, 1);
$out .= '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans('Modify')).'">' . '</td></tr>';
} else {
$out = '<td id="' . $object->element . '_extras_trainingsession_durations_' . $object->id . '" class="valuefield ' . $object->element . '_extras_trainingsession_durations">' . $picto . ($object->array_options['options_trainingsession_durations'] > 0 ? convertSecondToTime($object->array_options['options_trainingsession_durations'], 'allhourmin') : '00:00') . ' - ';
$out .= $langs->trans('CalculatedTotalSessionDuration') . ' ' . ($sessionDurations > 0 ? convertSecondToTime($sessionDurations, 'allhourmin') : '00:00');
if ($sessionDurations != $object->array_options['options_trainingsession_durations']) {
$out .= $form->textwithpicto('', $langs->trans('TrainingSessionDurationErrorMatching', $session->ref), 1, 'warning');
}
$out .= '</td></tr>';
} ?>
<script>
jQuery('.contrat_extras_trainingsession_location').closest('.trextrafields_collapse_' + <?php echo $object->id; ?>).after(<?php echo json_encode($out); ?>);
jQuery('.valuefield.contrat_extras_trainingsession_durations').replaceWith(<?php echo json_encode($out); ?>);
</script>
<?php
}
Expand Down Expand Up @@ -536,7 +550,7 @@ public function addMoreActionsButtons(array $parameters, $object): int
*/
public function doActions(array $parameters, $object, string $action): int
{
global $conf, $langs, $user;
global $conf, $user;

// Do something only for the current context.
if ($parameters['currentcontext'] == 'admincompany') {
Expand Down Expand Up @@ -585,6 +599,16 @@ public function doActions(array $parameters, $object, string $action): int
header('Location: ' . $urlToRedirect);
exit;
}

if ($action == 'update_extras' && GETPOST('attribute') == 'trainingsession_durations') {
$hours = GETPOST('durationhour', 'int');
$minutes = GETPOST('durationmin', 'int');
$duration = convertTime2Seconds($hours, $minutes);

$object->array_options['options_trainingsession_durations'] = $duration;
$object->updateExtrafield('trainingsession_durations');
return 1;
}
}

return 0; // or return 1 to replace standard code.
Expand Down
3 changes: 3 additions & 0 deletions core/modules/modDoliMeet.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,9 @@ public function init($options = ''): int
$extraFields->update('trainingsession_location', $langs->transnoentities('TrainingSessionLocation'), 'varchar', '', 'contrat', 0, 0, 1850, '', '', '', 1, 'TrainingSessionLocationHelp');
$extraFields->addExtraField('trainingsession_location', $langs->transnoentities('TrainingSessionLocation'), 'varchar', 1850, '', 'contrat', 0, 0, '', '', '', '', 1, 'TrainingSessionLocationHelp');

$extraFields->update('trainingsession_durations', $langs->transnoentities('TrainingSessionDurations'), 'int', '', 'contrat', 0, 0, 1860, '', '', '', 1, 'TrainingSessionDurationHelp');
$extraFields->addExtraField('trainingsession_durations', $langs->transnoentities('TrainingSessionDurations'), 'int', 1860, '', 'contrat', 0, 0, '', '', '', '', 1, 'TrainingSessionDurationHelp');

return $this->_init($sql, $options);
}

Expand Down
4 changes: 3 additions & 1 deletion langs/en_US/dolimeet.lang
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ TrainingSessionStartHelp = Start date of the first training session
TrainingSessionEndHelp = End date of the last training session of the contract
TrainingSessionTypeHelp = Type of training session linked to the contract
TrainingSessionLocationHelp = Place where the training session linked to the contract took place

TrainingSessionDurationHelp = Total duration of the sessions HH:MM (ex: 60:30) <br> The duration shown on the certificate corresponds to the total number of hours of sessions attended by a trainee.
CalculatedTotalSessionDuration = Total calculated duration time:
TrainingSessionDurationErrorMatching = <strong> Error: consistency of training session duration. </strong><br> The total duration of the sessions indicated in the contract is different from the calculated duration of all the sessions linked to the contract.

# Attendant role
SessionTrainer = Trainer
Expand Down
3 changes: 3 additions & 0 deletions langs/fr_FR/dolimeet.lang
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ TrainingSessionStartHelp = Date de début de la première session d
TrainingSessionEndHelp = Date de fin de la dernière session de formation du contrat
TrainingSessionTypeHelp = Type de formation liée au contrat
TrainingSessionLocationHelp = Lieu où s'est réalisé la formation liée au contrat
TrainingSessionDurationHelp = Durée totale des sessions HH:MM (ex: 60:30) <br> La durée affichée sur le certificat correspond aux heures additionnées des sessions où un stagiaire a été présent.
CalculatedTotalSessionDuration = Durée totale calculée :
TrainingSessionDurationErrorMatching = <strong> Erreur : cohérence de la durée des sessions de formation. </strong><br> La durée totale des sessions indiqué dans le contrat est différente de la durée calculé de l'ensemble des sessions liées au contrat.



Expand Down

0 comments on commit 98a5a15

Please sign in to comment.