From 3e58bbdea682636361cac339e66ecc5d299c9d78 Mon Sep 17 00:00:00 2001 From: Elke Kreim <elke.kreim@hs-hannover.de> Date: Tue, 4 Feb 2025 17:04:49 +0100 Subject: [PATCH] Add some docblocks --- classes/local/exporter.php | 49 +++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/classes/local/exporter.php b/classes/local/exporter.php index 4eb317f..12ace15 100644 --- a/classes/local/exporter.php +++ b/classes/local/exporter.php @@ -19,25 +19,36 @@ namespace local_hshexport\local; 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 - * @copyright 2024 Elke Kreim elke.kreim@hs-hannover.de - * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package local_hshexport + * @copyright 2025 Elke Kreim + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - class exporter { + /** @var int Status of activ course enrolment. */ const ENROLEMENT_STATUS = 0; + /** @var int Status of users who have not been deleted. */ const USER_DELETED = 0; + /** @var int Status of users who have not been suspended. */ const USER_SUSPENDED = 0; + /** @var int ID of a course. */ private int $courseid; + /** @var string Identifier for the evaluation of a course. */ private string $coursecode; + /** @var int[] Array of role ids. */ private array $roles; + /** @var string Name of the file to download. */ private string $filename; + /** @var string Content prepared in csv format for downloaded file. */ private string $content; - + /** + * Creates an exporter object. + * + * @param stdClass $data + */ public function __construct($data) { $this->courseid = $this->set_courseid($data); $this->coursecode = $this->set_coursecode($data); @@ -62,6 +73,11 @@ class exporter { } } + /** + * Create array of content in csv format. + * + * @return string + */ private function set_roles($data) { if (property_exists($data, 'roles')) { $roleids = array_filter(array_values($data->roles)); @@ -72,6 +88,11 @@ class exporter { } } + /** + * Create string content in csv format. + * + * @return string + */ private function set_content() { global $CFG; require_once($CFG->libdir . '/csvlib.class.php'); @@ -82,6 +103,15 @@ class exporter { 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() { // Use course shortname if no course code is given. @@ -104,6 +134,13 @@ class exporter { return clean_filename($filename); } + /** + * Add prefix to filename. + * + * This method inserts the given prefix before the name. + * + * @return string + */ private function add_prefix($name) { return 'TN_'.$name; } -- GitLab