Esempio n. 1
0
 /**
  * Gets courses fulfilling the given condition.
  *
  * @param String $seminare_condition SQL condition
  */
 function get_courses($seminare_condition)
 {
     global $perm, $user;
     list($institut_id, $all) = explode('_', $this->current_institut_id);
     // Prepare count statements
     $query = "SELECT count(*)\n                FROM seminar_user\n                WHERE seminar_id = ? AND status IN ('user', 'autor')";
     $count0_statement = DBManager::get()->prepare($query);
     $query = "SELECT SUM(status = 'accepted') AS count2,\n                SUM(status = 'awaiting') AS count3\n                FROM admission_seminar_user\n                WHERE seminar_id = ?\n                GROUP BY seminar_id";
     $count1_statement = DBManager::get()->prepare($query);
     $parameters = array();
     $sql = "SELECT seminare.seminar_id,seminare.Name as course_name,seminare.VeranstaltungsNummer as course_number,\n                admission_prelim, admission_turnout,seminar_courseset.set_id\n                FROM seminar_courseset\n                INNER JOIN courseset_rule csr ON csr.set_id=seminar_courseset.set_id AND csr.type='ParticipantRestrictedAdmission'\n                INNER JOIN seminare ON seminar_courseset.seminar_id=seminare.seminar_id\n                ";
     if ($institut_id == 'all' && $perm->have_perm('root')) {
         $sql .= "WHERE 1 {$seminare_condition} ";
     } elseif ($all == 'all') {
         $sql .= "INNER JOIN Institute USING (Institut_id)\n            WHERE Institute.fakultaets_id = ? {$seminare_condition}\n            ";
         $parameters[] = $institut_id;
     } else {
         $sql .= "WHERE seminare.Institut_id = ? {$seminare_condition}\n            ";
         $parameters[] = $institut_id;
     }
     $sql .= "GROUP BY seminare.Seminar_id ORDER BY seminar_courseset.set_id, seminare.Name";
     $statement = DBManager::get()->prepare($sql);
     $statement->execute($parameters);
     while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
         $seminar_id = $row['seminar_id'];
         $ret[$seminar_id] = $row;
         $count0_statement->execute(array($seminar_id));
         $count = $count0_statement->fetchColumn();
         $ret[$seminar_id]['count_teilnehmer'] = $count;
         $count1_statement->execute(array($seminar_id));
         $counts = $count1_statement->fetch(PDO::FETCH_ASSOC);
         $ret[$seminar_id]['count_prelim'] = (int) $counts['count2'];
         $ret[$seminar_id]['count_waiting'] = (int) $counts['count3'];
         $cs = new CourseSet($row['set_id']);
         $ret[$seminar_id]['cs_name'] = $cs->getName();
         $ret[$seminar_id]['distribution_time'] = $cs->getSeatDistributionTime();
         if ($ta = $cs->getAdmissionRule('TimedAdmission')) {
             $ret[$seminar_id]['start_time'] = $ta->getStartTime();
             $ret[$seminar_id]['end_time'] = $ta->getEndTime();
         }
         if (!$cs->hasAlgorithmRun()) {
             $ret[$seminar_id]['count_claiming'] = $cs->getNumApplicants();
         }
     }
     return $ret;
 }
Esempio n. 2
0
 public function execute($last_result, $parameters = array())
 {
     $verbose = $parameters['verbose'];
     $sets = DbManager::get()->fetchFirst("SELECT DISTINCT cr.set_id FROM courseset_rule cr INNER JOIN coursesets USING(set_id)\n                          WHERE type = 'ParticipantRestrictedAdmission' AND algorithm_run = 0");
     if (count($sets)) {
         if ($verbose) {
             echo date('r') . ' - Starting seat distribution ' . chr(10);
             $old_logger = Log::get()->getHandler();
             $old_log_level = Log::get()->getLogLevel();
             @mkdir($GLOBALS['TMP_PATH'] . '/seat_distribution_logs');
             $logfile = $GLOBALS['TMP_PATH'] . '/seat_distribution_logs/' . date('Y-m-d-H-i') . '_seat_distribution.log';
             if (is_dir($GLOBALS['TMP_PATH'] . '/seat_distribution_logs')) {
                 Log::get()->setHandler($logfile);
                 Log::get()->setLogLevel(Log::DEBUG);
                 echo 'logging to ' . $logfile . chr(10);
             } else {
                 echo 'could not create directory ' . $GLOBALS['TMP_PATH'] . '/seat_distribution_logs' . chr(10);
             }
         }
         foreach ($sets as $set_id) {
             $courseset = new CourseSet($set_id);
             if ($courseset->isSeatDistributionEnabled() && !$courseset->hasAlgorithmRun() && $courseset->getSeatDistributionTime() < time()) {
                 if ($verbose) {
                     echo ++$i . ' ' . $courseset->getId() . ' : ' . $courseset->getName() . chr(10);
                     $applicants = AdmissionPriority::getPriorities($set_id);
                     $courses = SimpleCollection::createFromArray(Course::findMany($courseset->getCourses()))->toGroupedArray('seminar_id', words('name veranstaltungsnummer'));
                     $captions = array(_("Nachname"), _("Vorname"), _("Nutzername"), _('Nutzer-ID'), _('Veranstaltung-ID'), _("Veranstaltung"), _("Nummer"), _("Priorität"));
                     $data = array();
                     $users = User::findEachMany(function ($user) use($courses, $applicants, &$data) {
                         $app_courses = $applicants[$user->id];
                         asort($app_courses);
                         foreach ($app_courses as $course_id => $prio) {
                             $row = array();
                             $row[] = $user->nachname;
                             $row[] = $user->vorname;
                             $row[] = $user->username;
                             $row[] = $user->id;
                             $row[] = $course_id;
                             $row[] = $courses[$course_id]['name'];
                             $row[] = $courses[$course_id]['veranstaltungsnummer'];
                             $row[] = $prio;
                             $data[] = $row;
                         }
                     }, array_keys($applicants), 'ORDER BY Nachname');
                     $applicants_file = $GLOBALS['TMP_PATH'] . '/seat_distribution_logs/applicants_' . $set_id . '.csv';
                     if (array_to_csv($data, $applicants_file, $captions)) {
                         echo 'applicants written to ' . $applicants_file . chr(10);
                     }
                 }
                 $courseset->distributeSeats();
             }
         }
         if ($verbose) {
             Log::get()->setHandler($old_logger);
             Log::get()->setLogLevel($old_log_level);
         }
     } else {
         if ($verbose) {
             echo date('r') . ' - Nothing to do' . chr(10);
         }
     }
 }