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

Make code checker happier, only dockblocks still missing

parent 2e634c49
No related branches found
No related tags found
No related merge requests found
......@@ -34,8 +34,7 @@ require_once($CFG->libdir.'/formslib.php');
class evaluserexportform extends moodleform {
public function definition()
{
public function definition() {
$mform = $this->_form;
$courseid = $this->_customdata['courseid'];
......@@ -52,20 +51,22 @@ class evaluserexportform extends moodleform {
$mform->setType('coursecontext', PARAM_INT);
$mform->setConstant('coursecontext', $coursecontext->id);
$placeholder = get_string('course_code_placeholder', 'local_hshexport');
$mform->addElement('text', 'course_code', get_string('course_code', 'local_hshexport'), 'maxlength="150" size="50" placeholder="'.$placeholder.'"');
$mform->setType('course_code', PARAM_TEXT);
$mform->addHelpButton('course_code', 'course_code', 'local_hshexport');
$mform->setDefault('course_code', null);
$placeholder = get_string('coursecode_placeholder', 'local_hshexport');
$mform->addElement('text', 'coursecode', get_string('coursecode', 'local_hshexport'),
'maxlength="150" size="50" placeholder="'.$placeholder.'"');
$mform->setType('coursecode', PARAM_TEXT);
$mform->addHelpButton('coursecode', 'coursecode', 'local_hshexport');
$mform->setDefault('coursecode', null);
$viewableroles = get_roles_used_in_context($coursecontext, false);
$roles = role_fix_names($viewableroles, $coursecontext, ROLENAME_ALIAS);
$roles_checkboxes = [];
$rolescheckboxes = [];
foreach ($roles as $role) {
$roles_checkboxes[] =& $mform->createElement('advcheckbox', 'role_'.$role->id, $role->localname, null, ['group' => 1], [null, $role->id]);
$rolescheckboxes[] =& $mform->createElement('advcheckbox', 'role_'.$role->id,
$role->localname, null, ['group' => 1], [null, $role->id]);
}
$mform->addGroup($roles_checkboxes, 'roles', get_string('select_roles', 'local_hshexport'), ['<br/>'], true);
$mform->addGroup($rolescheckboxes, 'roles', get_string('select_roles', 'local_hshexport'), );
$mform->addHelpButton('roles', 'select_roles', 'local_hshexport');
$mform->addGroupRule(
'roles',
......
......@@ -32,7 +32,7 @@ class exporter {
const USER_DELETED = 0;
const USER_SUSPENDED = 0;
private int $courseid;
private string $course_code;
private string $coursecode;
private array $roles;
private string $filename;
private string $content;
......@@ -40,7 +40,7 @@ class exporter {
public function __construct($data) {
$this->courseid = $this->set_courseid($data);
$this->course_code = $this->set_course_code($data);
$this->coursecode = $this->set_coursecode($data);
$this->roles = $this->set_roles($data);
$this->filename = $this->set_filename();
$this->content = $this->set_content();
......@@ -54,16 +54,15 @@ class exporter {
}
}
private function set_course_code($data) {
if (property_exists($data, 'course_code')) {
return $data->course_code;
private function set_coursecode($data) {
if (property_exists($data, 'coursecode')) {
return $data->coursecode;
} else {
return null;
}
}
private function set_roles($data): array
{
private function set_roles($data) {
if (property_exists($data, 'roles')) {
$roleids = array_filter(array_values($data->roles));
$roles = array_map('intval', $roleids);
......@@ -73,8 +72,7 @@ class exporter {
}
}
private function set_content(): ?string
{
private function set_content() {
global $CFG;
require_once($CFG->libdir . '/csvlib.class.php');
......@@ -84,11 +82,10 @@ class exporter {
return \csv_export_writer::print_array($rows, $delimiter, '"', true);
}
private function set_filename(): string
{
private function set_filename() {
// use course shortname if no course_code is given
$filename = $this->course_code;
// Use course shortname if no course code is given.
$filename = $this->coursecode;
if (!$filename) {
global $DB;
$course = $DB->get_record('course', ['id' => $this->courseid], '*', MUST_EXIST);
......@@ -100,47 +97,41 @@ class exporter {
$filename = str_replace(',', '-', $course->shortname);
}
// extend filename with prefix and date
// Extend filename with prefix and timestamp.
$filename = $this->add_prefix($filename);
$filename = $this->add_timestamp($filename);
$filename = $this->add_extension($filename);
return clean_filename($filename);
}
private function add_prefix($name): string
{
private function add_prefix($name) {
return 'TN_'.$name;
}
private function add_timestamp($name): string
{
private function add_timestamp($name) {
return $name.'_'.gmdate("Ymd_Hi");
}
private function add_extension($name): string
{
private function add_extension($name) {
return $name.'.csv';
}
private function get_delimiter(): string
{
private function get_delimiter() {
return 'semicolon';
}
private function get_mimetype(): string
{
private function get_mimetype() {
return 'application/download';
}
private function get_rows(): array
{
private function get_rows() {
$users = $this->get_users_by_role();
$rows = [];
foreach ($users as $user) {
if ($this->course_code) {
$row['course_code'] = $this->course_code;
if ($this->coursecode) {
$row['coursecode'] = $this->coursecode;
}
$row['email'] = $user->email;
$rows[] = $row;
......@@ -148,8 +139,7 @@ class exporter {
return $rows;
}
private function get_users_by_role():array
{
private function get_users_by_role() {
global $DB;
$context = context\course::instance($this->courseid, MUST_EXIST);
......@@ -184,8 +174,7 @@ class exporter {
return $users;
}
public function send_file(): void
{
public function send_file() {
global $CFG;
require_once($CFG->libdir.'/filelib.php');
......
......@@ -25,18 +25,18 @@
defined('MOODLE_INTERNAL') || die();
$string['checkall'] = 'Alle auswählen';
$string['coursecode'] = 'LV-Kennung';
$string['coursecode_help'] = 'Eine LV-Kennung muss eindeutig und einmalig sein, z.B. eine Modulkurzbezeichnung. Sie ist die eindeutige Kennung, unter der die Evaluation durchgeführt wird. Beispiele: BBA-422-01 oder 010-103. Bei Fragen zu Ihrer LV Kennung wenden Sie sich bitte an Ihr Dekanatsbüro.';
$string['coursecode_placeholder'] = 'Bitte hier LV Kennung eingeben';
$string['csvdownload'] = 'CSV herunterladen';
$string['evaluserexport_form_into'] = 'Nutzen Sie dieses Formular um eine CSV-Datei mit den Nutzern der ausgewählten Rollen für die Evaluation zu erzeugen.';
$string['hshexport:canexport'] = 'Kann Nutzer für Evasys als csv exportieren';
$string['pluginname'] = 'HSH Nutzer Export für Evaluation';
$string['nav_course'] = 'Link in Kursnavigation';
$string['nav_participants'] = 'Link in Auswahlbutton der Teilnehmerliste';
$string['navigation'] = 'Platzierung des Links';
$string['navigation_desc'] = 'Der Ort, an dem der Link für das Formular zum Export von Nutzern zur Evaluation innerhalb eines Kurses hinzugefügt wird.';
$string['course_code_placeholder'] = 'Bitte hier LV Kennung eingeben';
$string['course_code'] = 'LV-Kennung';
$string['course_code_help'] = 'Eine LV-Kennung muss eindeutig und einmalig sein, z.B. eine Modulkurzbezeichnung. Sie ist die eindeutige Kennung, unter der die Evaluation durchgeführt wird. Beispiele: BBA-422-01 oder 010-103. Bei Fragen zu Ihrer LV Kennung wenden Sie sich bitte an Ihr Dekanatsbüro.';
$string['noselectedroles'] = 'Mindestens eine Rolle muss ausgewählt werden.';
$string['pluginname'] = 'HSH Nutzer Export für Evaluation';
$string['select_roles'] = 'Rollen';
$string['select_roles_help'] = 'Nutzer mit dieser Rolle bzw. diesen Rollen exportieren.';
$string['checkall'] = 'Alle auswählen';
$string['csvdownload'] = 'CSV herunterladen';
$string['noselectedroles'] = 'Mindestens eine Rolle muss ausgewählt werden.';
$string['evaluserexport_form_into'] = 'Nutzen Sie dieses Formular um eine CSV-Datei mit den Nutzern der ausgewählten Rollen für die Evaluation zu erzeugen.';
......@@ -25,18 +25,18 @@
defined('MOODLE_INTERNAL') || die();
$string['checkall'] = 'Check all';
$string['coursecode'] = 'Course code';
$string['coursecode_help'] = 'A course code must be unique and unambiguous, e.g. a module abbreviation. It is the unique identifier under which the evaluation is carried out. Examples BBA-422-01 or 010-103. If you have any questions concerning your course code, please contact your dean\'s office.';
$string['coursecode_placeholder'] = 'Please enter course code here';
$string['csvdownload'] = 'Download csv';
$string['evaluserexport_form_into'] = 'Use this form to generate a CSV file with users of selected roles for evaluation purposes.';
$string['hshexport:canexport'] = 'Can export user csv for evasys';
$string['pluginname'] = 'HSH User export';
$string['nav_course'] = 'Navigation node in course navigation';
$string['nav_participants'] = 'Navigation node in participants page jump menu';
$string['navigation'] = 'Navigation node placement';
$string['navigation_desc'] = 'The location where the navigation node for evaluation user export form will be added within a course.';
$string['course_code_placeholder'] = 'Please enter course code here';
$string['course_code'] = 'Course code';
$string['course_code_help'] = 'A course code must be unique and unambiguous, e.g. a module abbreviation. It is the unique identifier under which the evaluation is carried out. Examples BBA-422-01 or 010-103. If you have any questions concerning your course code, please contact your dean\'s office.';
$string['noselectedroles'] = 'At least one role has to be selected.';
$string['pluginname'] = 'HSH User export';
$string['select_roles'] = 'Roles';
$string['select_roles_help'] = 'Export users with this role or these roles.';
$string['checkall'] = 'Check all';
$string['csvdownload'] = 'Download csv';
$string['noselectedroles'] = 'At least one role has to be selected.';
$string['evaluserexport_form_into'] = 'Use this form to generate a CSV file with users of selected roles for evaluation purposes.';
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment