Skip to content

Commit

Permalink
Dev: some static for getSurveyInfo
Browse files Browse the repository at this point in the history
Dev: don't doAssesment if survey don't have assesment (a lot of request in public)
  • Loading branch information
Shnoulle committed Dec 14, 2012
1 parent 8483831 commit 1ddb416
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 39 deletions.
78 changes: 40 additions & 38 deletions application/helpers/common_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1403,53 +1403,55 @@ function getUserList($outputformat='fullinfoarray')
*/
function getSurveyInfo($surveyid, $languagecode='')
{
global $siteadminname, $siteadminemail, $languagechanger;
static $staticSurveyInfo = array();// Use some static
$surveyid=sanitize_int($surveyid);
$languagecode=sanitize_languagecode($languagecode);
$thissurvey=false;

// Do job only if this survey exist
if(!Survey::model()->findByPk($surveyid))
{
return false;
}
// if no language code is set then get the base language one
if ((!isset($languagecode) || $languagecode=='') && Survey::model()->findByPk($surveyid))
if ((!isset($languagecode) || $languagecode==''))
{
$languagecode=Survey::model()->findByPk($surveyid)->language;
}

//$query="SELECT * FROM ".db_table_name('surveys').",".db_table_name('surveys_languagesettings')." WHERE sid=$surveyid and surveyls_survey_id=$surveyid and surveyls_language='$languagecode'";

$result = Surveys_languagesettings::model()->with('survey')->findAllByAttributes(array('surveyls_survey_id' => $surveyid, 'surveyls_language' => $languagecode));
foreach ($result as $row)
if(isset($staticSurveyInfo[$surveyid][$languagecode]) )
{
$thissurvey=$staticSurveyInfo[$surveyid][$languagecode];
}
else
{
$thissurvey=array();
foreach ($row as $k => $v)
$thissurvey[$k] = $v;
foreach ($row->survey as $k => $v)
$thissurvey[$k] = $v;

// now create some stupid array translations - needed for backward compatibility
// Newly added surveysettings don't have to be added specifically - these will be available by field name automatically
$thissurvey['name']=$thissurvey['surveyls_title'];
$thissurvey['description']=$thissurvey['surveyls_description'];
$thissurvey['welcome']=$thissurvey['surveyls_welcometext'];
$thissurvey['templatedir']=$thissurvey['template'];
$thissurvey['adminname']=$thissurvey['admin'];
$thissurvey['tablename']='{{survey_'.$thissurvey['sid'] . '}}';
$thissurvey['urldescrip']=$thissurvey['surveyls_urldescription'];
$thissurvey['url']=$thissurvey['surveyls_url'];
$thissurvey['expiry']=$thissurvey['expires'];
$thissurvey['email_invite_subj']=$thissurvey['surveyls_email_invite_subj'];
$thissurvey['email_invite']=$thissurvey['surveyls_email_invite'];
$thissurvey['email_remind_subj']=$thissurvey['surveyls_email_remind_subj'];
$thissurvey['email_remind']=$thissurvey['surveyls_email_remind'];
$thissurvey['email_confirm_subj']=$thissurvey['surveyls_email_confirm_subj'];
$thissurvey['email_confirm']=$thissurvey['surveyls_email_confirm'];
$thissurvey['email_register_subj']=$thissurvey['surveyls_email_register_subj'];
$thissurvey['email_register']=$thissurvey['surveyls_email_register'];
$thissurvey['attributedescriptions'] = $row->survey->tokenAttributes;
$thissurvey['attributecaptions'] = $row->attributeCaptions;
if (!isset($thissurvey['adminname'])) {$thissurvey['adminname']=$siteadminname;}
if (!isset($thissurvey['adminemail'])) {$thissurvey['adminemail']=$siteadminemail;}
if (!isset($thissurvey['urldescrip']) ||
$thissurvey['urldescrip'] == '' ) {$thissurvey['urldescrip']=$thissurvey['surveyls_url'];}
$result = Surveys_languagesettings::model()->with('survey')->findByPk(array('surveyls_survey_id' => $surveyid, 'surveyls_language' => $languagecode));
if($result)
{
$thissurvey=array_merge($result->survey->attributes,$result->attributes);
$thissurvey['name']=$thissurvey['surveyls_title'];
$thissurvey['description']=$thissurvey['surveyls_description'];
$thissurvey['welcome']=$thissurvey['surveyls_welcometext'];
$thissurvey['templatedir']=$thissurvey['template'];
$thissurvey['adminname']=$thissurvey['admin'];
$thissurvey['tablename']='{{survey_'.$thissurvey['sid'] . '}}';
$thissurvey['urldescrip']=$thissurvey['surveyls_urldescription'];
$thissurvey['url']=$thissurvey['surveyls_url'];
$thissurvey['expiry']=$thissurvey['expires'];
$thissurvey['email_invite_subj']=$thissurvey['surveyls_email_invite_subj'];
$thissurvey['email_invite']=$thissurvey['surveyls_email_invite'];
$thissurvey['email_remind_subj']=$thissurvey['surveyls_email_remind_subj'];
$thissurvey['email_remind']=$thissurvey['surveyls_email_remind'];
$thissurvey['email_confirm_subj']=$thissurvey['surveyls_email_confirm_subj'];
$thissurvey['email_confirm']=$thissurvey['surveyls_email_confirm'];
$thissurvey['email_register_subj']=$thissurvey['surveyls_email_register_subj'];
$thissurvey['email_register']=$thissurvey['surveyls_email_register'];
$thissurvey['attributedescriptions'] = $result->survey->tokenAttributes;
$thissurvey['attributecaptions'] = $result->attributeCaptions;
if (!isset($thissurvey['adminname'])) {$thissurvey['adminname']=Yii::app()->getConfig('siteadminemail');}
if (!isset($thissurvey['adminemail'])) {$thissurvey['adminemail']=Yii::app()->getConfig('siteadminname');}
if (!isset($thissurvey['urldescrip']) || $thissurvey['urldescrip'] == '' ) {$thissurvey['urldescrip']=$thissurvey['surveyls_url'];}
}
$staticSurveyInfo[$surveyid][$languagecode]=$thissurvey;
}

return $thissurvey;
Expand Down
6 changes: 5 additions & 1 deletion application/helpers/frontend_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2234,8 +2234,11 @@ function doAssessment($surveyid, $returndataonly=false)
{

$clang = Yii::app()->lang;

$baselang=Survey::model()->findByPk($surveyid)->language;
if(Survey::model()->findByPk($surveyid)->assessments!="Y")
{
return false;
}
$total=0;
if (!isset($_SESSION['survey_'.$surveyid]['s_lang']))
{
Expand All @@ -2244,6 +2247,7 @@ function doAssessment($surveyid, $returndataonly=false)
$query = "SELECT * FROM {{assessments}}
WHERE sid=$surveyid and language='".$_SESSION['survey_'.$surveyid]['s_lang']."'
ORDER BY scope, id";

if ($result = dbExecuteAssoc($query)) //Checked
{
$aResultSet=$result->readAll();
Expand Down

0 comments on commit 1ddb416

Please sign in to comment.