Skip to content

Commit

Permalink
ObjectTags: Remove superfluous table name prefix from the column defi…
Browse files Browse the repository at this point in the history
…nition (#151)

resolves #150
  • Loading branch information
nilmerg authored Jan 19, 2024
2 parents 4ba49e7 + 1b9b777 commit e3ccb69
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
7 changes: 1 addition & 6 deletions library/Notifications/Model/Behavior/ObjectTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,7 @@ public function rewriteColumn($column, $relation = null): AliasedExpression

public function rewriteColumnDefinition(ColumnDefinition $def, string $relation): void
{
$parts = explode('.', substr($relation, 0, -4));
$objectType = array_pop($parts);

$name = $def->getName();
// Programmatically translated since the full definition is available in class ObjectSuggestions
$def->setLabel(sprintf(t(ucfirst($objectType) . ' %s', '..<tag-name>'), $name));
$def->setLabel(ucfirst($def->getName()));
}

public function isSelectableColumn(string $name): bool
Expand Down
7 changes: 7 additions & 0 deletions library/Notifications/Model/ObjectExtraTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
use ipl\Orm\Model;
use ipl\Orm\Relations;

/**
* ObjectExtraTag database model
*
* @property int $object_id
* @property string $tag
* @property string $value
*/
class ObjectExtraTag extends Model
{
public function getTableName()
Expand Down
7 changes: 7 additions & 0 deletions library/Notifications/Model/ObjectIdTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
use ipl\Orm\Model;
use ipl\Orm\Relations;

/**
* ObjectIdTag database model
*
* @property int $object_id
* @property string $tag
* @property string $value
*/
class ObjectIdTag extends Model
{
public function getTableName(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ protected function fetchValueSuggestions($column, $searchTerm, Filter\Chain $sea

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

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

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

yield $relation . '.' . $tagName => $tagName;
yield $relation . '.' . $tag->tag => ucfirst($tag->tag);
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline-standard.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1025,11 +1025,6 @@ parameters:
count: 1
path: library/Notifications/Web/Control/SearchBar/ObjectSuggestions.php

-
message: "#^Parameter \\#1 \\$path of method ipl\\\\Orm\\\\Resolver\\:\\:qualifyPath\\(\\) expects string, mixed given\\.$#"
count: 1
path: library/Notifications/Web/Control/SearchBar/ObjectSuggestions.php

-
message: "#^Property Icinga\\\\Module\\\\Notifications\\\\Web\\\\Control\\\\SearchBar\\\\ObjectSuggestions\\:\\:\\$model \\(ipl\\\\Orm\\\\Model\\) does not accept object\\.$#"
count: 1
Expand Down

0 comments on commit e3ccb69

Please sign in to comment.