Skip to content

Commit

Permalink
Dev: Introduced constants for question types
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Jan 11, 2018
1 parent b0b1f17 commit 9d68417
Show file tree
Hide file tree
Showing 34 changed files with 1,398 additions and 1,324 deletions.
40 changes: 20 additions & 20 deletions application/controllers/Statistics_userController.php
Expand Up @@ -317,8 +317,8 @@ public function createSGQA(array $filters)

//let's switch through the question type for each question
switch ($flt[2]) {
case "K": // Multiple Numerical
case "Q": // Multiple Short Text
case Question::QT_K_MULTIPLE_NUMERICAL_QUESTION: // Multiple Numerical
case Question::QT_Q_MULTIPLE_SHORT_TEXT: // Multiple Short Text
//get answers
$query = "SELECT title as code, question as answer FROM {{questions}} WHERE parent_qid=:flt_0 AND language = :lang ORDER BY question_order";
$result = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":lang", $this->sLanguage, PDO::PARAM_STR)->queryAll();
Expand All @@ -329,12 +329,12 @@ public function createSGQA(array $filters)
$allfields[] = $myfield2;
}
break;
case "A": // ARRAY OF 5 POINT CHOICE QUESTIONS
case "B": // ARRAY OF 10 POINT CHOICE QUESTIONS
case "C": // ARRAY OF YES\No\gT("Uncertain") QUESTIONS
case "E": // ARRAY OF Increase/Same/Decrease QUESTIONS
case "F": // FlEXIBLE ARRAY
case "H": // ARRAY (By Column)
case Question::QT_A_ARRAY_5_CHOICE_QUESTIONS: // ARRAY OF 5 POINT CHOICE QUESTIONS
case Question::QT_B_ARRAY_10_CHOICE_QUESTIONS: // ARRAY OF 10 POINT CHOICE QUESTIONS
case Question::QT_C_ARRAY_YES_UNCERTAIN_NO: // ARRAY OF YES\No\gT("Uncertain") QUESTIONS
case Question::QT_E_ARRAY_OF_INC_SAME_DEC_QUESTIONS: // ARRAY OF Increase/Same/Decrease QUESTIONS
case Question::QT_F_ARRAY_FLEXIBLE_ROW: // FlEXIBLE ARRAY
case Question::QT_H_ARRAY_FLEXIBLE_COLUMN: // ARRAY (By Column)
//get answers
$query = "SELECT title as code, question as answer FROM {{questions}} WHERE parent_qid=:flt_0 AND language = :lang ORDER BY question_order";
$result = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":lang", $this->sLanguage, PDO::PARAM_STR)->queryAll();
Expand All @@ -346,14 +346,14 @@ public function createSGQA(array $filters)
}
break;
// all "free text" types (T, U, S) get the same prefix ("T")
case "T": // Long free text
case "U": // Huge free text
case "S": // Short free text
case Question::QT_T_LONG_FREE_TEXT: // Long free text
case Question::QT_U_HUGE_FREE_TEXT: // Huge free text
case Question::QT_S_SHORT_FREE_TEXT: // Short free text
$myfield = "T".$myfield;
$allfields[] = $myfield;
break;
case ";": //ARRAY (Multi Flex) (Text)
case ":": //ARRAY (Multi Flex) (Numbers)
case Question::QT_SEMICOLON_ARRAY_MULTI_FLEX_TEXT: //ARRAY (Multi Flex) (Text)
case Question::QT_COLON_ARRAY_MULTI_FLEX_NUMBERS: //ARRAY (Multi Flex) (Numbers)
$query = "SELECT title, question FROM {{questions}} WHERE parent_qid=:flt_0 AND language=:lang AND scale_id = 0 ORDER BY question_order";
$result = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":lang", $this->sLanguage, PDO::PARAM_STR)->queryAll();
foreach ($result as $row) {
Expand All @@ -365,7 +365,7 @@ public function createSGQA(array $filters)
}
}
break;
case "R": //RANKING
case Question::QT_R_RANKING_STYLE: //RANKING
//get some answers
$query = "SELECT code, answer FROM {{answers}} WHERE qid = :flt_0 AND language = :lang ORDER BY sortorder, answer";
$result = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":lang", $this->sLanguage, PDO::PARAM_STR)->queryAll();
Expand All @@ -380,9 +380,9 @@ public function createSGQA(array $filters)
}
break;
//Boilerplate questions are only used to put some text between other questions -> no analysis needed
case "X": //This is a boilerplate question and it has no business in this script
case Question::QT_X_BOILERPLATE_QUESTION: //This is a boilerplate question and it has no business in this script
break;
case "1": // MULTI SCALE
case Question::QT_1_ARRAY_MULTISCALE: // MULTI SCALE
//get answers
$query = "SELECT title, question FROM {{questions}} WHERE parent_qid = :flt_0 AND language = :lang ORDER BY question_order";
$result = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":lang", $this->sLanguage, PDO::PARAM_STR)->queryAll();
Expand All @@ -398,10 +398,10 @@ public function createSGQA(array $filters)
} //end WHILE -> loop through all answers
break;

