Skip to content

Commit

Permalink
#249 [Session] fix: check attendantRole before validate
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Mar 7, 2023
1 parent a79314d commit 4567dc8
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions view/session/session_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,23 +460,41 @@
// Print form confirm
print $formconfirm;

$signatoriesArray = $signatory->fetchSignatories($object->id, $object->element);
$nbSessionTrainer = 0;
$nbTrainee = 0;
foreach ($signatoriesArray as $objectSignatory) {
if ($objectSignatory->role == 'SessionTrainer') {
$nbSessionTrainer++;
switch ($object->element) {
case 'meeting' :
$attendantsRole = ['Contributor', 'Responsible'];
break;
case 'trainingsession' :
$attendantsRole = ['Trainee', 'SessionTrainer'];
break;
case 'audit' :
$attendantsRole = ['Auditor'];
break;
default :
$attendantsRole = ['Attendant'];
}

$mesg = '';
$nbAttendantByRole = [];
$nbAttendants = 0;
foreach ($attendantsRole as $attendantRole) {
$signatories = $signatory->fetchSignatory($attendantRole, $object->id, $object->element);
if (is_array($signatories) && !empty($signatories)) {
foreach ($signatories as $objectSignatory) {
if ($objectSignatory->role == $attendantRole) {
$nbAttendantByRole[$attendantRole]++;
}
}
} else {
$nbTrainee++;
$nbAttendantByRole[$attendantRole] = 0;
}
if ($nbAttendantByRole[$attendantRole] == 0) {
$mesg .= $langs->trans('NoAttendant', $langs->trans($attendantRole), $langs->transnoentities('The' . ucfirst($object->element))) . '<br>';
}
}

$mesg = '';
if ($nbSessionTrainer == 0) {
$mesg .= $langs->trans('NoAttendant', $langs-> trans('SessionTrainer'), $langs->transnoentities('The' . ucfirst($object->element))) . '<br>';
}
if ($nbTrainee == 0) {
$mesg .= $langs->trans('NoAttendant', $langs-> trans('Trainee'), $langs->transnoentities('The' . ucfirst($object->element)));
if (!in_array(0, $nbAttendantByRole)) {
$nbAttendants = 1;
}

print '<div class="fichecenter">';
Expand Down Expand Up @@ -528,7 +546,7 @@
}

// Validate
if ($object->status == $object::STATUS_DRAFT && $nbSessionTrainer > 0 && $nbTrainee > 0) {
if ($object->status == $object::STATUS_DRAFT && $nbAttendants > 0) {
print '<span class="butAction" id="actionButtonPendingSignature"><i class="fas fa-check"></i> ' . $langs->trans('Validate') . '</span>';
} else {
print '<span class="butActionRefused classfortooltip" title="' . dol_escape_htmltag($langs->trans('ObjectMustBeDraftToValidate', ucfirst($langs->transnoentities('The' . ucfirst($object->element)))) . '<br>' . $mesg) . '"><i class="fas fa-check"></i> ' . $langs->trans('Validate') . '</span>';
Expand All @@ -549,7 +567,7 @@
}

// Lock
if ($object->status == $object::STATUS_VALIDATED && $signatory->checkSignatoriesSignatures($object->id, $object->element) && $nbSessionTrainer > 0 && $nbTrainee > 0) {
if ($object->status == $object::STATUS_VALIDATED && $signatory->checkSignatoriesSignatures($object->id, $object->element) && $nbAttendants > 0) {
print '<span class="butAction" id="actionButtonLock"><i class="fas fa-lock"></i> ' . $langs->trans('Lock') . '</span>';
} else {
print '<span class="butActionRefused classfortooltip" title="' . dol_escape_htmltag($langs->trans('AllSignatoriesMustHaveSigned', $langs->transnoentities('The' . ucfirst($object->element))) . '<br>' . $mesg) . '"><i class="fas fa-lock"></i> ' . $langs->trans('Lock') . '</span>';
Expand Down Expand Up @@ -596,7 +614,7 @@
$filedir = $upload_dir . '/' . $dir_files;
$urlsource = $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&object_type=' . $object->element;

print saturne_show_documents('dolimeet:' . ucfirst($object->element) . 'Document', $dir_files, $filedir, $urlsource, $permissiontoadd, $permissiontodelete, '', 1, 0, 0, 0, 0, '', '', $langs->defaultlang, 0, $object, 0, 'remove_file', ($object->status > $object::STATUS_DRAFT && $nbSessionTrainer > 0 && $nbTrainee > 0), $langs->trans('ObjectMustBeValidatedToGenerate', ucfirst($langs->transnoentities('The' . ucfirst($object->element)))) . '<br>' . $mesg);
print saturne_show_documents('dolimeet:' . ucfirst($object->element) . 'Document', $dir_files, $filedir, $urlsource, $permissiontoadd, $permissiontodelete, '', 1, 0, 0, 0, 0, '', '', $langs->defaultlang, 0, $object, 0, 'remove_file', ($object->status > $object::STATUS_DRAFT && $nbAttendants > 0), $langs->trans('ObjectMustBeValidatedToGenerate', ucfirst($langs->transnoentities('The' . ucfirst($object->element)))) . '<br>' . $mesg);
}

print '</div><div class="fichehalfright">';
Expand Down

0 comments on commit 4567dc8

Please sign in to comment.