Skip to content

Commit e3ccb69

Browse files
authored
ObjectTags: Remove superfluous table name prefix from the column definition (#151)
resolves #150
2 parents 4ba49e7 + 1b9b777 commit e3ccb69

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

library/Notifications/Model/Behavior/ObjectTags.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,7 @@ public function rewriteColumn($column, $relation = null): AliasedExpression
6868

6969
public function rewriteColumnDefinition(ColumnDefinition $def, string $relation): void
7070
{
71-
$parts = explode('.', substr($relation, 0, -4));
72-
$objectType = array_pop($parts);
73-
74-
$name = $def->getName();
75-
// Programmatically translated since the full definition is available in class ObjectSuggestions
76-
$def->setLabel(sprintf(t(ucfirst($objectType) . ' %s', '..<tag-name>'), $name));
71+
$def->setLabel(ucfirst($def->getName()));
7772
}
7873

7974
public function isSelectableColumn(string $name): bool

library/Notifications/Model/ObjectExtraTag.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
use ipl\Orm\Model;
1010
use ipl\Orm\Relations;
1111

12+
/**
13+
* ObjectExtraTag database model
14+
*
15+
* @property int $object_id
16+
* @property string $tag
17+
* @property string $value
18+
*/
1219
class ObjectExtraTag extends Model
1320
{
1421
public function getTableName()

library/Notifications/Model/ObjectIdTag.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
use ipl\Orm\Model;
1010
use ipl\Orm\Relations;
1111

12+
/**
13+
* ObjectIdTag database model
14+
*
15+
* @property int $object_id
16+
* @property string $tag
17+
* @property string $value
18+
*/
1219
class ObjectIdTag extends Model
1320
{
1421
public function getTableName(): string

library/Notifications/Web/Control/SearchBar/ObjectSuggestions.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ protected function fetchValueSuggestions($column, $searchTerm, Filter\Chain $sea
104104

105105
if (strpos($column, ' ') !== false) {
106106
// $column may be a label
107-
list($path, $_) = Seq::find(
107+
/** @var string $path */
108+
[$path, $_] = Seq::find(
108109
self::collectFilterColumns($query->getModel(), $query->getResolver()),
109110
$column,
110111
false
@@ -185,7 +186,7 @@ protected function fetchColumnSuggestions($searchTerm)
185186
// Custom variables only after the columns are exhausted and there's actually a chance the user sees them
186187
foreach ([new ObjectIdTag(), new ObjectExtraTag()] as $model) {
187188
$titleAdded = false;
188-
/** @var Model $tag */
189+
/** @var ObjectIdTag|ObjectExtraTag $tag */
189190
foreach ($this->queryTags($model, $searchTerm) as $tag) {
190191
$isIdTag = $tag instanceof ObjectIdTag;
191192

@@ -199,9 +200,8 @@ protected function fetchColumnSuggestions($searchTerm)
199200
}
200201

201202
$relation = $isIdTag ? 'object.tag' : 'object.extra_tag';
202-
$tagName = $tag->tag;
203203

204-
yield $relation . '.' . $tagName => $tagName;
204+
yield $relation . '.' . $tag->tag => ucfirst($tag->tag);
205205
}
206206
}
207207
}

phpstan-baseline-standard.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,11 +1025,6 @@ parameters:
10251025
count: 1
10261026
path: library/Notifications/Web/Control/SearchBar/ObjectSuggestions.php
10271027

1028-
-
1029-
message: "#^Parameter \\#1 \\$path of method ipl\\\\Orm\\\\Resolver\\:\\:qualifyPath\\(\\) expects string, mixed given\\.$#"
1030-
count: 1
1031-
path: library/Notifications/Web/Control/SearchBar/ObjectSuggestions.php
1032-
10331028
-
10341029
message: "#^Property Icinga\\\\Module\\\\Notifications\\\\Web\\\\Control\\\\SearchBar\\\\ObjectSuggestions\\:\\:\\$model \\(ipl\\\\Orm\\\\Model\\) does not accept object\\.$#"
10351030
count: 1

0 commit comments

Comments
 (0)