unify access to custom fields (#3106)

This commit is contained in:
Kevin Papst
2022-01-28 00:04:58 +01:00
committed by GitHub
parent 7a6fab8624
commit 4cb0ac37a6
16 changed files with 132 additions and 9 deletions

View File

@@ -261,6 +261,20 @@ class Activity implements EntityWithMetaFields, EntityWithBudget
return null;
}
/**
* @param string $name
* @return bool|int|string|null
*/
public function getMetaFieldValue(string $name)
{
$field = $this->getMetaField($name);
if ($field === null) {
return null;
}
return $field->getValue();
}
public function setMetaField(MetaTableTypeInterface $meta): EntityWithMetaFields
{
if (null === ($current = $this->getMetaField($meta->getName()))) {

View File

@@ -531,6 +531,20 @@ class Customer implements EntityWithMetaFields, EntityWithBudget
return null;
}
/**
* @param string $name
* @return bool|int|string|null
*/
public function getMetaFieldValue(string $name)
{
$field = $this->getMetaField($name);
if ($field === null) {
return null;
}
return $field->getValue();
}
public function setMetaField(MetaTableTypeInterface $meta): EntityWithMetaFields
{
if (null === ($current = $this->getMetaField($meta->getName()))) {

View File

@@ -441,6 +441,20 @@ class Invoice implements EntityWithMetaFields
return null;
}
/**
* @param string $name
* @return bool|int|string|null
*/
public function getMetaFieldValue(string $name)
{
$field = $this->getMetaField($name);
if ($field === null) {
return null;
}
return $field->getValue();
}
public function setMetaField(MetaTableTypeInterface $meta): EntityWithMetaFields
{
if (null === ($current = $this->getMetaField($meta->getName()))) {

View File

@@ -29,7 +29,7 @@ interface MetaTableTypeInterface
public function setName(string $name): MetaTableTypeInterface;
/**
* @return mixed|null
* @return int|bool|string|null
*/
public function getValue();

View File

@@ -109,7 +109,7 @@ trait MetaTableTypeTrait
}
/**
* @return mixed|null
* @return int|bool|string|null
*/
public function getValue()
{

View File

@@ -425,6 +425,20 @@ class Project implements EntityWithMetaFields, EntityWithBudget
return null;
}
/**
* @param string $name
* @return bool|int|string|null
*/
public function getMetaFieldValue(string $name)
{
$field = $this->getMetaField($name);
if ($field === null) {
return null;
}
return $field->getValue();
}
public function setMetaField(MetaTableTypeInterface $meta): EntityWithMetaFields
{
if (null === ($current = $this->getMetaField($meta->getName()))) {

View File

@@ -719,6 +719,20 @@ class Timesheet implements EntityWithMetaFields, ExportItemInterface
return null;
}
/**
* @param string $name
* @return bool|int|string|null
*/
public function getMetaFieldValue(string $name)
{
$field = $this->getMetaField($name);
if ($field === null) {
return null;
}
return $field->getValue();
}
public function setMetaField(MetaTableTypeInterface $meta): EntityWithMetaFields
{
if (null === ($current = $this->getMetaField($meta->getName()))) {

View File

@@ -537,7 +537,7 @@ class User implements UserInterface, EquatableInterface, \Serializable
/**
* @param string $name
* @param mixed $default
* @return bool|int|null|string
* @return bool|int|string|null
*/
public function getPreferenceValue(string $name, $default = null)
{
@@ -549,6 +549,15 @@ class User implements UserInterface, EquatableInterface, \Serializable
return $preference->getValue();
}
/**
* @param string $name
* @return bool|int|string|null
*/
public function getMetaFieldValue(string $name)
{
return $this->getPreferenceValue($name);
}
/**
* @param UserPreference $preference
* @return User