432 lines
9.5 KiB
PHP
432 lines
9.5 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;
|
|
|
|
use App\Ramcar\JOStatus;
|
|
use App\Entity\ApiUser as APIUser;
|
|
|
|
/**
|
|
* @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")
|
|
* @ORM\OrderBy({"priority" = "ASC"})
|
|
*/
|
|
protected $job_orders;
|
|
|
|
// rider's active job order since we now support multiple job orders per rider
|
|
/**
|
|
* @ORM\OneToOne(targetEntity="JobOrder")
|
|
* @ORM\JoinColumn(name="active_jo_id", referencedColumnName="id")
|
|
*/
|
|
protected $active_job_order;
|
|
|
|
// picture of rider
|
|
/**
|
|
* @ORM\Column(type="string", nullable=true)
|
|
*/
|
|
protected $image_file;
|
|
|
|
// current rating of rider
|
|
/**
|
|
* @ORM\Column(type="float")
|
|
*/
|
|
protected $curr_rating;
|
|
|
|
// day schedules for rider
|
|
/**
|
|
* @ORM\OneToMany(targetEntity="RiderSchedule", mappedBy="rider", cascade={"persist"})
|
|
*/
|
|
protected $schedules;
|
|
|
|
// is the rider available or not (no job order assigned to them)
|
|
/**
|
|
* @ORM\Column(type="boolean")
|
|
*/
|
|
protected $flag_available;
|
|
|
|
// is the rider active or not (he has logged in and marked himself as active)
|
|
/**
|
|
* @ORM\Column(type="boolean")
|
|
*/
|
|
protected $flag_active;
|
|
|
|
// username for rider api
|
|
/**
|
|
* @ORM\Column(type="string", length=80, unique=true, nullable=true)
|
|
*/
|
|
protected $username;
|
|
|
|
// password for rider api
|
|
/**
|
|
* @ORM\Column(type="string", length=64)
|
|
*/
|
|
protected $password;
|
|
|
|
// rider sessions
|
|
/**
|
|
* @ORM\OneToMany(targetEntity="RiderSession", mappedBy="rider")
|
|
*/
|
|
protected $sessions;
|
|
|
|
// current job order
|
|
// NOTE: for forgotten reasons, we don't set active_job_order.
|
|
// but we now need rider's current JO for the time stamp events
|
|
/**
|
|
* @ORM\OneToOne(targetEntity="JobOrder")
|
|
* @ORM\JoinColumn(name="current_jo_id", referencedColumnName="id")
|
|
*/
|
|
protected $current_job_order;
|
|
|
|
/**
|
|
* @ORM\OneToOne(targetEntity="App\Entity\ApiUser", inversedBy="rider")
|
|
* @ORM\JoinColumn(name="api_user_id", referencedColumnName="id", nullable=true)
|
|
*/
|
|
protected $api_user;
|
|
|
|
/**
|
|
* @ORM\OneToMany(targetEntity="RiderRating", mappedBy="rider")
|
|
*/
|
|
protected $ratings;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->job_orders = new ArrayCollection();
|
|
$this->schedules = new ArrayCollection();
|
|
$this->sessions = new ArrayCollection();
|
|
$this->curr_rating = 0;
|
|
$this->flag_available = true;
|
|
$this->flag_active = true;
|
|
$this->username = null;
|
|
$this->password = '';
|
|
|
|
$this->active_job_order = null;
|
|
$this->current_job_order = null;
|
|
$this->api_user = null;
|
|
|
|
$this->ratings = new ArrayCollection();
|
|
}
|
|
|
|
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 updateRatingAverage()
|
|
{
|
|
$total = 0;
|
|
|
|
foreach ($this->ratings as $rating) {
|
|
$total += $rating->getRating();
|
|
}
|
|
|
|
$this->setCurrentRating(round($total / $this->ratings->count(), 2));
|
|
}
|
|
|
|
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)
|
|
{
|
|
// only set to available if they are active
|
|
// non-active riders cannot be available
|
|
if ($this->isActive() && $avail)
|
|
$this->flag_available = true;
|
|
else
|
|
$this->flag_available = false;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function isAvailable()
|
|
{
|
|
return $this->flag_available;
|
|
}
|
|
|
|
public function setActive($flag = true)
|
|
{
|
|
$this->flag_active = $flag;
|
|
return $this;
|
|
}
|
|
|
|
public function isActive()
|
|
{
|
|
return $this->flag_active;
|
|
}
|
|
|
|
public function setUsername($username)
|
|
{
|
|
$this->username = $username;
|
|
return $this;
|
|
}
|
|
|
|
public function getUsername()
|
|
{
|
|
return $this->username;
|
|
}
|
|
|
|
public function setPassword($pass)
|
|
{
|
|
// they have to pass the encoded password
|
|
$this->password = $pass;
|
|
return $this;
|
|
}
|
|
|
|
public function getPassword()
|
|
{
|
|
return $this->password;
|
|
}
|
|
|
|
public function setActiveJobOrder(JobOrder $jo = null)
|
|
{
|
|
$this->active_job_order = $jo;
|
|
return $this;
|
|
}
|
|
|
|
public function getActiveJobOrder()
|
|
{
|
|
// check if we have set a custom active
|
|
if ($this->active_job_order != null)
|
|
{
|
|
switch ($this->active_job_order->getStatus())
|
|
{
|
|
// if jo is open, return it
|
|
case JOStatus::ASSIGNED:
|
|
case JOStatus::IN_TRANSIT:
|
|
case JOStatus::IN_PROGRESS:
|
|
return $this->active_job_order;
|
|
}
|
|
|
|
// if active jo is not open, get the next open one
|
|
}
|
|
|
|
// no custom active job order
|
|
$active_status = [
|
|
JOStatus::ASSIGNED,
|
|
JOStatus::IN_TRANSIT,
|
|
JOStatus::IN_PROGRESS,
|
|
];
|
|
|
|
$criteria = Criteria::create();
|
|
$criteria->where(Criteria::expr()->in('status', $active_status))
|
|
->getFirstResult(1);
|
|
|
|
return $this->job_orders->matching($criteria)[0];
|
|
}
|
|
|
|
public function getOpenJobOrders()
|
|
{
|
|
$active_status = [
|
|
JOStatus::ASSIGNED,
|
|
JOStatus::IN_TRANSIT,
|
|
JOStatus::IN_PROGRESS,
|
|
];
|
|
|
|
$criteria = Criteria::create();
|
|
$criteria->where(Criteria::expr()->in('status', $active_status));
|
|
|
|
return $this->job_orders->matching($criteria);
|
|
}
|
|
|
|
public function getSessions()
|
|
{
|
|
return $this->sessions;
|
|
}
|
|
|
|
public function getMapLabel()
|
|
{
|
|
$map_label = $this->first_name .' ' . $this->last_name;
|
|
return $map_label;
|
|
}
|
|
|
|
public function setCurrentJobOrder(JobOrder $jo = null)
|
|
{
|
|
$this->current_job_order = $jo;
|
|
return $this;
|
|
}
|
|
|
|
public function getCurrentJobOrder()
|
|
{
|
|
return $this->current_job_order;
|
|
}
|
|
|
|
public function setAPIUser($user)
|
|
{
|
|
$this->api_user = $user;
|
|
return $this;
|
|
}
|
|
|
|
public function getAPIUser()
|
|
{
|
|
return $this->api_user;
|
|
}
|
|
}
|