Add Partner, Service, and Review entities. Add association for Partner and User. Add association for MobileSession and Review. #228

This commit is contained in:
Korina Cordero 2019-07-04 09:00:26 +00:00
parent 3083db9dc5
commit 47f1638be9
5 changed files with 338 additions and 0 deletions

View file

@ -3,6 +3,9 @@
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use DateTime;
/**
@ -91,6 +94,12 @@ class MobileSession
*/
protected $date_code_sent;
// reviews made by mobile session
/**
* @ORM\OneToMany(targetEntity="Review", mappedBy="mobile_session")
*/
protected $reviews;
public function __construct()
{
@ -101,6 +110,7 @@ class MobileSession
$this->confirm_flag = false;
$this->date_confirmed = null;
$this->date_code_sent = null;
$this->reviews = new ArrayCollection();
}
public function generateKeyID()
@ -239,4 +249,9 @@ class MobileSession
{
return $this->date_code_sent;
}
public function getReviews()
{
return $this->reviews;
}
}

118
src/Entity/Partner.php Normal file
View file

@ -0,0 +1,118 @@
<?php
namespace App\Entity;
use App\Ramcar\Location;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use DateTime;
/**
* @ORM\Entity
* @ORM\Table(name="partner")
*/
class Partner
{
use Location;
// unique id
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
// name
/**
* @ORM\Column(type="string", length=80)
* @Assert\NotBlank()
*/
protected $name;
// date created
/**
* @ORM\Column(type="datetime")
*/
protected $date_create;
// user that created the partner
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="partners_created")
* @ORM\JoinColumn(name="create_user_id", referencedColumnName="id", nullable=true)
*/
protected $created_by;
// services provided
/**
* @ORM\ManyToMany(targetEntity="Service", inversedBy="partners", indexBy="id")
* @ORM\JoinTable(name="partner_services")
*/
protected $services;
public function __construct()
{
$this->services = new ArrayCollection();
$this->date_create = new DateTime();
}
public function getID()
{
return $this->id;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
public function getName()
{
return $this->name;
}
public function getDateCreate()
{
return $this->date_create;
}
public function setCreatedBy(User $created_by)
{
$this->created_by = $created_by;
return $this;
}
public function getCreatedBy()
{
return $this->created_by;
}
public function addService(Service $service)
{
if (!isset($this->services[$service->getID()]))
unset($this->services[$service->getID()]);
return $this;
}
public function removeService(Service $service)
{
if (isset($this->services[$service->getID()]))
unset($this->services[$service->getID()]);
return $this;
}
public function clearServices()
{
$this->services->clear();
return $this;
}
public function getServices()
{
return $this->services;
}
}

117
src/Entity/Review.php Normal file
View file

@ -0,0 +1,117 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use DateTime;
/**
* @ORM\Entity
* @ORM\Table(name="review")
*/
class Review
{
// unique id
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
// partner being reviewed
/**
* @ORM\ManyToOne(targetEntity="Partner")
* @ORM\JoinColumn(name="partner_id", referencedColumnName="id")
*/
protected $partner;
// customer's rating of partner
/**
* @ORM\Column(type="integer")
*/
protected $rating;
// message that goes with the rating
/**
* @ORM\Column(type="text")
*/
protected $message;
// date created
/**
* @ORM\Column(type="datetime")
*/
protected $date_create;
// mobile session that sent review
/**
* @ORM\ManyToOne(targetEntity="MobileSession", inversedBy="reviews")
* @ORM\JoinColumn(name="mobile_session_id", referencedColumnName="id")
*/
protected $mobile_session;
public function __construct()
{
$this->date_create = new DateTime();
$this->rating = 0;
$this->comment = "";
}
public function getID()
{
return $this->id;
}
public function setPartner(Partner $partner)
{
$this->partner = $partner;
return $this;
}
public function getPartner()
{
return $this->partner;
}
public function setRating($rating)
{
$this->rating = $rating;
return $this;
}
public function getRating()
{
return $this->rating;
}
public function setMessage($message)
{
$this->message = $message;
return $this;
}
public function getMessage()
{
return $this->message;
}
public function getDateCreate()
{
return $this->date_create;
}
public function setMobileSession(MobileSession $mobile_session)
{
$this->mobile_session = $mobile_session;
return $this;
}
public function getMobileSession()
{
return $this->mobile_session;
}
}

76
src/Entity/Service.php Normal file
View file

@ -0,0 +1,76 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity
* @ORM\Table(name="service")
*/
class Service
{
// unique id
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
// name of service
/**
* @ORM\Column(type="string", length=80)
* @Assert\NotBlank()
*/
protected $name;
// link to partners with this service
/**
* @ORM\ManyToMany(targetEntity="Partner", mappedBy="services", indexBy="id", fetch="EXTRA_LAZY")
*/
protected $partners;
public function __construct()
{
$this->partners = new ArrayCollection();
}
public function getID()
{
return $this->id;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
public function getName()
{
return $this->name;
}
public function addPartner(Partner $partner)
{
$this->partners[$partner->getID()] = $partner;
return $this;
}
public function clearPartners()
{
$this->partners->clear();
return $this;
}
public function getPartners()
{
return $this->partners;
}
}

View file

@ -104,6 +104,12 @@ class User extends BaseUser implements Serializable
*/
protected $invoices;
// partners made by this user
/**
* @ORM\OneToMany(targetEntity="Partner", mappedBy="created_by")
*/
protected $partners_created;
public function __construct()
{
parent::__construct();
@ -112,6 +118,7 @@ class User extends BaseUser implements Serializable
$this->job_orders_created = new ArrayCollection();
$this->job_orders_assigned = new ArrayCollection();
$this->tickets = new ArrayCollection();
$this->partners_created = new ArrayCollection();
}
public function getID()
@ -297,4 +304,9 @@ class User extends BaseUser implements Serializable
{
return $this->invoices;
}
public function getPartnersCreated()
{
return $this->partners_created;
}
}