Skip to content

Commit

Permalink
Fixed issue: Numerous postgres problems due to improper table alias n…
Browse files Browse the repository at this point in the history
…ame casing

Dev Fixed relation names to be lowercase
  • Loading branch information
c-schmitz committed Mar 23, 2020
1 parent 2af1702 commit a24f6a4
Show file tree
Hide file tree
Showing 44 changed files with 263 additions and 263 deletions.
14 changes: 7 additions & 7 deletions application/controllers/Statistics_userController.php
Expand Up @@ -147,7 +147,7 @@ public function actionAction($surveyid, $language = null)

// ---------- CREATE SGQA OF ALL QUESTIONS WHICH USE "PUBLIC_STATISTICS" ----------
// only show questions where question attribute "public_statistics" is set to "1"
$questions = Question::model()->with(['group' => ['alias' => 'g'], 'questionAttributes' => ['alias' => 'qa']])->findAll([
$questions = Question::model()->with(['group' => ['alias' => 'g'], 'questionattributes' => ['alias' => 'qa']])->findAll([
'condition' => 't.sid = :surveyid AND t.parent_qid = :parent_qid AND qa.attribute = :attribute AND qa.value = :value',
'params' => [':surveyid' => $iSurveyID, ':parent_qid' => 0, ':attribute' => 'public_statistics', ':value' => '1'],
'order' => 'g.group_order, t.question_order'
Expand Down Expand Up @@ -280,7 +280,7 @@ public function createSGQA(array $filters)
switch ($type) {
case Question::QT_K_MULTIPLE_NUMERICAL_QUESTION: // Multiple Numerical
case Question::QT_Q_MULTIPLE_SHORT_TEXT: // Multiple Short Text
$results = Question::model()->with('questionL10ns')->findAll([
$results = Question::model()->with('questionl10ns')->findAll([
'condition' => 'language=:language AND parent_qid=:parent_qid',
'params' => [':language' => $this->sLanguage, ':parent_qid' => $flt->qid],
'order' => 'question_order'
Expand All @@ -295,7 +295,7 @@ public function createSGQA(array $filters)
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)
$results = Question::model()->with('questionL10ns')->findAll([
$results = Question::model()->with('questionl10ns')->findAll([
'condition' => 'language=:language AND parent_qid=:parent_qid',
'params' => [':language' => $this->sLanguage, ':parent_qid' => $flt->qid],
'order' => 'question_order'
Expand All @@ -312,12 +312,12 @@ public function createSGQA(array $filters)
break;
case Question::QT_SEMICOLON_ARRAY_MULTI_FLEX_TEXT: //ARRAY (Multi Flex) (Text)
case Question::QT_COLON_ARRAY_MULTI_FLEX_NUMBERS: //ARRAY (Multi Flex) (Numbers)
$resultsScale0 = Question::model()->with('questionL10ns')->findAll([
$resultsScale0 = Question::model()->with('questionl10ns')->findAll([
'condition' => 'language=:language AND parent_qid=:parent_qid AND scale_id=:scale:id',
'params' => [':language' => $this->sLanguage, ':parent_qid' => $flt->qid, ':scale_id' => 0],
'order' => 'question_order'
]);
$resultsScale1 = Question::model()->with('questionL10ns')->findAll([
$resultsScale1 = Question::model()->with('questionl10ns')->findAll([
'condition' => 'language=:language AND parent_qid=:parent_qid AND scale_id=:scale:id',
'params' => [':language' => $this->sLanguage, ':parent_qid' => $flt->qid, ':scale_id' => 1],
'order' => 'question_order'
Expand All @@ -329,7 +329,7 @@ public function createSGQA(array $filters)
}
break;
case Question::QT_R_RANKING_STYLE: //RANKING
$results = Question::model()->with('questionL10ns')->findAll([
$results = Question::model()->with('questionl10ns')->findAll([
'condition' => 'language=:language AND parent_qid=:parent_qid',
'params' => [':language' => $this->sLanguage, ':parent_qid' => $flt->qid],
'order' => 'question_order'
Expand All @@ -344,7 +344,7 @@ public function createSGQA(array $filters)
case Question::QT_X_BOILERPLATE_QUESTION: //This is a boilerplate question and it has no business in this script
break;
case Question::QT_1_ARRAY_MULTISCALE: // MULTI SCALE
$results = Question::model()->with('questionL10ns')->findAll([
$results = Question::model()->with('questionl10ns')->findAll([
'condition' => 'language=:language AND parent_qid=:parent_qid',
'params' => [':language' => $this->sLanguage, ':parent_qid' => $flt->qid],
'order' => 'question_order'
Expand Down
32 changes: 16 additions & 16 deletions application/controllers/admin/conditionsaction.php
Expand Up @@ -1222,7 +1222,7 @@ protected function getTheseRows(array $questionlist)
'alias' => 'group',
),
'group.questionGroupL10ns' => array('alias' =>'questiongroupl10ns' ),
'questionL10ns'
'questionl10ns'
))->findAllByAttributes(array('qid' => $ql, 'parent_qid' => 0, 'sid' => $this->iSurveyID));

// And store again these questions in this array...
Expand All @@ -1232,7 +1232,7 @@ protected function getTheseRows(array $questionlist)
"qid" => $myrows['qid'],
"sid" => $myrows['sid'],
"gid" => $myrows['gid'],
"question" => $myrows->questionL10ns[$this->language]['question'],
"question" => $myrows->questionl10ns[$this->language]['question'],
"type" => $myrows['type'],
"mandatory" => $myrows['mandatory'],
"other" => $myrows['other'],
Expand All @@ -1258,7 +1258,7 @@ protected function getPostRows(array $postquestionlist)
"qid" => $oQuestion['qid'],
"sid" => $oQuestion['sid'],
"gid" => $oQuestion['gid'],
"question" => $oQuestion->questionL10ns[$this->language]->question,
"question" => $oQuestion->questionl10ns[$this->language]->question,
"type" => $oQuestion['type'],
"mandatory" => $oQuestion['mandatory'],
"other" => $oQuestion['other'],
Expand All @@ -1276,7 +1276,7 @@ protected function getPostRows(array $postquestionlist)
protected function getQuestionTitleAndText($qid)
{
$oQuestion = Question::model()->findByPk($qid);
return array($oQuestion->title, $oQuestion->questionL10ns[$this->language]->question);
return array($oQuestion->title, $oQuestion->questionl10ns[$this->language]->question);
}

/**
Expand Down Expand Up @@ -1369,10 +1369,10 @@ protected function getCAnswersAndCQuestions(array $theserows)

if ($rows['type'] == "A" || $rows['type'] == "B" || $rows['type'] == "C" || $rows['type'] == "E" || $rows['type'] == "F" || $rows['type'] == "H") {

$aresult = Question::model()->with('questionL10ns')->findAllByAttributes(array('parent_qid'=>$rows['qid']), array('order' => 'question_order ASC'));
$aresult = Question::model()->with('questionl10ns')->findAllByAttributes(array('parent_qid'=>$rows['qid']), array('order' => 'question_order ASC'));

foreach ($aresult as $arows) {
$shortanswer = "{$arows['title']}: [".flattenText($arows->questionL10ns[$this->language]->question)."]";
$shortanswer = "{$arows['title']}: [".flattenText($arows->questionl10ns[$this->language]->question)."]";
$shortquestion = $rows['title'].":$shortanswer ".flattenText($rows['question']);
$cquestions[] = array($shortquestion, $rows['qid'], $rows['type'],
$rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['title']
Expand Down Expand Up @@ -1472,8 +1472,8 @@ protected function getCAnswersAndCQuestions(array $theserows)
} elseif ($rows['type'] == "1") {
//Multi Scale
$aresult = Question::model()->with(array(
'questionL10ns' => array(
'condition' => 'questionL10ns.language = :lang',
'questionl10ns' => array(
'condition' => 'questionl10ns.language = :lang',
'params' => array(':lang' => $this->language)
)))->findAllByAttributes(array('parent_qid' => $rows['qid']), array('order' => 'question_order desc'));
foreach ($aresult as $arows) {
Expand All @@ -1482,12 +1482,12 @@ protected function getCAnswersAndCQuestions(array $theserows)
// dualscale_header are allways set, but can be empty
$label1 = empty($attr['dualscale_headerA'][$sLanguage]) ? gT('Scale 1') : $attr['dualscale_headerA'][$sLanguage];
$label2 = empty($attr['dualscale_headerB'][$sLanguage]) ? gT('Scale 2') : $attr['dualscale_headerB'][$sLanguage];
$shortanswer = "{$arows['title']}: [".strip_tags($arows->questionL10ns[$this->language]->question)."][$label1]";
$shortquestion = $rows['title'].":$shortanswer ".strip_tags($arows->questionL10ns[$this->language]->question);
$shortanswer = "{$arows['title']}: [".strip_tags($arows->questionl10ns[$this->language]->question)."][$label1]";
$shortquestion = $rows['title'].":$shortanswer ".strip_tags($arows->questionl10ns[$this->language]->question);
$cquestions[] = array($shortquestion, $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['title']."#0");

$shortanswer = "{$arows['title']}: [".strip_tags($arows->questionL10ns[$this->language]->question)."][$label2]";
$shortquestion = $rows['title'].":$shortanswer ".strip_tags($arows->questionL10ns[$this->language]->question);
$shortanswer = "{$arows['title']}: [".strip_tags($arows->questionl10ns[$this->language]->question)."][$label2]";
$shortquestion = $rows['title'].":$shortanswer ".strip_tags($arows->questionl10ns[$this->language]->question);
$cquestions[] = array($shortquestion, $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['title']."#1");

// first label
Expand Down Expand Up @@ -1522,12 +1522,12 @@ protected function getCAnswersAndCQuestions(array $theserows)
} //foreach
} elseif ($rows['type'] == Question::QT_K_MULTIPLE_NUMERICAL_QUESTION || $rows['type'] == Question::QT_Q_MULTIPLE_SHORT_TEXT) {
//Multi shorttext/numerical
$aresult = Question::model()->with('questionL10ns')->findAllByAttributes(array(
$aresult = Question::model()->with('questionl10ns')->findAllByAttributes(array(
"parent_qid" => $rows['qid']
), array('order' => 'question_order desc'));

foreach ($aresult as $arows) {
$shortanswer = "{$arows['title']}: [".strip_tags($arows->questionL10ns[$this->language]->question)."]";
$shortanswer = "{$arows['title']}: [".strip_tags($arows->questionl10ns[$this->language]->question)."]";
$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']);

Expand Down Expand Up @@ -1576,12 +1576,12 @@ protected function getCAnswersAndCQuestions(array $theserows)
$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()->with('questionL10ns')->findAllByAttributes(array(
$aresult = Question::model()->with('questionl10ns')->findAllByAttributes(array(
"parent_qid" => $rows['qid'],
), array('order' => 'question_order desc'));

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

$shortanswer = "{$arows['title']}: [".strip_tags($theanswer)."]";
Expand Down
12 changes: 6 additions & 6 deletions application/controllers/admin/database.php
Expand Up @@ -239,7 +239,7 @@ private function actionUpdateDefaultValues($iSurveyID)
}
if ($aQuestionTypeList[$sQuestionType]['subquestions'] > 0) {
foreach ($aSurveyLanguages as $sLanguage) {
$arQuestions = Question::model()->with('questionL10ns', array('condition' => 'language = ' . $sLanguage))->findAllByAttributes(array('sid'=>$iSurveyID, 'gid'=>$this->iQuestionGroupID, 'parent_qid'=>$this->iQuestionID, 'scale_id'=>0));
$arQuestions = Question::model()->with('questionl10ns', array('condition' => 'language = ' . $sLanguage))->findAllByAttributes(array('sid'=>$iSurveyID, 'gid'=>$this->iQuestionGroupID, 'parent_qid'=>$this->iQuestionID, 'scale_id'=>0));

for ($iScaleID = 0; $iScaleID < $aQuestionTypeList[$sQuestionType]['subquestions']; $iScaleID++) {
foreach ($arQuestions as $aSubquestionrow) {
Expand Down Expand Up @@ -1357,7 +1357,7 @@ private function actionInsertCopyQuestion($iSurveyID)

// subquestions
$aOldNewSubquestions = array(); // track old and new sqid's
$oOldSubQuestions = Question::model()->with('questionL10ns')->findAllByAttributes(array("parent_qid"=>$oldQID), array('order'=>'question_order'));
$oOldSubQuestions = Question::model()->with('questionl10ns')->findAllByAttributes(array("parent_qid"=>$oldQID), array('order'=>'question_order'));
foreach ($oOldSubQuestions as $sSubquestionIndex => $subquestion) {
$aInsertData = $subquestion->attributes;
unset($aInsertData['qid']);
Expand All @@ -1366,12 +1366,12 @@ private function actionInsertCopyQuestion($iSurveyID)
$iNewSubquestionId = Yii::app()->db->getLastInsertID();
$aOldNewSubquestions[$subquestion->qid] = $iNewSubquestionId;

if (isset($subquestion->questionL10ns)){
foreach($subquestion->questionL10ns as $language => $questionL10ns){
if (isset($subquestion->questionl10ns)){
foreach($subquestion->questionl10ns as $language => $questionl10ns){
$oQuestionLS = new QuestionL10n;
$oQuestionLS->language = $language;
$oQuestionLS->question = $questionL10ns->question;
$oQuestionLS->help = $questionL10ns->help;
$oQuestionLS->question = $questionl10ns->question;
$oQuestionLS->help = $questionl10ns->help;
$oQuestionLS->qid = $iNewSubquestionId;
$oQuestionLS->save();
}
Expand Down
8 changes: 4 additions & 4 deletions application/controllers/admin/dataentry.php
Expand Up @@ -1845,8 +1845,8 @@ public function view($surveyid)
$cdata['deqrow'] = $arQuestion;

$cdata['thissurvey'] = $thissurvey;
if (!empty($arQuestion->questionL10ns[$sDataEntryLanguage]->help)) {
$hh = addcslashes($arQuestion->questionL10ns[$sDataEntryLanguage]->help, "\0..\37'\""); //Escape ASCII decimal 0-32 plus single and double quotes to make JavaScript happy.
if (!empty($arQuestion->questionl10ns[$sDataEntryLanguage]->help)) {
$hh = addcslashes($arQuestion->questionl10ns[$sDataEntryLanguage]->help, "\0..\37'\""); //Escape ASCII decimal 0-32 plus single and double quotes to make JavaScript happy.
$hh = htmlspecialchars($hh, ENT_QUOTES); //Change & " ' < > to HTML entities to make HTML happy.
$cdata['hh'] = $hh;
}
Expand Down Expand Up @@ -2073,7 +2073,7 @@ private function _array_filter_help($qidattributes, $surveyprintlang, $surveyid)
$question = Question::model()->findByAttributes(array('title' => $qidattributes['array_filter'], 'sid' => $surveyid));
if ($question) {
$output .= "\n<p class='extrahelp'>
".sprintf(gT("Only answer this question for the items you selected in question %s ('%s')"), $qidattributes['array_filter'], flattenText(breakToNewline($question->questionL10ns[$surveyprintlang]->question)))."
".sprintf(gT("Only answer this question for the items you selected in question %s ('%s')"), $qidattributes['array_filter'], flattenText(breakToNewline($question->questionl10ns[$surveyprintlang]->question)))."
</p>\n";
}
}
Expand All @@ -2082,7 +2082,7 @@ private function _array_filter_help($qidattributes, $surveyprintlang, $surveyid)
$question = Question::model()->findByAttributes(array('title' => $qidattributes['array_filter_exclude'], 'sid' => $surveyid));
if ($question) {
$output .= "\n <p class='extrahelp'>
".sprintf(gT("Only answer this question for the items you did not select in question %s ('%s')"), $qidattributes['array_filter_exclude'], breakToNewline($question->questionL10ns[$surveyprintlang]->question))."
".sprintf(gT("Only answer this question for the items you did not select in question %s ('%s')"), $qidattributes['array_filter_exclude'], breakToNewline($question->questionl10ns[$surveyprintlang]->question))."
</p>\n";
}
}
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/admin/index.php
Expand Up @@ -68,8 +68,8 @@ public function run()
$qrrow = Question::model()->findByAttributes(array('qid' => $qid, 'gid' => $gid, 'sid' => $sid));
if ($qrrow) {
$aData['last_question_name'] = $qrrow['title'];
if (!empty($qrrow->questionL10ns[$baselang]['question'])) {
$aData['last_question_name'] .= ' : '.$qrrow->questionL10ns[$baselang]['question'];
if (!empty($qrrow->questionl10ns[$baselang]['question'])) {
$aData['last_question_name'] .= ' : '.$qrrow->questionl10ns[$baselang]['question'];
}
$aData['last_question_link'] = $this->getController()->createUrl("admin/questions/sa/view/surveyid/$sid/gid/$gid/qid/$qid");
} else {
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/admin/limereplacementfields.php
Expand Up @@ -483,13 +483,13 @@ function ($a,$b) {
foreach ($aSubquestions as $oSubQuestion) {
$aResult[$oQuestion->title.'_'.$oSubQuestion->title] = [
'type' => 'question',
'value' => ' -('.$oQuestion->title.')| '.$oSubQuestion->questionL10ns[$oSurvey->language]->question
'value' => ' -('.$oQuestion->title.')| '.$oSubQuestion->questionl10ns[$oSurvey->language]->question
];
}
} else {
$aResult[$oQuestion->title] = [
'type' => 'question',
'value' => $oQuestion->questionL10ns[$oSurvey->language]->question,
'value' => $oQuestion->questionl10ns[$oSurvey->language]->question,
];
}
}
Expand Down

1 comment on commit a24f6a4

@olleharstedt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎈

Please sign in to comment.