|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics) |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU Affero General Public License as published |
|
9
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
|
10
|
|
|
* (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
18
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace App\Services\LabelSystem\PlaceholderProviders; |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
use App\Entity\Base\AbstractDBElement; |
|
25
|
|
|
use App\Entity\Base\AbstractStructuralDBElement; |
|
26
|
|
|
|
|
27
|
|
|
final class StructuralDBElementProvider implements PlaceholderProviderInterface |
|
28
|
|
|
{ |
|
29
|
|
|
|
|
30
|
|
|
public function replace(string $placeholder, object $label_target, array $options = []): ?string |
|
31
|
|
|
{ |
|
32
|
|
|
if ($label_target instanceof AbstractStructuralDBElement) { |
|
33
|
|
|
if ($placeholder === '[[COMMENT]]') { |
|
34
|
|
|
return $label_target->getComment(); |
|
35
|
|
|
} |
|
36
|
|
|
if ($placeholder === '[[COMMENT_T]]') { |
|
37
|
|
|
return strip_tags($label_target->getComment()); |
|
38
|
|
|
} |
|
39
|
|
|
if ($placeholder === '[[FULL_PATH]]') { |
|
40
|
|
|
return $label_target->getFullPath(); |
|
41
|
|
|
} |
|
42
|
|
|
if ($placeholder === '[[PARENT]]') { |
|
43
|
|
|
return $label_target->getParent() ? $label_target->getParent()->getName() : ''; |
|
44
|
|
|
} |
|
45
|
|
|
if ($placeholder === '[[PARENT_FULL_PATH]]') { |
|
46
|
|
|
return $label_target->getParent() ? $label_target->getParent()->getFullPath() : ''; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return null; |
|
51
|
|
|
} |
|
52
|
|
|
} |