Skip to content

Commit

Permalink
Fixed #6737: Browsing and export of timings no longer working
Browse files Browse the repository at this point in the history
  • Loading branch information
mennodekker committed Oct 19, 2012
1 parent dfb580d commit 347af29
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
4 changes: 4 additions & 0 deletions application/controllers/admin/export.php
Expand Up @@ -155,6 +155,10 @@ public function exportresults()
{
//FIND OUT HOW MANY FIELDS WILL BE NEEDED - FOR 255 COLUMN LIMIT
$aFieldMap = createFieldMap($iSurveyID,'full',false,false,getBaseLanguageFromSurveyID($iSurveyID));
if ($thissurvey['savetimings'] === "Y") {
//Append survey timings to the fieldmap array
$aFieldMap = $aFieldMap + createTimingsFieldMap($iSurveyID, 'full',false,false,getBaseLanguageFromSurveyID($iSurveyID));
}
$iFieldCount = count($aFieldMap);

$selecthide = "";
Expand Down
22 changes: 19 additions & 3 deletions application/helpers/admin/exportresults_helper.php
Expand Up @@ -235,13 +235,18 @@ public function loadSurveyById($id)
{
$survey = new SurveyObj();
$clang = Yii::app()->lang;

$intId = sanitize_int($id);
$survey->id = $intId;
$survey->info = getSurveyInfo($survey->id);
$lang = Survey::model()->findByPk($intId)->language;
$clang = new limesurvey_lang($lang);

$survey->fieldMap = createFieldMap($intId,'full',false,false,getBaseLanguageFromSurveyID($intId));
// Check to see if timings are present and add to fieldmap if needed
if ($survey->info['savetimings']=="Y") {
$survey->fieldMap = $survey->fieldMap + createTimingsFieldMap($intId,'full',false,false,getBaseLanguageFromSurveyID($intId));
}

if (empty($intId))
{
Expand Down Expand Up @@ -303,20 +308,24 @@ public function loadSurveyById($id)
*/
public function loadSurveyResults(SurveyObj $survey, $iLimit, $iOffset, $iMaximum, $sFilter='' )
{

// Get info about the survey
$oRecordSet = Yii::app()->db->createCommand()->select()->from('{{survey_' . $survey->id . '}}');
if (tableExists('tokens_'.$survey->id) && array_key_exists ('token',Survey_dynamic::model($survey->id)->attributes))
{
$oRecordSet->leftJoin('{{tokens_' . $survey->id . '}}','{{tokens_' . $survey->id . '}}.token={{survey_' . $survey->id . '}}.token');
}
if ($survey->info['savetimings']=="Y") {
$oRecordSet->leftJoin("{{survey_" . $survey->id . "_timings}} survey_timings", "{{survey_" . $survey->id . "}}.id = survey_timings.id");
}

if ($sFilter!='')
$oRecordSet->where($sFilter);
if ($iOffset+$iLimit>$iMaximum)
{
$iLimit=$iMaximum-$iOffset;
}

$survey->responses=$oRecordSet->order('id')->limit($iLimit, $iOffset)->query()->readAll();
$survey->responses=$oRecordSet->order('{{survey_' . $survey->id . '}}.id')->limit($iLimit, $iOffset)->query()->readAll();

return count($survey->responses);
}
Expand Down Expand Up @@ -357,6 +366,13 @@ class SurveyObj
* @var array[int][string]mixed
*/
public $groups;

/**
* info about the survey
*
* @var array
*/
public $info;

/**
* The questions in the survey.
Expand Down
11 changes: 7 additions & 4 deletions application/helpers/common_helper.php
Expand Up @@ -2258,14 +2258,15 @@ function createCompleteSGQA($iSurveyID,$aFilters,$sLanguage) {
* @param mixed $style 'short' (default) or 'full' - full creates extra information like default values
* @param mixed $force_refresh - Forces to really refresh the array, not just take the session copy
* @param int $questionid Limit to a certain qid only (for question preview) - default is false
* @param string $sQuestionLanguage The language to use
* @return array
*/
function createFieldMap($surveyid, $style='short', $force_refresh=false, $questionid=false, $sLanguage) {
global $aDuplicateQIDs;

$sLanguage = sanitize_languagecode($sLanguage);
$surveyid = sanitize_int($surveyid);
$clang = new Limesurvey_lang($sLanguage); ;
$clang = new Limesurvey_lang($sLanguage);

//checks to see if fieldmap has already been built for this page.
if (isset(Yii::app()->session['fieldmap-' . $surveyid . $sLanguage]) && !$force_refresh && $questionid == false) {
Expand Down Expand Up @@ -2885,16 +2886,18 @@ function hasFileUploadQuestion($surveyid) {
* @param mixed $style 'short' (default) or 'full' - full creates extra information like default values
* @param mixed $force_refresh - Forces to really refresh the array, not just take the session copy
* @param int $questionid Limit to a certain qid only (for question preview) - default is false
* @param string $sQuestionLanguage The language to use
* @return array
*/
function createTimingsFieldMap($surveyid, $style='full', $force_refresh=false, $questionid=false, $sQuestionLanguage=null) {

global $aDuplicateQIDs;
static $timingsFieldMap;

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

$surveyid=sanitize_int($surveyid);
$sLanguage = sanitize_languagecode($sQuestionLanguage);
$surveyid = sanitize_int($surveyid);
$clang = new Limesurvey_lang($sLanguage);

//checks to see if fieldmap has already been built for this page.
if (isset($timingsFieldMap[$surveyid][$style][$clang->langcode]) && $force_refresh==false) {
return $timingsFieldMap[$surveyid][$style][$clang->langcode];
Expand Down
24 changes: 24 additions & 0 deletions application/models/Survey_dynamic.php
Expand Up @@ -130,6 +130,30 @@ public static function deleteSomeRecords($condition = FALSE)

return $survey->deleteAll($criteria);
}

/**
* Return criteria updated with the ones needed for including results from the timings table
*
* @param CDbCriteria|string $criteria
*
* @return CDbCriteria
*/
public function addTimingCriteria($condition)
{
$newCriteria = new CDbCriteria();
$criteria = $this->getCommandBuilder()->createCriteria($condition);

if ($criteria->select == '*')
{
$criteria->select = 't.*';
}

$newCriteria->join = "LEFT JOIN {{survey_" . self::$sid . "_timings}} survey_timings ON t.id = survey_timings.id";
$newCriteria->select = 'tokens.*'; // Otherwise we don't get records from the token table
$newCriteria->mergeWith($criteria);

return $newCriteria;
}

/**
* Return criteria updated with the ones needed for including results from the token table
Expand Down

0 comments on commit 347af29

Please sign in to comment.