resq/src/Entity/Rider.php

232 lines
4.6 KiB
PHP

<?php
namespace App\Entity;
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
* @ORM\Table(name="rider")
*/
class Rider
{
// unique id
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
// 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;
// contact number
/**
* @ORM\Column(type="string", length=20, nullable=true)
*/
protected $contact_num;
// plate number
/**
* @ORM\Column(type="string", length=10)
* @Assert\NotBlank()
*/
protected $plate_number;
// hub that the rider is assigned to
/**
* @ORM\ManyToOne(targetEntity="Hub", inversedBy="riders")
* @ORM\JoinColumn(name="hub_id", referencedColumnName="id")
*/
protected $hub;
// job orders that the rider has done
/**
* @ORM\OneToMany(targetEntity="JobOrder", mappedBy="rider")
*/
protected $job_orders;
// picture of rider
/**
* @ORM\Column(type="string", nullable=true)
*/
protected $image_file;
// current rating of rider
/**
* @ORM\Column(type="integer")
*/
protected $curr_rating;
// day schedules for rider
/**
* @ORM\OneToMany(targetEntity="RiderSchedule", mappedBy="rider", cascade={"persist"})
*/
protected $schedules;
// is the rider available or not
/**
* @ORM\Column(type="boolean")
*/
protected $flag_available;
public function __construct()
{
$this->job_orders = new ArrayCollection();
$this->schedules = new ArrayCollection();
$this->curr_rating = 0;
$this->flag_available = false;
}
public function getID()
{
return $this->id;
}
public function setFirstName($first_name)
{
$this->first_name = $first_name;
return $this;
}
public function getFirstName()
{
return $this->first_name;
}
public function setLastName($last_name)
{
$this->last_name = $last_name;
return $this;
}
public function getLastName()
{
return $this->last_name;
}
public function getFullName()
{
return $this->first_name . ' ' . $this->last_name;
}
public function setPlateNumber($plate_number)
{
$this->plate_number = $plate_number;
return $this;
}
public function getPlateNumber()
{
return $this->plate_number;
}
public function setContactNumber($num)
{
$this->contact_num = $num;
return $this;
}
public function getContactNumber()
{
return $this->contact_num;
}
public function setHub(Hub $hub)
{
$this->hub = $hub;
return $this;
}
public function getHub()
{
return $this->hub;
}
public function clearHub()
{
$this->hub = null;
return $this;
}
public function setImageFile($image_file)
{
$this->image_file = $image_file;
return $this;
}
public function getImageFile()
{
return $this->image_file;
}
public function setCurrentRating($rating)
{
$this->curr_rating = $rating;
return $this;
}
public function getCurrentRating()
{
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];
}
public function setAvailable($avail = true)
{
$this->flag_available = $avail;
return $this;
}
public function isAvailable()
{
return $this->flag_available;
}
}