/**
  * Initialization method
  * Update $oOptions to use own, keep the old headingFormat in $this->oldHeadFormat
  *
  * @param Survey $survey
  * @param mixed $sLanguageCode
  * @param FormattingOptions $oOptions
  */
 public function init(\SurveyObj $oSurvey, $sLanguageCode, \FormattingOptions $oOptions)
 {
     $this->sLang = $sLanguageCode;
     // Change filename
     $now = date("Ymd-His");
     $this->oSurvey = $oSurvey;
     $this->oldHeadFormat = $oOptions->headingFormat;
     $oOptions->headingFormat = "full";
     // force to use own code
     $oOptions->answerFormat = "short";
     // force to use own code
     if ($this->exportAnswerPosition == 'aseperatecodetext' && $this->exportAnswerCode && $this->exportAnswerText) {
         // Need to double some $oOptions->selectedColumns
         $aSelectedColumns = array();
         foreach ($oOptions->selectedColumns as $sSelectedColumns) {
             $aSelectedColumns[] = $sSelectedColumns;
             $sFieldType = $oSurvey->fieldMap[$sSelectedColumns]['type'];
             if (!self::sameTextAndCode($sFieldType, $sSelectedColumns)) {
                 $aSelectedColumns[] = $sSelectedColumns;
             }
         }
         $oOptions->selectedColumns = $aSelectedColumns;
     }
     parent::init($oSurvey, $sLanguageCode, $oOptions);
     $this->csvFilename = "results-survey_{$oSurvey->id}_{$now}.csv";
 }
Esempio n. 2
0
 public function init(\SurveyObj $survey, $sLanguageCode, \FormattingOptions $oOptions)
 {
     parent::init($survey, $sLanguageCode, $oOptions);
     // Change filename
     $this->csvFilename = 'survey_' . $survey->id . '_R_data_file.csv';
     // Skip the first line with headers
     $this->doHeaders = true;
     $oOptions->answerFormat = "short";
     // force answer codes
     // Save fieldmap so we can use it in transformResponseValue
     $this->fieldmap = $survey->fieldMap;
 }
Esempio n. 3
0
 public function init(\SurveyObj $survey, $sLanguageCode, \FormattingOptions $oOptions)
 {
     parent::init($survey, $sLanguageCode, $oOptions);
     // Change filename
     $this->csvFilename = 'survey_' . $survey->id . '_R_data_file.csv';
     // Skip the first line with headers
     $this->doHeaders = false;
     $oOptions->answerFormat = "short";
     // force answer codes
     $oOptions->convertN = true;
     $oOptions->nValue = 1;
     $oOptions->convertY = true;
     $oOptions->yValue = 2;
 }
 /**
  * Root function for any export results action
  *
  * @param mixed $iSurveyId
  * @param mixed $sLanguageCode
  * @param csv|doc|pdf|xls $sExportPlugin Type of export
  * @param FormattingOptions $oOptions
  * @param string $sFilter 
  */
 function exportSurvey($iSurveyId, $sLanguageCode, $sExportPlugin, FormattingOptions $oOptions, $sFilter = '')
 {
     //Do some input validation.
     if (empty($iSurveyId)) {
         safeDie('A survey ID must be supplied.');
     }
     if (empty($sLanguageCode)) {
         safeDie('A language code must be supplied.');
     }
     if (empty($oOptions)) {
         safeDie('Formatting options must be supplied.');
     }
     if (empty($oOptions->selectedColumns)) {
         safeDie('At least one column must be selected for export.');
     }
     //echo $oOptions->toString().PHP_EOL;
     $writer = null;
     $iSurveyId = sanitize_int($iSurveyId);
     if ($oOptions->output == 'display') {
         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
         header("Pragma: public");
     }
     switch ($sExportPlugin) {
         case "doc":
             $writer = new DocWriter();
             break;
         case "xls":
             $writer = new ExcelWriter();
             break;
         case "pdf":
             $writer = new PdfWriter();
             break;
         case "csv":
         default:
             $writer = new CsvWriter();
             break;
     }
     $surveyDao = new SurveyDao();
     $survey = $surveyDao->loadSurveyById($iSurveyId);
     $writer->init($survey, $sLanguageCode, $oOptions);
     $iBatchSize = 100;
     $iCurrentRecord = $oOptions->responseMinRecord - 1;
     $bMoreRecords = true;
     $first = true;
     while ($bMoreRecords) {
         $iExported = $surveyDao->loadSurveyResults($survey, $iBatchSize, $iCurrentRecord, $oOptions->responseMaxRecord, $sFilter);
         $iCurrentRecord += $iExported;
         $writer->write($survey, $sLanguageCode, $oOptions, $first);
         $first = false;
         $bMoreRecords = $iExported == $iBatchSize;
     }
     $result = $writer->close();
     if ($oOptions->output == 'file') {
         return $writer->filename;
     } else {
         return $result;
     }
 }