Skip to content

#2028 [Question] add: custom not slider percentage #2038

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

Open
wants to merge 3 commits into
base: develop
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
9 changes: 6 additions & 3 deletions class/control.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@ public function getNbControlsByMonth(): array
*/
public function getControlListsByNextControl(): array
{
// require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
global $langs;

// Graph Title parameters.
Expand All @@ -1065,6 +1066,10 @@ public function getControlListsByNextControl(): array
if (is_array($controls) && !empty($controls)) {
foreach ($controls as $control) {
$control->fetchObjectLinked('', '', $control->id, 'digiquali_control', 'OR', 1, 'sourcetype', 0);
if (!empty($control->projectid)) {
$control->fk_project = $control->projectid;
$control->fetch_project();
}
$linkedObjectsInfos = $control->getLinkedObjectsWithQcFrequency($elementArray);
$linkedObjects = $linkedObjectsInfos['linkedObjects'];
$qcFrequencyArray = $linkedObjectsInfos['qcFrequencyArray'];
Expand All @@ -1076,11 +1081,9 @@ public function getControlListsByNextControl(): array
require_once __DIR__ . '/sheet.class.php';

$userTmp = new User($this->db);
$project = new Project($this->db);
$sheet = new Sheet($this->db);

$userTmp->fetch($control->fk_user_controller);
$project->fetch($control->projectid);
$sheet->fetch($control->fk_sheet);

if (!empty($control->next_control_date)) {
Expand All @@ -1091,7 +1094,7 @@ public function getControlListsByNextControl(): array
$arrayControlListsByNextControl[$control->id]['Ref']['value'] = $control->getNomUrl(1);
$arrayControlListsByNextControl[$control->id]['LinkedObject']['value'] = $currentObject->getNomUrl(1);
$arrayControlListsByNextControl[$control->id]['UserController']['value'] = $userTmp->getNomUrl(1);
$arrayControlListsByNextControl[$control->id]['Project']['value'] = $project->id > 0 ? $project->getNomUrl(1) : '';
$arrayControlListsByNextControl[$control->id]['Project']['value'] = $control->project->id > 0 ? $control->project->getNomUrl(1) : '';
$arrayControlListsByNextControl[$control->id]['Sheet']['value'] = $sheet->getNomUrl(1);
$arrayControlListsByNextControl[$control->id]['ControlDate']['value'] = dol_print_date($control->date_creation, 'day');
$arrayControlListsByNextControl[$control->id]['NextControl']['value'] = '<div class="wpeo-button" style="background-color: ' . $nextControlDateColor .'; border-color: ' . $nextControlDateColor . ' ">' . $nextControl . '<br>' . $langs->trans('Days') . '</div>';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public function fillTagsLines(Odf $odfHandler, Translate $outputLangs, array $mo
$questionAnswerLine = array_shift($controldets);
$tmpArray['ref_answer'] = $questionAnswerLine->ref;
$tmpArray['comment'] = $questionAnswerLine->comment ? dol_htmlentitiesbr_decode(strip_tags($questionAnswerLine->comment, '<br>')) : $langs->transnoentities('NoObservations');
$tmpArray['answer'] = '';

$answerResult = $questionAnswerLine->answer;

Expand All @@ -166,7 +167,20 @@ public function fillTagsLines(Odf $odfHandler, Translate $outputLangs, array $mo
$tmpArray['answer'] = $answerResult;
break;
case 'Percentage' :
$tmpArray['answer'] = $answerResult . ' %';
$config = json_decode($question->json, true);

if (!isset($config['config'][$question->type]['isCursor']) || !empty($config['config'][$question->type]['isCursor'])) {
$tmpArray['answer'] .= $questionAnswerLine->answer;
} else {
$result = $answer->fetch('', '', ' AND t.status = ' . Answer::STATUS_VALIDATED . ' AND t.fk_question = ' . $question->id . ' AND t.position = ' . $questionAnswerLine->answer);
if ($result <= 0) {
$tmpArray['answer'] = '0';
} else {
$tmpArray['answer'] = $answer->value;
}
}

$tmpArray['answer'] .= ' %';
break;
case 'MultipleChoices' :
$answers = explode(',', $answerResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public function fillTagsLines(Odf $odfHandler, Translate $outputLangs, array $mo
$tmpArray['description'] = strip_tags($question->description);
$tmpArray['ref_answer'] = $line->ref;
$tmpArray['comment'] = dol_htmlentitiesbr_decode(strip_tags($line->comment, '<br>'));
$tmpArray['answer'] = '';

$answersArray = [];
$answers = $answer->fetchAll('ASC', 'position', 0, 0, ['fk_question' => $line->fk_question]);
Expand All @@ -137,7 +138,20 @@ public function fillTagsLines(Odf $odfHandler, Translate $outputLangs, array $mo
$tmpArray['answer'] = $line->answer;
break;
case 'Percentage' :
$tmpArray['answer'] = $line->answer . ' %';
$config = json_decode($question->json, true);

if (!isset($config['config'][$question->type]['isCursor']) || !empty($config['config'][$question->type]['isCursor'])) {
$tmpArray['answer'] .= $line->answer;
} else {
$result = $answer->fetch('', '', ' AND t.status = ' . Answer::STATUS_VALIDATED . ' AND t.fk_question = ' . $question->id . ' AND t.position = ' . $line->answer);
if ($result <= 0) {
$tmpArray['answer'] = '0';
} else {
$tmpArray['answer'] = $answer->value;
}
}

$tmpArray['answer'] .= ' %';
break;
case 'MultipleChoices' :
$tmpArray['answer'] = '';
Expand Down Expand Up @@ -295,15 +309,26 @@ public function write_file(SaturneDocuments $objectDocument, Translate $outputLa

$averagePercentageQuestions = 0;
$percentQuestionCounter = 0;
$answer = new Answer($this->db);

foreach ($sheet->linkedObjects['digiquali_question'] as $questionLinked) {
if ($questionLinked->type !== 'Percentage') {
continue; // Skip non-percentage questions
}

$percentQuestionCounter++;
foreach ($object->lines as $line) {
if ($line->fk_question === $questionLinked->id) {
$config = json_decode($questionLinked->json, true);

if ($line->fk_question === $questionLinked->id && is_numeric($line->answer) && (!isset($config['config'][$question->type]['isCursor']) || !empty($config['config'][$question->type]['isCursor']))) {
$averagePercentageQuestions += $line->answer;
} else {
$result = $answer->fetch('', '', ' AND t.status = ' . Answer::STATUS_VALIDATED . ' AND t.fk_question = ' . $questionLinked->id . ' AND t.position = ' . $line->answer);

if ($result <= 0) {
continue; // Skip if answer is not valid
}
$averagePercentageQuestions += $answer->value;
}
}
}
Expand Down
86 changes: 47 additions & 39 deletions core/modules/modDigiQuali.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -828,48 +828,56 @@ public function init($options = ''): int
dolibarr_set_const($this->db, 'DIGIQUALI_QUESTION_BACKWARD_COMPATIBILITY', 1, 'integer', 0, '', $conf->entity);
}

if (getDolGlobalInt('DIGIQUALI_CONTROL_ANSWER_BACKWARD') == 0 && $result > 0) {
if (getDolGlobalInt('DIGIQUALI_ANSWER_BACKWARD') == 0 && $result > 0) {

require_once __DIR__ . '/../../class/control.class.php';
require_once __DIR__ . '/../../class/sheet.class.php';

$control = new Control($this->db);
$sheet = new Sheet($this->db);
$objectLine = new ControlLine($this->db);

$controls = $control->fetchAll();
if (is_array($controls) && !empty($controls)) {
foreach ($controls as $control) {
if (empty($control->fk_sheet)) {
continue;
}

$sheet->fetch($control->fk_sheet);
$sheet->fetchObjectLinked($control->fk_sheet, 'digiquali_' . $sheet->element);
if (empty($sheet->linkedObjects['digiquali_question'])) {
continue;
}

$firstQuestion = current($sheet->linkedObjects['digiquali_question']);
$res = $objectLine->fetchFromParentWithQuestion($control->id, $firstQuestion->id);
if (empty($res)) {
foreach ($sheet->linkedObjects['digiquali_question'] as $question) {
$objectLine->ref = $objectLine->getNextNumRef();
$fk_element = 'fk_'. $control->element;
$objectLine->$fk_element = $control->id;
$objectLine->fk_question = $question->id;
$objectLine->answer = '';
$objectLine->comment = '';
$objectLine->entity = $conf->entity;
$objectLine->status = 1;

$objectLine->create($user);
}
}
}
}
require_once __DIR__ . '/../../class/survey.class.php';
require_once __DIR__ . '/../../class/sheet.class.php';

$control = new Control($this->db);
$survey = new Survey($this->db);
$sheet = new Sheet($this->db);
$controlLine = new ControlLine($this->db);
$surveyLine = new SurveyLine($this->db);


$elements = [$control, $survey];
$lines = [$controlLine, $surveyLine];
foreach ($elements as $idx => $elementObject) {
$arrayElements = $elementObject->fetchAll();
if (is_array($arrayElements) && !empty($arrayElements)) {
foreach ($arrayElements as $element) {
if (empty($element->fk_sheet)) {
continue;
}

$sheet->fetch($element->fk_sheet);
$sheet->fetchObjectLinked($element->fk_sheet, 'digiquali_' . $sheet->element);
if (empty($sheet->linkedObjects['digiquali_question'])) {
continue;
}

$firstQuestion = current($sheet->linkedObjects['digiquali_question']);
$res = $lines[$idx]->fetchFromParentWithQuestion($element->id, $firstQuestion->id);
if (empty($res)) {
foreach ($sheet->linkedObjects['digiquali_question'] as $question) {
$lines[$idx]->ref = $lines[$idx]->getNextNumRef();
$fk_element = 'fk_'. $element->element;
$lines[$idx]->$fk_element = $element->id;
$lines[$idx]->fk_question = $question->id;
$lines[$idx]->answer = '';
$lines[$idx]->comment = '';
$lines[$idx]->entity = $conf->entity;
$lines[$idx]->status = 1;

$lines[$idx]->create($user);
}
}
}
}
}

dolibarr_set_const($this->db, 'DIGIQUALI_CONTROL_ANSWER_BACKWARD', 1, 'integer', 0, '', $conf->entity);
dolibarr_set_const($this->db, 'DIGIQUALI_ANSWER_BACKWARD', 1, 'integer', 0, '', $conf->entity);
}

require_once DOL_DOCUMENT_ROOT . '/cron/class/cronjob.class.php';
Expand Down
6 changes: 4 additions & 2 deletions core/tpl/digiquali_survey_list.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,10 @@
$sheet->fetch($object->fk_sheet);
$sheet->fetchObjectLinked($object->fk_sheet, 'digiquali_' . $sheet->element, null, '', 'OR', 1, 'position');
$questions = $sheet->linkedObjects['digiquali_question'];
foreach ($questions as $question) {
$questions[$question->id] = $question;
if (is_array($questions) && !empty($questions)) {
foreach ($questions as $question) {
$questions[$question->id] = $question;
}
}

$answers = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,31 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
// Load Digiquali libraries
require_once __DIR__ . '/../../class/sheet.class.php';

$sheet = new Sheet($this->db);
$sheet = new Sheet($this->db);
$objectLine = new SurveyLine($this->db);

$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);
}

$sheet->fetchObjectLinked($object->fk_sheet, 'digiquali_' . $sheet->element);
if (!empty($sheet->linkedObjects['digiquali_question'])) {
foreach ($sheet->linkedObjects['digiquali_question'] as $question) {
$objectLine->ref = $objectLine->getNextNumRef();
$fk_element = 'fk_'. $object->element;
$objectLine->$fk_element = $object->id;
$objectLine->fk_question = $question->id;
$objectLine->answer = '';
$objectLine->comment = '';
$objectLine->entity = $conf->entity;
$objectLine->status = 1;

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

if ($object->context != 'createfromclone') {
$elementArray = get_sheet_linkable_objects();
if (!empty($elementArray)) {
Expand Down
2 changes: 1 addition & 1 deletion js/digiquali.min.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions js/modules/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ window.digiquali.question.selectAnswerPicto = function() {
window.digiquali.question.changeQuestionType = function() {
let questionType = $(this).val();
if (questionType === 'Percentage') {
$(document).find('#percentage-question-step').removeClass('hidden');
$(document).find('#percentage-question-step').fadeIn();
$(document).find('#percentage-question-is-percentage').fadeIn();
} else {
$(document).find('#percentage-question-step').addClass('hidden');
$(document).find('#percentage-question-step').fadeOut();
$(document).find('#percentage-question-is-percentage').fadeOut();
}
};
2 changes: 2 additions & 0 deletions langs/fr_FR/digiquali.lang
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ ShowOnlyQuestionsWithNoAnswer = Afficher uniquement les questions qui n'ont pas
AveragePercentageQuestions = Moyenne des questions
AddToSheet = Ajouter au modèle
PercentageQuestionStep = Nombre d'étapes du curseur
IsCursorPercentageQuestion = Repondre a la question avec un curseur
IsCursorPercentageTooltip = Repondre a la question avec un curseur ou avec des emojis



Expand Down
Loading