a standard way of getting stuff from the images table
git-svn-id: file:///home/shish/svn/shimmie2/trunk@58 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
b9ec7c9f5b
commit
d5ebcb89e8
1 changed files with 6 additions and 10 deletions
|
@ -27,6 +27,7 @@ class Querylet { // {{{
|
||||||
class Database {
|
class Database {
|
||||||
var $db;
|
var $db;
|
||||||
var $extensions;
|
var $extensions;
|
||||||
|
var $get_images = "SELECT *,UNIX_TIMESTAMP(posted) AS posted_timestamp FROM images";
|
||||||
|
|
||||||
public function Database() {
|
public function Database() {
|
||||||
if(is_readable("config.php")) {
|
if(is_readable("config.php")) {
|
||||||
|
@ -121,7 +122,7 @@ class Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
if($positive_tag_count + $negative_tag_count == 0) {
|
if($positive_tag_count + $negative_tag_count == 0) {
|
||||||
$query = new Querylet("SELECT *,UNIX_TIMESTAMP(posted) AS posted_timestamp FROM images ");
|
$query = new Querylet($this->get_images);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$s_tag_array = array_map("sql_escape", $tag_search->variables);
|
$s_tag_array = array_map("sql_escape", $tag_search->variables);
|
||||||
|
@ -182,12 +183,7 @@ class Database {
|
||||||
if($limit < 1) $limit = 1;
|
if($limit < 1) $limit = 1;
|
||||||
|
|
||||||
if(count($tags) == 0) {
|
if(count($tags) == 0) {
|
||||||
$result = $this->db->Execute("
|
$result = $this->db->Execute("{$this->get_images} ORDER BY id DESC LIMIT ?,?", array($start, $limit));
|
||||||
SELECT *,UNIX_TIMESTAMP(posted) AS posted_timestamp
|
|
||||||
FROM images
|
|
||||||
ORDER BY id DESC
|
|
||||||
LIMIT ?,?
|
|
||||||
", array($start, $limit));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$querylet = $this->build_search_querylet($tags);
|
$querylet = $this->build_search_querylet($tags);
|
||||||
|
@ -213,7 +209,7 @@ class Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(count($tags) == 0) {
|
if(count($tags) == 0) {
|
||||||
$row = $this->db->GetRow("SELECT * FROM images WHERE id $gtlt ? ORDER BY id $dir", array((int)$id));
|
$row = $this->db->GetRow("{$this->get_images} WHERE id $gtlt ? ORDER BY id $dir", array((int)$id));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$tags[] = ($next ? "id<$id" : "id>$id");
|
$tags[] = ($next ? "id<$id" : "id>$id");
|
||||||
|
@ -232,13 +228,13 @@ class Database {
|
||||||
|
|
||||||
public function get_image($id) {
|
public function get_image($id) {
|
||||||
$image = null;
|
$image = null;
|
||||||
$row = $this->db->GetRow("SELECT * FROM images WHERE id=?", array($id));
|
$row = $this->db->GetRow("{$this->get_images} WHERE id=?", array($id));
|
||||||
return ($row ? new Image($row) : null);
|
return ($row ? new Image($row) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_image_by_hash($hash) {
|
public function get_image_by_hash($hash) {
|
||||||
$image = null;
|
$image = null;
|
||||||
$row = $this->db->GetRow("SELECT * FROM images WHERE hash=?", array($hash));
|
$row = $this->db->GetRow("{$this->get_images} WHERE hash=?", array($hash));
|
||||||
return ($row ? new Image($row) : null);
|
return ($row ? new Image($row) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue