added tags for timesheets (#604)

This commit is contained in:
Mathias
2019-05-12 01:40:04 +02:00
committed by Kevin Papst
parent f31118292c
commit e29e183e84
84 changed files with 2132 additions and 158 deletions

View File

@@ -9,6 +9,7 @@
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
@@ -122,6 +123,30 @@ class Timesheet
*/
private $exported = false;
/**
* @var \App\Entity\Tag[]
*
* @ORM\ManyToMany(targetEntity="Tag", inversedBy="timesheets", cascade={"persist"})
* @ORM\JoinTable(
* name="kimai2_timesheet_tags",
* joinColumns={
* @ORM\JoinColumn(name="timesheet_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="tag_id", referencedColumnName="id")
* }
* )
*/
protected $tags;
/**
* Default constructor, initializes collections
*/
public function __construct()
{
$this->tags = new ArrayCollection();
}
/**
* Get entry id
*
@@ -319,6 +344,54 @@ class Timesheet
return $this->rate;
}
/**
* @param Tag $tag
* @return Timesheet
*/
public function addTag(Tag $tag)
{
if ($this->tags->contains($tag)) {
return $this;
}
$this->tags->add($tag);
$tag->addTimesheet($this);
return $this;
}
/**
* @param Tag $tag
*/
public function removeTag(Tag $tag)
{
if (!$this->tags->contains($tag)) {
return;
}
$this->tags->removeElement($tag);
$tag->removeTimesheet($this);
}
/**
* @return Tag[]|ArrayCollection
*/
public function getTags()
{
return $this->tags;
}
/**
* @return string[]
*/
public function getTagsAsArray()
{
return array_map(
function (Tag $element) {
return $element->getName();
},
$this->getTags()->toArray()
);
}
/**
* @return bool
*/