diff --git a/src/Entity/Rider.php b/src/Entity/Rider.php index a99e8bae..d6bdb173 100644 --- a/src/Entity/Rider.php +++ b/src/Entity/Rider.php @@ -6,6 +6,7 @@ use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Criteria; /** * @ORM\Entity @@ -24,12 +25,14 @@ class Rider // first name /** * @ORM\Column(type="string", length=50, nullable=true) + * @Assert\NotBlank() */ protected $first_name; // last name /** * @ORM\Column(type="string", length=50, nullable=true) + * @Assert\NotBlank() */ protected $last_name; @@ -71,9 +74,16 @@ class Rider */ protected $curr_rating; + // day schedules for rider + /** + * @ORM\OneToMany(targetEntity="RiderSchedule", mappedBy="rider", cascade={"persist"}) + */ + protected $schedules; + public function __construct() { $this->job_orders = new ArrayCollection(); + $this->schedules = new ArrayCollection(); $this->curr_rating = 0; } @@ -169,4 +179,36 @@ class Rider { return $this->curr_rating; } + + public function addSchedule(RiderSchedule $schedule) + { + $this->schedules->add($schedule); + return $this; + } + + public function clearSchedules() + { + $this->schedules->clear(); + return $this; + } + + public function removeSchedule(RiderSchedule $schedule) + { + $this->schedules->removeElement($schedule); + return $this; + } + + public function getSchedules() + { + return $this->schedules; + } + + public function getScheduleForDay($day_of_week) + { + $criteria = Criteria::create(); + $criteria->where(Criteria::expr()->eq('day_of_week', $day_of_week)) + ->getFirstResult(1); + + return $this->schedules->matching($criteria)[0]; + } } diff --git a/src/Entity/RiderSchedule.php b/src/Entity/RiderSchedule.php new file mode 100644 index 00000000..d805af05 --- /dev/null +++ b/src/Entity/RiderSchedule.php @@ -0,0 +1,144 @@ +time_start = new DateTime(); + $this->time_end = new DateTime(); + $this->break_start = new DateTime(); + $this->break_end = new DateTime(); + } + + public function getID() + { + return $this->id; + } + + public function setRider(Rider $rider) + { + $this->rider = $rider; + return $this; + } + + public function getRider() + { + return $this->rider; + } + + public function setDayOfWeek($day) + { + $this->day_of_week = $day; + return $this; + } + + public function getDayOfWeek() + { + return $this->day_of_week; + } + + public function setTimeStart($time) + { + $this->time_start = $this->parseTime($time); + return $this; + } + + public function getTimeStart() + { + return $this->time_start; + } + + public function setTimeEnd($time) + { + $this->time_end = $this->parseTime($time); + return $this; + } + + public function getTimeEnd() + { + return $this->time_end; + } + + public function setBreakStart($time) + { + $this->break_start = $this->parseTime($time); + return $this; + } + + public function getBreakStart() + { + return $this->break_start; + } + + public function setBreakEnd($time) + { + $this->break_end = $this->parseTime($time); + return $this; + } + + public function getBreakEnd() + { + return $this->break_end; + } + + protected function parseTime($string, $format = 'g:i A') + { + return DateTime::createFromFormat($format, $string) ?? null; + } +}