support custom fields for timesheets, customers, projects and activities (#871)

This commit is contained in:
Kevin Papst
2019-06-26 00:39:05 +02:00
committed by GitHub
parent 994c671fd8
commit d8621f0b7a
103 changed files with 2567 additions and 238 deletions

View File

@@ -18,7 +18,7 @@ use Symfony\Component\Validator\Constraints as Assert;
* @ORM\Table(name="kimai2_activities")
* @ORM\Entity(repositoryClass="App\Repository\ActivityRepository")
*/
class Activity
class Activity implements EntityWithMetaFields
{
/**
* @var int
@@ -73,9 +73,17 @@ class Activity
use ColorTrait;
use BudgetTrait;
/**
* @var ActivityMeta[]|Collection
*
* @ORM\OneToMany(targetEntity="App\Entity\ActivityMeta", mappedBy="activity", cascade={"persist"})
*/
private $meta;
public function __construct()
{
$this->timesheets = new ArrayCollection();
$this->meta = new ArrayCollection();
}
public function getId(): ?int
@@ -139,6 +147,55 @@ class Activity
return $this->visible;
}
/**
* @internal only here for symfony forms
* @return Collection|MetaTableTypeInterface[]
*/
public function getMetaFields(): Collection
{
return $this->meta;
}
/**
* @return MetaTableTypeInterface[]
*/
public function getVisibleMetaFields(): array
{
$all = [];
foreach ($this->meta as $meta) {
if ($meta->isVisible()) {
$all[] = $meta;
}
}
return $all;
}
public function getMetaField(string $name): ?MetaTableTypeInterface
{
foreach ($this->meta as $field) {
if ($field->getName() === $name) {
return $field;
}
}
return null;
}
public function setMetaField(MetaTableTypeInterface $meta): EntityWithMetaFields
{
if (null === ($current = $this->getMetaField($meta->getName()))) {
$meta->setEntity($this);
$this->meta->add($meta);
return $this;
}
$current->merge($meta);
return $this;
}
/**
* @return string
*/