Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajout des réponses paramétrables dans le dictionnaire question (rétrocompatibilité non complète) #1923

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function fillTagsLines(Odf $odfHandler, Translate $outputLangs, array $mo
$tmpArray['answer'] = rtrim($tmpArray['answer'], ', ');
break;
default:
$tmpArray['answer'] = '';
$tmpArray['answer'] = is_array($answersArray)?$answersArray[$answerResult]:'';
}

$path = $conf->digiquali->multidir_output[$conf->entity] . '/control/' . $object->ref . '/answer_photo/' . $question->ref;
Expand Down
8 changes: 4 additions & 4 deletions core/modules/modDigiQuali.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public function __construct($db)
],
// Request to select fields
'tabsql' => [
'SELECT f.rowid as rowid, f.ref, f.label, f.description, f.position, f.active FROM ' . MAIN_DB_PREFIX . 'c_question_type as f',
'SELECT f.rowid as rowid, f.ref, f.label, f.description, f.default_answers, f.position, f.active FROM ' . MAIN_DB_PREFIX . 'c_question_type as f',
'SELECT f.rowid as rowid, f.ref, f.label, f.description, f.position, f.active FROM ' . MAIN_DB_PREFIX . 'c_control_attendants_role as f',
'SELECT f.rowid as rowid, f.ref, f.label, f.description, f.position, f.active FROM ' . MAIN_DB_PREFIX . 'c_survey_attendants_role as f'
],
Expand All @@ -346,19 +346,19 @@ public function __construct($db)
],
// List of fields (result of select to show dictionary)
'tabfield' => [
'ref,label,description,position',
'ref,label,description,default_answers,position',
'ref,label,description,position',
'ref,label,description,position'
],
// List of fields (list of fields to edit a record)
'tabfieldvalue' => [
'ref,label,description,position',
'ref,label,description,default_answers,position',
'ref,label,description,position',
'ref,label,description,position'
],
// List of fields (list of fields for insert)
'tabfieldinsert' => [
'ref,label,description,position',
'ref,label,description,default_answers,position',
'ref,label,description,position',
'ref,label,description,position'
],
Expand Down
38 changes: 20 additions & 18 deletions core/tpl/digiquali_answers.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,24 +133,7 @@
}
?>
</div>
<?php elseif ($question->type == 'UniqueChoice' || $question->type == 'OkKo' || $question->type == 'OkKoToFixNonApplicable') :
$answerList = $answer->fetchAll('ASC', 'position', 0, 0, ['customsql' => 't.status > ' . Answer::STATUS_DELETED . ' AND t.fk_question = ' . $question->id]); ?>
<div class="table-cell table-end select-answer answer-cell table-300" <?php echo ($object->status > 0) ? 'style="pointer-events: none"' : '' ?> data-questionId="<?php echo $question->id; ?>">
<?php
print '<input type="hidden" class="question-answer" name="answer' . $question->id . '" id="answer' . $question->id . '" value="0">';
if (is_array($answerList) && !empty($answerList)) {
foreach($answerList as $answerLinked) {
print '<input type="hidden" class="answer-color answer-color-' . $answerLinked->position . '" value="' . $answerLinked->color . '">';
print '<span style="' . ($questionAnswer == $answerLinked->position ? 'background:' . $answerLinked->color . '; ' : '') . 'color:' . $answerLinked->color . ';" class="answer ' . ($object->status > 0 ? 'disable' : '') . ' ' . ($questionAnswer == $answerLinked->position ? 'active' : '') . '" value="' . $answerLinked->position . '">';
if (!empty($answerLinked->pictogram)) {
print $pictosArray[$answerLinked->pictogram]['picto_source'];
} else {
print $answerLinked->value;
}
print '</span>';
}
} ?>
</div>

