Exemplo n.º 1
0
 function get_seminars_by_sem_tree_id_action($api_key, $sem_tree_id, $term_id)
 {
     $seminar_infos = array();
     $seminar_ids = StudipLectureTreeHelper::get_seminars_by_sem_tree_id($sem_tree_id, $term_id);
     foreach ($seminar_ids as $seminar_id) {
         $sem_obj = new Seminar($seminar_id['seminar_id']);
         $lecturers = StudipSeminarHelper::get_participants($seminar_id['seminar_id'], 'dozent');
         foreach ($lecturers as $lecturer) {
             $lecturers[] = Studip_User::find_by_user_name($lecturer);
         }
         $seminar_info = new Studip_Seminar_Info();
         $seminar_info->title = $sem_obj->getName();
         $seminar_info->lecturers = $lecturers;
         $seminar_info->turnus = $sem_obj->getDatesTemplate('dates/seminar_export', array('semester_id' => $term_id));
         $seminar_info->lecture_number = $sem_obj->seminar_number;
         $seminar_infos[] = $seminar_info;
     }
     return $seminar_infos;
 }
Exemplo n.º 2
0
/**
* Exports lecture-data.
*
* This function gets the data of the lectures at an institute and writes it into $data_object.
* It calls output_data afterwards.
*
* @access   public
* @param        string  $inst_id    Stud.IP-inst_id for export
* @param        string  $ex_sem_id  allows to choose if only a specific lecture is to be exported
*/
function export_sem($inst_id, $ex_sem_id = 'all')
{
    global $range_id, $xml_file, $o_mode, $xml_names_lecture, $xml_groupnames_lecture, $object_counter, $SEM_TYPE, $SEM_CLASS, $filter, $ex_sem, $ex_sem_class, $ex_person_details, $persons;
    $ex_only_homeinst = Request::int('ex_only_homeinst', 0);
    // Prepare user count statement
    $query = "SELECT COUNT(user_id)\n              FROM seminar_user\n              WHERE seminar_id = ? AND status = 'autor'";
    $count_statement = DBManager::get()->prepare($query);
    // Prepare inner statement
    $query = "SELECT seminar_user.position,\n                     auth_user_md5.user_id, auth_user_md5.username, auth_user_md5.Vorname, auth_user_md5.Nachname,\n                     user_info.title_front, user_info.title_rear\n              FROM seminar_user\n              LEFT JOIN user_info USING (user_id)\n              LEFT JOIN auth_user_md5 USING (user_id)\n              WHERE seminar_user.status = 'dozent' AND seminar_user.Seminar_id = ?\n              ORDER BY seminar_user.position";
    $inner_statement = DBManager::get()->prepare($query);
    // Prepare (build) and execute outmost query
    switch ($filter) {
        case "seminar":
            $order = " seminare.Name";
            break;
        case "status":
            $order = "seminare.status, seminare.Name";
            $group = "FIRSTGROUP";
            $group_tab_zelle = "status";
            $do_group = true;
            break;
        default:
            $order = "seminare.status, seminare.Name";
            $group = "FIRSTGROUP";
            $group_tab_zelle = "status";
            $do_group = true;
    }
    $parameters = array();
    if (isset($ex_sem) && ($semester = Semester::find($ex_sem))) {
        $addquery = " AND seminare.start_time <= :begin AND (:begin <= (seminare.start_time + seminare.duration_time) OR seminare.duration_time = -1) ";
        $parameters[':begin'] = $semester->beginn;
    }
    if ($ex_sem_id != 'all') {
        if ($ex_sem_id == 'root') {
            $addquery .= " AND EXISTS (SELECT * FROM seminar_sem_tree WHERE seminar_sem_tree.seminar_id = seminare.Seminar_id) ";
        } else {
            if (!is_array($ex_sem_id)) {
                $ex_sem_id = array($ex_sem_id);
            }
            $ex_sem_id = array_flip($ex_sem_id);
        }
    }
    if (!$GLOBALS['perm']->have_perm('root') && !$GLOBALS['perm']->have_studip_perm('admin', $inst_id)) {
        $addquery .= " AND visible = 1 ";
    }
    if (count($ex_sem_class) > 0) {
        $allowed_sem_types = array();
        foreach (array_keys($ex_sem_class) as $semclassid) {
            $allowed_sem_types += array_keys(SeminarCategories::get($semclassid)->getTypes());
        }
        $addquery .= " AND seminare.status IN (:status) ";
        $parameters[':status'] = $allowed_sem_types;
    } else {
        $addquery .= " AND seminare.status NOT IN (:status) ";
        $parameters[':status'] = studygroup_sem_types() ?: '';
    }
    if ($ex_only_homeinst) {
        $query = "SELECT seminare.*,Seminar_id as seminar_id, Institute.Name AS heimateinrichtung\n                  FROM seminare\n                  LEFT JOIN Institute USING (Institut_id)\n                  WHERE Institut_id = :institute_id {$addquery}\n                  ORDER BY " . $order;
        $parameters[':institute_id'] = $inst_id;
    } else {
        $query = "SELECT seminare.*,Seminar_id as seminar_id, Institute.Name AS heimateinrichtung\n                  FROM seminar_inst\n                  LEFT JOIN seminare USING (Seminar_id)\n                  LEFT JOIN Institute ON seminare.Institut_id = Institute.Institut_id\n                  WHERE seminar_inst.Institut_id = :institute_id {$addquery}\n                  ORDER BY " . $order;
        $parameters[':institute_id'] = $inst_id;
    }
    $statement = DBManager::get()->prepare($query);
    $statement->execute($parameters);
    $data = $statement->fetchAll(PDO::FETCH_ASSOC);
    $data_object .= xml_open_tag($xml_groupnames_lecture['group']);
    foreach ($data as $row) {
        if (is_array($ex_sem_id) && !isset($ex_sem_id[$row['seminar_id']])) {
            continue;
        }
        $group_string = '';
        if ($do_group && $group != $row[$group_tab_zelle]) {
            if ($group != 'FIRSTGROUP') {
                $group_string .= xml_close_tag($xml_groupnames_lecture['subgroup1']);
            }
            if ($group_tab_zelle == 'status') {
                $group_string .= xml_open_tag($xml_groupnames_lecture['subgroup1'], $SEM_TYPE[$row[$group_tab_zelle]]['name']);
            } else {
                $group_string .= xml_open_tag($xml_groupnames_lecture['subgroup1'], $row[$group_tab_zelle]);
            }
            $group = $row[$group_tab_zelle];
            if ($do_subgroup && $subgroup == $row[$subgroup_tab_zelle]) {
                $subgroup = "NEXTGROUP";
            }
        }
        if ($do_subgroup && $subgroup != $row[$subgroup_tab_zelle]) {
            if ($subgroup != 'FIRSTGROUP') {
                $group_string = xml_close_tag($xml_groupnames_lecture['subgroup2']) . $group_string;
            }
            $group_string .= xml_open_tag($xml_groupnames_lecture['subgroup2'], $row[$subgroup_tab_zelle]);
            $subgroup = $row[$subgroup_tab_zelle];
        }
        $data_object .= $group_string;
        $object_counter += 1;
        $data_object .= xml_open_tag($xml_groupnames_lecture['object'], $row['seminar_id']);
        $sem_obj = new Seminar($row['seminar_id']);
        while (list($key, $val) = each($xml_names_lecture)) {
            if ($val == '') {
                $val = $key;
            }
            if ($key == 'status') {
                $data_object .= xml_tag($val, $SEM_TYPE[$row[$key]]['name']);
            } elseif ($key == 'ort') {
                $data_object .= xml_tag($val, $sem_obj->getDatesTemplate('dates/seminar_export_location'));
            } elseif ($key == 'bereich' && $SEM_CLASS[$SEM_TYPE[$row['status']]['class']]['bereiche']) {
                $data_object .= xml_open_tag($xml_groupnames_lecture['childgroup3']);
                $pathes = get_sem_tree_path($row['seminar_id']);
                if (is_array($pathes)) {
                    foreach ($pathes as $path_name) {
                        $data_object .= xml_tag($val, $path_name);
                    }
                } else {
                    $data_object .= xml_tag($val, 'n.a.');
                }
                $data_object .= xml_close_tag($xml_groupnames_lecture['childgroup3']);
            } elseif ($key == 'admission_turnout') {
                $data_object .= xml_open_tag($val, $row['admission_type'] ? _('max.') : _('erw.'));
                $data_object .= $row[$key];
                $data_object .= xml_close_tag($val);
            } elseif ($key == 'teilnehmer_anzahl_aktuell') {
                $count_statement->execute(array($row['seminar_id']));
                $count = $count_statement->fetchColumn();
                $count_statement->closeCursor();
                $data_object .= xml_tag($val, $count);
            } elseif ($key == 'metadata_dates') {
                $data_object .= xml_open_tag($xml_groupnames_lecture['childgroup1']);
                $vorb = vorbesprechung($row['seminar_id'], 'export');
                if ($vorb != false) {
                    $data_object .= xml_tag($val[0], $vorb);
                }
                if (($first_date = SeminarDB::getFirstDate($row['seminar_id'])) && count($first_date)) {
                    $really_first_date = new SingleDate($first_date[0]);
                    $data_object .= xml_tag($val[1], $really_first_date->getDatesExport());
                }
                $data_object .= xml_tag($val[2], $sem_obj->getDatesExport());
                $data_object .= xml_close_tag($xml_groupnames_lecture["childgroup1"]);
            } elseif ($key == 'Institut_id') {
                $data_object .= xml_tag($val, $row['heimateinrichtung'], array('key' => $row[$key]));
            } elseif ($row[$key] != '') {
                $data_object .= xml_tag($val, $row[$key]);
            }
        }
        $data_object .= "<" . $xml_groupnames_lecture['childgroup2'] . ">\n";
        $inner_statement->execute(array($row['seminar_id']));
        while ($inner = $inner_statement->fetch(PDO::FETCH_ASSOC)) {
            if ($ex_person_details) {
                $persons[$inner['user_id']] = true;
            }
            $content_string = $inner['Vorname'] . ' ' . $inner['Nachname'];
            if ($inner['title_front'] != '') {
                $content_string = $inner['title_front'] . ' ' . $content_string;
            }
            if ($inner['title_rear'] != '') {
                $content_string .= ', ' . $inner['title_rear'];
            }
            $data_object .= xml_tag($xml_groupnames_lecture['childobject2'], $content_string, array('key' => $inner['username']));
        }
        $data_object .= xml_close_tag($xml_groupnames_lecture['childgroup2']);
        // freie Datenfelder ausgeben
        $data_object .= export_datafields($row['seminar_id'], $xml_groupnames_lecture['childgroup4'], $xml_groupnames_lecture['childobject4'], 'sem', $row['status']);
        $data_object .= xml_close_tag($xml_groupnames_lecture['object']);
        reset($xml_names_lecture);
        output_data($data_object, $o_mode);
        $data_object = '';
    }
    if ($do_subgroup && $subgroup != 'FIRSTGROUP') {
        $data_object .= xml_close_tag($xml_groupnames_lecture['subgroup2']);
    }
    if ($do_group && $group != 'FIRSTGROUP') {
        $data_object .= xml_close_tag($xml_groupnames_lecture['subgroup1']);
    }
    $data_object .= xml_close_tag($xml_groupnames_lecture['group']);
    output_data($data_object, $o_mode);
}