Add riderschedule entity #8
This commit is contained in:
parent
8513e563f6
commit
3c27cf53bf
2 changed files with 186 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ use Doctrine\ORM\Mapping as ORM;
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Doctrine\Common\Collections\Criteria;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
|
|
@ -24,12 +25,14 @@ class Rider
|
||||||
// first name
|
// first name
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=50, nullable=true)
|
* @ORM\Column(type="string", length=50, nullable=true)
|
||||||
|
* @Assert\NotBlank()
|
||||||
*/
|
*/
|
||||||
protected $first_name;
|
protected $first_name;
|
||||||
|
|
||||||
// last name
|
// last name
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=50, nullable=true)
|
* @ORM\Column(type="string", length=50, nullable=true)
|
||||||
|
* @Assert\NotBlank()
|
||||||
*/
|
*/
|
||||||
protected $last_name;
|
protected $last_name;
|
||||||
|
|
||||||
|
|
@ -71,9 +74,16 @@ class Rider
|
||||||
*/
|
*/
|
||||||
protected $curr_rating;
|
protected $curr_rating;
|
||||||
|
|
||||||
|
// day schedules for rider
|
||||||
|
/**
|
||||||
|
* @ORM\OneToMany(targetEntity="RiderSchedule", mappedBy="rider", cascade={"persist"})
|
||||||
|
*/
|
||||||
|
protected $schedules;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->job_orders = new ArrayCollection();
|
$this->job_orders = new ArrayCollection();
|
||||||
|
$this->schedules = new ArrayCollection();
|
||||||
$this->curr_rating = 0;
|
$this->curr_rating = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -169,4 +179,36 @@ class Rider
|
||||||
{
|
{
|
||||||
return $this->curr_rating;
|
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];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
144
src/Entity/RiderSchedule.php
Normal file
144
src/Entity/RiderSchedule.php
Normal file
|
|
@ -0,0 +1,144 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Entity
|
||||||
|
* @ORM\Table(name="rider_schedule")
|
||||||
|
*/
|
||||||
|
class RiderSchedule
|
||||||
|
{
|
||||||
|
// unique id
|
||||||
|
/**
|
||||||
|
* @ORM\Id
|
||||||
|
* @ORM\Column(type="integer")
|
||||||
|
* @ORM\GeneratedValue(strategy="AUTO")
|
||||||
|
*/
|
||||||
|
protected $id;
|
||||||
|
|
||||||
|
// rider the schedule is for
|
||||||
|
/**
|
||||||
|
* @ORM\ManyToOne(targetEntity="Rider", inversedBy="schedules")
|
||||||
|
* @ORM\JoinColumn(name="rider_id", referencedColumnName="id")
|
||||||
|
*/
|
||||||
|
protected $rider;
|
||||||
|
|
||||||
|
// start time
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="integer")
|
||||||
|
*/
|
||||||
|
protected $day_of_week;
|
||||||
|
|
||||||
|
// start time
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="time")
|
||||||
|
*/
|
||||||
|
protected $time_start;
|
||||||
|
|
||||||
|
// end time
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="time")
|
||||||
|
*/
|
||||||
|
protected $time_end;
|
||||||
|
|
||||||
|
// break start time
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="time")
|
||||||
|
*/
|
||||||
|
protected $break_start;
|
||||||
|
|
||||||
|
// break end time
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="time")
|
||||||
|
*/
|
||||||
|
protected $break_end;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue