From ac7a7e66747b99369bac8338c43206a991b1d470 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 23 Jun 2015 15:05:03 +0200 Subject: [PATCH] Ldap\Connection: Add method fetchColumn() --- library/Icinga/Protocol/Ldap/Connection.php | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/library/Icinga/Protocol/Ldap/Connection.php b/library/Icinga/Protocol/Ldap/Connection.php index 56f43d460..3931f59a5 100644 --- a/library/Icinga/Protocol/Ldap/Connection.php +++ b/library/Icinga/Protocol/Ldap/Connection.php @@ -147,6 +147,28 @@ class Connection implements Selectable return array_shift($row) ?: false; } + public function fetchColumn(Query $query, array $fields = null) + { + if ($fields === null) { + $fields = $query->getColumns(); + } + + $column = current($fields); + if (! $column) { + throw new ProgrammingError('You must request at least one attribute when fetching a single column'); + } + + $results = $this->fetchAll($query, array($column)); + $values = array(); + foreach ($results as $row) { + if (isset($row->$column)) { + $values[] = $row->$column; + } + } + + return $values; + } + public function hasDN($dn) { $this->connect();