Skip to content

Commit

Permalink
Dev: Move query to model (getTotalQuestions)
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Aug 30, 2016
1 parent bf0a34d commit 6417eab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
9 changes: 1 addition & 8 deletions application/helpers/frontend_helper.php
Expand Up @@ -1017,16 +1017,9 @@ function buildsurveysession($surveyid,$preview=false)
// Always SetSurveyLanguage : surveys controller SetSurveyLanguage too, if different : broke survey (#09769)
SetSurveyLanguage($surveyid, $language_to_set);


UpdateGroupList($surveyid, $_SESSION['survey_'.$surveyid]['s_lang']);

$sQuery = "SELECT count(*)\n"
." FROM {{groups}} INNER JOIN {{questions}} ON {{groups}}.gid = {{questions}}.gid\n"
." WHERE {{questions}}.sid=".$surveyid."\n"
." AND {{groups}}.language='".App()->getLanguage()."'\n"
." AND {{questions}}.language='".App()->getLanguage()."'\n"
." AND {{questions}}.parent_qid=0\n";
$totalquestions = Yii::app()->db->createCommand($sQuery)->queryScalar();
$totalquestions = Question::model()->getTotalQuestions($surveyid);

$sQuery= "select count(*) from {{groups}}
left join {{questions}} on {{groups}}.gid={{questions}}.gid
Expand Down
16 changes: 16 additions & 0 deletions application/models/Question.php
Expand Up @@ -937,4 +937,20 @@ protected function beforeSave()
return false;
}
}

/**
* Used in frontend helper, buildsurveysession.
* @param int $surveyid
* @return int
*/
public static function getTotalQuestions($surveyid)
{
$sQuery = "SELECT count(*)\n"
." FROM {{groups}} INNER JOIN {{questions}} ON {{groups}}.gid = {{questions}}.gid\n"
." WHERE {{questions}}.sid=".$surveyid."\n"
." AND {{groups}}.language='".App()->getLanguage()."'\n"
." AND {{questions}}.language='".App()->getLanguage()."'\n"
." AND {{questions}}.parent_qid=0\n";
return Yii::app()->db->createCommand($sQuery)->queryScalar();
}
}

0 comments on commit 6417eab

Please sign in to comment.