Exemplo n.º 1
0
 /**
  * Seminar group administration - cluster your seminars by colors or
  * change grouping mechanism
  */
 public function groups_action($sem = null, $studygroups = false)
 {
     if ($GLOBALS['perm']->have_perm('admin')) {
         throw new AccessDeniedException();
     }
     $this->title = _('Meine Veranstaltungen') . ' - ' . _('Farbgruppierungen');
     if (Request::isXhr()) {
         $this->set_layout(null);
         $this->response->add_header('Content-Type', 'text/html;charset=Windows-1252');
         header('X-Title: ' . $this->title);
     } else {
         PageLayout::setTitle($this->title);
         PageLayout::setHelpKeyword('Basis.VeranstaltungenOrdnen');
         Navigation::activateItem('/browse/my_courses/list');
     }
     $this->current_semester = $sem ?: Semester::findCurrent()->semester_id;
     $this->semesters = SemesterData::GetSemesterArray();
     $forced_grouping = Config::get()->MY_COURSES_FORCE_GROUPING;
     if ($forced_grouping == 'not_grouped') {
         $forced_grouping = 'sem_number';
     }
     $no_grouping_allowed = $forced_grouping == 'sem_number' || !in_array($forced_grouping, getValidGroupingFields());
     $group_field = $GLOBALS['user']->cfg->MY_COURSES_GROUPING ?: $forced_grouping;
     $groups = array();
     $add_fields = '';
     $add_query = '';
     if ($group_field == 'sem_tree_id') {
         $add_fields = ', sem_tree_id';
         $add_query = "LEFT JOIN seminar_sem_tree sst ON (sst.seminar_id=seminare.Seminar_id)";
     } else {
         if ($group_field == 'dozent_id') {
             $add_fields = ', su1.user_id as dozent_id';
             $add_query = "LEFT JOIN seminar_user as su1 ON (su1.seminar_id=seminare.Seminar_id AND su1.status='dozent')";
         }
     }
     $dbv = DbView::getView('sem_tree');
     $query = "SELECT seminare.VeranstaltungsNummer AS sem_nr, seminare.Name, seminare.Seminar_id,\n                         seminare.status AS sem_status, seminar_user.gruppe, seminare.visible,\n                         {$dbv->sem_number_sql} AS sem_number,\n                         {$dbv->sem_number_end_sql} AS sem_number_end {$add_fields}\n                  FROM seminar_user\n                  JOIN semester_data sd\n                  LEFT JOIN seminare USING (Seminar_id)\n                  {$add_query}\n                  WHERE seminar_user.user_id = ?";
     if (Config::get()->MY_COURSES_ENABLE_STUDYGROUPS && !$studygroups) {
         $query .= " AND seminare.status != 99";
     }
     if ($studygroups) {
         $query .= " AND seminare.status = 99";
     }
     if (get_config('DEPUTIES_ENABLE')) {
         $query .= " UNION " . getMyDeputySeminarsQuery('gruppe', $dbv->sem_number_sql, $dbv->sem_number_end_sql, $add_fields, $add_query);
     }
     $query .= " ORDER BY sem_nr ASC";
     $statement = DBManager::get()->prepare($query);
     $statement->execute(array($GLOBALS['user']->id));
     while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
         $my_sem[$row['Seminar_id']] = array('obj_type' => 'sem', 'sem_nr' => $row['sem_nr'], 'name' => $row['Name'], 'visible' => $row['visible'], 'gruppe' => $row['gruppe'], 'sem_status' => $row['sem_status'], 'sem_number' => $row['sem_number'], 'sem_number_end' => $row['sem_number_end']);
         if ($group_field) {
             fill_groups($groups, $row[$group_field], array('seminar_id' => $row['Seminar_id'], 'sem_nr' => $row['sem_nr'], 'name' => $row['Name'], 'gruppe' => $row['gruppe']));
         }
     }
     if ($group_field == 'sem_number') {
         correct_group_sem_number($groups, $my_sem);
     } else {
         add_sem_name($my_sem);
     }
     sort_groups($group_field, $groups);
     // Ensure that a seminar is never in multiple groups
     $sem_ids = array();
     foreach ($groups as $group_id => $seminars) {
         foreach ($seminars as $index => $seminar) {
             if (in_array($seminar['seminar_id'], $sem_ids)) {
                 unset($seminars[$index]);
             } else {
                 $sem_ids[] = $seminar['seminar_id'];
             }
         }
         if (empty($seminars)) {
             unset($groups[$group_id]);
         } else {
             $groups[$group_id] = $seminars;
         }
     }
     $this->studygroups = $studygroups;
     $this->no_grouping_allowed = $no_grouping_allowed;
     $this->groups = $groups;
     $this->group_names = get_group_names($group_field, $groups);
     $this->group_field = $group_field;
     $this->my_sem = $my_sem;
 }
Exemplo n.º 2
0
/**
 *
 * @param unknown_type $groups
 * @param unknown_type $my_obj
 */
