From b5bbb074974fcced7c79defd4b495f937eaa2ad6 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 13 Sep 2016 20:21:47 -0700 Subject: [PATCH] CRM_Core_DAO::fetchMap() - Add helper to return key-value pairs from SQL --- CRM/Core/DAO.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 4747adee2f..7836d9dde2 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -1008,6 +1008,24 @@ FROM civicrm_domain return $result; } + /** + * Get all the result records as mapping between columns. + * + * @param string $keyColumn + * Ex: "name" + * @param string $valueColumn + * Ex: "label" + * @return array + * Ex: ["foo" => "The Foo Bar", "baz" => "The Baz Qux"] + */ + public function fetchMap($keyColumn, $valueColumn) { + $result = array(); + while ($this->fetch()) { + $result[$this->{$keyColumn}] = $this->{$valueColumn}; + } + return $result; + } + /** * Given a DAO name, a column name and a column value, find the record and GET the value of another column in that record * -- 2.25.1