case "P": //P - Multiple choice with comments
case "M": //M - Multiple choice
case "N": //N - Numerical input
case "D": //D - Date
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_N_NUMERICAL: //N - Numerical input
case Question::QT_D_DATE: //D - Date
$myfield2 = $flt[2].$myfield;
$allfields[] = $myfield2;
break;
Expand Down
61 changes: 32 additions & 29 deletions application/controllers/admin/conditionsaction.php
Expand Up @@ -1375,7 +1375,7 @@ protected function getCAnswersAndCQuestions(array $theserows)

} //foreach

} elseif ($rows['type'] == ":" || $rows['type'] == ";") {
} elseif ($rows['type'] == Question::QT_COLON_ARRAY_MULTI_FLEX_NUMBERS || $rows['type'] == Question::QT_SEMICOLON_ARRAY_MULTI_FLEX_TEXT) {
// Multiflexi
// Get the Y-Axis
$fquery = "SELECT sq.*, q.other"
Expand Down Expand Up @@ -1420,7 +1420,6 @@ protected function getCAnswersAndCQuestions(array $theserows)
$shortquestion = $rows['title'].":{$yrow['title']}:$key: [".strip_tags($yrow['question'])."][".strip_tags($val)."] ".flattenText($rows['question']);
$cquestions[] = array($shortquestion, $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$yrow['title']."_".$key);
if ($rows['mandatory'] != 'Y') {
$canswers[] = array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$yrow['title']."_".$key, "", gT("No answer"));
}
}
}
Expand Down Expand Up @@ -1465,7 +1464,7 @@ protected function getCAnswersAndCQuestions(array $theserows)
$canswers[] = array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['title']."#1", "", gT("No answer"));
}
} //foreach
} elseif ($rows['type'] == "K" || $rows['type'] == "Q") {
} elseif ($rows['type'] == Question::QT_K_MULTIPLE_NUMERICAL_QUESTION ||$rows['type'] == Question::QT_Q_MULTIPLE_SHORT_TEXT) {
//Multi shorttext/numerical
$aresult = Question::model()->findAllByAttributes(array(
"parent_qid" => $rows['qid'],
Expand All @@ -1483,7 +1482,7 @@ protected function getCAnswersAndCQuestions(array $theserows)
}

} //foreach
} elseif ($rows['type'] == "R") {
} elseif ($rows['type'] == Question::QT_R_RANKING_STYLE) {
//Answer Ranking
$aresult = Answer::model()->findAllByAttributes(
array(
Expand Down Expand Up @@ -1511,61 +1510,61 @@ protected function getCAnswersAndCQuestions(array $theserows)
$canswers[] = array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$i, " ", gT("No answer"));
}
}
unset($quicky);
unset($quicky);
// End if type R
} elseif ($rows['type'] == "M" || $rows['type'] == "P") {

$shortanswer = " [".gT("Group of checkboxes")."]";
$shortquestion = $rows['title'].":$shortanswer ".strip_tags($rows['question']);
$cquestions[] = array($shortquestion, $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid']);

$aresult = Question::model()->findAllByAttributes(array(
"parent_qid" => $rows['qid'],
"language" => $this->language
), array('order' => 'question_order desc'));
} ($rows['type'] == Question::QT_M_MULTIPLE_CHOICE || $rows['type'] == Question::QT_P_MULTIPLE_CHOICE_WITH_COMMENTS) {

$shortanswer = " [".gT("Group of checkboxes")."]";
$shortquestion = $rows['title'].":$shortanswer ".strip_tags($rows['question']);
$cquestions[] = array($shortquestion, $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid']);

$aresult = Question::model()->findAllByAttributes(array(
"parent_qid" => $rows['qid'],
"language" => $this->language
), array('order' => 'question_order desc'));

foreach ($aresult as $arows) {
$theanswer = $arows['question'];
$theanswer = $arows['question'];
$canswers[] = array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], $arows['title'], $theanswer);

$shortanswer = "{$arows['title']}: [".strip_tags($arows['question'])."]";
$shortanswer .= "[".gT("Single checkbox")."]";
$shortanswer .= "[".gT("Single checkbox")."]";
$shortquestion = $rows['title'].":$shortanswer ".strip_tags($rows['question']);
$cquestions[] = array($shortquestion, $rows['qid'], $rows['type'], "+".$rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['title']);
$canswers[] = array("+".$rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['title'], 'Y', gT("checked"));
$canswers[] = array("+".$rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['title'], '', gT("not checked"));
}
}

} else {
$cquestions[] = array($shortquestion, $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid']);

switch ($rows['type']) {
case "Y": // Y/N/NA
case Question::QT_Y_YES_NO_RADIO: // Y/N/NA
$canswers[] = array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], "Y", gT("Yes"));
$canswers[] = array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], "N", gT("No"));
// Only Show No-Answer if question is not mandatory
if ($rows['mandatory'] != 'Y') {
$canswers[] = array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], " ", gT("No answer"));
}
break;
case "G": //Gender
case Question::QT_G_GENDER_DROPDOWN: //Gender
$canswers[] = array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], "F", gT("Female"));
$canswers[] = array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], "M", gT("Male"));
// Only Show No-Answer if question is not mandatory
if ($rows['mandatory'] != 'Y') {
$canswers[] = array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], " ", gT("No answer"));
}
break;
case "5": // 5 choice
case Question::QT_5_POINT_CHOICE: // 5 choice
for ($i = 1; $i <= 5; $i++) {
$canswers[] = array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], $i, $i);
}
// Only Show No-Answer if question is not mandatory
if ($rows['mandatory'] != 'Y') {
$canswers[] = array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], " ", gT("No answer"));
}
break;
case "N": // Simple Numerical questions
break;
case Question::QT_N_NUMERICAL: // Simple Numerical questions
// Only Show No-Answer if question is not mandatory
if ($rows['mandatory'] != 'Y') {
$canswers[] = array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], " ", gT("No answer"));
Expand All @@ -1583,17 +1582,21 @@ protected function getCAnswersAndCQuestions(array $theserows)
$theanswer = $arows['answer'];
$canswers[] = array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], $arows['code'], $theanswer);
}

