Skip to content

Commit

Permalink
New feature #17226: Ability to export to SPSS .sav format (#1877)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamzammit committed Jun 10, 2021
1 parent 3963f29 commit 0662c99
Show file tree
Hide file tree
Showing 414 changed files with 66,596 additions and 52 deletions.
1 change: 1 addition & 0 deletions application/config/config-defaults.php
Expand Up @@ -791,6 +791,7 @@
'AuditLog',
'ExportR',
'ExportSTATAxml',
'ExportSPSSsav',
'extendedStartPage',
'oldUrlCompat',
'AuthLDAP',
Expand Down
2 changes: 1 addition & 1 deletion application/config/version.php
Expand Up @@ -12,7 +12,7 @@
*/

$config['versionnumber'] = '5.1.0-dev';
$config['dbversionnumber'] = 449;
$config['dbversionnumber'] = 450;
$config['buildnumber'] = '';
$config['updatable'] = true;
$config['templateapiversion'] = 3;
Expand Down
1 change: 1 addition & 0 deletions application/core/LsDefaultDataSets.php
Expand Up @@ -1748,6 +1748,7 @@ public static function getDefaultPluginsData()
$addRow('Authwebserver'),
$addRow('ExportR', 1),
$addRow('ExportSTATAxml', 1),
$addRow('ExportSPSSsav', 1),
$addRow('oldUrlCompat'),
$addRow('expressionQuestionHelp'),
$addRow('expressionQuestionForAll'),
Expand Down
81 changes: 81 additions & 0 deletions application/core/plugins/ExportSPSSsav/ExportSPSSsav.php
@@ -0,0 +1,81 @@
<?php
class ExportSPSSsav extends \LimeSurvey\PluginManager\PluginBase
{

protected $storage = 'DbStorage';

static protected $description = 'Core: Export survey results to an SPSS sav file';
static protected $name = 'SPSS Export';

public function init()
{
/**
* Here you should handle subscribing to the events your plugin will handle
*/
$this->subscribe('listExportPlugins');
$this->subscribe('listExportOptions');
$this->subscribe('newExport');
}

protected $settings = array(
'spssfileversion' => array(
'type' => 'select',
'label' => 'Export for SPSS',
'options' => array('16' => 'versions 14 and above', '13' => 'version 13 and below (limited string length)'),
'default' => '16',
'submitonchange'=> false
)
);

public function listExportOptions()
{
$event = $this->getEvent();
$type = $event->get('type');

switch ($type) {
case 'spsssav':
$event->set('label', gT("SPSS (.sav)"));
$event->set('onclick', '
document.getElementById("answers-short").checked=true;
document.getElementById("answers-long").disabled=true;
document.getElementById("converty").checked=true;
document.getElementById("convertn").checked=true;
document.getElementById("convertnto").value=0;
document.getElementById("convertyto").value=1;
document.getElementById("headstyle-code").disabled=true;
document.getElementById("headstyle-abbreviated").disabled=true;
document.getElementById("headstyle-full").checked=true;
document.getElementById("headstyle-codetext").disabled=true;
');
break;

default:
break;
}
}

/**
* Registers this export type
*/
public function listExportPlugins()
{
$event = $this->getEvent();
$exports = $event->get('exportplugins');

// Yes we overwrite existing classes if available
$exports['spsssav'] = get_class();
$event->set('exportplugins', $exports);
}

/**
* Returns the required IWriter
*/
public function newExport()
{
$event = $this->getEvent();

$pluginsettings = $this->getPluginSettings(true);
$writer = new SPSSWriter($pluginsettings);
$event->set('writer', $writer);
}
}

5 comments on commit 0662c99

@olleharstedt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit breaks survey logic file view for some surveys using BigInteger class.

Class 'phpseclib\Math\BigInteger' not found

Possible fix, to use phpseclib3 instead, but must check for php compatibility.

@olleharstedt
Copy link
Contributor

@olleharstedt olleharstedt commented on 0662c99 Jun 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

43 "phpseclib/bcmath_compat": "^2.0"

I think locking bcmath_compat to version 1 was the problem. But you'd have to try your SPSS feature after the changes.

@olleharstedt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamzammit Please test your feature on the latest master commits.

@adamzammit
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @olleharstedt . Just tested on commit 59ad72d and seems fine

@olleharstedt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @olleharstedt . Just tested on commit 59ad72d and seems fine

Great :)

Please sign in to comment.