Skip to content

Commit

Permalink
Dev Moved language-dependent settings in group/question/answers to su…
Browse files Browse the repository at this point in the history
…btables
  • Loading branch information
c-schmitz committed Jan 9, 2018
1 parent 129f5fa commit 6b077d7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 94 deletions.
1 change: 0 additions & 1 deletion application/controllers/admin/statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,6 @@ public function run($surveyid = 0, $subaction = null)
}

$this->_renderWrappedTemplate('export', 'statistics_view', $aData);

}


Expand Down
122 changes: 47 additions & 75 deletions application/helpers/admin/statistics_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,20 +602,21 @@ protected function buildOutputList($rt, $language, $surveyid, $outputType, $sql,
list($qsid, $qgid, $qqid) = explode("X", substr($rt, 1, strlen($rt)), 3);

//select details for this question
$nresult = Question::model()->find('language=:language AND parent_qid=0 AND qid=:qid', array(':language'=>$language, ':qid'=>$qqid));
$qtitle = $nresult->title;
$qtype = $nresult->type;
$qquestion = flattenText($nresult->question);
$qother = $nresult->other;
$nresult = Question::model()->find('parent_qid=0 AND qid=:qid', array(':qid'=>$qqid));
$qother = 'N';
if (!empty($nresult)) {
$qother = $nresult->other;
}


//1. Get list of answers
$result = Question::model()->findAll(array('order'=>'question_order',
'condition'=>'language=:language AND parent_qid=:qid AND scale_id=0',
'params'=>array(':language'=>$language, ':qid'=>$qqid)
'condition'=>'parent_qid=:qid AND scale_id=0',
'params'=>array(':qid'=>$qqid)
));
foreach ($result as $row) {
$mfield = substr($rt, 1, strlen($rt)).$row['title'];
$alist[] = array($row['title'], flattenText($row['question']), $mfield);
$alist[] = array($row['title'], flattenText($row->questionL10ns[$language]->question), $mfield);
}

//Add the "other" answer if it exists
Expand All @@ -633,10 +634,10 @@ protected function buildOutputList($rt, $language, $surveyid, $outputType, $sql,
$fielddata = $fieldmap[$fld];

//get question data
$nresult = Question::model()->find('language=:language AND parent_qid=0 AND qid=:qid', array(':language'=>$language, ':qid'=>$fielddata['qid']));
$nresult = Question::model()->find('parent_qid=0 AND qid=:qid', array(':qid'=>$fielddata['qid']));
$qtitle = $nresult->title;
$qtype = $nresult->type;
$qquestion = flattenText($nresult->question);
$qquestion = flattenText($nresult->questionL10ns[$language]->question);

$mfield = substr($rt, 1, strlen($rt));

Expand Down Expand Up @@ -1152,38 +1153,30 @@ protected function buildOutputList($rt, $language, $surveyid, $outputType, $sql,
$rqid = $qqid;

//get question data
$nquery = "SELECT title, type, question, qid, parent_qid, other FROM {{questions}} WHERE qid='{$rqid}' AND parent_qid=0 and language='{$language}'";
$nresult = Yii::app()->db->createCommand($nquery)->query();

//loop though question data
foreach ($nresult->readAll() as $nrow) {
$nrow = array_values($nrow);
$qtitle = flattenText($nrow[0]);
$qtype = $nrow[1];
$qquestion = flattenText($nrow[2]);
$qiqid = $nrow[3];
$qother = $nrow[5];
}
$nrow=Question::model()->findByPk($rqid);
$qtitle = flattenText($nrow['title']);
$qtype = $nrow['type'];
$qquestion = flattenText($nrow->questionL10ns[$language]->question);
$qiqid = $nrow['qid'];
$qother = $nrow['other'];

//check question types
switch ($qtype) {
//Array of 5 point choices (several items to rank!)
case "A":

//get data
$qquery = "SELECT title, question FROM {{questions}} WHERE parent_qid='$qiqid' AND title='$qanswer' AND language='{$language}' ORDER BY question_order";
$qresult = Yii::app()->db->createCommand($qquery)->query();

$qresult = Question::model()->findAll(array('condition'=>'parent_qid=:parent_qid AND title=:title', 'params'=>array(":parent_qid"=>$qiqid,':title'=>$qanswer)));
//loop through results
foreach ($qresult->readAll() as $qrow) {
foreach ($qresult as $qrow) {
$qrow = array_values($qrow);
//5-point array
for ($i = 1; $i <= 5; $i++) {
//add data
$alist[] = array("$i", "$i");
}
//add counter
$atext = flattenText($qrow[1]);
$atext = flattenText($qrow->questionL10ns[$language]->question);
}

//list IDs and answer codes in brackets
Expand All @@ -1196,73 +1189,62 @@ protected function buildOutputList($rt, $language, $surveyid, $outputType, $sql,
//Array of 10 point choices
//same as above just with 10 items
case "B":
$qquery = "SELECT title, question FROM {{questions}} WHERE parent_qid='$qiqid' AND title='$qanswer' AND language='{$language}' ORDER BY question_order";
$qresult = Yii::app()->db->createCommand($qquery)->query();
foreach ($qresult->readAll() as $qrow) {
$qrow = array_values($qrow);
$qresult = Question::model()->findAll(array('condition'=>'parent_qid=:parent_qid AND title=:title', 'params'=>array(":parent_qid"=>$qiqid,':title'=>$qanswer)));
foreach ($qresult as $qrow) {
for ($i = 1; $i <= 10; $i++) {
$alist[] = array("$i", "$i");
}
$atext = flattenText($qrow[1]);
$atext = flattenText($qrow->questionL10ns[$language]->question);
}

$qquestion .= $linefeed."[".$atext."]";
$qtitle .= "($qanswer)";
$qtitle .= "({$qanswer})";
break;



//Array of Yes/No/gT("Uncertain")
case "C":
$qquery = "SELECT title, question FROM {{questions}} WHERE parent_qid='$qiqid' AND title='$qanswer' AND language='{$language}' ORDER BY question_order";
$qresult = Yii::app()->db->createCommand($qquery)->query();

$qresult = Question::model()->findAll(array('condition'=>'parent_qid=:parent_qid AND title=:title', 'params'=>array(":parent_qid"=>$qiqid,':title'=>$qanswer)));
//loop thorugh results
foreach ($qresult->readAll() as $qrow) {
$qrow = array_values($qrow);
foreach ($qresult as $qrow) {
//add results
$alist[] = array("Y", gT("Yes"));
$alist[] = array("N", gT("No"));
$alist[] = array("U", gT("Uncertain"));
$atext = flattenText($qrow[1]);
$atext = flattenText($qrow->questionL10ns[$language]->question);
}
//output
$qquestion .= $linefeed."[".$atext."]";
$qtitle .= "($qanswer)";
$qtitle .= "({$qanswer})";
break;



//Array of Yes/No/gT("Uncertain")
//same as above
case "E":
$qquery = "SELECT title, question FROM {{questions}} WHERE parent_qid='$qiqid' AND title='$qanswer' AND language='{$language}' ORDER BY question_order";
$qresult = Yii::app()->db->createCommand($qquery)->query();
foreach ($qresult->readAll() as $qrow) {
$qrow = array_values($qrow);
$qresult = Question::model()->findAll(array('condition'=>'parent_qid=:parent_qid AND title=:title', 'params'=>array(":parent_qid"=>$qiqid,':title'=>$qanswer)));
foreach ($qresult as $qrow) {
$alist[] = array("I", gT("Increase"));
$alist[] = array("S", gT("Same"));
$alist[] = array("D", gT("Decrease"));
$atext = flattenText($qrow[1]);
$atext = flattenText($qrow->questionL10ns[$language]->question);
}
$qquestion .= $linefeed."[".$atext."]";
$qtitle .= "($qanswer)";
$qtitle .= "({$qanswer})";
break;


case ";": //Array (Multi Flexi) (Text)
list($qacode, $licode) = explode("_", $qanswer);

$qquery = "SELECT title, question FROM {{questions}} WHERE parent_qid='$qiqid' AND title='$qacode' AND language='{$language}' ORDER BY question_order";
$qresult = Yii::app()->db->createCommand($qquery)->query();

foreach ($qresult->readAll() as $qrow) {
$qrow = array_values($qrow);
$fquery = "SELECT * FROM {{answers}} WHERE qid='{$qiqid}' AND scale_id=0 AND code = '{$licode}' AND language='{$language}'ORDER BY sortorder, code";
$fresult = Yii::app()->db->createCommand($fquery)->query();
foreach ($fresult->readAll() as $frow) {
$alist[] = array($frow['code'], $frow['answer']);
$ltext = $frow['answer'];
$qresult = Question::model()->findAll(array('condition'=>'parent_qid=:parent_qid AND title=:title', 'params'=>array(":parent_qid"=>$qiqid,':title'=>$qanswer)));
foreach ($qresult as $qrow) {
$fresult = Answer::model()->findAll(array('condition'=>'qid=:qid AND code=:code ND scale_id=0', 'params'=>array(":qid"=>$qiqid,':code'=>$licode)));
foreach ($fresult as $frow) {
$alist[] = array($frow['code'], $frow->answerL10ns[$language]->answer);
$ltext = $frow->answerL10ns[$language]->answer;
}
$atext = flattenText($qrow[1]);
}
Expand Down Expand Up @@ -1308,24 +1290,18 @@ protected function buildOutputList($rt, $language, $surveyid, $outputType, $sql,

case "F": //Array of Flexible
case "H": //Array of Flexible by Column
$qquery = "SELECT title, question FROM {{questions}} WHERE parent_qid='$qiqid' AND title='$qanswer' AND language='{$language}' ORDER BY question_order";
$qresult = Yii::app()->db->createCommand($qquery)->query();

$qresult = Question::model()->findAll(array('order'=>'question_order', 'condition'=>'parent_qid=:parent_qid AND title=:title', 'params'=>array(":parent_qid"=>$qiqid,':title'=>$qanswer)));
//loop through answers
foreach ($qresult->readAll() as $qrow) {
$qrow = array_values($qrow);

foreach ($qresult as $qrow) {
$fresult = Answer::model()->findAllByAttributes(['qid'=>$qiqid,'scale_id'=>0]);
//this question type uses its own labels
$fquery = "SELECT * FROM {{answers}} WHERE qid='{$qiqid}' AND scale_id=0 AND language='{$language}'ORDER BY sortorder, code";
$fresult = Yii::app()->db->createCommand($fquery)->query();

//add code and title to results for outputting them later
foreach ($fresult->readAll() as $frow) {
$alist[] = array($frow['code'], flattenText($frow['answer']));
foreach ($fresult as $frow) {
$alist[] = array($frow['code'], flattenText($frow->answerL10ns[$language]->answer));
}

//counter
$atext = flattenText($qrow[1]);
$atext = flattenText($qrow->questionL10ns[$language]->question);
}

//output
Expand Down Expand Up @@ -1433,13 +1409,10 @@ protected function buildOutputList($rt, $language, $surveyid, $outputType, $sql,
default: //default handling

//get answer code and title
$qquery = "SELECT code, answer FROM {{answers}} WHERE qid='$qqid' AND scale_id=0 AND language='{$language}' ORDER BY sortorder, answer";
$qresult = Yii::app()->db->createCommand($qquery)->query();

$qresult = Answer::model()->findAllByAttributes(['qid'=>$qqid,'scale_id'=>0]);
//put answer code and title into array
foreach ($qresult->readAll() as $qrow) {
$qrow = array_values($qrow);
$alist[] = array("$qrow[0]", flattenText($qrow[1]));
foreach ($qresult as $qrow) {
$alist[] = array($qrow->code, flattenText($qrow->answerL10ns[$language]->answer));
}

//handling for "other" field for list radio or list drowpdown
Expand All @@ -1450,7 +1423,6 @@ protected function buildOutputList($rt, $language, $surveyid, $outputType, $sql,
if ($qtype == "O") {
//add "comment"
$alist[] = array(gT("Comments"), gT("Comments"), $fielddata['fieldname'].'comment', 'is_comment');
//
}

} //end switch question type
Expand Down
16 changes: 3 additions & 13 deletions application/models/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,19 +373,9 @@ public function getQuestionsForStatistics($fields, $condition, $orderby = false)
* @param string $language
* @return array
*/
public function getQuestionList($surveyid, $language)
{
$query = "SELECT questions.*, groups.group_name, groups.group_order"
." FROM {{questions}} as questions, {{groups}} as groups"
." WHERE groups.gid=questions.gid"
." AND groups.language=:language1"
." AND questions.language=:language2"
." AND questions.parent_qid=0"
." AND questions.sid=:sid";
return Yii::app()->db->createCommand($query)
->bindParam(":language1", $language, PDO::PARAM_STR)
->bindParam(":language2", $language, PDO::PARAM_STR)
->bindParam(":sid", $surveyid, PDO::PARAM_INT)->queryAll();
public function getQuestionList($surveyid)
{
return Question::model()->with('group')->findAll(array('condition'=>'t.sid='.$surveyid,'order'=>'group_order DESC, question_order'));
}

/**
Expand Down
5 changes: 0 additions & 5 deletions application/views/admin/export/statistics_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,6 @@
<div class="row">
<div class="col-lg-12 content-right">

<?php
// TODO : show the css loader
flush(); //Let's give the user something to look at while they wait for the pretty pictures
?>

<!-- Statistics header -->
<?php $this->renderPartial('/admin/export/statistics_subviews/_statistics_header', array()) ; ?>

Expand Down

0 comments on commit 6b077d7

Please sign in to comment.