ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPRGMembersExportGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Data\Factory as DataFactory;
22
27{
28 public const USERFORMSETTINGS_ID = 'prg_export_settings';
29 public const EXPORT_FILENAME = '%s_PRGAssignment_export_%s_%s'; //keep underscores/params!
30
32 protected int $obj_id;
33
34 public function __construct(
35 protected int $ref_id,
36 protected ilStudyProgrammeUserTable $prg_user_table,
37 protected DataFactory $data_factory
38 ) {
39 $this->obj_id = ilObject::_lookupObjId($ref_id);
41 }
42
46 protected function initSettingsForm(bool $a_is_excel = false): ilPropertyFormGUI
47 {
48 $this->exportSettings = new ilUserFormSettings(self::USERFORMSETTINGS_ID);
49
50 $form = new ilPropertyFormGUI();
51 $form->setFormAction($this->ctrl->getFormAction($this));
52 $form->setTitle($this->lng->txt('ps_export_settings'));
53
54 if ((bool) $a_is_excel) {
55 $form->addCommandButton('exportExcel', $this->lng->txt('ps_export_excel'));
56 } else {
57 $form->addCommandButton('export', $this->lng->txt('ps_perform_export'));
58 }
59 $form->addCommandButton('show', $this->lng->txt('cancel'));
60
61 $current_udata = array();
62 $udata = new ilCheckboxGroupInputGUI($this->lng->txt('ps_export_user_data'), 'export_members');
63 $form->addItem($udata);
64
65 $columns = array_merge($this->prg_user_table->getColumns($this->obj_id, true));
66
67 foreach ($columns as $field_info) {
68 $udata->addOption(new ilCheckboxOption($field_info[1], $field_info[0]));
69 if ($this->exportSettings->enabled($field_info[0])) {
70 $current_udata[] = $field_info[0];
71 }
72 }
73
74 $udata->setValue($current_udata);
75 return $form;
76 }
77
81 protected function handleIncoming(): void
82 {
83 $settings = [];
84 $incoming = [];
85 if ($this->http->wrapper()->post()->has('export_members')) {
86 $incoming = $this->http->wrapper()->post()->retrieve(
87 'export_members',
88 $this->refinery->kindlyTo()->dictOf(
89 $this->refinery->kindlyTo()->string()
90 )
91 );
92 }
93 if (count($incoming)) {
94 foreach ($incoming as $id) {
95 $settings[$id] = true;
96 }
97 }
98
99 $this->exportSettings = new ilUserFormSettings(self::USERFORMSETTINGS_ID);
100 $this->exportSettings->set($settings);
101 $this->exportSettings->store();
102 }
103
107 protected function initFileSystemStorage(): void
108 {
109 $this->fss_export = new ilFSStoragePRG($this->obj_id);
110 }
111
115 public function export(): void
116 {
118 }
119
123 public function exportExcel(): void
124 {
126 }
127
128 private function exportAssignments($type)
129 {
130 $this->handleIncoming();
131 $prg_user_table = ilStudyProgrammeDIC::specificDicFor(
132 new ilObjStudyProgramme($this->obj_id, false)
133 )['ilStudyProgrammeUserTable'];
134 $prg_user_table->disablePermissionCheck(true);
135
137 $this->ref_id,
138 $this->obj_id,
139 $prg_user_table,
140 $this->exportSettings,
141 $this->lng,
142 $this->data_factory
143 );
144
145 $type_str = ($type === ilPRGMemberExport::EXPORT_CSV) ? 'csv' : 'xls';
146
147 $filename = sprintf(
148 self::EXPORT_FILENAME,
149 time(),
150 $type_str,
151 $this->obj_id
152 );
153
155 $filename .= '.csv';
156 }
157 $filepath = $this->fss_export->getMemberExportDirectory() . DIRECTORY_SEPARATOR . $filename;
158
159
160 $this->fss_export->initMemberExportDirectory();
161 $export->create($type, $filepath);
162
164 $this->fss_export->addMemberExportFile($export->getCSVString(), $filename);
165 }
166 $this->ctrl->redirect($this, 'show');
167 }
168
169 public function deleteExportFile(): void
170 {
171 $file_ids = $this->initFileIdsFromPost();
172 if (!count($file_ids)) {
173 $this->ctrl->redirect($this, 'show');
174 }
175
176 foreach ($this->fss_export->getMemberExportFiles() as $file) {
177 if (!in_array(md5($file['name']), $_POST['id'])) {
178 continue;
179 }
180 $this->fss_export->deleteMemberExportFile($file['name']);
181 }
182
183 $this->tpl->setOnScreenMessage('success', $this->lng->txt('ps_files_deleted'), true);
184 $this->ctrl->redirect($this, 'show');
185 }
186
187 public function downloadExportFile(): void
188 {
189 $fl = '';
190 if ($this->http->wrapper()->query()->has('fl')) {
191 $fl = $this->http->wrapper()->query()->retrieve(
192 'fl',
193 $this->refinery->kindlyTo()->string()
194 );
195 }
196
197 $hash = trim($fl);
198 if (!$hash) {
199 $this->ctrl->redirect($this, 'show');
200 }
201
202 foreach ($this->fss_export->getMemberExportFiles() as $file) {
203 if (md5($file['name']) == $hash) {
204 $contents = $this->fss_export->getMemberExportFile($file['name']);
205 $fts = $file['timest'];
206 $dat = date('Y_m_d_H-i', (int)$fts);
207 $down_name = str_replace($fts, $dat, $file['name']);
208
209 $mime = 'text/csv';
210 if ($file['type'] === 'xlsx') {
211 $mime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
212 }
213 ilUtil::deliverData($contents, $down_name, $mime);
214 }
215 }
216 }
217}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$filename
Definition: buildRTE.php:78
Builds data types.
Definition: Factory.php:36
This class represents a property in a property form.
This class represents an option in a checkbox group.
store prg-files
static _lookupObjId(int $ref_id)
export assignments of PRG
export assignments of PRG
export()
Export, create member export file and store it in data directory.
initSettingsForm(bool $a_is_excel=false)
downloadExportFile()
Download export file.
deleteExportFile()
Delete member export files.
__construct(protected int $ref_id, protected ilStudyProgrammeUserTable $prg_user_table, protected DataFactory $data_factory)
This class represents a property form user interface.
static specificDicFor(ilObjStudyProgramme $prg)
ilStudyProgrammeUserTable provides a flattened list of progresses at a programme-node.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static deliverData(string $a_data, string $a_filename, string $mime="application/octet-stream")
$_POST['cmd']
Definition: lti.php:27
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc