Ticket* OTicketDAO::getTicket(int id) { for(int i =0; i < tickets.size(); i++) { Ticket* temp = tickets.at(i); if(temp->getTicketID() == id) return temp; } return 0; }
//Geeft de positie van een element in de array; Enkel noodzakelijk om de database te simuleren int OTicketDAO::getPositie(int id) { for(int i = 0; i < tickets.size(); i++) { Ticket* temp = tickets.at(i); if(temp->getTicketID() == id) return i; } return -1; }
vector<Ticket*> OTicketDAO::vindTicketDoorID(int ID) { vector<Ticket*> results = vector<Ticket*>(); for(int i =0; i < tickets.size(); i++) { Ticket* temp = tickets.at(i); if(temp->getTicketID() == ID) results.push_back(temp); } return results; }
Ticket* OTicketDAO::bewaarTicket(Ticket* ticket) { if(ticket->getTicketID() == -1) { //Dit is een nieuw adres en simuleert de toekenning van een sequentiële ID door de database Ticket* temp = tickets.at(tickets.size()-1); int nieuweID = temp->getTicketID()+1; ticket->setTicketID(nieuweID); } Ticket* temp = getTicket(ticket->getTicketID()); if(temp == 0) { tickets.push_back(ticket); return ticket; } else { //Ticket updaten temp->setTicketID(ticket->getTicketID()); return temp; } return 0; }