1 redirect.module | redirect_load_multiple(array $rids = array(), array $conditions = array(), $reset = FALSE) |
Load multiple URL redirects from the database.
Parameters
$rids: An array of redirect IDs.
$conditions: An array of conditions on the {redirect} table in the form 'field' => $value.
$reset: Whether to reset the redirect_load_multiple cache.
Return value
Redirect[]: An array of URL redirect objects indexed by redirect IDs.
Related topics
File
- core/
modules/ redirect/ redirect.module, line 526
Code
function redirect_load_multiple(array $rids = array(), array $conditions = array(), $reset = FALSE) {
$cached_redirects = &backdrop_static(__FUNCTION__, array());
if ($reset) {
$cached_redirects = array();
}
$new_rids = array_diff($rids, array_keys($cached_redirects));
$added_redirects = array();
if ($new_rids || $conditions) {
$query = db_select('redirect')->fields('redirect');
if ($rids) {
$query->condition('rid', $new_rids, 'IN');
}
foreach ($conditions as $key => $value) {
$query->condition($key, $value);
}
$rows = $query->execute()->fetchAllAssoc('rid', PDO::FETCH_ASSOC);
foreach ($rows as $rid => $row) {
if ($rows[$rid]) {
$added_redirects[$rid] = new Redirect($row);
}
else {
$added_redirects[$rid] = FALSE;
}
}
$cached_redirects += $added_redirects;
}
// Return the requested redirects.
$redirects = array();
if ($rids) {
foreach ($rids as $rid) {
if (isset($cached_redirects[$rid])) {
$redirects[$rid] = $cached_redirects[$rid];
}
}
}
elseif ($conditions) {
$redirects = $added_redirects;
}
return $redirects;
}