function correct_group_sem_number(&$groups, &$my_obj)
{
    if (is_array($groups) && is_array($my_obj)) {
        $sem_data = SemesterData::GetSemesterArray();
        //end($sem_data);
        //$max_sem = key($sem_data);
        foreach ($sem_data as $sem_key => $one_sem) {
            $current_sem = $sem_key;
            if (!$one_sem['past']) {
                break;
            }
        }
        if (isset($sem_data[$current_sem + 1])) {
            $max_sem = $current_sem + 1;
        } else {
            $max_sem = $current_sem;
        }
        foreach ($my_obj as $seminar_id => $values) {
            if ($values['obj_type'] == 'sem' && $values['sem_number'] != $values['sem_number_end']) {
                if ($values['sem_number_end'] == -1 && $values['sem_number'] < $current_sem) {
                    unset($groups[$values['sem_number']][$seminar_id]);
                    fill_groups($groups, $current_sem, array('seminar_id' => $seminar_id, 'name' => $values['name'], 'gruppe' => $values['gruppe']));
                    if (!count($groups[$values['sem_number']])) {
                        unset($groups[$values['sem_number']]);
                    }
                } else {
                    $to_sem = $values['sem_number_end'];
                    for ($i = $values['sem_number']; $i <= $to_sem; ++$i) {
                        fill_groups($groups, $i, array('seminar_id' => $seminar_id, 'name' => $values['name'], 'gruppe' => $values['gruppe']));
                    }
                }
                if ($GLOBALS['user']->cfg->getValue('SHOWSEM_ENABLE')) {
                    $sem_name = " (" . $sem_data[$values['sem_number']]['name'] . " - ";
                    $sem_name .= ($values['sem_number_end'] == -1 ? _("unbegrenzt") : $sem_data[$values['sem_number_end']]['name']) . ")";
                    $my_obj[$seminar_id]['name'] .= $sem_name;
                }
            }
        }
        return true;
    }
    return false;
}
Exemplo n.º 3
0
 /**
  * Display the notification settings of a user.
  */
 public function index_action()
 {
     $group_field = UserConfig::get($this->user->user_id)->MY_COURSES_GROUPING ?: 'not_grouped';
     $add_fields = $add_query = '';
     if ($group_field == 'sem_tree_id') {
         $add_fields = ',sem_tree_id';
         $add_query = "LEFT JOIN seminar_sem_tree sst ON (sst.seminar_id=seminare.Seminar_id)";
     } else {
         if ($group_field == 'dozent_id') {
             $add_fields = ', su1.user_id as dozent_id';
             $add_query = "LEFT JOIN seminar_user as su1 ON (su1.seminar_id=seminare.Seminar_id AND su1.status='dozent')";
         }
     }
     $dbv = DbView::getView('sem_tree');
     $query = "SELECT seminare.VeranstaltungsNummer AS sem_nr, seminare.Name, seminare.Seminar_id,\n                         seminare.status AS sem_status, seminar_user.gruppe, seminare.visible,\n                         {$dbv->sem_number_sql} AS sem_number, {$dbv->sem_number_end_sql} AS sem_number_end\n                         {$add_fields}\n                  FROM seminar_user\n                  LEFT JOIN seminare  USING (Seminar_id)\n                  {$add_query}\n                  WHERE seminar_user.user_id = ?";
     if (get_config('DEPUTIES_ENABLE')) {
         $query .= " UNION " . getMyDeputySeminarsQuery('notification', $dbv->sem_number_sql, $dbv->sem_number_end_sql, $add_fields, $add_query);
     }
     $query .= " ORDER BY sem_nr ASC";
     $statement = DBManager::get()->prepare($query);
     $statement->execute(array($this->user->user_id));
     $seminars = $statement->fetchAll(PDO::FETCH_ASSOC);
     if (!count($seminars)) {
         $message = sprintf(_('Sie haben zur Zeit keine Veranstaltungen belegt. Bitte nutzen Sie %s<b>Veranstaltung suchen / hinzufügen</b>%s um sch für Veranstaltungen anzumdelden.'), '<a href="' . URLHelper::getLink('dispatch.php/search/courses') . '">', '</a>');
         PageLayout::postMessage(MessageBox::info($message));
         $this->set_layout($GLOBALS['template_factory']->open('layouts/base_without_infobox'));
         $this->render_nothing();
         return;
     }
     $modules = new ModulesNotification();
     $enabled_modules = $modules->getGlobalEnabledNotificationModules('sem');
     $groups = array();
     $my_sem = array();
     foreach ($seminars as $seminar) {
         $my_sem[$seminar['Seminar_id']] = array('obj_type' => "sem", 'sem_nr' => $seminar['sem_nr'], 'name' => $seminar['Name'], 'visible' => $seminar['visible'], 'gruppe' => $seminar['gruppe'], 'sem_status' => $seminar['sem_status'], 'sem_number' => $seminar['sem_number'], 'sem_number_end' => $seminar['sem_number_end']);
         if ($group_field) {
             fill_groups($groups, $seminar[$group_field], array('seminar_id' => $seminar['Seminar_id'], 'sem_nr' => $seminar['sem_nr'], 'name' => $seminar['Name'], 'gruppe' => $seminar['gruppe']));
         }
     }
     if ($group_field == 'sem_number') {
         correct_group_sem_number($groups, $my_sem);
     } else {
         add_sem_name($my_sem);
     }
     sort_groups($group_field, $groups);
     $group_names = get_group_names($group_field, $groups);
     $notifications = $modules->getModuleNotification();
     $open = UserConfig::get($this->user->user_id)->MY_COURSES_OPEN_GROUPS;
     $checked = array();
     foreach ($groups as $group_id => $group_members) {
         if ($group_id !== 'not_grouped' && !isset($open[$group_id])) {
             continue;
         }
         foreach ($group_members as $member) {
             $checked[$member['seminar_id']] = array();
             foreach (array_values($enabled_modules) as $index => $m_data) {
                 $checked[$member['seminar_id']][$index] = $modules->isBit($notifications[$member['seminar_id']], $m_data['id']);
             }
             $checked[$member['seminar_id']]['all'] = count($enabled_modules) === count(array_filter($checked[$member['seminar_id']]));
         }
     }
     $this->modules = $enabled_modules;
     $this->groups = $groups;
     $this->group_names = $group_names;
     $this->group_field = $group_field;
     $this->open = $open;
     $this->seminars = $my_sem;
     $this->notifications = $modules->getModuleNotification();
     $this->checked = $checked;
 }