1<?php
2class ExportSTATAxml extends \LimeSurvey\PluginManager\PluginBase
3{
4
5    protected $storage = 'DbStorage';
6
7    static protected $description = 'Core: Export survey results to a STATA xml file';
8    static protected $name = 'STATA Export';
9
10    public function init()
11    {
12
13        /**
14         * Here you should handle subscribing to the events your plugin will handle
15         */
16        $this->subscribe('listExportPlugins');
17        $this->subscribe('listExportOptions');
18        $this->subscribe('newExport');
19    }
20
21    protected $settings = array(
22        'statafileversion' => array(
23            'type' => 'select',
24            'label' => 'Export for Stata',
25            'options' => array('113' => 'version 8 through 12', '117'  => 'version 13 and up'),
26            'default' => '113',
27            'submitonchange'=> false
28            )
29        );
30
31    public function listExportOptions()
32    {
33        $event = $this->getEvent();
34        $type = $event->get('type');
35
36        switch ($type) {
37            case 'stataxml':
38                $event->set('label', gT("STATA (.xml)"));
39                $event->set('onclick', '
40				 document.getElementById("answers-short").checked=true;
41				 document.getElementById("answers-long").disabled=true;
42                     document.getElementById("converty").checked=true;
43                     document.getElementById("convertn").checked=true;
44                     document.getElementById("convertnto").value=0;
45                     document.getElementById("convertyto").value=1;
46                     document.getElementById("headstyle-code").disabled=true;
47                     document.getElementById("headstyle-abbreviated").disabled=true;
48                     document.getElementById("headstyle-full").checked=true;
49                     document.getElementById("headstyle-codetext").disabled=true;
50				 ');
51                break;
52
53            default:
54                break;
55        }
56    }
57
58    /**
59     * Registers this export type
60     */
61    public function listExportPlugins()
62    {
63        $event = $this->getEvent();
64        $exports = $event->get('exportplugins');
65
66        // Yes we overwrite existing classes if available
67        $exports['stataxml'] = get_class();
68        $event->set('exportplugins', $exports);
69    }
70
71    /**
72     * Returns the required IWriter
73     */
74    public function newExport()
75    {
76        $event = $this->getEvent();
77
78        $pluginsettings = $this->getPluginSettings(true);
79        $writer = new STATAxmlWriter($pluginsettings);
80        $event->set('writer', $writer);
81    }
82}