From 14594230d9a90a7fdefe568fadf97dcf0071ff92 Mon Sep 17 00:00:00 2001 From: nbm Date: Mon, 3 Jan 2005 11:13:30 +0000 Subject: [PATCH] KTEntityUtil::getList simplifies the disparate getList implementations, and provides for parameterised where clauses. --- lib/ktentity.inc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+), 0 deletions(-) diff --git a/lib/ktentity.inc b/lib/ktentity.inc index 05b0dba..baa5b63 100644 --- a/lib/ktentity.inc +++ b/lib/ktentity.inc @@ -88,4 +88,27 @@ class KTEntity { } } +class KTEntityUtil { + function &getList($sTable, $sClassName, $sWhereClause = null) { + $sQuery = "SELECT id FROM " . $sTable; + $aParams = array(); + if (!is_null($sWhereClause)) { + if (is_string($sWhereClause)) { + $sQuery .= ' ' . $sWhereClause; + } else if (is_array($sWhereClause)) { + $sQuery .= ' ' . $sWhereClause[0]; + $aParams = $sWhereClause[1]; + } else { + return new PEAR_Error('Weird WhereClause passed'); + } + } + $aIDs = DBUtil::getResultArrayKey(array($sQuery, $aParams), 'id'); + $aRet = array(); + foreach ($aIDs as $iID) { + $aRet[] =& call_user_func(array($sClassName, 'get'), $iID); + } + return $aRet; + } +} + ?> -- libgit2 0.21.4