<?php elseif ($question->type == 'Percentage') : ?>
<div class="table-cell table-end answer-cell table-flex <?php echo ($object->status > 0) ? 'style="pointer-events: none"' : '' ?>" data-questionId="<?php echo $question->id; ?>">
<?php
Expand All @@ -173,7 +156,26 @@
print '</span>';
?>
</div>
<?php else://if ($question->type == 'UniqueChoice' || $question->type == 'OkKo' || $question->type == 'OkKoToFixNonApplicable') :
$answerList = $answer->fetchAll('ASC', 'position', 0, 0, ['customsql' => 't.status > ' . Answer::STATUS_DELETED . ' AND t.fk_question = ' . $question->id]); ?>
<div class="table-cell table-end select-answer answer-cell table-300" <?php echo ($object->status > 0) ? 'style="pointer-events: none"' : '' ?> data-questionId="<?php echo $question->id; ?>">
<?php
print '<input type="hidden" class="question-answer" name="answer' . $question->id . '" id="answer' . $question->id . '" value="0">';
if (is_array($answerList) && !empty($answerList)) {
foreach($answerList as $answerLinked) {
print '<input type="hidden" class="answer-color answer-color-' . $answerLinked->position . '" value="' . $answerLinked->color . '">';
print '<span style="' . ($questionAnswer == $answerLinked->position ? 'background:' . $answerLinked->color . '; ' : '') . 'color:' . $answerLinked->color . ';" class="answer ' . ($object->status > 0 ? 'disable' : '') . ' ' . ($questionAnswer == $answerLinked->position ? 'active' : '') . '" value="' . $answerLinked->position . '">';
if (!empty($answerLinked->pictogram)) {
print $pictosArray[$answerLinked->pictogram]['picto_source'];
} else {
print $answerLinked->value;
}
print '</span>';
}
} ?>
</div>
<?php endif; ?>

</div>
</div>
<?php
Expand Down
85 changes: 52 additions & 33 deletions view/question/question_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,37 +288,56 @@
// Category association
$categories = GETPOST('categories', 'array');
$object->setCategories($categories);

if ($object->type == 'OkKo' || $object->type == 'OkKoToFixNonApplicable') {
$answer->fk_question = $result;
$answer->value = $langs->transnoentities('OK');
$answer->pictogram = 'check';
$answer->color = '#47e58e';

$answer->create($user);

$answer->fk_question = $result;
$answer->value = $langs->transnoentities('KO');
$answer->pictogram = 'times';
$answer->color = '#e05353';

$answer->create($user);
}

if ($object->type == 'OkKoToFixNonApplicable') {
$answer->fk_question = $result;
$answer->value = $langs->transnoentities('ToFix');
$answer->pictogram = 'tools';
$answer->color = '#e9ad4f';

$answer->create($user);

$answer->fk_question = $result;
$answer->value = $langs->transnoentities('NonApplicable');
$answer->pictogram = 'N/A';
$answer->color = '#2b2b2b';

$answer->create($user);

//Mon super test
$defaultAnswers = saturne_get_value_dictionary('c_question_type', 'default_answers', $object->type);

if($defaultAnswers>0 && !empty($defaultAnswers->default_answers)){
$arrayDefaultAnswers = explode(',',$defaultAnswers->default_answers);
foreach($arrayDefaultAnswers as $answerp){
$answerParameters = explode(':', $answerp);
if(sizeof($answerParameters)==3){ //only if there are all parameters
$answer->fk_question = $result;
$answer->value = $langs->transnoentities($answerParameters[0]);
$answer->pictogram = $answerParameters[1];
$answer->color = $answerParameters[2];
$answer->create($user);
}
}

}else{
//backward compatibility
if ($object->type == 'OkKo' || $object->type == 'OkKoToFixNonApplicable') {
$answer->fk_question = $result;
$answer->value = $langs->transnoentities('OK');
$answer->pictogram = 'check';
$answer->color = '#47e58e';

$answer->create($user);

$answer->fk_question = $result;
$answer->value = $langs->transnoentities('KO');
$answer->pictogram = 'times';
$answer->color = '#e05353';

$answer->create($user);
}

if ($object->type == 'OkKoToFixNonApplicable') {
$answer->fk_question = $result;
$answer->value = $langs->transnoentities('ToFix');
$answer->pictogram = 'tools';
$answer->color = '#e9ad4f';

$answer->create($user);

$answer->fk_question = $result;
$answer->value = $langs->transnoentities('NonApplicable');
$answer->pictogram = 'N/A';
$answer->color = '#2b2b2b';

$answer->create($user);
}
}


Expand Down Expand Up @@ -1124,7 +1143,7 @@
print '</div>';
}

if ($object->type == 'MultipleChoices' || $object->type == 'UniqueChoice' || $object->type == 'OkKo' || $object->type == 'OkKoToFixNonApplicable') {
//if ($object->type == 'MultipleChoices' || $object->type == 'UniqueChoice' || $object->type == 'OkKo' || $object->type == 'OkKoToFixNonApplicable') {

$pictosArray = get_answer_pictos_array();

Expand Down Expand Up @@ -1278,7 +1297,7 @@
print '</form>';
print '</div>';
}
}
//}
print dol_get_fiche_end();

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