mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-12 11:24:31 +02:00
Fixed coding style.
This commit is contained in:
parent
24939f2342
commit
fd61c8d9e2
129 changed files with 962 additions and 1091 deletions
|
@ -45,7 +45,6 @@ namespace App\Services;
|
|||
use App\Entity\Attachments\Attachment;
|
||||
use App\Entity\Attachments\AttachmentType;
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Base\AbstractNamedDBElement;
|
||||
use App\Entity\Contracts\NamedElementInterface;
|
||||
use App\Entity\Devices\Device;
|
||||
use App\Entity\Parameters\AbstractParameter;
|
||||
|
@ -93,7 +92,7 @@ class ElementTypeNameGenerator
|
|||
Pricedetail::class => $this->translator->trans('pricedetail.label'),
|
||||
Group::class => $this->translator->trans('group.label'),
|
||||
User::class => $this->translator->trans('user.label'),
|
||||
AbstractParameter::class => $this->translator->trans('parameter.label')
|
||||
AbstractParameter::class => $this->translator->trans('parameter.label'),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -135,7 +134,7 @@ class ElementTypeNameGenerator
|
|||
* It uses getLocalizedLabel to determine the type.
|
||||
*
|
||||
* @param NamedElementInterface $entity the entity for which the string should be generated
|
||||
* @param bool $use_html If set to true, a html string is returned, where the type is set italic
|
||||
* @param bool $use_html If set to true, a html string is returned, where the type is set italic
|
||||
*
|
||||
* @return string The localized string
|
||||
*
|
||||
|
|
|
@ -43,14 +43,6 @@ declare(strict_types=1);
|
|||
namespace App\Services;
|
||||
|
||||
use App\Entity\Base\AbstractNamedDBElement;
|
||||
use Symfony\Component\Serializer\Encoder\CsvEncoder;
|
||||
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
||||
use Symfony\Component\Serializer\Encoder\XmlEncoder;
|
||||
use Symfony\Component\Serializer\Encoder\YamlEncoder;
|
||||
use Symfony\Component\Serializer\Normalizer\DataUriNormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
||||
use Symfony\Component\Serializer\Serializer;
|
||||
use function in_array;
|
||||
use InvalidArgumentException;
|
||||
use function is_array;
|
||||
|
@ -59,6 +51,13 @@ use ReflectionException;
|
|||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
use Symfony\Component\Serializer\Encoder\CsvEncoder;
|
||||
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
||||
use Symfony\Component\Serializer\Encoder\XmlEncoder;
|
||||
use Symfony\Component\Serializer\Encoder\YamlEncoder;
|
||||
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
||||
use Symfony\Component\Serializer\Serializer;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
|
||||
/**
|
||||
|
|
|
@ -43,7 +43,6 @@ declare(strict_types=1);
|
|||
namespace App\Services;
|
||||
|
||||
use App\Entity\Base\AbstractStructuralDBElement;
|
||||
use Symfony\Bundle\MakerBundle\Str;
|
||||
use function count;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use InvalidArgumentException;
|
||||
|
@ -70,10 +69,10 @@ class EntityImporter
|
|||
* Creates many entries at once, based on a (text) list of name.
|
||||
* The created enties are not persisted to database yet, so you have to do it yourself.
|
||||
*
|
||||
* @param string $lines The list of names seperated by \n
|
||||
* @param string $class_name The name of the class for which the entities should be created
|
||||
* @param string $lines The list of names seperated by \n
|
||||
* @param string $class_name The name of the class for which the entities should be created
|
||||
* @param AbstractStructuralDBElement|null $parent the element which will be used as parent element for new elements
|
||||
* @param array $errors an associative array containing all validation errors
|
||||
* @param array $errors an associative array containing all validation errors
|
||||
*
|
||||
* @return AbstractStructuralDBElement[] An array containing all valid imported entities (with the type $class_name)
|
||||
*/
|
||||
|
@ -228,8 +227,8 @@ class EntityImporter
|
|||
/**
|
||||
* This functions corrects the parent setting based on the children value of the parent.
|
||||
*
|
||||
* @param iterable $entities the list of entities that should be fixed
|
||||
* @param null|AbstractStructuralDBElement $parent the parent, to which the entity should be set
|
||||
* @param iterable $entities the list of entities that should be fixed
|
||||
* @param AbstractStructuralDBElement|null $parent the parent, to which the entity should be set
|
||||
*/
|
||||
protected function correctParentEntites(iterable $entities, $parent = null): void
|
||||
{
|
||||
|
|
|
@ -125,9 +125,8 @@ class EntityURLGenerator
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets the URL to view the given element at a given timestamp
|
||||
* @param AbstractDBElement $entity
|
||||
* @param \DateTime $dateTime
|
||||
* Gets the URL to view the given element at a given timestamp.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function timeTravelURL(AbstractDBElement $entity, \DateTime $dateTime): string
|
||||
|
@ -154,32 +153,32 @@ class EntityURLGenerator
|
|||
$this->mapToController($map, $entity),
|
||||
[
|
||||
'id' => $entity->getID(),
|
||||
'timestamp' => $dateTime->getTimestamp()
|
||||
'timestamp' => $dateTime->getTimestamp(),
|
||||
]
|
||||
);
|
||||
} catch (EntityNotSupportedException $exception) {
|
||||
if ($entity instanceof PartLot) {
|
||||
return $this->urlGenerator->generate('part_info', [
|
||||
'id' => $entity->getPart()->getID(),
|
||||
'timestamp' => $dateTime->getTimestamp()
|
||||
'timestamp' => $dateTime->getTimestamp(),
|
||||
]);
|
||||
}
|
||||
if ($entity instanceof PartAttachment) {
|
||||
return $this->urlGenerator->generate('part_info', [
|
||||
'id' => $entity->getElement()->getID(),
|
||||
'timestamp' => $dateTime->getTimestamp()
|
||||
'timestamp' => $dateTime->getTimestamp(),
|
||||
]);
|
||||
}
|
||||
if ($entity instanceof Orderdetail) {
|
||||
return $this->urlGenerator->generate('part_info', [
|
||||
'id' => $entity->getPart()->getID(),
|
||||
'timestamp' => $dateTime->getTimestamp()
|
||||
'timestamp' => $dateTime->getTimestamp(),
|
||||
]);
|
||||
}
|
||||
if ($entity instanceof Pricedetail) {
|
||||
return $this->urlGenerator->generate('part_info', [
|
||||
'id' => $entity->getOrderdetail()->getPart()->getID(),
|
||||
'timestamp' => $dateTime->getTimestamp()
|
||||
'timestamp' => $dateTime->getTimestamp(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -20,7 +23,6 @@
|
|||
|
||||
namespace App\Services\LogSystem;
|
||||
|
||||
|
||||
class EventCommentHelper
|
||||
{
|
||||
protected const MAX_MESSAGE_LENGTH = 255;
|
||||
|
@ -36,7 +38,6 @@ class EventCommentHelper
|
|||
* Set the message that will be saved for all ElementEdited/Created/Deleted messages during the next flush.
|
||||
* Set to null if no message should be shown.
|
||||
* After the flush this message is cleared.
|
||||
* @param string|null $message
|
||||
*/
|
||||
public function setMessage(?string $message): void
|
||||
{
|
||||
|
@ -46,6 +47,7 @@ class EventCommentHelper
|
|||
|
||||
/**
|
||||
* Returns the currently set message, or null if no message is set yet.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getMessage(): ?string
|
||||
|
@ -63,10 +65,11 @@ class EventCommentHelper
|
|||
|
||||
/**
|
||||
* Check if a message is currently set.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMessageSet(): bool
|
||||
{
|
||||
return is_string($this->message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -20,7 +23,6 @@
|
|||
|
||||
namespace App\Services\LogSystem;
|
||||
|
||||
|
||||
use App\Entity\LogSystem\AbstractLogEntry;
|
||||
|
||||
class EventUndoHelper
|
||||
|
@ -41,7 +43,7 @@ class EventUndoHelper
|
|||
|
||||
public function setMode(string $mode): void
|
||||
{
|
||||
if (!in_array($mode, self::ALLOWED_MODES)) {
|
||||
if (! in_array($mode, self::ALLOWED_MODES, true)) {
|
||||
throw new \InvalidArgumentException('Invalid mode passed!');
|
||||
}
|
||||
$this->mode = $mode;
|
||||
|
@ -55,7 +57,6 @@ class EventUndoHelper
|
|||
/**
|
||||
* Set which event log is currently undone.
|
||||
* After the flush this message is cleared.
|
||||
* @param AbstractLogEntry|null $undone_event
|
||||
*/
|
||||
public function setUndoneEvent(?AbstractLogEntry $undone_event): void
|
||||
{
|
||||
|
@ -64,6 +65,7 @@ class EventUndoHelper
|
|||
|
||||
/**
|
||||
* Returns event that is currently undone.
|
||||
*
|
||||
* @return AbstractLogEntry|null
|
||||
*/
|
||||
public function getUndoneEvent(): ?AbstractLogEntry
|
||||
|
@ -80,11 +82,12 @@ class EventUndoHelper
|
|||
}
|
||||
|
||||
/**
|
||||
* Check if a event is undone
|
||||
* Check if a event is undone.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isUndo(): bool
|
||||
{
|
||||
return ($this->undone_event instanceof AbstractLogEntry);
|
||||
return $this->undone_event instanceof AbstractLogEntry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -20,7 +23,6 @@
|
|||
|
||||
namespace App\Services\LogSystem;
|
||||
|
||||
|
||||
use App\Entity\Attachments\AttachmentContainingDBElement;
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Parts\Part;
|
||||
|
@ -29,13 +31,12 @@ class HistoryHelper
|
|||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing all elements that are associated with the argument.
|
||||
* The returned array contains the given element.
|
||||
* @param AbstractDBElement $element
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAssociatedElements(AbstractDBElement $element): array
|
||||
|
@ -58,4 +59,4 @@ class HistoryHelper
|
|||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,6 @@ use App\Entity\LogSystem\UserLoginLogEntry;
|
|||
use App\Entity\LogSystem\UserLogoutLogEntry;
|
||||
use App\Entity\LogSystem\UserNotAllowedLogEntry;
|
||||
use App\Services\ElementTypeNameGenerator;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
|
@ -64,12 +63,11 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||
*/
|
||||
class LogEntryExtraFormatter
|
||||
{
|
||||
protected const CONSOLE_SEARCH = ['<i class="fas fa-long-arrow-alt-right"></i>', '<i>', '</i>', '<b>', '</b>'];
|
||||
protected const CONSOLE_REPLACE = ['→', '<info>', '</info>', '<error>', '</error>'];
|
||||
protected $translator;
|
||||
protected $elementTypeNameGenerator;
|
||||
|
||||
protected const CONSOLE_SEARCH = ['<i class="fas fa-long-arrow-alt-right"></i>', '<i>', '</i>', '<b>', '</b>', ];
|
||||
protected const CONSOLE_REPLACE = ['→', '<info>', '</info>', '<error>', '</error>'];
|
||||
|
||||
public function __construct(TranslatorInterface $translator, ElementTypeNameGenerator $elementTypeNameGenerator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
|
@ -90,15 +88,40 @@ class LogEntryExtraFormatter
|
|||
foreach ($arr as $key => $value) {
|
||||
$str = '';
|
||||
if (is_string($key)) {
|
||||
$str .= '<error>' . $this->translator->trans($key) . '</error>: ';
|
||||
$str .= '<error>'.$this->translator->trans($key).'</error>: ';
|
||||
}
|
||||
$str .= $value;
|
||||
if (!empty($str)) {
|
||||
if (! empty($str)) {
|
||||
$tmp[] = $str;
|
||||
}
|
||||
}
|
||||
|
||||
return str_replace(static::CONSOLE_SEARCH, static::CONSOLE_REPLACE, implode("; ", $tmp));
|
||||
return str_replace(static::CONSOLE_SEARCH, static::CONSOLE_REPLACE, implode('; ', $tmp));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a HTML formatted string containing a user viewable form of the Extra data.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function format(AbstractLogEntry $context): string
|
||||
{
|
||||
$arr = $this->getInternalFormat($context);
|
||||
$tmp = [];
|
||||
|
||||
//Make an array with entries in the form "<b>Key:</b> Value"
|
||||
foreach ($arr as $key => $value) {
|
||||
$str = '';
|
||||
if (is_string($key)) {
|
||||
$str .= '<b>'.$this->translator->trans($key).'</b>: ';
|
||||
}
|
||||
$str .= $value;
|
||||
if (! empty($str)) {
|
||||
$tmp[] = $str;
|
||||
}
|
||||
}
|
||||
|
||||
return implode('; ', $tmp);
|
||||
}
|
||||
|
||||
protected function getInternalFormat(AbstractLogEntry $context): array
|
||||
|
@ -129,9 +152,9 @@ class LogEntryExtraFormatter
|
|||
|
||||
if ($context instanceof LogWithEventUndoInterface) {
|
||||
if ($context->isUndoEvent()) {
|
||||
if ($context->getUndoMode() === 'undo') {
|
||||
if ('undo' === $context->getUndoMode()) {
|
||||
$array['log.undo_mode.undo'] = (string) $context->getUndoEventID();
|
||||
} elseif ($context->getUndoMode() === 'revert') {
|
||||
} elseif ('revert' === $context->getUndoMode()) {
|
||||
$array['log.undo_mode.revert'] = (string) $context->getUndoEventID();
|
||||
}
|
||||
}
|
||||
|
@ -146,7 +169,7 @@ class LogEntryExtraFormatter
|
|||
}
|
||||
|
||||
if ($context instanceof ElementDeletedLogEntry) {
|
||||
if ($context->getOldName() !== null) {
|
||||
if (null !== $context->getOldName()) {
|
||||
$array['log.element_deleted.old_name'] = htmlspecialchars($context->getOldName());
|
||||
} else {
|
||||
$array['log.element_deleted.old_name'] = $this->translator->trans('log.element_deleted.old_name.unknown');
|
||||
|
@ -183,29 +206,4 @@ class LogEntryExtraFormatter
|
|||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a HTML formatted string containing a user viewable form of the Extra data.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function format(AbstractLogEntry $context): string
|
||||
{
|
||||
$arr = $this->getInternalFormat($context);
|
||||
$tmp = [];
|
||||
|
||||
//Make an array with entries in the form "<b>Key:</b> Value"
|
||||
foreach ($arr as $key => $value) {
|
||||
$str = '';
|
||||
if (is_string($key)) {
|
||||
$str .= '<b>' . $this->translator->trans($key) . '</b>: ';
|
||||
}
|
||||
$str .= $value;
|
||||
if (!empty($str)) {
|
||||
$tmp[] = $str;
|
||||
}
|
||||
}
|
||||
|
||||
return implode("; ", $tmp);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -21,7 +24,6 @@
|
|||
|
||||
namespace App\Services\LogSystem;
|
||||
|
||||
|
||||
use App\Entity\Attachments\AttachmentType;
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Base\AbstractStructuralDBElement;
|
||||
|
@ -47,8 +49,10 @@ class TimeTravel
|
|||
|
||||
/**
|
||||
* Undeletes the element with the given ID.
|
||||
* @param string $class The class name of the element that should be undeleted
|
||||
* @param int $id The ID of the element that should be undeleted.
|
||||
*
|
||||
* @param string $class The class name of the element that should be undeleted
|
||||
* @param int $id The ID of the element that should be undeleted.
|
||||
*
|
||||
* @return AbstractDBElement
|
||||
*/
|
||||
public function undeleteEntity(string $class, int $id): AbstractDBElement
|
||||
|
@ -61,21 +65,21 @@ class TimeTravel
|
|||
$this->setField($element, 'id', $id);
|
||||
|
||||
//Let database determine when it will be created
|
||||
$this->setField($element,'addedDate', null);
|
||||
$this->setField($element, 'addedDate', null);
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Revert the given element to the state it has on the given timestamp
|
||||
* @param AbstractDBElement $element
|
||||
* @param \DateTime $timestamp
|
||||
* @param AbstractLogEntry[] $reverted_elements
|
||||
* Revert the given element to the state it has on the given timestamp.
|
||||
*
|
||||
* @param AbstractLogEntry[] $reverted_elements
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function revertEntityToTimestamp(AbstractDBElement $element, \DateTime $timestamp, array $reverted_elements = [])
|
||||
public function revertEntityToTimestamp(AbstractDBElement $element, \DateTime $timestamp, array $reverted_elements = []): void
|
||||
{
|
||||
if (!$element instanceof TimeStampableInterface) {
|
||||
if (! $element instanceof TimeStampableInterface) {
|
||||
throw new \InvalidArgumentException('$element must have a Timestamp!');
|
||||
}
|
||||
|
||||
|
@ -84,7 +88,7 @@ class TimeTravel
|
|||
}
|
||||
|
||||
//Skip this process if already were reverted...
|
||||
if (in_array($element, $reverted_elements)) {
|
||||
if (in_array($element, $reverted_elements, true)) {
|
||||
return;
|
||||
}
|
||||
$reverted_elements[] = $element;
|
||||
|
@ -122,35 +126,34 @@ class TimeTravel
|
|||
$associations = $metadata->getAssociationMappings();
|
||||
foreach ($associations as $field => $mapping) {
|
||||
if (
|
||||
($element instanceof AbstractStructuralDBElement && ($field === 'parts' || $field === 'children'))
|
||||
|| ($element instanceof AttachmentType && $field === 'attachments')
|
||||
($element instanceof AbstractStructuralDBElement && ('parts' === $field || 'children' === $field))
|
||||
|| ($element instanceof AttachmentType && 'attachments' === $field)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
//Revert many to one association (one element in property)
|
||||
if (
|
||||
$mapping['type'] === ClassMetadata::MANY_TO_ONE
|
||||
|| $mapping['type'] === ClassMetadata::ONE_TO_ONE
|
||||
ClassMetadata::MANY_TO_ONE === $mapping['type']
|
||||
|| ClassMetadata::ONE_TO_ONE === $mapping['type']
|
||||
) {
|
||||
$target_element = $this->getField($element, $field);
|
||||
if ($target_element !== null && $element->getLastModified() > $timestamp) {
|
||||
if (null !== $target_element && $element->getLastModified() > $timestamp) {
|
||||
$this->revertEntityToTimestamp($target_element, $timestamp, $reverted_elements);
|
||||
}
|
||||
} elseif ( //Revert *_TO_MANY associations (collection properties)
|
||||
($mapping['type'] === ClassMetadata::MANY_TO_MANY
|
||||
|| $mapping['type'] === ClassMetadata::ONE_TO_MANY)
|
||||
&& $mapping['isOwningSide'] === false
|
||||
(ClassMetadata::MANY_TO_MANY === $mapping['type']
|
||||
|| ClassMetadata::ONE_TO_MANY === $mapping['type'])
|
||||
&& false === $mapping['isOwningSide']
|
||||
) {
|
||||
$target_elements = $this->getField($element, $field);
|
||||
if ($target_elements === null || count($target_elements) > 10) {
|
||||
if (null === $target_elements || count($target_elements) > 10) {
|
||||
continue;
|
||||
}
|
||||
foreach ($target_elements as $target_element) {
|
||||
if ($target_element !== null && $element->getLastModified() >= $timestamp) {
|
||||
if (null !== $target_element && $element->getLastModified() >= $timestamp) {
|
||||
//Remove the element from collection, if it did not existed at $timestamp
|
||||
if (!$this->repo->getElementExistedAtTimestamp($target_element, $timestamp)) {
|
||||
if (! $this->repo->getElementExistedAtTimestamp($target_element, $timestamp)) {
|
||||
if ($target_elements instanceof Collection) {
|
||||
$target_elements->removeElement($target_element);
|
||||
}
|
||||
|
@ -159,23 +162,21 @@ class TimeTravel
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the changeset in the given LogEntry to the element
|
||||
* @param AbstractDBElement $element
|
||||
* @param TimeTravelInterface $logEntry
|
||||
* Apply the changeset in the given LogEntry to the element.
|
||||
*
|
||||
* @throws \Doctrine\ORM\Mapping\MappingException
|
||||
*/
|
||||
public function applyEntry(AbstractDBElement $element, TimeTravelInterface $logEntry): void
|
||||
{
|
||||
//Skip if this does not provide any info...
|
||||
if (!$logEntry->hasOldDataInformations()) {
|
||||
if (! $logEntry->hasOldDataInformations()) {
|
||||
return;
|
||||
}
|
||||
if (!$element instanceof TimeStampableInterface) {
|
||||
if (! $element instanceof TimeStampableInterface) {
|
||||
return;
|
||||
}
|
||||
$metadata = $this->em->getClassMetadata(get_class($element));
|
||||
|
@ -204,14 +205,15 @@ class TimeTravel
|
|||
$reflection = new \ReflectionClass(get_class($element));
|
||||
$property = $reflection->getProperty($field);
|
||||
$property->setAccessible(true);
|
||||
|
||||
return $property->getValue($element);
|
||||
}
|
||||
|
||||
protected function setField(AbstractDBElement $element, string $field, $new_value)
|
||||
protected function setField(AbstractDBElement $element, string $field, $new_value): void
|
||||
{
|
||||
$reflection = new \ReflectionClass(get_class($element));
|
||||
$property = $reflection->getProperty($field);
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($element, $new_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,6 @@ use Symfony\Component\Config\ConfigCache;
|
|||
use Symfony\Component\Config\Definition\Processor;
|
||||
use Symfony\Component\Config\Resource\FileResource;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class PermissionResolver
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -20,7 +23,6 @@
|
|||
|
||||
namespace App\Services;
|
||||
|
||||
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Entity\Attachments\AttachmentType;
|
||||
use App\Entity\Devices\Device;
|
||||
|
@ -49,7 +51,7 @@ class StatisticsHelper
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the count of distinct parts
|
||||
* Returns the count of distinct parts.
|
||||
*/
|
||||
public function getDistinctPartsCount(): int
|
||||
{
|
||||
|
@ -57,8 +59,10 @@ class StatisticsHelper
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the summed instocked over all parts (only parts without a measurement unit)
|
||||
* Returns the summed instocked over all parts (only parts without a measurement unit).
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \Doctrine\ORM\NoResultException
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
*/
|
||||
|
@ -68,8 +72,10 @@ class StatisticsHelper
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the number of all parts which have price informations
|
||||
* Returns the number of all parts which have price informations.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @throws \Doctrine\ORM\NoResultException
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
*/
|
||||
|
@ -80,7 +86,7 @@ class StatisticsHelper
|
|||
|
||||
/**
|
||||
* Returns the number of datastructures for the given type.
|
||||
* @param string $type
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getDataStructuresCount(string $type): int
|
||||
|
@ -97,17 +103,19 @@ class StatisticsHelper
|
|||
'currency' => Currency::class,
|
||||
];
|
||||
|
||||
if (!isset($arr[$type])) {
|
||||
if (! isset($arr[$type])) {
|
||||
throw new \InvalidArgumentException('No count for the given type available!');
|
||||
}
|
||||
|
||||
/** @var EntityRepository $repo */
|
||||
$repo = $this->em->getRepository($arr[$type]);
|
||||
|
||||
return $repo->count([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the count of all attachments.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getAttachmentsCount(): int
|
||||
|
@ -116,7 +124,8 @@ class StatisticsHelper
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets the count of all private/secure attachments
|
||||
* Gets the count of all private/secure attachments.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPrivateAttachmentsCount(): int
|
||||
|
@ -125,8 +134,10 @@ class StatisticsHelper
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets the count of all external (only containing an URL) attachments
|
||||
* Gets the count of all external (only containing an URL) attachments.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @throws \Doctrine\ORM\NoResultException
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
*/
|
||||
|
@ -137,7 +148,9 @@ class StatisticsHelper
|
|||
|
||||
/**
|
||||
* Gets the count of all attachments where the user uploaded an file.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @throws \Doctrine\ORM\NoResultException
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
*/
|
||||
|
@ -145,4 +158,4 @@ class StatisticsHelper
|
|||
{
|
||||
return $this->attachment_repo->getUserUploadedAttachments();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,12 +58,12 @@ class StructuralElementRecursionHelper
|
|||
* Executes an function (callable) recursivly for $element and every of its children.
|
||||
*
|
||||
* @param AbstractStructuralDBElement $element The element on which the func should be executed
|
||||
* @param callable $func The function which should be executed for each element.
|
||||
* $func has the signature function(StructuralDBElement $element) : void
|
||||
* @param int $max_depth The maximum depth for which should be recursivly called. So if this is set to 5, after the
|
||||
* 5th level the execution is stopped.
|
||||
* @param bool $call_from_bottom If set to true the bottom elements (elements with high level) will be called first.
|
||||
* Set to false if you want to call the top elements first.
|
||||
* @param callable $func The function which should be executed for each element.
|
||||
* $func has the signature function(StructuralDBElement $element) : void
|
||||
* @param int $max_depth The maximum depth for which should be recursivly called. So if this is set to 5, after the
|
||||
* 5th level the execution is stopped.
|
||||
* @param bool $call_from_bottom If set to true the bottom elements (elements with high level) will be called first.
|
||||
* Set to false if you want to call the top elements first.
|
||||
*/
|
||||
public function execute(AbstractStructuralDBElement $element, callable $func, int $max_depth = -1, $call_from_bottom = true): void
|
||||
{
|
||||
|
@ -94,8 +94,8 @@ class StructuralElementRecursionHelper
|
|||
* Deletes the $element and all its subelements recursivly.
|
||||
*
|
||||
* @param AbstractStructuralDBElement $element the element which should be deleted
|
||||
* @param bool $flush When set to true the changes will also be flushed to DB. Set to false if you want to flush
|
||||
* later.
|
||||
* @param bool $flush When set to true the changes will also be flushed to DB. Set to false if you want to flush
|
||||
* later.
|
||||
*/
|
||||
public function delete(AbstractStructuralDBElement $element, bool $flush = true): void
|
||||
{
|
||||
|
|
|
@ -69,7 +69,7 @@ class NodesListBuilder
|
|||
* Gets a flattened hierachical tree. Useful for generating option lists.
|
||||
* In difference to the Repository Function, the results here are cached.
|
||||
*
|
||||
* @param string $class_name The class name of the entity you want to retrieve.
|
||||
* @param string $class_name The class name of the entity you want to retrieve.
|
||||
* @param AbstractStructuralDBElement|null $parent This entity will be used as root element. Set to null, to use global root
|
||||
*
|
||||
* @return AbstractStructuralDBElement[] A flattened list containing the tree elements.
|
||||
|
|
|
@ -76,10 +76,10 @@ class TreeViewGenerator
|
|||
/**
|
||||
* Gets a TreeView list for the entities of the given class.
|
||||
*
|
||||
* @param string $class The class for which the treeView should be generated
|
||||
* @param string $class The class for which the treeView should be generated
|
||||
* @param AbstractStructuralDBElement|null $parent The root nodes in the tree should have this element as parent (use null, if you want to get all entities)
|
||||
* @param string $href_type The link type that will be generated for the hyperlink section of each node (see EntityURLGenerator for possible values).
|
||||
* Set to empty string, to disable href field.
|
||||
* @param string $href_type The link type that will be generated for the hyperlink section of each node (see EntityURLGenerator for possible values).
|
||||
* Set to empty string, to disable href field.
|
||||
* @param AbstractDBElement|null $selectedElement The element that should be selected. If set to null, no element will be selected.
|
||||
*
|
||||
* @return TreeViewNode[] An array of TreeViewNode[] elements of the root elements.
|
||||
|
@ -132,7 +132,7 @@ class TreeViewGenerator
|
|||
* Gets a tree of TreeViewNode elements. The root elements has $parent as parent.
|
||||
* The treeview is generic, that means the href are null and ID values are set.
|
||||
*
|
||||
* @param string $class The class for which the tree should be generated
|
||||
* @param string $class The class for which the tree should be generated
|
||||
* @param AbstractStructuralDBElement|null $parent The parent the root elements should have.
|
||||
*
|
||||
* @return TreeViewNode[]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue