/
RDataWriter.php
63 lines (56 loc) · 2.01 KB
/
RDataWriter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
Yii::import('application.helpers.admin.export.*');
class RDataWriter extends CsvWriter {
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;
}
/**
* Perform response transformation, for example F/M for female/male will be mapped to 1/2 values
*
* @param type $value
* @param type $fieldType
* @param FormattingOptions $oOptions
* @return mixed
*/
protected function transformResponseValue($value, $fieldType, FormattingOptions $oOptions) {
parent::transformResponseValue($value, $fieldType, $oOptions);
switch ($fieldType) {
case 'G': // Gender question
if ($value == 'F') {
return 1;
} elseif ($value == 'M') {
return 2;
}
break;
case 'C': // Yes/no/uncertain
if ($value == 'Y') {
return 1;
} elseif ($value == 'N') {
return 2;
} elseif ($value == 'U') {
return 3;
}
break;
case 'E': // Increase/same/decrease
if ($value == 'I') {
return 1;
} elseif ($value == 'S') {
return 2;
} elseif ($value == 'D') {
return 3;
}
break;
default:
break;
}
}
}