Skip to content
Snippets Groups Projects
Commit ad3a0198 authored by Moritz Strohm's avatar Moritz Strohm
Browse files

added CourseExporter

parent 620a4fbc
No related branches found
No related tags found
No related merge requests found
<?php
namespace Flexexport;
require_once(__DIR__ . '/Exporter.class.php');
class CourseExporter extends Exporter
{
/**
* @inheritDoc
*/
public static function getDisplayName(): string
{
return dgettext('Flexexport', 'Veranstaltungen');
}
/**
* @inheritDoc
*/
public static function getConfigIndex(): string
{
return 'CourseExporter';
}
/**
* @inheritDoc
*/
public function getConfigurationTemplate(string $config_prefix): \Flexi_Template
{
$factory = new \Flexi_TemplateFactory(__DIR__ . '/../../templates/exporters/');
$template = $factory->open('course_exporter');
$semester_id = $this->config->getParameter('semester_id');
if (!$semester_id) {
$semester = \Semester::findCurrent();
$semester_id = $semester->id ?? '';
}
$institute_id = $this->config->getParameter('institute_id') ?? '';
$template->set_attribute('config_prefix', $config_prefix);
$template->set_attribute('available_institutes', \Institute::getInstitutes());
$template->set_attribute('available_semesters', \Semester::getAll());
$template->set_attribute('semester_id', $semester_id);
$template->set_attribute('institute_id', $institute_id);
return $template;
}
/**
* @inheritDoc
*/
public function getDataFieldNames(): array
{
return [
'course_id' => [
'name' => 'course_id',
'display_name' => (isset($this->enabled_field_config['course_id']['display_name'])
? $this->enabled_field_config['course_id']['display_name']
: 'course_id'
),
'decorator_allowed' => true
],
'name' => [
'name' => 'name',
'display_name' => (isset($this->enabled_field_config['name']['display_name'])
? $this->enabled_field_config['name']['display_name']
: 'name'
),
'decorator_allowed' => true
],
'number' => [
'name' => 'number',
'display_name' => (isset($this->enabled_field_config['number']['display_name'])
? $this->enabled_field_config['number']['display_name']
: 'number'
),
'decorator_allowed' => true
],
'course_type' => [
'name' => 'course_type',
'display_name' => (isset($this->enabled_field_config['course_type']['display_name'])
? $this->enabled_field_config['course_type']['display_name']
: 'course_type'
),
'decorator_allowed' => true
],
'subtitle' => [
'name' => 'subtitle',
'display_name' => (isset($this->enabled_field_config['subtitle']['display_name'])
? $this->enabled_field_config['subtitle']['display_name']
: 'subtitle'
),
'decorator_allowed' => true
],
'description' => [
'name' => 'description',
'display_name' => (isset($this->enabled_field_config['description']['display_name'])
? $this->enabled_field_config['description']['display_name']
: 'description'
),
'decorator_allowed' => true
],
'parent_course_id' => [
'name' => 'parent_course_id',
'display_name' => (isset($this->enabled_field_config['parent_course_id']['display_name'])
? $this->enabled_field_config['parent_course_id']['display_name']
: 'parent_course_id'
),
'decorator_allowed' => true
],
'home_institute_id' => [
'name' => 'home_institute_id',
'display_name' => (isset($this->enabled_field_config['home_institute_id']['display_name'])
? $this->enabled_field_config['home_institute_id']['display_name']
: 'home_institute_id'
),
'decorator_allowed' => true
],
'home_institute_name' => [
'name' => 'home_institute_name',
'display_name' => (isset($this->enabled_field_config['home_institute_name']['display_name'])
? $this->enabled_field_config['home_institute_name']['display_name']
: 'home_institute_name'
),
'decorator_allowed' => true
],
'other_institute_ids' => [
'name' => 'other_institute_ids',
'display_name' => (isset($this->enabled_field_config['other_institute_ids']['display_name'])
? $this->enabled_field_config['other_institute_ids']['display_name']
: 'other_institute_ids'
),
'decorator_allowed' => true
],
'other_institute_names' => [
'name' => 'other_institute_names',
'display_name' => (isset($this->enabled_field_config['other_institute_names']['display_name'])
? $this->enabled_field_config['other_institute_names']['display_name']
: 'other_institute_names'
),
'decorator_allowed' => true
],
'study_area_ids' => [
'name' => 'study_area_ids',
'display_name' => (isset($this->enabled_field_config['study_area_ids']['display_name'])
? $this->enabled_field_config['study_area_ids']['display_name']
: 'study_area_ids'
),
'decorator_allowed' => true
],
'study_area_names' => [
'name' => 'study_area_names',
'display_name' => (isset($this->enabled_field_config['study_area_names']['display_name'])
? $this->enabled_field_config['study_area_names']['display_name']
: 'study_area_names'
),
'decorator_allowed' => true
],
'location' => [
'name' => 'location',
'display_name' => (isset($this->enabled_field_config['location']['display_name'])
? $this->enabled_field_config['location']['display_name']
: 'location'
),
'decorator_allowed' => true
],
'start_semester_id' => [
'name' => 'start_semester_id',
'display_name' => (isset($this->enabled_field_config['start_semester_id']['display_name'])
? $this->enabled_field_config['start_semester_id']['display_name']
: 'start_semester_id'
),
'decorator_allowed' => true
],
'end_semester_id' => [
'name' => 'end_semester_id',
'display_name' => (isset($this->enabled_field_config['end_semester_id']['display_name'])
? $this->enabled_field_config['end_semester_id']['display_name']
: 'end_semester_id'
),
'decorator_allowed' => true
],
'read_access' => [
'name' => 'read_access',
'display_name' => (isset($this->enabled_field_config['read_access']['display_name'])
? $this->enabled_field_config['read_access']['display_name']
: 'read_access'
),
'decorator_allowed' => true
],
'write_access' => [
'name' => 'write_access',
'display_name' => (isset($this->enabled_field_config['write_access']['display_name'])
? $this->enabled_field_config['write_access']['display_name']
: 'write_access'
),
'decorator_allowed' => true
],
'participation_notes' => [
'name' => 'participation_notes',
'display_name' => (isset($this->enabled_field_config['participation_notes']['display_name'])
? $this->enabled_field_config['participation_notes']['display_name']
: 'participation_notes'
),
'decorator_allowed' => true
],
'requirements' => [
'name' => 'requirements',
'display_name' => (isset($this->enabled_field_config['requirements']['display_name'])
? $this->enabled_field_config['requirements']['display_name']
: 'requirements'
),
'decorator_allowed' => true
],
'learning_organisation' => [
'name' => 'learning_organisation',
'display_name' => (isset($this->enabled_field_config['learning_organisation']['display_name'])
? $this->enabled_field_config['learning_organisation']['display_name']
: 'learning_organisation'
),
'decorator_allowed' => true
],
'exam_details' => [
'name' => 'exam_details',
'display_name' => (isset($this->enabled_field_config['exam_details']['display_name'])
? $this->enabled_field_config['exam_details']['display_name']
: 'exam_details'
),
'decorator_allowed' => true
],
'ects' => [
'name' => 'ects',
'display_name' => (isset($this->enabled_field_config['ects']['display_name'])
? $this->enabled_field_config['ects']['display_name']
: 'ects'
),
'decorator_allowed' => true
],
'admission_turnout' => [
'name' => 'admission_turnout',
'display_name' => (isset($this->enabled_field_config['admission_turnout']['display_name'])
? $this->enabled_field_config['admission_turnout']['display_name']
: 'admission_turnout'
),
'decorator_allowed' => true
],
'admission_binding' => [
'name' => 'admission_binding',
'display_name' => (isset($this->enabled_field_config['admission_binding']['display_name'])
? $this->enabled_field_config['admission_binding']['display_name']
: 'admission_binding'
),
'decorator_allowed' => true
],
'admission_prelim' => [
'name' => 'admission_prelim',
'display_name' => (isset($this->enabled_field_config['admission_prelim']['display_name'])
? $this->enabled_field_config['admission_prelim']['display_name']
: 'admission_prelim'
),
'decorator_allowed' => true
],
'admission_prelim_text' => [
'name' => 'admission_prelim_text',
'display_name' => (isset($this->enabled_field_config['admission_prelim_text']['display_name'])
? $this->enabled_field_config['admission_prelim_text']['display_name']
: 'admission_prelim_text'
),
'decorator_allowed' => true
],
'admission_disable_waitlist' => [
'name' => 'admission_disable_waitlist',
'display_name' => (isset($this->enabled_field_config['admission_disable_waitlist']['display_name'])
? $this->enabled_field_config['admission_disable_waitlist']['display_name']
: 'admission_disable_waitlist'
),
'decorator_allowed' => true
],
'admission_disable_waitlist_move' => [
'name' => 'admission_disable_waitlist_move',
'display_name' => (isset($this->enabled_field_config['admission_disable_waitlist_move']['display_name'])
? $this->enabled_field_config['admission_disable_waitlist_move']['display_name']
: 'admission_disable_waitlist_move'
),
'decorator_allowed' => true
],
'visible' => [
'name' => 'visible',
'display_name' => (isset($this->enabled_field_config['visible']['display_name'])
? $this->enabled_field_config['visible']['display_name']
: 'visible'
),
'decorator_allowed' => true
],
'show_score' => [
'name' => 'show_score',
'display_name' => (isset($this->enabled_field_config['show_score']['display_name'])
? $this->enabled_field_config['show_score']['display_name']
: 'show_score'
),
'decorator_allowed' => true
],
'aux_lock_rule' => [
'name' => 'aux_lock_rule',
'display_name' => (isset($this->enabled_field_config['aux_lock_rule']['display_name'])
? $this->enabled_field_config['aux_lock_rule']['display_name']
: 'aux_lock_rule'
),
'decorator_allowed' => true
],
'aux_lock_rule_forced' => [
'name' => 'aux_lock_rule_forced',
'display_name' => (isset($this->enabled_field_config['aux_lock_rule_forced']['display_name'])
? $this->enabled_field_config['aux_lock_rule_forced']['display_name']
: 'aux_lock_rule_forced'
),
'decorator_allowed' => true
],
'lock_rule' => [
'name' => 'lock_rule',
'display_name' => (isset($this->enabled_field_config['lock_rule']['display_name'])
? $this->enabled_field_config['lock_rule']['display_name']
: 'lock_rule'
),
'decorator_allowed' => true
],
'admission_waitlist_max' => [
'name' => 'admission_waitlist_max',
'display_name' => (isset($this->enabled_field_config['admission_waitlist_max']['display_name'])
? $this->enabled_field_config['admission_waitlist_max']['display_name']
: 'admission_waitlist_max'
),
'decorator_allowed' => true
],
'completion' => [
'name' => 'completion',
'display_name' => (isset($this->enabled_field_config['completion']['display_name'])
? $this->enabled_field_config['completion']['display_name']
: 'completion'
),
'decorator_allowed' => true
]
];
}
/**
* @inheritDoc
*/
public function getData(): array
{
$semester = $this->config->getParameter('semester_id')
? \Semester::find($this->config->getParameter('semester_id'))
: \Semester::findCurrent();
if (!$semester) {
return [];
}
$institute_id = $this->config->getParameter('institute_id');
$institute = null;
if ($institute_id) {
$institute = \Institute::find($institute_id);
}
$courses = [];
if ($institute) {
$courses = \Course::findBySQL(
'INNER JOIN `seminar_inst` USING (`seminar_id`)
INNER JOIN `semester_courses`
ON `seminare`.`seminar_id` = `semester_courses`.`course_id`
WHERE `seminar_inst`.`institut_id` = :institute_id
AND `semester_id` = :semester_id',
[
'institute_id' => $institute->id,
'semester_id' => $semester->id
]
);
} else {
$courses = \Course::findBySQL(
'INNER JOIN `semester_courses`
ON `seminare`.`seminar_id` = `semester_courses`.`course_id`
WHERE `semester_id` = :semester_id',
[
'semester_id' => $semester->id
]
);
}
if (!$courses) {
return [];
}
$with_course_id = array_key_exists('course_id', $this->enabled_field_config);
$with_name = array_key_exists('name', $this->enabled_field_config);
$with_full_name = array_key_exists('full_name', $this->enabled_field_config);
$with_number = array_key_exists('number', $this->enabled_field_config);
$with_course_type = array_key_exists('course_type', $this->enabled_field_config);
$with_subtitle = array_key_exists('subtitle', $this->enabled_field_config);
$with_description = array_key_exists('description', $this->enabled_field_config);
$with_parent_course_id = array_key_exists('parent_course_id', $this->enabled_field_config);
$with_home_institute_id = array_key_exists('home_institute_id', $this->enabled_field_config);
$with_home_institute_name = array_key_exists('home_institute_name', $this->enabled_field_config);
$with_institute_ids = array_key_exists('institute_ids', $this->enabled_field_config);
$with_institute_names = array_key_exists('institute_names', $this->enabled_field_config);
$with_study_area_ids = array_key_exists('study_area_ids', $this->enabled_field_config);
$with_study_area_names = array_key_exists('study_area_names', $this->enabled_field_config);
$with_location = array_key_exists('location', $this->enabled_field_config);
$with_start_semester_id = array_key_exists('start_semester_id', $this->enabled_field_config);
$with_end_semester_id = array_key_exists('end_semester_id', $this->enabled_field_config);
$with_read_access = array_key_exists('read_access', $this->enabled_field_config);
$with_write_access = array_key_exists('write_access', $this->enabled_field_config);
$with_participation_notes = array_key_exists('participation_notes', $this->enabled_field_config);
$with_requirements = array_key_exists('requirements', $this->enabled_field_config);
$with_learning_organisation = array_key_exists('learning_organisation', $this->enabled_field_config);
$with_exam_details = array_key_exists('exam_details', $this->enabled_field_config);
$with_ects = array_key_exists('ects', $this->enabled_field_config);
$with_admission_turnout = array_key_exists('admission_turnout', $this->enabled_field_config);
$with_admission_binding = array_key_exists('admission_binding', $this->enabled_field_config);
$with_admission_prelim = array_key_exists('admission_prelim', $this->enabled_field_config);
$with_admission_prelim_text = array_key_exists('admission_prelim_text', $this->enabled_field_config);
$with_admission_disable_waitlist = array_key_exists('admission_disable_waitlist', $this->enabled_field_config);
$with_admission_disable_waitlist_move = array_key_exists('admission_disable_waitlist_move', $this->enabled_field_config);
$with_visible = array_key_exists('visible', $this->enabled_field_config);
$with_show_score = array_key_exists('show_score', $this->enabled_field_config);
$with_aux_lock_rule = array_key_exists('aux_lock_rule', $this->enabled_field_config);
$with_aux_lock_rule_forced = array_key_exists('aux_lock_rule_forced', $this->enabled_field_config);
$with_lock_rule = array_key_exists('lock_rule', $this->enabled_field_config);
$with_admission_waitlist_max = array_key_exists('admission_waitlist_max', $this->enabled_field_config);
$with_completion = array_key_exists('completion', $this->enabled_field_config);
$data = [];
foreach ($courses as $course) {
$row = [];
if ($with_course_id) {
$row['course_id'] = $course->id;
}
if ($with_name) {
$row['name'] = $course->name;
}
if ($with_full_name) {
$row['full_name'] = $course->getFullName();
}
if ($with_number) {
$row['number'] = $course->veranstaltungsnummer;
}
if ($with_course_type) {
$row['course_type'] = $course->status;
}
if ($with_subtitle) {
$row['subtitle'] = $course->untertitel;
}
if ($with_description) {
$row['description'] = $course->description;
}
if ($with_parent_course_id) {
$row['parent_course_id'] = $course->parent_course;
}
if ($with_home_institute_id || $with_home_institute_name) {
$institute = $course->home_institut;
if ($institute) {
if ($with_home_institute_id) {
$row['home_institute_id'] = $institute->id;
}
if ($with_home_institute_name) {
$row['home_institute_name'] = $institute->name;
}
} else {
if ($with_home_institute_id) {
$row['home_institute_id'] = '';
}
if ($with_home_institute_name) {
$row['home_institute_name'] = '';
}
}
}
if ($with_institute_ids || $with_institute_names) {
$institute_ids = [];
$institute_names = [];
foreach ($course->institutes->orderBy('name ASC') as $institute) {
if ($with_institute_ids) {
$institute_ids[] = $institute->id;
}
if ($with_institute_names) {
$institute_names[] = $institute->name;
}
}
if ($with_institute_ids) {
$row['institute_ids'] = implode(',', $institute_ids);
}
if ($with_institute_names) {
$row['institute_names'] = implode(', ', $institute_names);
}
}
if ($with_study_area_ids || $with_study_area_names) {
$study_area_ids = [];
$study_area_names = [];
foreach ($course->study_areas->orderBy('name ASC') as $study_area) {
if ($with_study_area_ids) {
$study_area_ids[] = $study_area->id;
}
if ($with_study_area_names) {
$study_area_names[] = $study_area->name;
}
}
if ($with_study_area_ids) {
$row['study_area_ids'] = implode(',', $study_area_ids);
}
if ($with_study_area_names) {
$row['study_area_names'] = implode(', ', $study_area_names);
}
}
if ($with_location) {
$row['location'] = $course->ort;
}
if ($with_start_semester_id) {
$row['start_semester_id'] = $course->getStartSemester()->id ?? '';
}
if ($with_end_semester_id) {
$row['end_semester_id'] = $course->getEndSemester()->id ?? '';
}
if ($with_read_access) {
$row['read_access'] = $course->lesezugriff;
}
if ($with_write_access) {
$row['write_access'] = $course->schreibzugriff;
}
if ($with_participation_notes) {
$row['participation_notes'] = $course->teilnehmer;
}
if ($with_requirements) {
$row['requirements'] = $course->vorrausetzungen;
}
if ($with_learning_organisation) {
$row['learning_organisation'] = $course->lernorga;
}
if ($with_exam_details) {
$row['exam_details'] = $course->leistungsnachweis;
}
if ($with_ects) {
$row['ects'] = $course->ects;
}
if ($with_admission_turnout) {
$row['admission_turnout'] = $course->admission_turnout;
}
if ($with_admission_binding) {
$row['admission_binding'] = $course->admission_binding;
}
if ($with_admission_prelim) {
$row['admission_prelim'] = $course->admission_prelim;
}
if ($with_admission_prelim_text) {
$row['admission_prelim_text'] = $course->admission_prelim_txt;
}
if ($with_admission_disable_waitlist) {
$row['admission_disable_waitlist'] = $course->admission_disable_waitlist;
}
if ($with_admission_disable_waitlist_move) {
$row['admission_disable_waitlist_move'] = $course->admission_disable_waitlist_move;
}
if ($with_visible) {
$row['visible'] = $course->visible;
}
if ($with_show_score) {
$row['show_score'] = $course->show_score;
}
if ($with_aux_lock_rule) {
$row['aux_lock_rule'] = $course->aux_lock_rule;
}
if ($with_aux_lock_rule_forced) {
$row['aux_lock_rule_forced'] = $course->aux_lock_rule_forced;
}
if ($with_lock_rule) {
$row['lock_rule'] = $course->lock_rule;
}
if ($with_admission_waitlist_max) {
$row['admission_waitlist_max'] = $course->admission_waitlist_max;
}
if ($with_completion) {
$row['completion'] = $course->completion;
}
$data[] = $row;
}
return $data;
}
}
pluginname=Flexexport pluginname=Flexexport
pluginclassname=Flexexport pluginclassname=Flexexport
origin=data-quest origin=data-quest
version=0.7.5 version=0.8-rc1
studipMinVersion=4.5 studipMinVersion=4.5
studipMaxVersion=5.2.99 studipMaxVersion=5.2.99
description=Das Flexexport-Plugin erlaubt den Export von Stud.IP-Inhalten in verschiedenen Formaten. description=Das Flexexport-Plugin erlaubt den Export von Stud.IP-Inhalten in verschiedenen Formaten.
<label>
<?= dgettext('Flexexport', 'Semester') ?>
<select name="<?= htmlReady($config_prefix ?: 'CONFIG_PREFIX') ?>[semester_id]">
<? foreach ($available_semesters as $semester) : ?>
<option value="<?= htmlReady($semester->id) ?>"
<?= $semester['semester_id'] == $semester_id ? 'selected' : '' ?>>
<?= htmlReady($semester['name']) ?>
</option>
<? endforeach ?>
</select>
</label>
<label>
<?= dgettext('Flexexport', 'Beschränkung auf eine Einrichtung') ?>
<select name="<?= htmlReady($config_prefix ?: 'CONFIG_PREFIX') ?>[institute_id]">
<option value="" <?= !$institute_id ? 'selected' : '' ?>>
<?= dgettext('Flexexport', 'Keine Beschränkung') ?>
</option>
<? foreach ($available_institutes as $institute) : ?>
<option value="<?= htmlReady($institute['Institut_id']) ?>"
<?= $institute['Institut_id'] == $institute_id ? 'selected' : '' ?>>
<?= htmlReady($institute['Name']) ?>
</option>
<? endforeach ?>
</select>
</label>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment