diff --git a/application/core/LSWebUser.php b/application/core/LSWebUser.php index 30bd802a9aa..dfaa5b60d2e 100644 --- a/application/core/LSWebUser.php +++ b/application/core/LSWebUser.php @@ -1,6 +1,9 @@ loadHelper("export"); $tmpFieldmap = SPSSFieldMap($survey->id); + $fieldmap = []; foreach ($tmpFieldmap as $field => $values) { $fieldmap[$values['title']] = $values; if (array_key_exists('sql_name', $values)) { @@ -84,17 +85,18 @@ protected function outputRecord($headers, $values, FormattingOptions $oOptions) public function close() { $errors = ''; - foreach ($this->headers as $id => $title) { + foreach ($this->headers as $id => $title) { $field = $this->customFieldmap[$title]; $i = $id + 1; if ($field['SPSStype'] == 'DATETIME23.2') { - $field['size'] = ''; + $field['size'] = ''; } if ($field['LStype'] == 'N' || $field['LStype'] == 'K') { $field['size'] .= '.'.($field['size'] - 1); } + $type=''; switch ($field['SPSStype']) { case 'F': $type = "numeric"; @@ -107,73 +109,76 @@ public function close() $type = "character"; //@TODO set $type to format for date break; + default: + safeDie('Unknown type'); + break; } - $this->out("# LimeSurvey Field type: {$field['SPSStype']}"); - $this->out("data[, ".$i."] <- " + $this->out("# LimeSurvey Field type: {$field['SPSStype']}"); + $this->out("data[, ".$i."] <- " . "as.$type(data[, ".$i."])"); - $this->out('attributes(data)$variable.labels['.$i.'] <- "' + $this->out('attributes(data)$variable.labels['.$i.'] <- "' . addslashes( - htmlspecialchars_decode( - mb_substr( - stripTagsFull( - $field['VariableLabel'] - ), 0, $this->maxLength - ) + htmlspecialchars_decode( + mb_substr( + stripTagsFull( + $field['VariableLabel'] + ), 0, $this->maxLength ) + ) ) . '"'); - // Create the value Labels! - if (isset($field['answers'])) { - $answers = $field['answers']; - - //print out the value labels! - $str = 'data[, '.$i.'] <- factor(data[, '.$i.'], levels=c('; - foreach ($answers as $answer) { - if ($field['SPSStype'] == "F" && isNumericExtended($answer['code'])) { - $str .= "{$answer['code']},"; - } else { - $str .= "\"{$answer['code']}\","; - } - } - - $str = mb_substr($str, 0, -1); - $str .= '),labels=c('; + // Create the value Labels! + if (isset($field['answers'])) { + $answers = $field['answers']; - foreach ($answers as $answer) { - $str .= '"'.addslashes($answer['value']).'", '; + //print out the value labels! + $str = 'data[, '.$i.'] <- factor(data[, '.$i.'], levels=c('; + foreach ($answers as $answer) { + if ($field['SPSStype'] == "F" && isNumericExtended($answer['code'])) { + $str .= "{$answer['code']},"; + } else { + $str .= "\"{$answer['code']}\","; } + } - $str = mb_substr($str, 0, -2); + $str = mb_substr($str, 0, -1); + $str .= '),labels=c('; - if ($field['scale'] !== '' && $field['scale'] == 2) { - $scale = ", ordered=TRUE"; - } else { - $scale = ""; - } + foreach ($answers as $answer) { + $str .= '"'.addslashes($answer['value']).'", '; + } - $this->out("{$str}){$scale})"); + $str = mb_substr($str, 0, -2); + + if ($field['scale'] !== '' && $field['scale'] == 2) { + $scale = ", ordered=TRUE"; + } else { + $scale = ""; } - //Rename the Variables (in case somethings goes wrong, we still have the OLD values - if (isset($field['sql_name'])) { - $ftitle = $field['title']; - if (!preg_match("/^([a-z]|[A-Z])+.*$/", $ftitle)) { - $ftitle = "q_".$ftitle; - } + $this->out("{$str}){$scale})"); + } - $ftitle = str_replace(array("-", ":", ";", "!"), array("_hyph_", "_dd_", "_dc_", "_excl_"), $ftitle); + //Rename the Variables (in case somethings goes wrong, we still have the OLD values + if (isset($field['sql_name'])) { + $ftitle = $field['title']; + if (!preg_match("/^([a-z]|[A-Z])+.*$/", $ftitle)) { + $ftitle = "q_".$ftitle; + } - if ($ftitle != $field['title']) { - $errors .= "# Variable name was incorrect and was changed from {$field['title']} to $ftitle .\n"; - } + $ftitle = str_replace(array("-", ":", ";", "!"), array("_hyph_", "_dd_", "_dc_", "_excl_"), $ftitle); - $this->out("names(data)[".$i."] <- " - . "\"".$ftitle."\""); // added \n - } else { - $this->out("#sql_name not set"); + if ($ftitle != $field['title']) { + $errors .= "# Variable name was incorrect and was changed from {$field['title']} to $ftitle .\n"; } + + $this->out("names(data)[".$i."] <- " + . "\"".$ftitle."\""); // added \n + } else { + $this->out("#sql_name not set"); + } } // end foreach if (!empty($errors)) { $this->out($errors); diff --git a/application/helpers/admin/export/ExcelWriter.php b/application/helpers/admin/export/ExcelWriter.php index caa15edf54e..b24e2ab5632 100644 --- a/application/helpers/admin/export/ExcelWriter.php +++ b/application/helpers/admin/export/ExcelWriter.php @@ -14,9 +14,6 @@ class ExcelWriter extends Writer private $rowCounter; private $forceDownload = true; - //Indicates if the Writer is outputting to a file rather than sending via HTTP. - private $outputToFile = false; - /** * The presence of a filename will cause the writer to output to * a file rather than send. @@ -24,7 +21,7 @@ class ExcelWriter extends Writer * @param string $filename * @return ExcelWriter */ - public function __construct($filename = null) + public function __construct() { require_once(APPPATH.'/third_party/xlsx_writer/xlsxwriter.class.php'); $this->separator = '~|'; diff --git a/application/helpers/admin/export/JsonWriter.php b/application/helpers/admin/export/JsonWriter.php index 737f2ecf238..bbc4c3931ab 100644 --- a/application/helpers/admin/export/JsonWriter.php +++ b/application/helpers/admin/export/JsonWriter.php @@ -25,13 +25,18 @@ public function init(SurveyObj $survey, $sLanguageCode, FormattingOptions $oOpti echo $sStartOutput; } elseif ($oOptions->output == 'file') { $this->file = fopen($this->filename, 'w'); - fwrite($this->file, $sStartOutput); + if ($this->file!==false) { + fwrite($this->file, $sStartOutput); + } else { + safeDie('Could not open JSON file'); + } } } protected function outputRecord($headers, $values, FormattingOptions $oOptions) { + $aJson = []; $aJson[$values[0]] = array_combine($headers, $values); $sJson = json_encode($aJson); Yii::log($this->havePrev, 'info', 'info'); diff --git a/application/libraries/PluginManager/Question/QuestionPluginBase.php b/application/libraries/PluginManager/Question/QuestionPluginBase.php index b0ca4011fa8..32f5aea11d4 100644 --- a/application/libraries/PluginManager/Question/QuestionPluginBase.php +++ b/application/libraries/PluginManager/Question/QuestionPluginBase.php @@ -24,6 +24,12 @@ abstract class QuestionPluginBase extends PluginBase * @param string $id */ + /** + * + * + * @param PluginManager $manager + * @param integer $id + */ public function __construct(PluginManager $manager, $id) { parent::__construct($manager, $id); @@ -66,4 +72,3 @@ protected function registerCss($fileName) } -?> diff --git a/application/models/Label.php b/application/models/Label.php index ddcc13a113f..806af0a0c49 100644 --- a/application/models/Label.php +++ b/application/models/Label.php @@ -108,7 +108,7 @@ public function getLabelCodeInfo($lid) return Yii::app()->db->createCommand()->select('code, title, sortorder, language, assessment_value')->order('language, sortorder, code')->where('lid=:lid')->from($this->tableName())->bindParam(":lid", $lid, PDO::PARAM_INT)->query()->readAll(); } - function insertRecords($data) + public function insertRecords($data) { $lbls = new self; foreach ($data as $k => $v) { diff --git a/application/models/QuotaMember.php b/application/models/QuotaMember.php index 6fa3758237d..70dd5f44326 100644 --- a/application/models/QuotaMember.php +++ b/application/models/QuotaMember.php @@ -103,7 +103,7 @@ public function getMemberInfo() case "A": case "B": $temp = explode('-', $this->code); - $sFieldName = $this->sid->sid.'X'.$this->question->gid.'X'.$this->qid.$temp[0]; + $sFieldName = $this->sid.'X'.$this->question->gid.'X'.$this->qid.$temp[0]; $sValue = $temp[1]; break; default: @@ -132,7 +132,7 @@ public function getMemberInfo() } - function insertRecords($data) + public function insertRecords($data) { $members = new self; foreach ($data as $k => $v) { diff --git a/application/models/Response.php b/application/models/Response.php index 7589d24268f..ce1d89ec6fd 100644 --- a/application/models/Response.php +++ b/application/models/Response.php @@ -42,7 +42,7 @@ public static function create($surveyId, $scenario = 'insert') * @param integer $sQID The question ID - optional - Default 0 * @return array */ - public function getFiles($sQID = 0) + public function getFiles() { $survey = Survey::model()->findByPk($this->dynamicId); $questions = Question::model()->findAllByAttributes(array('sid' => $this->dynamicId, 'type' => '|', 'language'=>$survey->language)); @@ -120,7 +120,7 @@ public function deleteFiles() * Delete uploaded files for this response AND modify * response data to reflect all changes. * Keep comment and title of file, but remove name/filename. - * @return string[] Name of files that could not be removed. + * @return array Number of successfully moved files and names of files that could not be removed/failed */ public function deleteFilesAndFilename() { diff --git a/application/models/SavedControl.php b/application/models/SavedControl.php index 498ca7b9147..4cf985cd7c6 100644 --- a/application/models/SavedControl.php +++ b/application/models/SavedControl.php @@ -53,7 +53,7 @@ public static function model($class = __CLASS__) } - function getAllRecords($condition = false) + public function getAllRecords($condition = false) { if ($condition != false) { $this->db->where($condition); @@ -97,7 +97,7 @@ public function deleteSomeRecords($condition) return $record->deleteAll($criteria); } - function insertRecords($data) + public function insertRecords($data) { return $this->db->insert('saved_control', $data); }