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
3e58bbde
Commit
3e58bbde
authored
4 months ago
by
Elke Kreim
Browse files
Options
Downloads
Patches
Plain Diff
Add some docblocks
parent
c8807cd3
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
classes/local/exporter.php
+43
-6
43 additions, 6 deletions
classes/local/exporter.php
with
43 additions
and
6 deletions
classes/local/exporter.php
+
43
−
6
View file @
3e58bbde
...
@@ -19,25 +19,36 @@ namespace local_hshexport\local;
...
@@ -19,25 +19,36 @@ namespace local_hshexport\local;
use
core\context
;
use
core\context
;
/**
/**
*
Plugin version and other meta-data are defined here
.
*
File exporter for course participants in csv format for evaluation
.
*
*
* @package local_hshexport
* @package local_hshexport
* @copyright
202
4
Elke Kreim
elke.kreim@hs-hannover.de
* @copyright 202
5
Elke Kreim
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
*/
class
exporter
{
class
exporter
{
/** @var int Status of activ course enrolment. */
const
ENROLEMENT_STATUS
=
0
;
const
ENROLEMENT_STATUS
=
0
;
/** @var int Status of users who have not been deleted. */
const
USER_DELETED
=
0
;
const
USER_DELETED
=
0
;
/** @var int Status of users who have not been suspended. */
const
USER_SUSPENDED
=
0
;
const
USER_SUSPENDED
=
0
;
/** @var int ID of a course. */
private
int
$courseid
;
private
int
$courseid
;
/** @var string Identifier for the evaluation of a course. */
private
string
$coursecode
;
private
string
$coursecode
;
/** @var int[] Array of role ids. */
private
array
$roles
;
private
array
$roles
;
/** @var string Name of the file to download. */
private
string
$filename
;
private
string
$filename
;
/** @var string Content prepared in csv format for downloaded file. */
private
string
$content
;
private
string
$content
;
/**
* Creates an exporter object.
*
* @param stdClass $data
*/
public
function
__construct
(
$data
)
{
public
function
__construct
(
$data
)
{
$this
->
courseid
=
$this
->
set_courseid
(
$data
);
$this
->
courseid
=
$this
->
set_courseid
(
$data
);
$this
->
coursecode
=
$this
->
set_coursecode
(
$data
);
$this
->
coursecode
=
$this
->
set_coursecode
(
$data
);
...
@@ -62,6 +73,11 @@ class exporter {
...
@@ -62,6 +73,11 @@ class exporter {
}
}
}
}
/**
* Create array of content in csv format.
*
* @return string
*/
private
function
set_roles
(
$data
)
{
private
function
set_roles
(
$data
)
{
if
(
property_exists
(
$data
,
'roles'
))
{
if
(
property_exists
(
$data
,
'roles'
))
{
$roleids
=
array_filter
(
array_values
(
$data
->
roles
));
$roleids
=
array_filter
(
array_values
(
$data
->
roles
));
...
@@ -72,6 +88,11 @@ class exporter {
...
@@ -72,6 +88,11 @@ class exporter {
}
}
}
}
/**
* Create string content in csv format.
*
* @return string
*/
private
function
set_content
()
{
private
function
set_content
()
{
global
$CFG
;
global
$CFG
;
require_once
(
$CFG
->
libdir
.
'/csvlib.class.php'
);
require_once
(
$CFG
->
libdir
.
'/csvlib.class.php'
);
...
@@ -82,6 +103,15 @@ class exporter {
...
@@ -82,6 +103,15 @@ class exporter {
return
\csv_export_writer
::
print_array
(
$rows
,
$delimiter
,
'"'
,
true
);
return
\csv_export_writer
::
print_array
(
$rows
,
$delimiter
,
'"'
,
true
);
}
}
/**
* Create filename.
*
* This method creates a filename for the file to be downloaded. The filename consists of a given prefix,
* a coursecode, a timestamp and the appending extension. If no coursecode is set this part is replaced by the
* short name of the course.
*
* @return string
*/
private
function
set_filename
()
{
private
function
set_filename
()
{
// Use course shortname if no course code is given.
// Use course shortname if no course code is given.
...
@@ -104,6 +134,13 @@ class exporter {
...
@@ -104,6 +134,13 @@ class exporter {
return
clean_filename
(
$filename
);
return
clean_filename
(
$filename
);
}
}
/**
* Add prefix to filename.
*
* This method inserts the given prefix before the name.
*
* @return string
*/
private
function
add_prefix
(
$name
)
{
private
function
add_prefix
(
$name
)
{
return
'TN_'
.
$name
;
return
'TN_'
.
$name
;
}
}
...
...
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