}
return $i;
}
-
+
/**
* Get multiple items from the database by key
- *
+ *
* @param string $cls Class to fetch
* @param string $keyCol name of column for key
* @param array $keyVals key values to fetch
* @param boolean $skipNulls return only non-null results?
- *
+ *
* @return array Array of objects, in order
*/
function multiGet($cls, $keyCol, $keyVals, $skipNulls=true)
{
- $result = self::pivotGet($cls, $keyCol, $keyVals);
-
- $values = array_values($result);
-
- if ($skipNulls) {
- $tmp = array();
- foreach ($values as $value) {
- if (!empty($value)) {
- $tmp[] = $value;
- }
- }
- $values = $tmp;
- }
-
- return new ArrayWrapper($values);
+ $result = self::pivotGet($cls, $keyCol, $keyVals);
+
+ $values = array_values($result);
+
+ if ($skipNulls) {
+ $tmp = array();
+ foreach ($values as $value) {
+ if (!empty($value)) {
+ $tmp[] = $value;
+ }
+ }
+ $values = $tmp;
+ }
+
+ return new ArrayWrapper($values);
}
-
+
/**
* Get multiple items from the database by key
- *
+ *
* @param string $cls Class to fetch
* @param string $keyCol name of column for key
* @param array $keyVals key values to fetch
* @param boolean $otherCols Other columns to hold fixed
- *
+ *
* @return array Array mapping $keyVals to objects, or null if not found
*/
static function pivotGet($cls, $keyCol, $keyVals, $otherCols = array())
function listGet($cls, $keyCol, $keyVals)
{
$pkeyMap = array_fill_keys($keyVals, array());
- $results = array_fill_keys($keyVals, array());
+ $result = array_fill_keys($keyVals, array());
$pkeyCols = self::pkeyCols($cls);
-
+
$toFetch = array();
$allPkeys = array();
$l = self::cacheGet(sprintf("%s:list-ids:%s:%s", $cls, $keyCol, $keyVal));
if ($l !== false) {
$pkeyMap[$keyVal] = $l;
- $allPkeys = array_merge($allPkeys, $l);
+ foreach ($l as $pkey) {
+ $allPkeys[] = $pkey;
+ }
} else {
$toFetch[] = $keyVal;
}
}
- $keyResults = self::pivotGet($cls, $pkeyCols, $allPkeys);
+ if (count($allPkeys) > 0) {
+ $keyResults = self::pivotGet($cls, $pkeyCols, $allPkeys);
- foreach ($pkeyMap as $keyVal => $pkeyList) {
- foreach ($pkeyList as $pkeyVal) {
- $i = $keyResults[$pkeyVal];
- if (!empty($i)) {
- $results[$keyVal][] = $i;
+ foreach ($pkeyMap as $keyVal => $pkeyList) {
+ foreach ($pkeyList as $pkeyVal) {
+ $i = $keyResults[implode(',',$pkeyVal)];
+ if (!empty($i)) {
+ $result[$keyVal][] = $i;
+ }
}
}
}
}
$i->whereAddIn($keyCol, $toFetch, $i->columnType($keyCol));
if ($i->find()) {
+ sprintf("listGet() got {$i->N} results for class $cls key $keyCol");
while ($i->fetch()) {
$copy = clone($i);
$copy->encache();
$pkeyMap[$keyVal]);
}
}
-
+
return $result;
}
}
/**
- * @fixme Should this return false on lookup fail to match staticGet?
+ * @todo FIXME: Should this return false on lookup fail to match staticGet?
*/
function pkeyGet($cls, $kv)
{
return false;
}
foreach ($kv as $k => $v) {
- if (is_null($v)) {
- // XXX: possible SQL injection...? Don't
- // pass keys from the browser, eh.
- $i->whereAdd("$k is null");
- } else {
- $i->$k = $v;
- }
+ if (is_null($v)) {
+ // XXX: possible SQL injection...? Don't
+ // pass keys from the browser, eh.
+ $i->whereAdd("$k is null");
+ } else {
+ $i->$k = $v;
+ }
}
if ($i->find(true)) {
$i->encache();
continue;
}
if (in_array($func, $ignoreStatic)) {
- continue; // @fixme this shouldn't be needed?
+ continue; // @todo FIXME: This shouldn't be needed?
}
$here = get_class($frame['object']) . '->' . $func;
break;
if (!$dsn) {
// TRANS: Exception thrown when database name or Data Source Name could not be found.
- throw new Exception(_("No database name or DSN found anywhere."));
+ throw new Exception(_('No database name or DSN found anywhere.'));
}
return $dsn;