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; }
$db->update_object($wbo); } } else { report_problem(WEAVE_ERROR_INVALID_WBO, 400); } echo json_encode($server_time); } else { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $json = get_json(); check_quota($db); check_timestamp($collection, $db); $success_ids = array(); $failed_ids = array(); $db->begin_transaction(); foreach ($json as $wbo_data) { $wbo = new wbo(); if (!$wbo->extract_json($wbo_data)) { $failed_ids[$wbo->id()] = $wbo->get_error(); continue; } $wbo->collection($collection); $wbo->modified($server_time); if ($wbo->validate()) { #if there's no payload (as opposed to blank), then update the metadata if ($wbo->payload_exists()) { $db->store_object($wbo); } else { $db->update_object($wbo); } $success_ids[] = $wbo->id(); } else {
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; }