Skip to content

Commit

Permalink
Fixed issue #19452: Improve usage of getQuestionAttributes PrintableS…
Browse files Browse the repository at this point in the history
…urvey (#3789)

* Dev #19452: Improve usage of getQuestionAttributes PrintableSurvey
Dev: simple for question
Dev: add specific array for conditions (again array dual scale)

* Dev: avoid multiple call of same question attributes

* MW-1040: Applied some fixes

* Added a comment

* MW-1040: Fixed a typo

---------

Co-authored-by: Lajos Arpad <arpad@endpoint.com>
  • Loading branch information
Shnoulle and Lajos Arpad committed Mar 21, 2024
1 parent 1f84686 commit 570b810
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions application/controllers/admin/PrintableSurvey.php
Expand Up @@ -137,6 +137,20 @@ public function index($surveyid, $lang = null, $bReturn = false)

$fieldmap = createFieldMap($oSurvey, 'full', false, false, $sLanguageCode);

// For print condition text : need questionobject of some specific question
$criteria = new CDBCriteria();
$criteria->select = ['cqid'];
$criteria->with = ['questions'];
$criteria->compare('questions.sid', $surveyid);
$neededTypes = [QuestionType::QT_1_ARRAY_DUAL];
$criteria->addInCondition('questions.type', $neededTypes);
$oConditions = Condition::model()->with('questions')->findAll($criteria);
// We need only the question attributes
/* array[] Needed question attributes for condition question */
$conditionQuestionsAttributes = [];
foreach ($oConditions as $oCondition) {
$conditionQuestionsAttributes[$oCondition->cqid] = QuestionAttribute::model()->getQuestionAttributes($oCondition->questions);
}
// =========================================================
// START doin the business:
foreach ($arGroups as $arQuestionGroup) {
Expand Down Expand Up @@ -170,10 +184,7 @@ public function index($surveyid, $lang = null, $bReturn = false)
foreach ($arQuestions as $arQuestion) {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// START doing questions

$qidattributes = QuestionAttribute::model()->getQuestionAttributes($arQuestion['qid']);


$qidattributes = QuestionAttribute::model()->getQuestionAttributes($arQuestion);
if ($qidattributes['hidden'] == 1 && $arQuestion['type'] != Question::QT_ASTERISK_EQUATION) {
continue;
}
Expand All @@ -184,8 +195,6 @@ public function index($surveyid, $lang = null, $bReturn = false)
$sExplanation = ''; //reset conditions explanation
$s = 0;
// TMSW Condition->Relevance: show relevance instead of this whole section to create $explanation


$scenarioresult = Condition::model()->getScenarios($arQuestion['qid']);
$scenarioresult = $scenarioresult->readAll();
//Loop through distinct scenarios, thus grouping them together.
Expand Down Expand Up @@ -238,7 +247,7 @@ public function index($surveyid, $lang = null, $bReturn = false)
// cqid == 0 ==> token attribute match
$tokenData = getTokenFieldsAndNames($surveyid);
preg_match('/^{TOKEN:([^}]*)}$/', (string) $distinctrow['cfieldname'], $extractedTokenAttr);
$sExplanation .= "Your " . $tokenData[strtolower($extractedTokenAttr[1])]['description'] . " ";
$sExplanation .= "Your " . ($tokenData[strtolower($extractedTokenAttr[1])]['description'] ?? "") . " ";
if ($distinctrow['method'] == '==') {
$sExplanation .= gT("is") . " ";
} elseif ($distinctrow['method'] == '!=') {
Expand All @@ -256,11 +265,10 @@ public function index($surveyid, $lang = null, $bReturn = false)
} else {
$sExplanation .= gT("is") . " ";
}
$answer_section = ' ' . $distinctrow['value'] . ' ';
$answer_section = ' ' . ($distinctrow['value'] ?? "") . ' ';
}

$conresult = Condition::model()->getConditionsQuestions($distinctrow['cqid'], $arQuestion['qid'], $scenariorow['scenario'], $sLanguageCode);

$conditions = array();
foreach ($conresult->readAll() as $conrow) {
$value = $conrow['value'];
Expand Down Expand Up @@ -389,7 +397,7 @@ public function index($surveyid, $lang = null, $bReturn = false)
$thiscquestion = $fieldmap[$conrow['cfieldname']];
$condition = "parent_qid='{$conrow['cqid']}' AND title='{$thiscquestion['aid']}'";
$ansresult = Question::model()->findAll(['condition' => $condition, 'order' => 'question_order']);
$cqidattributes = QuestionAttribute::model()->getQuestionAttributes($conrow['cqid']);
$cqidattributes = $conditionQuestionsAttributes[$conrow['cqid']];
if ($labelIndex == 0) {
if (trim((string) $cqidattributes['dualscale_headerA'][$sLanguageCode]) != '') {
$header = gT($cqidattributes['dualscale_headerA'][$sLanguageCode]);
Expand Down Expand Up @@ -442,15 +450,22 @@ public function index($surveyid, $lang = null, $bReturn = false)
if ($distinctrow['cqid']) {
$sExplanation .= " <span class='scenario-at-separator'>" . gT("at question") . "</span> '" . " [" . $subresult['title'] . "]' (" . strip_tags((string) $subresult->questionl10ns[$sLanguageCode]->question) . "$answer_section)";
} else {
$sExplanation .= " " . $distinctrow['value'];
$sExplanation .= " " . ($distinctrow['value'] ?? "");
}
//$distinctrow
$x++;
}
$s++;
}

$qinfo = LimeExpressionManager::GetQuestionStatus($arQuestion['qid']);
//Defaulting to dummy array to avoid crashes when qinfo is not found for this question
$qinfo = LimeExpressionManager::GetQuestionStatus($arQuestion['qid']) ?? [
"info" => [
"relevance" => ""
],
"relEqn" => "",
"validTip" => ""
];
$relevance = trim((string) $qinfo['info']['relevance']);
$sEquation = $qinfo['relEqn'];

Expand Down Expand Up @@ -631,7 +646,7 @@ public function index($surveyid, $lang = null, $bReturn = false)
}
}

if ($arQuestion['other'] == 'Y') {
if (($arQuestion['other'] == 'Y') && isset($qidattributes["printable_help"])) {
/*echo '<pre>';
print_r($qidattributes);
echo '</pre>';
Expand Down Expand Up @@ -709,7 +724,7 @@ public function index($surveyid, $lang = null, $bReturn = false)
++$colcounter;
}
}
if ($arQuestion['other'] == "Y") {
if (($arQuestion['other'] == "Y") && (isset($qidattributes["printable_help"]))) {
if (trim((string) $qidattributes["printable_help"][$sLanguageCode]) == '') {
$qidattributes["printable_help"][$sLanguageCode] = "Other";
}
Expand Down

0 comments on commit 570b810

Please sign in to comment.