Commit 14594230d9a90a7fdefe568fadf97dcf0071ff92
1 parent
1b78e166
KTEntityUtil::getList simplifies the disparate getList implementations,
and provides for parameterised where clauses. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3094 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
23 additions
and
0 deletions
lib/ktentity.inc
| @@ -88,4 +88,27 @@ class KTEntity { | @@ -88,4 +88,27 @@ class KTEntity { | ||
| 88 | } | 88 | } |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | +class KTEntityUtil { | ||
| 92 | + function &getList($sTable, $sClassName, $sWhereClause = null) { | ||
| 93 | + $sQuery = "SELECT id FROM " . $sTable; | ||
| 94 | + $aParams = array(); | ||
| 95 | + if (!is_null($sWhereClause)) { | ||
| 96 | + if (is_string($sWhereClause)) { | ||
| 97 | + $sQuery .= ' ' . $sWhereClause; | ||
| 98 | + } else if (is_array($sWhereClause)) { | ||
| 99 | + $sQuery .= ' ' . $sWhereClause[0]; | ||
| 100 | + $aParams = $sWhereClause[1]; | ||
| 101 | + } else { | ||
| 102 | + return new PEAR_Error('Weird WhereClause passed'); | ||
| 103 | + } | ||
| 104 | + } | ||
| 105 | + $aIDs = DBUtil::getResultArrayKey(array($sQuery, $aParams), 'id'); | ||
| 106 | + $aRet = array(); | ||
| 107 | + foreach ($aIDs as $iID) { | ||
| 108 | + $aRet[] =& call_user_func(array($sClassName, 'get'), $iID); | ||
| 109 | + } | ||
| 110 | + return $aRet; | ||
| 111 | + } | ||
| 112 | +} | ||
| 113 | + | ||
| 91 | ?> | 114 | ?> |