resq/src/Entity/Rider.php

328 lines
6.7 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;
/**
* @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 (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;
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 = '';
}
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)
{
// 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 getActiveJobOrder()
{
$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 getSessions()
{
return $this->sessions;
}
public function getMapLabel()
{
$map_label = $this->first_name .' ' . $this->last_name;
return $map_label;
}
}