<?php
class photo_model extends model {
public function count_albums() {
$query = "select count(*) as count from photo_albums";
if (($result = $this->db->execute($query)) == false) {
return false;
}
return $result[0]["count"];
}
public function get_albums($offset, $limit) {
$query = "select * from photo_albums order by timestamp desc limit %d,%d";
if (($albums = $this->db->execute($query, $offset, $limit)) === false) {
return false;
}
$query = "select id, content_type from photos where photo_album_id=%d and overview=%d";
foreach ($albums as &$album) {
if (($thumbnails = $this->db->execute($query, $album["id"], YES)) == false) {
continue;
}
$photo = rand(0, count($thumbnails) - 1);
$album["content_type"] = $thumbnails[$photo]["content_type"];
$album["thumbnail"] = $thumbnails[$photo]["id"];
}
return $albums;
}
public function get_photo_info($album_id) {
$query = "select id, title, content_type from photos where photo_album_id=%d";
return $this->db->execute($query, $album_id);
}
public function get_image($photo_id) {
$query = "select image, content_type from photos where id=%d limit 1";
if (($result = $this->db->execute($query, $photo_id)) == false) {
return false;
}
return $result[0];
}
public function get_thumbnail($photo_id) {
$query = "select thumbnail, content_type from photos where id=%d limit 1";
if (($result = $this->db->execute($query, $photo_id)) == false) {
return false;
}
return $result[0];
}
}
?>