src/Entity/Task.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\TaskRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. /**
  9.  * @ORM\Entity(repositoryClass=TaskRepository::class)
  10.  */
  11. class Task
  12. {
  13.     /**
  14.      * Available status
  15.      */
  16.     const STATUS_PLANNED 1;
  17.     /**
  18.      *
  19.      */
  20.     const STATUS_DELAYED 2;
  21.     /**
  22.      *
  23.      */
  24.     const STATUS_COMPLETED 3;
  25.     /**
  26.      *
  27.      */
  28.     const STATUS_NOT_TO_DO 4;
  29.     /**
  30.      *
  31.      */
  32.     const STATUS_PAUSED 5;
  33.     /**
  34.      * Available status
  35.      */
  36.     const STATUS_REPLANNED 6;
  37.     /**
  38.      * AVAILABLE REPEATER
  39.      */
  40.     const REPEAT_TYPE_DAY 1;
  41.     /**
  42.      *
  43.      */
  44.     const REPEAT_TYPE_WEEKLY 2;
  45.     /**
  46.      *
  47.      */
  48.     const REPEAT_TYPE_MONTHLY 3;
  49.     /**
  50.      *
  51.      */
  52.     const REPEAT_TYPE_TWO_DAYS 4;
  53.     /**
  54.      *
  55.      */
  56.     const REPEAT_TYPE_THREE_DAYS 5;
  57.     /**
  58.      *
  59.      */
  60.     const REPEAT_TYPE_FOUR_DAYS 6;
  61.     /**
  62.      * @ORM\Id
  63.      * @ORM\GeneratedValue
  64.      * @ORM\Column(type="integer")
  65.      */
  66.     private $id;
  67.     /**
  68.      * @ORM\Column(type="text", nullable=true)
  69.      */
  70.     private $name;
  71.     /**
  72.      * @ORM\Column(type="text", nullable=true)
  73.      */
  74.     private $content;
  75.     /**
  76.      * @ORM\ManyToOne(targetEntity=Project::class, inversedBy="tasks")
  77.      * @ORM\JoinColumn(nullable=false)
  78.      */
  79.     private $project;
  80.     /**
  81.      * @ORM\Column(type="datetime_immutable")
  82.      */
  83.     private $createdAt;
  84.     /**
  85.      * @ORM\Column(type="datetime_immutable", nullable=true)
  86.      */
  87.     private $updatedAt;
  88.     /**
  89.      * @ORM\Column(type="datetime")
  90.      */
  91.     private $plannedOnDay;
  92.     /**
  93.      * @ORM\Column(type="integer", nullable=true)
  94.      */
  95.     private $status;
  96.     /**
  97.      * @ORM\ManyToOne(targetEntity=User::class)
  98.      */
  99.     private $createdBy;
  100.     /**
  101.      * @ORM\Column(type="integer", nullable=true)
  102.      */
  103.     private $repeatType;
  104.     /**
  105.      * @ORM\ManyToOne(targetEntity=OfferPackageTask::class, inversedBy="tasks")
  106.      */
  107.     private $offerPackageTask;
  108.     /**
  109.      * @ORM\Column(type="datetime_immutable", nullable=true)
  110.      */
  111.     private $completedAt;
  112.     /**
  113.      * @ORM\ManyToMany(targetEntity=User::class, inversedBy="tasks")
  114.      */
  115.     private $users;
  116.     /**
  117.      * @ORM\Column(type="text", nullable=true)
  118.      */
  119.     private $info;
  120.     /**
  121.      * @ORM\Column(type="text", nullable=true)
  122.      */
  123.     private $graphic_url;
  124.     /**
  125.      * @ORM\Column(type="boolean", options={"default": false})
  126.      */
  127.     private $isGraphic;
  128.     /**
  129.      * @param User|UserInterface $createdBy
  130.      */
  131.     public function __construct(User $createdBy)
  132.     {
  133.         $this->createdBy $createdBy;
  134.         $this->users = new ArrayCollection();
  135.         $this->createdAt = new \DateTimeImmutable();
  136.         $this->status self::STATUS_PLANNED;
  137.         $this->isGraphic false;
  138.         $this->addUser($createdBy);
  139.     }
  140.     /**
  141.      * @return int|null
  142.      */
  143.     public function getId(): ?int
  144.     {
  145.         return $this->id;
  146.     }
  147.     /**
  148.      * @return string|null
  149.      */
  150.     public function getName(): ?string
  151.     {
  152.         return $this->name;
  153.     }
  154.     /**
  155.      * @param string $name
  156.      * @return $this
  157.      */
  158.     public function setName(string $name): self
  159.     {
  160.         $this->name $name;
  161.         return $this;
  162.     }
  163.     /**
  164.      * @return string|null
  165.      */
  166.     public function getContent(): ?string
  167.     {
  168.         return $this->content;
  169.     }
  170.     /**
  171.      * @param string|null $content
  172.      * @return $this
  173.      */
  174.     public function setContent(?string $content): self
  175.     {
  176.         $this->content $content;
  177.         return $this;
  178.     }
  179.     /**
  180.      * @return Project|null
  181.      */
  182.     public function getProject(): ?Project
  183.     {
  184.         return $this->project;
  185.     }
  186.     /**
  187.      * @param Project|null $project
  188.      * @return $this
  189.      */
  190.     public function setProject(?Project $project): self
  191.     {
  192.         $this->project $project;
  193.         return $this;
  194.     }
  195.     /**
  196.      * @return \DateTimeImmutable|null
  197.      */
  198.     public function getCreatedAt(): ?\DateTimeImmutable
  199.     {
  200.         return $this->createdAt;
  201.     }
  202.     /**
  203.      * @param \DateTimeImmutable $createdAt
  204.      * @return $this
  205.      */
  206.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  207.     {
  208.         $this->createdAt $createdAt;
  209.         return $this;
  210.     }
  211.     /**
  212.      * @return \DateTimeImmutable|null
  213.      */
  214.     public function getUpdatedAt(): ?\DateTimeImmutable
  215.     {
  216.         return $this->updatedAt;
  217.     }
  218.     /**
  219.      * @param \DateTimeImmutable|null $updatedAt
  220.      * @return $this
  221.      */
  222.     public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self
  223.     {
  224.         $this->updatedAt $updatedAt;
  225.         return $this;
  226.     }
  227.     /**
  228.      * @return \DateTimeInterface|null
  229.      */
  230.     public function getPlannedOnDay(): ?\DateTimeInterface
  231.     {
  232.         return $this->plannedOnDay;
  233.     }
  234.     /**
  235.      * @param \DateTimeInterface $plannedOnDay
  236.      * @return $this
  237.      */
  238.     public function setPlannedOnDay(\DateTimeInterface $plannedOnDay): self
  239.     {
  240.         $this->plannedOnDay $plannedOnDay;
  241.         return $this;
  242.     }
  243.     /**
  244.      * @return int|null
  245.      */
  246.     public function getStatus(): ?int
  247.     {
  248.         return $this->status;
  249.     }
  250.     /**
  251.      * @param int|null $status
  252.      * @return $this
  253.      */
  254.     public function setStatus(?int $status): self
  255.     {
  256.         $this->status $status;
  257.         return $this;
  258.     }
  259.     public function getStatusText()
  260.     {
  261.         switch($this->status) {
  262.             case self::STATUS_NOT_TO_DO:
  263.                 return "Niewykonywane |".$this->getInfo()."|";
  264.             case self::STATUS_PAUSED:
  265.                 return "Zapauzowane |".$this->getInfo()."|";
  266.             default:
  267.                 return "";
  268.         }
  269.     }
  270.     /**
  271.      * @return User|null
  272.      */
  273.     public function getCreatedBy(): ?User
  274.     {
  275.         return $this->createdBy;
  276.     }
  277.     /**
  278.      * @param User|UserInterface|null $createdBy
  279.      * @return $this
  280.      */
  281.     public function setCreatedBy(?User $createdBy): self
  282.     {
  283.         $this->createdBy $createdBy;
  284.         return $this;
  285.     }
  286.     /**
  287.      * @return int|null
  288.      */
  289.     public function getRepeatType(): ?int
  290.     {
  291.         return $this->repeatType;
  292.     }
  293.     /**
  294.      * @param int|null $repeatType
  295.      * @return $this
  296.      */
  297.     public function setRepeatType(?int $repeatType): self
  298.     {
  299.         $this->repeatType $repeatType;
  300.         return $this;
  301.     }
  302.     /**
  303.      * @return bool
  304.      */
  305.     public function isRepeatable(): bool
  306.     {
  307.         return $this->repeatType != null;
  308.     }
  309.     /**
  310.      * @return bool
  311.      */
  312.     public function repeatDays(): bool
  313.     {
  314.         return $this->checkRepeatType(self::REPEAT_TYPE_DAY);
  315.     }
  316.     /**
  317.      * @return bool
  318.      */
  319.     public function repeatWeekly(): bool
  320.     {
  321.         return $this->checkRepeatType(self::REPEAT_TYPE_WEEKLY);
  322.     }
  323.     /**
  324.      * @return bool
  325.      */
  326.     public function repeatMonthly(): bool
  327.     {
  328.         return $this->checkRepeatType(self::REPEAT_TYPE_MONTHLY);
  329.     }
  330.     /**
  331.      * @return bool
  332.      */
  333.     public function repeatTwoDays(): bool
  334.     {
  335.         return $this->checkRepeatType(self::REPEAT_TYPE_TWO_DAYS);
  336.     }
  337.     /**
  338.      * @return bool
  339.      */
  340.     public function repeatThreeDays(): bool
  341.     {
  342.         return $this->checkRepeatType(self::REPEAT_TYPE_THREE_DAYS);
  343.     }
  344.     /**
  345.      * @return bool
  346.      */
  347.     public function repeatFourDays(): bool
  348.     {
  349.         return $this->checkRepeatType(self::REPEAT_TYPE_FOUR_DAYS);
  350.     }
  351.     /**
  352.      * @param int $type
  353.      * @return bool
  354.      */
  355.     private function checkRepeatType(int $type): bool
  356.     {
  357.         return $type === $this->repeatType;
  358.     }
  359.     public function getOfferPackageTask(): ?OfferPackageTask
  360.     {
  361.         return $this->offerPackageTask;
  362.     }
  363.     public function setOfferPackageTask(?OfferPackageTask $offerPackageTask): self
  364.     {
  365.         $this->offerPackageTask $offerPackageTask;
  366.         return $this;
  367.     }
  368.     public function isCompleted(): bool
  369.     {
  370.         return $this->status === self::STATUS_COMPLETED;
  371.     }
  372.     public function getCompletedAt(): ?\DateTimeImmutable
  373.     {
  374.         return $this->completedAt;
  375.     }
  376.     public function setCompletedAt(?\DateTimeImmutable $completedAt): self
  377.     {
  378.         $this->completedAt $completedAt;
  379.         return $this;
  380.     }
  381.     /**
  382.      * @return Collection|User[]
  383.      */
  384.     public function getUsers(): Collection
  385.     {
  386.         return $this->users;
  387.     }
  388.     public function addUser(User $user): self
  389.     {
  390.         if (!$this->users->contains($user)) {
  391.             $this->users[] = $user;
  392.         }
  393.         return $this;
  394.     }
  395.     public function removeUser(User $user): self
  396.     {
  397.         $this->users->removeElement($user);
  398.         return $this;
  399.     }
  400.     public function getInfo(): ?string
  401.     {
  402.         return $this->info;
  403.     }
  404.     public function setInfo(?string $info): self
  405.     {
  406.         $this->info $info;
  407.         return $this;
  408.     }
  409.     public function getGraphicUrl(): ?string
  410.     {
  411.         return $this->graphic_url;
  412.     }
  413.     public function setGraphicUrl(?string $graphic_url): self
  414.     {
  415.         $this->graphic_url $graphic_url;
  416.         return $this;
  417.     }
  418.     public function getIsGraphic(): ?bool
  419.     {
  420.         return $this->isGraphic;
  421.     }
  422.     public function setIsGraphic(bool $isGraphic): self
  423.     {
  424.         $this->isGraphic $isGraphic;
  425.         return $this;
  426.     }
  427. }