mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-02 22:44:33 +02:00
Merge branch 'master' into php81-migration
This commit is contained in:
commit
58b2c2bd69
12 changed files with 483 additions and 438 deletions
|
@ -26,6 +26,7 @@ use App\Entity\Attachments\Attachment;
|
|||
use App\Entity\Attachments\AttachmentType;
|
||||
use App\Entity\Attachments\PartAttachment;
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Parameters\PartParameter;
|
||||
use App\Entity\ProjectSystem\Project;
|
||||
use App\Entity\LabelSystem\LabelProfile;
|
||||
use App\Entity\Parts\Category;
|
||||
|
@ -106,7 +107,7 @@ class EntityURLGenerator
|
|||
/**
|
||||
* Gets the URL to view the given element at a given timestamp.
|
||||
*/
|
||||
public function timeTravelURL(AbstractDBElement $entity, DateTime $dateTime): string
|
||||
public function timeTravelURL(AbstractDBElement $entity, \DateTimeInterface $dateTime): string
|
||||
{
|
||||
$map = [
|
||||
Part::class => 'part_info',
|
||||
|
@ -158,10 +159,16 @@ class EntityURLGenerator
|
|||
'timestamp' => $dateTime->getTimestamp(),
|
||||
]);
|
||||
}
|
||||
if ($entity instanceof PartParameter) {
|
||||
return $this->urlGenerator->generate('part_info', [
|
||||
'id' => $entity->getElement()->getID(),
|
||||
'timestamp' => $dateTime->getTimestamp(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
//Otherwise throw an error
|
||||
throw new EntityNotSupportedException('The given entity is not supported yet!');
|
||||
throw new EntityNotSupportedException('The given entity is not supported yet! Passed class type: '.get_class($entity));
|
||||
}
|
||||
|
||||
public function viewURL(Attachment $entity): string
|
||||
|
|
|
@ -34,6 +34,7 @@ use App\Entity\Parts\Supplier;
|
|||
use App\Entity\PriceInformations\Currency;
|
||||
use App\Entity\UserSystem\Group;
|
||||
use App\Entity\UserSystem\User;
|
||||
use App\Exceptions\EntityNotSupportedException;
|
||||
use App\Services\ElementTypeNameGenerator;
|
||||
use App\Services\EntityURLGenerator;
|
||||
use App\Services\Trees\TreeViewGenerator;
|
||||
|
@ -72,7 +73,7 @@ final class EntityExtension extends AbstractExtension
|
|||
/* Returns the URL to the given entity */
|
||||
new TwigFunction('entity_url', [$this, 'generateEntityURL']),
|
||||
/* Returns the URL to the given entity in timetravel mode */
|
||||
new TwigFunction('timetravel_url', [$this->entityURLGenerator, 'timetravelURL']),
|
||||
new TwigFunction('timetravel_url', [$this, 'timeTravelURL']),
|
||||
/* Generates a JSON array of the given tree */
|
||||
new TwigFunction('tree_data', [$this, 'treeData']),
|
||||
|
||||
|
@ -81,6 +82,15 @@ final class EntityExtension extends AbstractExtension
|
|||
];
|
||||
}
|
||||
|
||||
public function timeTravelURL(AbstractDBElement $element, \DateTimeInterface $dateTime): ?string
|
||||
{
|
||||
try {
|
||||
return $this->entityURLGenerator->timeTravelURL($element, $dateTime);
|
||||
} catch (EntityNotSupportedException $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function treeData(AbstractDBElement $element, string $type = 'newEdit'): string
|
||||
{
|
||||
$tree = $this->treeBuilder->getTreeView(get_class($element), null, $type, $element);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue