Skip to content

Commit

Permalink
Fixed issue #17647: Strange sort order of question groups in statisti…
Browse files Browse the repository at this point in the history
…cs (#2143)

Dev: order is already set in request for run
Dev: fix request for simple statistics
Dev: check where function is used to add it in comment
Dev: Some clean up on quick stat logic
  • Loading branch information
Shnoulle committed Nov 22, 2021
1 parent de9be03 commit 7238a60
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 28 deletions.
24 changes: 6 additions & 18 deletions application/controllers/admin/statistics.php
Expand Up @@ -167,13 +167,7 @@ public function run($surveyid = 0, $subaction = null)
* b) "groups" -> group_name + group_order *
*/


$rows = Question::model()
->with(array('group' => array('alias' => 'g')))
->findAll(array('condition' => 'parent_qid = 0 AND g.sid=' . $surveyid, 'order' => 'group_order,question_order'));

//SORT IN NATURAL ORDER!
usort($rows, 'groupOrderThenQuestionOrder');
$rows = Question::model()->primary()->getQuestionList($surveyid);

//put the question information into the filter array
$filters = array();
Expand Down Expand Up @@ -693,19 +687,13 @@ public function simpleStatistics($surveyid)
$summary[4] = "idL";

// 1: Get list of questions from survey
$rows = Question::model()->getQuestionList($surveyid);

//SORT IN NATURAL ORDER!
usort($rows, 'groupOrderThenQuestionOrder');
$rows = Question::model()->primary()->getQuestionList($surveyid);;

// The questions to display (all question)
foreach ($rows as $row) {
$type = $row['type'];
if ($type == Question::QT_T_LONG_FREE_TEXT || $type == Question::QT_N_NUMERICAL) {
$summary[] = $type . $iSurveyId . 'X' . $row['gid'] . 'X' . $row['qid'];
}
switch ($type) {
// Double scale cases
// Double scale cases
case Question::QT_COLON_ARRAY_MULTI_FLEX_NUMBERS:
$qidattributes = QuestionAttribute::model()->getQuestionAttributes($row['qid']);
if (!$qidattributes['input_boxes']) {
Expand Down Expand Up @@ -759,17 +747,17 @@ public function simpleStatistics($surveyid)
case Question::QT_P_MULTIPLE_CHOICE_WITH_COMMENTS: //P - Multiple choice with comments
case Question::QT_M_MULTIPLE_CHOICE: //M - Multiple choice
case Question::QT_S_SHORT_FREE_TEXT:
case Question::QT_T_LONG_FREE_TEXT: // Long free text
case Question::QT_N_NUMERICAL:
$summary[] = $type . $iSurveyId . 'X' . $row['gid'] . 'X' . $row['qid'];
break;

// Not shown (else would only show 'no answer' )
case Question::QT_K_MULTIPLE_NUMERICAL_QUESTION:
case Question::QT_ASTERISK_EQUATION:
case Question::QT_D_DATE:
case Question::QT_T_LONG_FREE_TEXT: // Long free text
case Question::QT_U_HUGE_FREE_TEXT: // Huge free text
case Question::QT_VERTICAL_FILE_UPLOAD: // File Upload, we don't show it
case Question::QT_N_NUMERICAL:
case Question::QT_U_HUGE_FREE_TEXT: // Huge free text
case Question::QT_Q_MULTIPLE_SHORT_TEXT:
case Question::QT_SEMICOLON_ARRAY_MULTI_FLEX_TEXT:
break;
Expand Down
5 changes: 4 additions & 1 deletion application/helpers/common_helper.php
Expand Up @@ -837,7 +837,10 @@ function templateDefaultTexts($sLanguage, $mode = 'html', $sNewlines = 'text')
* Compares two elements from an array (passed by the usort function)
* and returns -1, 0 or 1 depending on the result of the comparison of
* the sort order of the group_order and question_order field
*
* Used by :
* - conditionsaction->getQuestionRows with merging group and question attributes (all in same array)
* - remotecontrol_handle->export_statistics with merging group and question attributes (all in same array)
* - checkQuestions() in activate_helper function with ?
* @param mixed $a
* @param mixed $b
* @return int
Expand Down
3 changes: 0 additions & 3 deletions application/helpers/frontend_helper.php
Expand Up @@ -669,9 +669,6 @@ function buildsurveysession($surveyid, $preview = false)
breakOutAndCrash($sTemplateViewPath, $totalquestions, $iTotalGroupsWithoutQuestions, $thissurvey);
}

//Perform a case insensitive natural sort on group name then question title of a multidimensional array
// usort($arows, 'groupOrderThenQuestionOrder');

//3. SESSION VARIABLE - insertarray
//An array containing information about used to insert the data into the db at the submit stage
//4. SESSION VARIABLE - fieldarray
Expand Down
17 changes: 11 additions & 6 deletions application/models/Question.php
Expand Up @@ -500,16 +500,13 @@ public function getQuestionsForStatistics($fields, $condition, $orderby = false)
*/
public function getQuestionList($surveyid)
{
$db = Yii::app()->db;
$quotedGroup = $db->quoteTableName('group');
$quotedGrouporder = $db->quoteColumnName('group_order');
$quotedQuestionorder = $db->quoteColumnName('question_order');
return Question::model()
->with('group')
->findAll(
array(
'condition' => 't.sid=' . $surveyid,
'order' => $quotedGroup . '.' . $quotedGrouporder . ' DESC, ' . $quotedQuestionorder
'condition' => 't.sid=:sid',
'order' => 'group.group_order,question_order',
'params' => array(':sid' => $surveyid)
)
);
}
Expand Down Expand Up @@ -1025,6 +1022,14 @@ public function search()
return $dataProvider;
}

/** @inheritdoc */
public function scopes()
{
return array(
'primary' => array('condition' => "parent_qid = 0"),
);
}

/**
* Make sure we don't save a new question group
* while the survey is active.
Expand Down

0 comments on commit 7238a60

Please sign in to comment.