function retrieve_objects($collection, $id = null, $full = null, $direct_output = null, $parentid = null, $predecessorid = null, $newer = null, $older = null, $sort = null, $limit = null, $offset = null, $ids = null, $index_above = null, $index_below = null) { $full_list = $full ? '*' : 'id'; $select_stmt = "select {$full_list} from wbo where username = ? and collection = ?"; $params[] = $this->_username; $params[] = $collection; if ($id) { $select_stmt .= " and id = ?"; $params[] = $id; } if ($ids && count($ids) > 0) { $qmarks = array(); $select_stmt .= " and id in ("; foreach ($ids as $temp) { $params[] = $temp; $qmarks[] = '?'; } $select_stmt .= implode(",", $qmarks); $select_stmt .= ')'; } if ($parentid) { $select_stmt .= " and parentid = ?"; $params[] = $parentid; } if ($predecessorid) { $select_stmt .= " and predecessorid = ?"; $params[] = $predecessorid; } if ($index_above) { $select_stmt .= " and sortindex > ?"; $params[] = $parentid; } if ($index_below) { $select_stmt .= " and sortindex < ?"; $params[] = $parentid; } if ($newer) { $select_stmt .= " and modified > ?"; $params[] = $newer; } if ($older) { $select_stmt .= " and modified < ?"; $params[] = $older; } if ($sort == 'index') { $select_stmt .= " order by sortindex desc"; } else { if ($sort == 'newest') { $select_stmt .= " order by modified desc"; } else { if ($sort == 'oldest') { $select_stmt .= " order by modified"; } } } if ($limit) { $select_stmt .= " limit " . intval($limit); if ($offset) { $select_stmt .= " offset " . intval($offset); } } try { $sth = $this->_dbh->prepare($select_stmt); $sth->execute($params); } catch (PDOException $exception) { error_log("retrieve_collection: " . $exception->getMessage()); throw new Exception("Database unavailable", 503); } if ($direct_output) { return $direct_output->output($sth); } $ids = array(); while ($result = $sth->fetch(PDO::FETCH_ASSOC)) { if ($full) { $wbo = new wbo(); $wbo->populate($result); $ids[] = $wbo; } else { $ids[] = $result['id']; } } return $ids; }
function output_newlines($sth) { while ($result = $sth->fetch(PDO::FETCH_ASSOC)) { if ($this->_full) { $wbo = new wbo(); $wbo->populate($result); echo preg_replace('/\\n/', '\\u000a', $wbo->json()); } else { echo json_encode($result['id']); } echo "\n"; } return 1; }