if ($rows['type'] == "D") {
if ($rows['type'] == Question::QT_D_DATE) {
// Only Show No-Answer if question is not mandatory
if ($rows['mandatory'] != 'Y') {
$canswers[] = array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], " ", gT("No answer"));
}
} elseif ($rows['type'] != "M" && $rows['type'] != "P" && $rows['type'] != "J" && $rows['type'] != "I") {
} elseif ($rows['type'] != Question::QT_M_MULTIPLE_CHOICE &&
$rows['type'] != Question::QT_P_MULTIPLE_CHOICE_WITH_COMMENTS &&
$rows['type'] != QT_J &&
$rows['type'] != Question::QT_I_LANGUAGE ) {
// For dropdown questions
// optinnaly add the 'Other' answer
if (($rows['type'] == "L" || $rows['type'] == "!")
&& $rows['other'] == "Y") {
if ( ($rows['type'] == Question::QT_L_LIST_DROPDOWN ||
$rows['type'] == Question::QT_EXCLAMATION_LIST_DROPDOWN) &&
$rows['other'] == "Y" )
{
$canswers[] = array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], "-oth-", gT("Other"));
}

Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/database.php
Expand Up @@ -251,7 +251,7 @@ private function actionUpdateAnswerOptions($iSurveyID)
$iScaleCount = $aQuestionTypeList[$sQuestionType]['answerscales'];
/* for already activated survey and rank question type : fix the maxDbAnswer before deleting answers */
/* @todo : add it to upgrage DB system, and see for the lsa */
if ($sQuestionType == "R" && $survey->isActive) {
if ($sQuestionType == Question::QT_R_RANKING_STYLE && $survey->isActive) {
QuestionAttribute::model()->find(
"qid = :qid AND attribute = 'max_subquestions'",
array(':qid' => $this->iQuestionID)
Expand Down

0 comments on commit 9d68417

Please sign in to comment.