<?php
namespace App\Entity;
use App\Repository\TaskRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass=TaskRepository::class)
*/
class Task
{
/**
* Available status
*/
const STATUS_PLANNED = 1;
/**
*
*/
const STATUS_DELAYED = 2;
/**
*
*/
const STATUS_COMPLETED = 3;
/**
*
*/
const STATUS_NOT_TO_DO = 4;
/**
*
*/
const STATUS_PAUSED = 5;
/**
* Available status
*/
const STATUS_REPLANNED = 6;
/**
* AVAILABLE REPEATER
*/
const REPEAT_TYPE_DAY = 1;
/**
*
*/
const REPEAT_TYPE_WEEKLY = 2;
/**
*
*/
const REPEAT_TYPE_MONTHLY = 3;
/**
*
*/
const REPEAT_TYPE_TWO_DAYS = 4;
/**
*
*/
const REPEAT_TYPE_THREE_DAYS = 5;
/**
*
*/
const REPEAT_TYPE_FOUR_DAYS = 6;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $name;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $content;
/**
* @ORM\ManyToOne(targetEntity=Project::class, inversedBy="tasks")
* @ORM\JoinColumn(nullable=false)
*/
private $project;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*/
private $updatedAt;
/**
* @ORM\Column(type="datetime")
*/
private $plannedOnDay;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $status;
/**
* @ORM\ManyToOne(targetEntity=User::class)
*/
private $createdBy;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $repeatType;
/**
* @ORM\ManyToOne(targetEntity=OfferPackageTask::class, inversedBy="tasks")
*/
private $offerPackageTask;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*/
private $completedAt;
/**
* @ORM\ManyToMany(targetEntity=User::class, inversedBy="tasks")
*/
private $users;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $info;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $graphic_url;
/**
* @ORM\Column(type="boolean", options={"default": false})
*/
private $isGraphic;
/**
* @param User|UserInterface $createdBy
*/
public function __construct(User $createdBy)
{
$this->createdBy = $createdBy;
$this->users = new ArrayCollection();
$this->createdAt = new \DateTimeImmutable();
$this->status = self::STATUS_PLANNED;
$this->isGraphic = false;
$this->addUser($createdBy);
}
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @return string|null
*/
public function getName(): ?string
{
return $this->name;
}
/**
* @param string $name
* @return $this
*/
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return string|null
*/
public function getContent(): ?string
{
return $this->content;
}
/**
* @param string|null $content
* @return $this
*/
public function setContent(?string $content): self
{
$this->content = $content;
return $this;
}
/**
* @return Project|null
*/
public function getProject(): ?Project
{
return $this->project;
}
/**
* @param Project|null $project
* @return $this
*/
public function setProject(?Project $project): self
{
$this->project = $project;
return $this;
}
/**
* @return \DateTimeImmutable|null
*/
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
/**
* @param \DateTimeImmutable $createdAt
* @return $this
*/
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return \DateTimeImmutable|null
*/
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
/**
* @param \DateTimeImmutable|null $updatedAt
* @return $this
*/
public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return \DateTimeInterface|null
*/
public function getPlannedOnDay(): ?\DateTimeInterface
{
return $this->plannedOnDay;
}
/**
* @param \DateTimeInterface $plannedOnDay
* @return $this
*/
public function setPlannedOnDay(\DateTimeInterface $plannedOnDay): self
{
$this->plannedOnDay = $plannedOnDay;
return $this;
}
/**
* @return int|null
*/
public function getStatus(): ?int
{
return $this->status;
}
/**
* @param int|null $status
* @return $this
*/
public function setStatus(?int $status): self
{
$this->status = $status;
return $this;
}
public function getStatusText()
{
switch($this->status) {
case self::STATUS_NOT_TO_DO:
return "Niewykonywane |".$this->getInfo()."|";
case self::STATUS_PAUSED:
return "Zapauzowane |".$this->getInfo()."|";
default:
return "";
}
}
/**
* @return User|null
*/
public function getCreatedBy(): ?User
{
return $this->createdBy;
}
/**
* @param User|UserInterface|null $createdBy
* @return $this
*/
public function setCreatedBy(?User $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
/**
* @return int|null
*/
public function getRepeatType(): ?int
{
return $this->repeatType;
}
/**
* @param int|null $repeatType
* @return $this
*/
public function setRepeatType(?int $repeatType): self
{
$this->repeatType = $repeatType;
return $this;
}
/**
* @return bool
*/
public function isRepeatable(): bool
{
return $this->repeatType != null;
}
/**
* @return bool
*/
public function repeatDays(): bool
{
return $this->checkRepeatType(self::REPEAT_TYPE_DAY);
}
/**
* @return bool
*/
public function repeatWeekly(): bool
{
return $this->checkRepeatType(self::REPEAT_TYPE_WEEKLY);
}
/**
* @return bool
*/
public function repeatMonthly(): bool
{
return $this->checkRepeatType(self::REPEAT_TYPE_MONTHLY);
}
/**
* @return bool
*/
public function repeatTwoDays(): bool
{
return $this->checkRepeatType(self::REPEAT_TYPE_TWO_DAYS);
}
/**
* @return bool
*/
public function repeatThreeDays(): bool
{
return $this->checkRepeatType(self::REPEAT_TYPE_THREE_DAYS);
}
/**
* @return bool
*/
public function repeatFourDays(): bool
{
return $this->checkRepeatType(self::REPEAT_TYPE_FOUR_DAYS);
}
/**
* @param int $type
* @return bool
*/
private function checkRepeatType(int $type): bool
{
return $type === $this->repeatType;
}
public function getOfferPackageTask(): ?OfferPackageTask
{
return $this->offerPackageTask;
}
public function setOfferPackageTask(?OfferPackageTask $offerPackageTask): self
{
$this->offerPackageTask = $offerPackageTask;
return $this;
}
public function isCompleted(): bool
{
return $this->status === self::STATUS_COMPLETED;
}
public function getCompletedAt(): ?\DateTimeImmutable
{
return $this->completedAt;
}
public function setCompletedAt(?\DateTimeImmutable $completedAt): self
{
$this->completedAt = $completedAt;
return $this;
}
/**
* @return Collection|User[]
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
}
return $this;
}
public function removeUser(User $user): self
{
$this->users->removeElement($user);
return $this;
}
public function getInfo(): ?string
{
return $this->info;
}
public function setInfo(?string $info): self
{
$this->info = $info;
return $this;
}
public function getGraphicUrl(): ?string
{
return $this->graphic_url;
}
public function setGraphicUrl(?string $graphic_url): self
{
$this->graphic_url = $graphic_url;
return $this;
}
public function getIsGraphic(): ?bool
{
return $this->isGraphic;
}
public function setIsGraphic(bool $isGraphic): self
{
$this->isGraphic = $isGraphic;
return $this;
}
}