Skip to content

Commit

Permalink
Evarisk#1680 [Control] add: control answers & lock
Browse files Browse the repository at this point in the history
  • Loading branch information
theodaviddd committed Sep 3, 2024
1 parent 0980076 commit 24b3947
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 28 deletions.
44 changes: 38 additions & 6 deletions core/tpl/digiquali_mass_control_list.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// Fetch the list of mass controls linked to the object
$massControlList = $object->fetchAll('', '', 0, 0, ['fk_control' => $object->id]);

print '</form>';
// Start the responsive table container
print '<div class="div-table-responsive-no-min" style="overflow-x: unset !important">';

Expand Down Expand Up @@ -36,9 +36,13 @@
}
print '</div>';

$mainControlId = $object->id;
// Check if there are any mass controls and print them
if (is_array($massControlList) && !empty($massControlList)) {
foreach ($massControlList as $massControl) {
$object = $massControl;
$massControl->fetch_optionals();
$massControl->fetchLines();
// Fetch the public note if it exists

print '<div class="table-row sub-control-'. $massControl->id .'">';
Expand All @@ -62,28 +66,55 @@
print '<div class="table-cell center"><textarea type="text" class="note-public">' . $massControl->note_public . '</textarea></div>';

print '<div class="table-cell center">';
print '<button class="butAction answerSubControl" data-control-id="'. $massControl->id .'">Répondre</button>';
$questionCounter = 0;
if (!empty($questionIds)) {
$questionCounter = count($questionIds);
}

$answerCounter = 0;
if (is_array($massControl->lines) && !empty($massControl->lines)) {
foreach ($massControl->lines as $massControlLine) {
if (dol_strlen($massControlLine->answer) > 0) {
$answerCounter++;
}
}
}
//affiche le nombre de questions répondues
print '<span class="answerCounter">' . $answerCounter . '/' . $questionCounter . '</span>';
print '<button class="butAction answerSubControl modal-open" data-control-id="'. $massControl->id .'">';
print $langs->trans('Answers');
print '<input type="hidden" class="modal-options" data-modal-to-open="modalSubControl'. $massControl->id .'">';
print '</button>';
print '</div>';

// Additional cells for QRCode, Document, and Action can be filled in as needed
print '<div class="table-cell center">'. saturne_show_medias_linked('digiquali', $conf->digiquali->multidir_output[$conf->entity] . '/control/' . $massControl->ref . '/qrcode/', 'small', 1, 0, 0, 0, 80, 80, 0, 0, 0, 'control/' . $massControl->ref . '/qrcode/', $massControl, '', 0, 0) . '</div>';
print '<div class="table-cell center">';
print '</div>';
print '<div class="table-cell center">';
$displayButton = $onPhone ? '<i class="fas fa-check fa-2x"></i>' : '<i class="fas fa-check"></i>' . ' ' . $langs->trans('Save');
print '<span class="saveSubControl butAction" id="actionButtonSaveSubControl" data-control-id="'. $massControl->id .'" data-mass-control-id="'. $object->id .'">' . $displayButton . '</span>';
print '</div>';
if ($massControl->verdict > 0 && $answerCounter == $questionCounter) {
$displayButton = $onPhone ? '<i class="fas fa-lock fa-2x"></i>' : '<i class="fas fa-lock"></i>' . ' ' . $langs->trans('Lock');
print '<span class="lockSubControl butAction" id="actionButtonLockSubControl" data-control-id="'. $massControl->id .'" data-mass-control-id="'. $mainControlId .'">' . $displayButton . '</span>';
} else {
$displayButton = $onPhone ? '<i class="fas fa-check fa-2x"></i>' : '<i class="fas fa-check"></i>' . ' ' . $langs->trans('Save');
print '<span class="saveSubControl butAction" id="actionButtonSaveSubControl" data-control-id="'. $massControl->id .'" data-mass-control-id="'. $mainControlId .'">' . $displayButton . '</span>';
}

print '</div>';

print '<div class="wpeo-modal" id="modalSubControl'. $massControl->id .'">';
print '<div class="modal-container">';
print '<div class="modal-content">';
print load_fiche_titre($langs->trans('LinkedQuestionsList'), '', '');
print load_fiche_titre($langs->trans('LinkedQuestionsList') . ' - ' . $massControl->getNomUrl(1), '', '');
$conf->global->DIGIQUALI_CONTROLDET_AUTO_SAVE_ACTION = 0;
print '<div id="tablelines" class="question-answer-container noborder noshadow">';
require __DIR__ . '/../../core/tpl/digiquali_answers.tpl.php';
print '</div>';
print '</div>';
print '</div>';
print '</div>';
print '</div>';


}
} else {
Expand All @@ -92,6 +123,7 @@
print '<div class="table-cell" colspan="6">' . $langs->trans('NoMassControlFound') . '</div>';
print '</div>';
}
$object->fetch($id);
print '</div>'; // End of table
print '</div>'; // End of responsive container
?>
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,20 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
require_once __DIR__ . '/../../class/sheet.class.php';
require_once __DIR__ . '/../../class/control.class.php';

// Load Saturne libraries.
require_once __DIR__ . '/../../../saturne/class/saturnesignature.class.php';

$sheet = new Sheet($this->db);
$signatory = new SaturneSignature($this->db, 'digiquali');

$sheet->fetch($object->fk_sheet);
if ($sheet->success_rate > 0) {
$object->success_rate = $sheet->success_rate;
$object->setValueFrom('success_rate', $object->success_rate, '', '', 'text', '', $user);
}

$isMassControl = $object->mass_control;

$elementArray = [];

if ($object->context != 'createfromclone') {
Expand All @@ -150,19 +156,22 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
foreach ($elementArray as $linkableElementType => $linkableElement) {
$post = GETPOST('multi_' . $linkableElement['post_name'], 'array');
if (!empty($post) && $post > 0) {

foreach($post as $postElement) {
if ($object->mass_control) {
if ($isMassControl) {
$control = new Control($this->db);

$control->status = $control::STATUS_DRAFT;
$control->label = $object->label;
$control->fk_sheet = $object->fk_sheet;
$control->fk_user_controller = $object->fk_user_controller;
$control->fk_control = $object->id;
$control->create($user);
$controlId = $control->create($user, true);

$control->fetch($controlId);
$control->add_object_linked($linkableElement['link_name'], $postElement);

$signatory->setSignatory($control->id, $control->element, 'user', [$control->fk_user_controller], 'Controller', 1);
} else {
$object->add_object_linked($linkableElement['link_name'], $postElement);
}
Expand All @@ -171,8 +180,6 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
}
}

// Load Saturne libraries.
require_once __DIR__ . '/../../../saturne/class/saturnesignature.class.php';

$signatory = new SaturneSignature($this->db, 'digiquali');
$signatory->setSignatory($object->id, $object->element, 'user', [$object->fk_user_controller], 'Controller', 1);
Expand Down
Loading

0 comments on commit 24b3947

Please sign in to comment.