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

Add excelfile export of participants for evasys

parent d5f9c1af
Branches
Tags
No related merge requests found
...@@ -118,3 +118,4 @@ $string['coursespending'] = 'Ihre beantragten Kurse (Freischaltung in Arbeit)'; ...@@ -118,3 +118,4 @@ $string['coursespending'] = 'Ihre beantragten Kurse (Freischaltung in Arbeit)';
// Export Module // Export Module
$string['navigationtext'] = 'Teilnehmer*innen als Liste (Excel)'; $string['navigationtext'] = 'Teilnehmer*innen als Liste (Excel)';
$string['modulecode'] = 'Modulkürzel';
\ No newline at end of file
...@@ -142,3 +142,12 @@ $string['nopendingcourses'] = 'Keine Kursbeantragungen vorhanden.'; ...@@ -142,3 +142,12 @@ $string['nopendingcourses'] = 'Keine Kursbeantragungen vorhanden.';
// Export Module // Export Module
$string['navigationtext'] = 'Teilnehmer*innen als Liste (Excel)'; $string['navigationtext'] = 'Teilnehmer*innen als Liste (Excel)';
// modulecode form
$string['modulecode'] = 'Modulkürzel';
$string['modulecode_default'] = 'Geben Sie das Modulkürzel des Kurses ein.';
$string['modulecode_submit'] = 'Liste erstellen';
$string['modulecode_rule'] = 'Modulkürzel fehlt.';
$string['evasysexport_navigationtext'] = 'Liste der Teilnehmer*innen für EvaSys (Excel)';
...@@ -134,3 +134,4 @@ $string['coursespending'] = 'Ihre beantragten Kurse (Freischaltung in Arbeit)'; ...@@ -134,3 +134,4 @@ $string['coursespending'] = 'Ihre beantragten Kurse (Freischaltung in Arbeit)';
// Export Module // Export Module
$string['navigationtext'] = 'Excel export'; $string['navigationtext'] = 'Excel export';
$string['modulecode'] = 'Module code';
\ No newline at end of file
...@@ -154,3 +154,11 @@ $string['nopendingcourses'] = 'There are no courses pending approval'; ...@@ -154,3 +154,11 @@ $string['nopendingcourses'] = 'There are no courses pending approval';
// Export Module // Export Module
$string['navigationtext'] = 'Excel export'; $string['navigationtext'] = 'Excel export';
// modulecode form
$string['modulecode'] = 'Module code';
$string['modulecode_default'] = 'Enter the module code of the course.';
$string['modulecode_submit'] = 'Create list';
$string['modulecode_rule'] = 'Missing module code.';
$string['evasysexport_navigationtext'] = 'Course participants list for EvaSys (Excel)';
\ No newline at end of file
...@@ -553,9 +553,20 @@ function local_hsh_extend_navigation_course(navigation_node $parentnode, stdClas ...@@ -553,9 +553,20 @@ function local_hsh_extend_navigation_course(navigation_node $parentnode, stdClas
$url = new moodle_url('/local/hsh/participants_export_form.php', array('id' => $course->id)); $url = new moodle_url('/local/hsh/participants_export_form.php', array('id' => $course->id));
$settingsnode = navigation_node::create( $settingsnode = navigation_node::create(
$strfoo, $url, navigation_node::NODETYPE_LEAF, 'hsh', 'hsh', new pix_icon('i/export', $strfoo)); $strfoo, $url, navigation_node::NODETYPE_LEAF, 'hsh', 'hsh', new pix_icon('i/export', $strfoo));
$evasysexport_mavigation = get_string('evasysexport_navigationtext', 'local_hsh');
$evasysexport_url = new moodle_url('/local/hsh/participants_evasysexport.php', array('id' => $course->id));
$evasysexport_settingsnode = navigation_node::create(
$evasysexport_mavigation, $evasysexport_url, navigation_node::NODETYPE_LEAF, 'hsh1', 'hsh1', new pix_icon('i/export', $evasysexport_mavigation));
$reportnode = $parentnode->get('users'); $reportnode = $parentnode->get('users');
if (isset($settingsnode) && !empty($reportnode)) { if (!empty($reportnode)) {
if (isset($settingsnode)) {
$reportnode->add_node($settingsnode); $reportnode->add_node($settingsnode);
} }
if (isset($evasysexport_settingsnode)) {
$reportnode->add_node($evasysexport_settingsnode);
}
}
} }
} }
<?php
require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->libdir . '/formslib.php');
class modulcode_form extends moodleform {
public function definition()
{
global $COURSE;
$mform = $this->_form;
$mform->addElement(
'text',
'modulecode',
get_string('modulecode', 'local_hsh'),
array(
'placeholder'=> get_string('modulecode_default', 'local_hsh'),
'width'=>'100%',
)
);
$mform->setType('modulecode', PARAM_NOTAGS);
$mform->addRule('modulecode', get_string('modulecode_rule', 'local_hsh'), 'required');
$this->add_action_buttons(true, get_string('modulecode_submit', 'local_hsh'));
}
}
\ No newline at end of file
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
require_once(__DIR__ . '/../../config.php');
require_once $CFG->dirroot.'/grade/export/lib.php';
require_once 'modulcode_form.php';
require_once 'participants_evasysexport_xls.php';
$id = required_param('id', PARAM_INT); // course id
$returnurl = new moodle_url('/course/view.php', array('id'=>$id));
$url = new moodle_url('/local/hsh/participants_evasysexport.php', array('id'=>$id));
$PAGE->set_url($url);
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('nocourseid');
}
require_login($course);
$context = context_course::instance($id);
require_capability('moodle/grade:export', $context);
$mform = new modulcode_form($url);
if ($mform->is_cancelled()) {
// redirect to course
redirect($returnurl);
} else if ($data = $mform->get_data()) {
$export = new participants_evasysexport_xls($course, $data->modulecode, $returnurl);
$export->print_participants(); // add participants and download file
} else {
echo $OUTPUT->header();
$mform->display();
echo $OUTPUT->footer();
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once($CFG->dirroot . '/grade/export/lib.php');
require_once($CFG->dirroot . '/lib/excellib.class.php');
class participants_evasysexport_xls {
public $course = '';
public $users = null;
public $context = 0;
/**
* Constructor should set up all the private variables ready to be pulled
* @param object $course
* @param boolean $groups
*/
public function __construct($course, $modulecode, $returnurl) {
$this->course = $course;
$this->modulecode = $modulecode;
$this->returnurl = $returnurl;
}
public function print_participants() {
$this->context = context_course::instance($this->course->id);
require_capability('moodle/grade:export', $this->context);
// Calculate file name
$fullname = format_string($this->course->fullname, true, array('context' => $this->context));
$downloadfilename = clean_filename("$fullname.xls");
// Creating a workbook
$workbook = new MoodleExcelWorkbook("-");
// Set name of the downloaded file
$workbook->send($downloadfilename);
// Print names of all the fields
$this->profilefields = array('email' => get_string('email'));
$this->users = get_enrolled_users($this->context, null, 0, 'u.*');
$myxls = $workbook->add_worksheet(strip_tags($this->modulecode));
$this->print_values($myxls);
/// Close the workbook
$workbook->close();
exit;
}
public function print_values($myxls) {
$i = 0;
foreach ($this->users as $userid => $value) {
$myxls->write_string($i, 0, $this->modulecode);
$j = 1;
foreach ($this->profilefields as $id => $field) {
$array = (array) $value;
$myxls->write_string($i, $j++, $array[$id]);
}
$i++;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment