Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
moodle-local_hshexport
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elc
moodle-local_hshexport
Commits
b7562e74
Commit
b7562e74
authored
3 months ago
by
Elke Kreim
Browse files
Options
Downloads
Patches
Plain Diff
Replace special characters in filename
parent
cab3a230
Branches
main
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
classes/local/exporter.php
+3
-14
3 additions, 14 deletions
classes/local/exporter.php
export.php
+2
-3
2 additions, 3 deletions
export.php
with
5 additions
and
17 deletions
classes/local/exporter.php
+
3
−
14
View file @
b7562e74
...
@@ -37,8 +37,6 @@ class exporter {
...
@@ -37,8 +37,6 @@ class exporter {
private
int
$courseid
;
private
int
$courseid
;
/** @var string Identifier for the evaluation of a course. */
/** @var string Identifier for the evaluation of a course. */
private
string
$code
;
private
string
$code
;
/** @var string identifier for the course. */
private
string
$codereplacement
;
/** @var int[] Array of role ids. */
/** @var int[] Array of role ids. */
private
array
$roles
;
private
array
$roles
;
/** @var string Name of the file to download. */
/** @var string Name of the file to download. */
...
@@ -54,10 +52,9 @@ class exporter {
...
@@ -54,10 +52,9 @@ class exporter {
* @param string $codereplacement
* @param string $codereplacement
* @param array $roles
* @param array $roles
*/
*/
public
function
__construct
(
$courseid
=
0
,
$code
=
null
,
$codereplacement
=
null
,
$roles
=
[])
{
public
function
__construct
(
$courseid
=
0
,
$code
=
null
,
$roles
=
[])
{
$this
->
courseid
=
$this
->
set_courseid
(
$courseid
);
$this
->
courseid
=
$this
->
set_courseid
(
$courseid
);
$this
->
code
=
$code
;
$this
->
code
=
$code
;
$this
->
codereplacement
=
$codereplacement
;
$this
->
roles
=
$this
->
set_roles
(
$roles
);
$this
->
roles
=
$this
->
set_roles
(
$roles
);
$this
->
filename
=
$this
->
set_filename
();
$this
->
filename
=
$this
->
set_filename
();
$this
->
content
=
$this
->
set_content
();
$this
->
content
=
$this
->
set_content
();
...
@@ -97,14 +94,6 @@ class exporter {
...
@@ -97,14 +94,6 @@ class exporter {
return
\csv_export_writer
::
print_array
(
$rows
,
$delimiter
,
'"'
,
true
);
return
\csv_export_writer
::
print_array
(
$rows
,
$delimiter
,
'"'
,
true
);
}
}
private
function
get_base_filename
()
{
$base
=
$this
->
code
;
if
(
!
$base
)
{
$base
=
str_replace
(
','
,
'-'
,
$this
->
codereplacement
);
}
return
$base
;
}
/**
/**
* Create filename.
* Create filename.
*
*
...
@@ -116,8 +105,8 @@ class exporter {
...
@@ -116,8 +105,8 @@ class exporter {
*/
*/
private
function
set_filename
()
{
private
function
set_filename
()
{
//
Use course shortname if no course code is given
.
//
Replace special characters with '-' to create a "clean" filename
.
$filename
=
$this
->
get_base_filename
(
);
$filename
=
preg_replace
(
"/[^A-Za-z0-9_-]/"
,
'-'
,
$this
->
code
);
// Extend filename with prefix and timestamp.
// Extend filename with prefix and timestamp.
$filename
=
$this
->
add_prefix
(
$filename
);
$filename
=
$this
->
add_prefix
(
$filename
);
$filename
=
$this
->
add_timestamp
(
$filename
);
$filename
=
$this
->
add_timestamp
(
$filename
);
...
...
This diff is collapsed.
Click to expand it.
export.php
+
2
−
3
View file @
b7562e74
...
@@ -62,10 +62,9 @@ if ($mform->is_cancelled()) {
...
@@ -62,10 +62,9 @@ if ($mform->is_cancelled()) {
redirect
(
$returnurl
);
redirect
(
$returnurl
);
}
else
if
(
$formdata
)
{
}
else
if
(
$formdata
)
{
$courseid
=
$formdata
->
courseid
;
$courseid
=
$formdata
->
courseid
;
$code
=
$formdata
->
coursecode
;
$code
=
$formdata
->
coursecode
?
$formdata
->
coursecode
:
$course
->
shortname
;
$codereplacement
=
$course
->
shortname
;
$roles
=
$formdata
->
roles
;
$roles
=
$formdata
->
roles
;
$exporter
=
new
exporter
(
$courseid
,
$code
,
$codereplacement
,
$roles
);
$exporter
=
new
exporter
(
$courseid
,
$code
,
$roles
);
$exporter
->
send_file
();
$exporter
->
send_file
();
}
else
{
}
else
{
$mform
->
set_data
(
$formdata
);
$mform
->
set_data
(
$formdata
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment