Esempio n. 1
0
 static function storeSingleDate($termin)
 {
     $table = 'termine';
     if ($termin->isExTermin()) {
         $table = 'ex_termine';
         $query = "SELECT assign_id FROM resources_assign WHERE assign_user_id = ?";
         $statement = DBManager::get()->prepare($query);
         $statement->execute(array($termin->getTerminID()));
         $assign_id = $statement->fetchColumn();
         if ($assign_id) {
             // delete resource-request, if any
             if ($request_id = self::getRequestID($termin->getTerminID())) {
                 $rr = new RoomRequest($request_id);
                 $rr->delete();
             }
             // delete resource assignment, if any
             AssignObject::Factory($assign_id)->delete();
         }
     }
     $issueIDs = $termin->getIssueIDs();
     if (is_array($issueIDs)) {
         $query = "REPLACE INTO themen_termine (termin_id, issue_id)\n                      VALUES (?, ?)";
         $statement = DBManager::get()->prepare($query);
         foreach ($issueIDs as $val) {
             $statement->execute(array($termin->getTerminID(), $val));
         }
     }
     if ($termin->isUpdate()) {
         $query = "UPDATE :table\n                      SET metadate_id = :metadate_id, date_typ = :date_typ,\n                          date = :date, end_time = :end_time,\n                          range_id = :range_id, autor_id = :autor_id,\n                          raum = :raum, content = :content\n                      WHERE termin_id = :termin_id";
         $statement = DBManager::get()->prepare($query);
         $statement->bindValue(':table', $table, StudipPDO::PARAM_COLUMN);
         $statement->bindValue(':metadate_id', $termin->getMetaDateID() ?: null);
         $statement->bindValue(':date_typ', $termin->getDateType());
         $statement->bindValue(':date', $termin->getStartTime());
         $statement->bindValue(':end_time', $termin->getEndTime());
         $statement->bindValue(':range_id', $termin->getRangeID());
         $statement->bindValue(':autor_id', $termin->getAuthorID());
         $statement->bindValue(':raum', $termin->getFreeRoomText());
         $statement->bindValue(':content', $termin->getComment());
         $statement->bindValue(':termin_id', $termin->getTerminID());
         $statement->execute();
         if ($statement->rowCount() > 0) {
             $query = "UPDATE :table SET chdate = :chdate WHERE termin_id = :termin_id";
             $statement = DBManager::get()->prepare($query);
             $statement->bindValue(':table', $table, StudipPDO::PARAM_COLUMN);
             $statement->bindValue(':chdate', $termin->getChDate());
             $statement->bindValue(':termin_id', $termin->getTerminID());
             $statement->execute();
         }
     } else {
         $query = "REPLACE INTO :table\n                        (metadate_id, date_typ, date, end_time, mkdate, chdate,\n                         termin_id, range_id, autor_id, raum, content)\n                      VALUES\n                        (:metadate_id, :date_typ, :date, :end_time, :mkdate, :chdate,\n                         :termin_id, :range_id, :autor_id, :raum, :content)";
         $statement = DBManager::get()->prepare($query);
         $statement->bindValue(':table', $table, StudipPDO::PARAM_COLUMN);
         $statement->bindValue(':metadate_id', $termin->getMetaDateID());
         $statement->bindValue(':date_typ', $termin->getDateType());
         $statement->bindValue(':date', $termin->getStartTime());
         $statement->bindValue(':end_time', $termin->getEndTime());
         $statement->bindValue(':mkdate', $termin->getMkDate());
         $statement->bindValue(':chdate', $termin->getChDate());
         $statement->bindValue(':termin_id', $termin->getTerminID());
         $statement->bindValue(':range_id', $termin->getRangeID());
         $statement->bindValue(':autor_id', $termin->getAuthorID());
         $statement->bindValue(':raum', $termin->getFreeRoomText());
         $statement->bindValue(':content', $termin->getComment());
         $statement->execute();
     }
     $query = "DELETE FROM termin_related_persons WHERE range_id = ?";
     $statement = DBManager::get()->prepare($query);
     $statement->execute(array($termin->getTerminId()));
     if (count($termin->related_persons) && count($termin->related_persons) < CourseMember::countBySQL("Seminar_id = ? AND status = 'dozent'", array($termin->range_id))) {
         $query = "INSERT IGNORE INTO termin_related_persons (range_id, user_id) VALUES (?, ?)";
         $statement = DBManager::get()->prepare($query);
         foreach ($termin->getRelatedPersons() as $user_id) {
             $statement->execute(array($termin->getTerminId(), $user_id));
         }
     }
     $query = "DELETE FROM termin_related_groups WHERE termin_id = ?";
     $statement = DBManager::get()->prepare($query);
     $statement->execute(array($termin->getTerminId()));
     if (count($termin->related_groups) && count($termin->related_groups) < Statusgruppen::countBySQL("range_id = ?", array($termin->range_id))) {
         $query = "INSERT IGNORE INTO termin_related_groups (termin_id, statusgruppe_id) VALUES (?, ?)";
         $statement = DBManager::get()->prepare($query);
         foreach ($termin->getRelatedGroups() as $statusgruppe_id) {
             $statement->execute(array($termin->getTerminId(), $statusgruppe_id));
         }
     }
     return true;
 }