-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexportAttachedFilesUrl.php
132 lines (113 loc) · 4.67 KB
/
exportAttachedFilesUrl.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/**
* E Plugin for LimeSurvey
* Export code and complete answer in CSV
*
* @author Etienne Bohm <[email protected]>
* @copyright 2016 Etienne Bohm <http://univ-paris1.fr>
* @license AGPL v3
* @version 0.1
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Affero Public License for more details.
*
*/
class exportAttachedFilesUrl extends \ls\pluginmanager\PluginBase {
protected $storage = 'DbStorage';
static protected $name = 'Links attached export results';
static protected $description = 'Include an url in the export of the csv results if there are attached files in the survey';
public function __construct(PluginManager $manager, $id) {
parent::__construct($manager, $id);
$this->subscribe('newSurveySettings');
$this->subscribe('beforeSurveySettings');
$this->subscribe('listExportPlugins');
$this->subscribe('listExportOptions');
$this->subscribe('newExport');
}
/* Mandatory implementation why I don't know */
public function newSurveySettings() {
$event = $this->getEvent();
foreach ($event->get('settings') as $name => $value) {
$this->set($name, $value, 'Survey', $event->get('survey'));
}
}
public function beforeSurveySettings() {
$event = $this->getEvent();
$event->set("surveysettings.{$this->id}", array(
'name' => get_class($this),
'settings' => array(
'title' => array(
'type' => 'info',
'content' => '<legend><small>Export Attached Files Url</small></legend>'
),
'ExportAttachedFilesUrlBool' => array(
'type' => 'select',
'options' => array(
0 => 'No',
1 => 'Yes'
),
'label' => 'Activate the export url for this survey',
'current' => $this->get(
'ExportAttachedFilesUrlBool', 'Survey', $event->get('survey')
),
),
'ExportAttachedFilesUrlBase' => array(
'type' => 'string',
'label' => "What's the base url for this survey",
'current' => $this->get('ExportAttachedFilesUrlBase', 'Survey', $event->get('survey'), null)
),
)
));
}
/**
* Registers this export type
*/
public function listExportPlugins()
{
$surveyid = $_GET['surveyid'];
$event = $this->getEvent();
$ExportAttachedFilesUrlBool = $this->get('ExportAttachedFilesUrlBool', 'Survey', $surveyid, $event->get('surveyId'));
if ($ExportAttachedFilesUrlBool == "1") {
$event = $this->getEvent();
$exports = $event->get('exportplugins');
unset($exports['csv']);
$newExport=array('csv'=>get_class());
$exports=$newExport+$exports;
$event->set('exportplugins', $exports);
}
else {
$this->unsubscribe('newExport');
}
}
public function listExportOptions()
{
$surveyid = $_GET['surveyid'];
$event = $this->getEvent();
$ExportAttachedFilesUrlBool = $this->get('ExportAttachedFilesUrlBool', 'Survey', $surveyid, $event->get('surveyId'));
if ($ExportAttachedFilesUrlBool == '1') {
$event->set('label',$this->get('title',null,null,'CSV'));
if($this->get('default',null,null,$this->settings['default']['default'])) {
$event->set('default', true);
}
}
}
public function newExport()
{
$surveyid = $_GET['surveyid'];
$event = $this->getEvent();
$ExportAttachedFilesUrlBool = $this->get('ExportAttachedFilesUrlBool', 'Survey', $surveyid, $event->get('surveyId'));
$ExportAttachedFilesUrlBase = $this->get('ExportAttachedFilesUrlBase', 'Survey', $surveyid, $event->get('surveyId'));
if ($ExportAttachedFilesUrlBool == "0") {
throw new CHttpException(500, 'Error Check survey extension settings');
}
$writer = new exportAttachedFilesUrlWriter($ExportAttachedFilesUrlBase);
$event->set('writer', $writer);
}
}