|
| 1 | +#include "Student.hpp" |
| 2 | +#include "Utils.hpp" |
| 3 | +#include <cstdint> |
| 4 | +#include <string> |
| 5 | +#include <vector> |
| 6 | + |
| 7 | +Student::Student(uint32_t code, std::string name) { |
| 8 | + this->code = code; |
| 9 | + this->name = name; |
| 10 | + this->classes = std::vector<ClassSchedule *>(); |
| 11 | +} |
| 12 | + |
| 13 | +std::vector<ClassSchedule *> *Student::get_schedule() { return &this->classes; } |
| 14 | + |
| 15 | +OperationResult Student::add_to_class(ClassSchedule *c) { |
| 16 | + std::vector<Class *> *new_lessons = c->get_class_schedule(); |
| 17 | + // return false; |
| 18 | + for (ClassSchedule *a : this->classes) { |
| 19 | + std::vector<Class *> *lessons = a->get_class_schedule(); |
| 20 | + for (Class *lesson : *lessons) { |
| 21 | + for (Class *new_lesson : *new_lessons) { |
| 22 | + if (lesson->get_start_hour() < new_lesson->get_start_hour() && |
| 23 | + new_lesson->get_start_hour() < |
| 24 | + (lesson->get_start_hour() + lesson->get_duration())) { |
| 25 | + if (lesson->get_type() == Type::T || |
| 26 | + new_lesson->get_type() == Type::T) { |
| 27 | + return OperationResult::Conlicts; // We return conflicts so that the |
| 28 | + // handler function can ask the |
| 29 | + // user whether or not they want |
| 30 | + // to proceed. |
| 31 | + } |
| 32 | + return OperationResult::Error; |
| 33 | + } |
| 34 | + if (lesson->get_start_hour() < |
| 35 | + (new_lesson->get_start_hour() + new_lesson->get_duration()) && |
| 36 | + (new_lesson->get_start_hour() + new_lesson->get_duration()) < |
| 37 | + (lesson->get_start_hour() + lesson->get_duration())) { |
| 38 | + if (lesson->get_type() == Type::T || |
| 39 | + new_lesson->get_type() == Type::T) { |
| 40 | + return OperationResult::Conlicts; |
| 41 | + } |
| 42 | + return OperationResult::Error; |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + c->add_student(); |
| 48 | + this->classes.push_back(c); |
| 49 | + return OperationResult::Success; |
| 50 | +} |
| 51 | + |
| 52 | +void Student::remove_from_class(ClassSchedule *c) { |
| 53 | + c->remove_student(); |
| 54 | + for (std::vector<ClassSchedule*>::iterator itr = this->classes.begin(); itr != this->classes.end(); ++itr) { |
| 55 | + if (c == *itr) { |
| 56 | + this->classes.erase(itr); |
| 57 | + return; |
| 58 | + } |
| 59 | + } |
| 60 | + this->classes.push_back(c); |
| 61 | +} |
| 62 | + |
| 63 | +OperationResult Student::switch_class_with(Student other, ClassSchedule *thisone, |
| 64 | + ClassSchedule *theoother) { |
| 65 | + return OperationResult::Success; //TODO |
| 66 | +} |
0 commit comments