Skip to content
Snippets Groups Projects
Commit 3e58bbde authored by Elke Kreim's avatar Elke Kreim
Browse files

Add some docblocks

parent c8807cd3
No related branches found
No related tags found
No related merge requests found
...@@ -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 2024 Elke Kreim elke.kreim@hs-hannover.de * @copyright 2025 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;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment