summaryrefslogtreecommitdiffstats
path: root/library/Director/Data/FieldReferenceLoader.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:43:12 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:43:12 +0000
commitcd989f9c3aff968e19a3aeabc4eb9085787a6673 (patch)
treefbff2135e7013f196b891bbde54618eb050e4aaf /library/Director/Data/FieldReferenceLoader.php
parentInitial commit. (diff)
downloadicingaweb2-module-director-upstream.tar.xz
icingaweb2-module-director-upstream.zip
Adding upstream version 1.10.2.upstream/1.10.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Director/Data/FieldReferenceLoader.php')
-rw-r--r--library/Director/Data/FieldReferenceLoader.php51
1 files changed, 51 insertions, 0 deletions
diff --git a/library/Director/Data/FieldReferenceLoader.php b/library/Director/Data/FieldReferenceLoader.php
new file mode 100644
index 0000000..1e3d92e
--- /dev/null
+++ b/library/Director/Data/FieldReferenceLoader.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace Icinga\Module\Director\Data;
+
+use gipfl\ZfDb\Adapter\Adapter;
+use Icinga\Module\Director\Db;
+use Icinga\Module\Director\Objects\IcingaObject;
+
+class FieldReferenceLoader
+{
+ /** @var Adapter|\Zend_Db_Adapter_Abstract */
+ protected $db;
+
+ public function __construct(Db $connection)
+ {
+ $this->db = $connection->getDbAdapter();
+ }
+
+ /**
+ * @param int $id
+ * @return array
+ */
+ public function loadFor(IcingaObject $object)
+ {
+ $db = $this->db;
+ $id = $object->get('id');
+ if ($id === null) {
+ return [];
+ }
+ $type = $object->getShortTableName();
+ $res = $db->fetchAll(
+ $db->select()->from(['f' => "icinga_${type}_field"], [
+ 'f.datafield_id',
+ 'f.is_required',
+ 'f.var_filter',
+ ])->join(['df' => 'director_datafield'], 'df.id = f.datafield_id', [])
+ ->where("${type}_id = ?", (int) $id)
+ ->order('varname ASC')
+ );
+
+ if (empty($res)) {
+ return [];
+ }
+
+ foreach ($res as $field) {
+ $field->datafield_id = (int) $field->datafield_id;
+ }
+
+ return $res;
+ }
+}