mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-12 11:24:31 +02:00
Use [[PLACEHOLDER]] instead of %%PLACEHOLDER%% for label placeholders.
This commit is contained in:
parent
cb2d0d9845
commit
3163a7ba09
14 changed files with 80 additions and 78 deletions
|
@ -65,7 +65,7 @@ class LabelTextReplacer
|
|||
public function replace(string $lines, object $target): string
|
||||
{
|
||||
$patterns = [
|
||||
'/(%%[A-Z_]+%%)/' => function ($match) use ($target) {
|
||||
'/(\[\[[A-Z_]+\]\])/' => function ($match) use ($target) {
|
||||
return $this->handlePlaceholder($match[0], $target);
|
||||
},
|
||||
];
|
||||
|
|
|
@ -40,11 +40,11 @@ class AbstractDBElementProvider implements PlaceholderProviderInterface
|
|||
{
|
||||
if ($label_target instanceof AbstractDBElement) {
|
||||
|
||||
if ($placeholder === '%%TYPE%%') {
|
||||
if ($placeholder === '[[TYPE]]') {
|
||||
return $this->elementTypeNameGenerator->getLocalizedTypeLabel($label_target);
|
||||
}
|
||||
|
||||
if ($placeholder === '%%ID%%') {
|
||||
if ($placeholder === '[[ID]]') {
|
||||
return (string) ($label_target->getID() ?? 'unknown');
|
||||
}
|
||||
|
||||
|
|
|
@ -47,20 +47,20 @@ class GlobalProviders implements PlaceholderProviderInterface
|
|||
*/
|
||||
public function replace(string $placeholder, object $label_target, array $options = []): ?string
|
||||
{
|
||||
if ($placeholder === "%%INSTALL_NAME%%") {
|
||||
if ($placeholder === "[[INSTALL_NAME]]") {
|
||||
return $this->partdb_title;
|
||||
}
|
||||
|
||||
|
||||
$user = $this->security->getUser();
|
||||
if ($placeholder === "%%USERNAME%%") {
|
||||
if ($placeholder === "[[USERNAME]]") {
|
||||
if ($user instanceof User) {
|
||||
return $user->getName();
|
||||
}
|
||||
return 'anonymous';
|
||||
}
|
||||
|
||||
if ($placeholder === "%%USERNAME_FULL%%") {
|
||||
if ($placeholder === "[[USERNAME_FULL]]") {
|
||||
if ($user instanceof User) {
|
||||
return $user->getFullName(true);
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ class GlobalProviders implements PlaceholderProviderInterface
|
|||
|
||||
$now = new \DateTime();
|
||||
|
||||
if ($placeholder === '%%DATETIME%%') {
|
||||
if ($placeholder === '[[DATETIME]]') {
|
||||
$formatter = IntlDateFormatter::create(
|
||||
Locale::getDefault(),
|
||||
IntlDateFormatter::SHORT,
|
||||
|
@ -80,7 +80,7 @@ class GlobalProviders implements PlaceholderProviderInterface
|
|||
return $formatter->format($now);
|
||||
}
|
||||
|
||||
if ($placeholder === '%%DATE%%') {
|
||||
if ($placeholder === '[[DATE]]') {
|
||||
$formatter = IntlDateFormatter::create(
|
||||
Locale::getDefault(),
|
||||
IntlDateFormatter::SHORT,
|
||||
|
@ -91,7 +91,7 @@ class GlobalProviders implements PlaceholderProviderInterface
|
|||
return $formatter->format($now);
|
||||
}
|
||||
|
||||
if ($placeholder === '%%TIME%%') {
|
||||
if ($placeholder === '[[TIME]]') {
|
||||
$formatter = IntlDateFormatter::create(
|
||||
Locale::getDefault(),
|
||||
IntlDateFormatter::NONE,
|
||||
|
|
|
@ -31,7 +31,7 @@ class NamedElementProvider implements PlaceholderProviderInterface
|
|||
*/
|
||||
public function replace(string $placeholder, object $label_target, array $options = []): ?string
|
||||
{
|
||||
if ($label_target instanceof NamedElementInterface && $placeholder === '%%NAME%%') {
|
||||
if ($label_target instanceof NamedElementInterface && $placeholder === '[[NAME]]') {
|
||||
return $label_target->getName();
|
||||
}
|
||||
|
||||
|
|
|
@ -41,19 +41,19 @@ class PartLotProvider implements PlaceholderProviderInterface
|
|||
public function replace(string $placeholder, object $label_target, array $options = []): ?string
|
||||
{
|
||||
if ($label_target instanceof PartLot) {
|
||||
if ($placeholder === '%%LOT_ID%%') {
|
||||
if ($placeholder === '[[LOT_ID]]') {
|
||||
return $label_target->getID() ?? 'unknown';
|
||||
}
|
||||
|
||||
if ($placeholder === '%%LOT_NAME%%') {
|
||||
if ($placeholder === '[[LOT_NAME]]') {
|
||||
return $label_target->getName();
|
||||
}
|
||||
|
||||
if ($placeholder === '%%LOT_COMMENT%%') {
|
||||
if ($placeholder === '[[LOT_COMMENT]]') {
|
||||
return $label_target->getComment();
|
||||
}
|
||||
|
||||
if ($placeholder === '%%EXPIRATION_DATE%%') {
|
||||
if ($placeholder === '[[EXPIRATION_DATE]]') {
|
||||
if ($label_target->getExpirationDate() === null) {
|
||||
return '';
|
||||
}
|
||||
|
@ -67,18 +67,18 @@ class PartLotProvider implements PlaceholderProviderInterface
|
|||
return $formatter->format($label_target->getExpirationDate());
|
||||
}
|
||||
|
||||
if ($placeholder === '%%AMOUNT%%') {
|
||||
if ($placeholder === '[[AMOUNT]]') {
|
||||
if ($label_target->isInstockUnknown()) {
|
||||
return '?';
|
||||
}
|
||||
return $this->amountFormatter->format($label_target->getAmount(), $label_target->getPart()->getPartUnit());
|
||||
}
|
||||
|
||||
if ($placeholder === '%%LOCATION%%') {
|
||||
if ($placeholder === '[[LOCATION]]') {
|
||||
return $label_target->getStorageLocation() ? $label_target->getStorageLocation()->getName() : '';
|
||||
}
|
||||
|
||||
if ($placeholder === '%%LOCATION_FULL%%') {
|
||||
if ($placeholder === '[[LOCATION_FULL]]') {
|
||||
return $label_target->getStorageLocation() ? $label_target->getStorageLocation()->getFullPath() : '';
|
||||
}
|
||||
|
||||
|
|
|
@ -46,43 +46,43 @@ class PartProvider implements PlaceholderProviderInterface
|
|||
return null;
|
||||
}
|
||||
|
||||
if ($placeholder === '%%CATEGORY%%') {
|
||||
if ($placeholder === '[[CATEGORY]]') {
|
||||
return $part->getCategory() ? $part->getCategory()->getName() : '';
|
||||
}
|
||||
|
||||
if ($placeholder === '%%CATEGORY_FULL%%') {
|
||||
if ($placeholder === '[[CATEGORY_FULL]]') {
|
||||
return $part->getCategory() ? $part->getCategory()->getFullPath() : '';
|
||||
}
|
||||
|
||||
if ($placeholder === '%%MANUFACTURER%%') {
|
||||
if ($placeholder === '[[MANUFACTURER]]') {
|
||||
return $part->getManufacturer() ? $part->getManufacturer()->getName() : '';
|
||||
}
|
||||
|
||||
if ($placeholder === '%%MANUFACTURER_FULL%%') {
|
||||
if ($placeholder === '[[MANUFACTURER_FULL]]') {
|
||||
return $part->getManufacturer() ? $part->getManufacturer()->getFullPath() : '';
|
||||
}
|
||||
|
||||
if ($placeholder === '%%FOOTPRINT%%') {
|
||||
if ($placeholder === '[[FOOTPRINT]]') {
|
||||
return $part->getFootprint() ? $part->getFootprint()->getName() : '';
|
||||
}
|
||||
|
||||
if ($placeholder === '%%FOOTPRINT_FULL%%') {
|
||||
if ($placeholder === '[[FOOTPRINT_FULL]]') {
|
||||
return $part->getFootprint() ? $part->getFootprint()->getFullPath() : '';
|
||||
}
|
||||
|
||||
if ($placeholder === '%%MASS%%') {
|
||||
if ($placeholder === '[[MASS]]') {
|
||||
return $part->getMass() ? $this->siFormatter->format($part->getMass(), 'g', 1) : '';
|
||||
}
|
||||
|
||||
if ($placeholder === '%%MPN%%') {
|
||||
if ($placeholder === '[[MPN]]') {
|
||||
return $part->getManufacturerProductNumber();
|
||||
}
|
||||
|
||||
if ($placeholder === '%%TAGS%%') {
|
||||
if ($placeholder === '[[TAGS]]') {
|
||||
return $part->getTags();
|
||||
}
|
||||
|
||||
if ($placeholder === '%%M_STATUS%%') {
|
||||
if ($placeholder === '[[M_STATUS]]') {
|
||||
if ($part->getManufacturingStatus() === '') {
|
||||
return '';
|
||||
}
|
||||
|
@ -91,19 +91,19 @@ class PartProvider implements PlaceholderProviderInterface
|
|||
|
||||
$parsedown = new \Parsedown();
|
||||
|
||||
if ($placeholder === '%%DESCRIPTION%%') {
|
||||
if ($placeholder === '[[DESCRIPTION]]') {
|
||||
return $parsedown->line($part->getDescription());
|
||||
}
|
||||
|
||||
if ($placeholder === '%%DESCRIPTION_T%%') {
|
||||
if ($placeholder === '[[DESCRIPTION_T]]') {
|
||||
return strip_tags($parsedown->line($part->getDescription()));
|
||||
}
|
||||
|
||||
if ($placeholder === '%%COMMENT%%') {
|
||||
if ($placeholder === '[[COMMENT]]') {
|
||||
return $parsedown->line($part->getComment());
|
||||
}
|
||||
|
||||
if ($placeholder === '%%COMMENT_T%%') {
|
||||
if ($placeholder === '[[COMMENT_T]]') {
|
||||
return strip_tags($parsedown->line($part->getComment()));
|
||||
}
|
||||
|
||||
|
|
|
@ -33,11 +33,11 @@ class TimestampableElementProvider implements PlaceholderProviderInterface
|
|||
public function replace(string $placeholder, object $label_target, array $options = []): ?string
|
||||
{
|
||||
if ($label_target instanceof TimeStampableInterface) {
|
||||
if ($placeholder === '%%LAST_MODIFIED%%') {
|
||||
if ($placeholder === '[[LAST_MODIFIED]]') {
|
||||
return IntlDateFormatter::formatObject($label_target->getLastModified() ?? new \DateTime(), IntlDateFormatter::SHORT, Locale::getDefault());
|
||||
}
|
||||
|
||||
if ($placeholder === '%%CREATION_DATE%%') {
|
||||
if ($placeholder === '[[CREATION_DATE]]') {
|
||||
return IntlDateFormatter::formatObject($label_target->getAddedDate() ?? new \DateTime(), IntlDateFormatter::SHORT, Locale::getDefault());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue