Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Nov 11, 2012
2 parents 62c82a3 + 1e869c7 commit f346a6f
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 3 deletions.
14 changes: 12 additions & 2 deletions application/controllers/admin/export.php
Expand Up @@ -313,7 +313,7 @@ public function exportspss()
Yii::app()->session['spssversion'] = $spssver;
}

$length_varlabel = '255'; // Set the max text length of Variable Labels
$length_varlabel = '231'; // Set the max text length of Variable Labels
$length_vallabel = '120'; // Set the max text length of Value Labels

switch ( $spssver )
Expand Down Expand Up @@ -482,7 +482,17 @@ public function exportspss()
{
if ( ! $field['hide'] )
{
echo "VARIABLE LABELS " . $field['id'] . " \"" . str_replace('"','""',mb_substr(stripTagsFull($field['VariableLabel']), 0, $length_varlabel)) . "\".\n";
$label_parts = strSplitUnicode(str_replace('"','""',stripTagsFull($field['VariableLabel'])), $length_varlabel-strlen($field['id']));
//if replaced quotes are splitted by, we need to mve the first quote to the next row
foreach($label_parts as $idx => $label_part)
{
if($idx != count($label_parts) && substr($label_part,-1) == '"' && substr($label_part,-2) != '"')
{
$label_parts[$idx] = rtrim($label_part, '"');
$label_parts[$idx + 1] = '"' . $label_parts[$idx + 1];
}
}
echo "VARIABLE LABELS " . $field['id'] . " \"" . implode("\"+\n\"", $label_parts) . "\".\n";
}
}

Expand Down
22 changes: 21 additions & 1 deletion application/helpers/export_helper.php
Expand Up @@ -46,7 +46,27 @@ function isNumericExtended($value) {
return ($eng_or_world);
}


/**
* Returns splitted unicode string correctly
* source: http://www.php.net/manual/en/function.str-split.php#107658
*
* @param $str
* @param $l
* @return string
*/
function strSplitUnicode($str, $l = 0) {
if ($l > 0)
{
$ret = array();
$len = mb_strlen($str, "UTF-8");
for ($i = 0; $i < $len; $i += $l)
{
$ret[] = mb_substr($str, $i, $l, "UTF-8");
}
return $ret;
}
return preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY);
}

/**
* Exports CSV response data for SPSS and R
Expand Down
Binary file modified locale/ca/LC_MESSAGES/ca.mo
Binary file not shown.
Binary file modified locale/de/LC_MESSAGES/de.mo
Binary file not shown.
Binary file modified locale/fi/LC_MESSAGES/fi.mo
Binary file not shown.
Binary file modified locale/nn/LC_MESSAGES/nn.mo
Binary file not shown.
Binary file modified locale/tr/LC_MESSAGES/tr.mo
Binary file not shown.
Binary file modified locale/uk/LC_MESSAGES/uk.mo
Binary file not shown.

0 comments on commit f346a6f

Please sign in to comment.