Exemple #1
0
 /**
  * Export action
  */
 public function export_csv_action()
 {
     $filter_config = $this->getFilterConfig();
     unset($filter_config['contents']);
     if (empty($filter_config)) {
         return;
     }
     $sortby = $GLOBALS['user']->cfg->getValue('MEINE_SEMINARE_SORT');
     $config_my_course_type_filter = $GLOBALS['user']->cfg->getValue('MY_COURSES_TYPE_FILTER');
     $courses = $this->getCourses(array('sortby' => $sortby, 'sortFlag' => 'asc', 'typeFilter' => $config_my_course_type_filter, 'view_filter' => $filter_config));
     $view_filters = $this->getViewFilters();
     $data = array();
     foreach ($courses as $course_id => $course) {
         $sem = new Seminar(Course::buildExisting($course));
         $row = array();
         if (in_array('number', $filter_config)) {
             $row['number'] = $course['VeranstaltungsNummer'];
         }
         if (in_array('name', $filter_config)) {
             $row['name'] = $course['Name'];
         }
         if (in_array('type', $filter_config)) {
             $row['type'] = sprintf('%s: %s', $sem->getSemClass()['name'], $sem->getSemType()['name']);
         }
         if (in_array('room_time', $filter_config)) {
             $_room = $sem->getDatesExport(array('semester_id' => $this->semester->id, 'show_room' => true));
             $row['room_time'] = $_room ?: _('nicht angegeben');
         }
         if (in_array('teachers', $filter_config)) {
             $row['teachers'] = implode(', ', array_map(function ($d) {
                 return $d['fullname'];
             }, $course['dozenten']));
         }
         if (in_array('members', $filter_config)) {
             $row['members'] = $course['teilnehmer'];
         }
         if (in_array('waiting', $filter_config)) {
             $row['waiting'] = $course['waiting'];
         }
         if (in_array('preliminary', $filter_config)) {
             $row['preliminary'] = $course['prelim'];
         }
         $data[$course_id] = $row;
     }
     $captions = array();
     foreach ($filter_config as $index) {
         $captions[$index] = $view_filters[$index];
     }
     $tmpname = md5(uniqid('Veranstaltungsexport'));
     if (array_to_csv($data, $GLOBALS['TMP_PATH'] . '/' . $tmpname, $captions)) {
         $this->redirect(GetDownloadLink($tmpname, 'Veranstaltungen_Export.csv', 4, 'force'));
         return;
     }
 }