summaryrefslogtreecommitdiffstats
path: root/library/Icingadb/Model/CustomvarFlat.php
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--library/Icingadb/Model/CustomvarFlat.php25
1 files changed, 25 insertions, 0 deletions
diff --git a/library/Icingadb/Model/CustomvarFlat.php b/library/Icingadb/Model/CustomvarFlat.php
index 99d8aca..e7a0459 100644
--- a/library/Icingadb/Model/CustomvarFlat.php
+++ b/library/Icingadb/Model/CustomvarFlat.php
@@ -6,11 +6,22 @@ namespace Icinga\Module\Icingadb\Model;
use ipl\Orm\Behavior\Binary;
use ipl\Orm\Behaviors;
+use ipl\Orm\Contract\RewriteFilterBehavior;
use ipl\Orm\Model;
use ipl\Orm\Query;
use ipl\Orm\Relations;
+use ipl\Stdlib\Filter;
+use ipl\Stdlib\Filter\Condition;
use Traversable;
+/**
+ * @property string $id
+ * @property string $environment_id
+ * @property string $customvar_id
+ * @property string $flatname_checksum
+ * @property string $flatname
+ * @property ?string $flatvalue
+ */
class CustomvarFlat extends Model
{
public function getTableName()
@@ -42,6 +53,20 @@ class CustomvarFlat extends Model
'customvar_id',
'flatname_checksum'
]));
+ $behaviors->add(new class implements RewriteFilterBehavior {
+ public function rewriteCondition(Condition $condition, $relation = null)
+ {
+ if ($condition->metaData()->has('requiresTransformation')) {
+ /** @var string $columnName */
+ $columnName = $condition->metaData()->get('columnName');
+ $nameFilter = Filter::like($relation . 'flatname', $columnName);
+ $class = get_class($condition);
+ $valueFilter = new $class($relation . 'flatvalue', $condition->getValue());
+
+ return Filter::all($nameFilter, $valueFilter);
+ }
+ }
+ });
}
public function createRelations(Relations $relations)