2012-07-31 09:09:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace KekRozsak\FrontBundle\Entity;
|
|
|
|
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints as DoctrineAssert;
|
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
use KekRozsak\SecurityBundle\Entity\User;
|
|
|
|
use KekRozsak\FrontBundle\Entity\Group;
|
|
|
|
|
2012-07-31 09:09:52 +00:00
|
|
|
/**
|
|
|
|
* @ORM\Entity
|
|
|
|
* @ORM\Table(name="events")
|
|
|
|
*
|
|
|
|
* @DoctrineAssert\UniqueEntity(fields={"startDate", "slug"})
|
|
|
|
* @DoctrineAssert\UniqueEntity(fields={"startDate", "title"})
|
|
|
|
*/
|
|
|
|
class Event
|
|
|
|
{
|
2012-08-16 13:52:41 +00:00
|
|
|
/**
|
|
|
|
* The ID of the Event
|
|
|
|
*
|
|
|
|
* @var integer $id
|
|
|
|
*
|
|
|
|
* @ORM\Id
|
|
|
|
* @ORM\GeneratedValue(strategy="AUTO")
|
|
|
|
* @ORM\Column(type="integer")
|
|
|
|
*/
|
|
|
|
protected $id;
|
2012-08-17 14:18:43 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
/**
|
|
|
|
* Get id
|
|
|
|
*
|
|
|
|
* @return integer
|
|
|
|
*/
|
|
|
|
public function getId()
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
2012-08-17 14:18:43 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
/**
|
|
|
|
* The User who created the Event
|
|
|
|
*
|
|
|
|
* @var KekRozsak\SecurityBundle\Entity\User $createdBy
|
|
|
|
*
|
|
|
|
* @ORM\ManyToOne(targetEntity="KekRozsak\SecurityBundle\Entity\User")
|
|
|
|
* @ORM\JoinColumn(name="created_by_id")
|
|
|
|
*/
|
|
|
|
protected $createdBy;
|
2012-08-17 14:18:43 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
/**
|
|
|
|
* Set createdBy
|
|
|
|
*
|
2012-08-17 14:18:43 +00:00
|
|
|
* @param KekRozsak\SecurityBundle\Entity\User $createdBy
|
2012-08-16 13:52:41 +00:00
|
|
|
* @return Event
|
|
|
|
*/
|
|
|
|
public function setCreatedBy(User $createdBy)
|
|
|
|
{
|
|
|
|
$this->createdBy = $createdBy;
|
2012-08-17 14:18:43 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
return $this;
|
|
|
|
}
|
2012-08-17 14:18:43 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
/**
|
|
|
|
* Get createdBy
|
|
|
|
*
|
|
|
|
* @return KekRozsak\SecurityBundle\Entity\User
|
|
|
|
*/
|
|
|
|
public function getCreatedBy()
|
|
|
|
{
|
|
|
|
return $this->createdBy;
|
|
|
|
}
|
2012-08-17 14:18:43 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
/**
|
|
|
|
* The date on which the Event starts
|
|
|
|
*
|
|
|
|
* @var DateTime $startDate
|
|
|
|
*
|
|
|
|
* @ORM\Column(type="date", nullable=true, name="start_date", nullable=false)
|
|
|
|
*/
|
|
|
|
protected $startDate;
|
2012-08-17 14:18:43 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
/**
|
|
|
|
* Set startDate
|
|
|
|
*
|
2012-08-17 14:18:43 +00:00
|
|
|
* @param DateTime $startDate
|
2012-08-16 13:52:41 +00:00
|
|
|
* @return Event
|
|
|
|
*/
|
|
|
|
public function setStartDate(\DateTime $startDate = null)
|
|
|
|
{
|
|
|
|
$this->startDate = $startDate;
|
2012-08-17 14:18:43 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
return $this;
|
|
|
|
}
|
2012-08-17 14:18:43 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
/**
|
|
|
|
* Get startDate
|
|
|
|
*
|
|
|
|
* @return DateTime
|
|
|
|
*/
|
|
|
|
public function getStartDate()
|
|
|
|
{
|
|
|
|
return $this->startDate;
|
|
|
|
}
|
2012-08-17 14:18:43 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
/**
|
|
|
|
* The date on which the Event ends. May be null if same as $startDate
|
|
|
|
*
|
|
|
|
* @var DateTime $endDate
|
|
|
|
*
|
|
|
|
* @ORM\Column(type="date", nullable=true, name="end_date")
|
|
|
|
*/
|
|
|
|
protected $endDate;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set endDate
|
|
|
|
*
|
2012-08-17 14:18:43 +00:00
|
|
|
* @param DateTime $endDate
|
2012-08-16 13:52:41 +00:00
|
|
|
* @return Event
|
|
|
|
*/
|
|
|
|
public function setEndDate(\DateTime $endDate = null)
|
|
|
|
{
|
|
|
|
// TODO: Check if endDate is later than startDate
|
|
|
|
$this->endDate = $endDate;
|
2012-08-17 14:18:43 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get endDate
|
|
|
|
*
|
|
|
|
* @return DateTime
|
|
|
|
*/
|
|
|
|
public function getEndDate()
|
|
|
|
{
|
|
|
|
return $this->endDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An ArrayCollection of Users who wish to attend on this Event
|
|
|
|
*
|
|
|
|
* @var Doctrine\Common\Collections\ArrayCollection $attendees
|
|
|
|
*
|
|
|
|
* @ORM\ManyToMany(targetEntity="KekRozsak\SecurityBundle\Entity\User")
|
|
|
|
* @ORM\JoinTable(name="event_attendees")
|
|
|
|
*/
|
|
|
|
protected $attendees;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add attendee
|
|
|
|
*
|
2012-08-17 14:18:43 +00:00
|
|
|
* @param KekRozsak\SecurityBundle\Entity\User $attendee
|
2012-08-16 13:52:41 +00:00
|
|
|
* @return Event
|
|
|
|
*/
|
|
|
|
public function addAttendee(User $attendee)
|
|
|
|
{
|
|
|
|
$this->attendees[] = $attendee;
|
2012-08-17 14:18:43 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all attendees
|
|
|
|
*
|
|
|
|
* @return Doctrine\Common\Collections\ArrayCollection
|
|
|
|
*/
|
|
|
|
public function getAttendees()
|
|
|
|
{
|
|
|
|
return $this->attendees;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a user is attending
|
|
|
|
*
|
2012-08-17 14:18:43 +00:00
|
|
|
* @param KekRozsak\SecurityBundle\Entity\User $user
|
2012-08-16 13:52:41 +00:00
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function isAttending(User $user)
|
|
|
|
{
|
2012-08-17 14:18:43 +00:00
|
|
|
$users = $this->attendees->filter(function ($attendee) use ($user) {
|
2012-08-16 13:52:41 +00:00
|
|
|
if ($attendee == $user) {
|
|
|
|
return true;
|
2012-08-15 16:07:46 +00:00
|
|
|
}
|
2012-08-16 13:52:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return ($users->count() != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The title of the Event
|
|
|
|
*
|
|
|
|
* @var string $title
|
|
|
|
*
|
|
|
|
* @ORM\Column(type="string", length=150)
|
|
|
|
*
|
|
|
|
* @Assert\NotBlank()
|
|
|
|
*/
|
|
|
|
protected $title;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set title
|
|
|
|
*
|
2012-08-17 14:18:43 +00:00
|
|
|
* @param string $title
|
2012-08-16 13:52:41 +00:00
|
|
|
* @return Event
|
|
|
|
*/
|
|
|
|
public function setTitle($title)
|
|
|
|
{
|
|
|
|
// TODO: Check if empty or null!
|
|
|
|
$this->title = $title;
|
2012-08-17 14:18:43 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get title
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getTitle()
|
|
|
|
{
|
|
|
|
return $this->title;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Slugified title of the event
|
|
|
|
*
|
|
|
|
* @var string $slug
|
|
|
|
*
|
|
|
|
* @ORM\Column(type="string", length=150)
|
|
|
|
*
|
|
|
|
* @Assert\NotBlank()
|
|
|
|
*/
|
|
|
|
protected $slug;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set slug
|
|
|
|
*
|
2012-08-17 14:18:43 +00:00
|
|
|
* @param string $slug
|
2012-08-16 13:52:41 +00:00
|
|
|
* @return Event
|
|
|
|
*/
|
|
|
|
public function setSlug($slug)
|
|
|
|
{
|
|
|
|
// TODO: Check if empty or null!
|
|
|
|
$this->slug = $slug;
|
2012-08-17 14:18:43 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get slug
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getSlug()
|
|
|
|
{
|
|
|
|
return $this->slug;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Description of the Event
|
|
|
|
*
|
|
|
|
* @var string $description
|
|
|
|
*
|
|
|
|
* @ORM\Column(type="text")
|
|
|
|
*
|
|
|
|
* @Assert\NotBlank()
|
|
|
|
*/
|
|
|
|
protected $description;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set description
|
|
|
|
*
|
2012-08-17 14:18:43 +00:00
|
|
|
* @param string $description
|
2012-08-16 13:52:41 +00:00
|
|
|
* @return Event
|
|
|
|
*/
|
|
|
|
public function setDescription($description)
|
|
|
|
{
|
|
|
|
// TODO: Check if empty!
|
|
|
|
$this->description = $description;
|
2012-08-17 14:18:43 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get description
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getDescription()
|
|
|
|
{
|
|
|
|
return $this->description;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var KekRozsak\FrontBundle\Entity\Group $group
|
|
|
|
*
|
|
|
|
* @ORM\ManyToOne(targetEntity="KekRozsak\FrontBundle\Entity\Group")
|
|
|
|
*/
|
|
|
|
protected $group;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set group
|
|
|
|
*
|
2012-08-17 14:18:43 +00:00
|
|
|
* @param KekRozsak\FrontBundle\Entity\Group $group
|
2012-08-16 13:52:41 +00:00
|
|
|
* @return Event
|
|
|
|
*/
|
|
|
|
public function setGroup(Group $group = null)
|
|
|
|
{
|
|
|
|
$this->group = $group;
|
2012-08-17 14:18:43 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get group
|
|
|
|
*
|
|
|
|
* @return KekRozsak\FrontBundle\Entity\Group
|
|
|
|
*/
|
|
|
|
public function getGroup()
|
|
|
|
{
|
|
|
|
return $this->group;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TRUE if the Event is cancelled
|
|
|
|
*
|
|
|
|
* @var boolean $cancelled
|
|
|
|
*
|
|
|
|
* @ORM\Column(type="boolean", nullable=false)
|
|
|
|
*/
|
|
|
|
protected $cancelled;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set cancelled
|
|
|
|
*
|
2012-08-17 14:18:43 +00:00
|
|
|
* @param boolean $cancelled
|
2012-08-16 13:52:41 +00:00
|
|
|
* @return Event
|
|
|
|
*/
|
|
|
|
public function setCancelled($cancelled = false)
|
|
|
|
{
|
|
|
|
// TODO: Check if parameter is boolean
|
|
|
|
$this->cancelled = $cancelled;
|
2012-08-17 14:18:43 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get cancelled
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function getCancelled()
|
|
|
|
{
|
|
|
|
return $this->cancelled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The time when the Event starts
|
|
|
|
*
|
|
|
|
* @var DateTime $startTime
|
|
|
|
*
|
|
|
|
* @ORM\Column(type="time", nullable=false, name="start_time")
|
|
|
|
*/
|
|
|
|
protected $startTime;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set startTime
|
|
|
|
*
|
2012-08-17 14:18:43 +00:00
|
|
|
* @param DateTime $startTime
|
2012-08-16 13:52:41 +00:00
|
|
|
* @return Event
|
|
|
|
*/
|
|
|
|
public function setStartTime(\DateTime $startTime)
|
|
|
|
{
|
|
|
|
$this->startTime = $startTime;
|
2012-08-17 14:18:43 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get startTime
|
|
|
|
*
|
|
|
|
* @return DateTime
|
|
|
|
*/
|
|
|
|
public function getStartTime()
|
|
|
|
{
|
|
|
|
return $this->startTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The time when the Event ends
|
|
|
|
*
|
|
|
|
* @var DateTime $endTime
|
|
|
|
*
|
|
|
|
* @ORM\Column(type="time", nullable=true, name="end_time")
|
|
|
|
*/
|
|
|
|
protected $endTime;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set endTime
|
|
|
|
*
|
2012-08-17 14:18:43 +00:00
|
|
|
* @param DateTime $endTime
|
2012-08-16 13:52:41 +00:00
|
|
|
* @return Event
|
|
|
|
*/
|
|
|
|
public function setEndTime(\DateTime $endTime = null)
|
|
|
|
{
|
|
|
|
// TODO: Check if endTime is later than startDate + startTime
|
|
|
|
$this->endTime = $endTime;
|
2012-08-17 14:18:43 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get endTime
|
|
|
|
*
|
|
|
|
* @return DateTime
|
|
|
|
*/
|
|
|
|
public function getEndTime()
|
|
|
|
{
|
|
|
|
return $this->endTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if an event will go on a specific date
|
|
|
|
*
|
2012-08-17 14:18:43 +00:00
|
|
|
* @param DateTime $date
|
2012-08-16 13:52:41 +00:00
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function isOnDate(\DateTime $date)
|
|
|
|
{
|
|
|
|
$date->setTime(0, 0, 0);
|
|
|
|
|
|
|
|
return (
|
|
|
|
(
|
|
|
|
($this->startDate == $date)
|
|
|
|
&& ($this->endDate === null)
|
|
|
|
)
|
|
|
|
|| (
|
|
|
|
($this->startDate <= $date)
|
|
|
|
&& ($this->endDate >= $date)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the event happened before a given date
|
|
|
|
*
|
2012-08-17 14:18:43 +00:00
|
|
|
* @param DateTime $date
|
2012-08-16 13:52:41 +00:00
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function isPast(\DateTime $date = null)
|
|
|
|
{
|
|
|
|
if ($date === null) {
|
|
|
|
$date = new \DateTime('now');
|
2012-08-15 16:07:46 +00:00
|
|
|
}
|
2012-08-16 13:52:41 +00:00
|
|
|
|
|
|
|
return ($this->endDate < $date);
|
|
|
|
}
|
2012-07-31 09:09:52 +00:00
|
|
|
}
|