1
0

Virtual album support for CalendarView.

This commit is contained in:
rWatcher 2012-04-30 18:58:52 -04:00
parent 9b971a9160
commit 341e062c53
2 changed files with 142 additions and 83 deletions

View File

@ -18,17 +18,13 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class CalendarView_Controller extends Controller {
public function calendar($display_year="", $display_user="") {
public function calendar($display_year="", $display_user="-1") {
// Draw a calendar for the year specified by $display_year.
// Make sure the function parameters aren't null,
// give them default values if they are.
// Display the current year by default if a year wasn't provided.
if ($display_year == "") {
$display_year = date('Y');
}
if ($display_user == "") {
$display_user = "-1";
}
// Draw the page.
$root = item::root();
@ -50,26 +46,16 @@ class CalendarView_Controller extends Controller {
public function day($display_year, $display_user, $display_month, $display_day) {
// Display all images for the specified day.
// Figure out the total number of photos to display.
$day_count = 0;
if ($display_user == "-1") {
$day_count = ORM::factory("item")
->viewable()
->where("type", "!=", "album")
->where("captured", ">=", mktime(0, 0, 0, $display_month, $display_day, $display_year))
->where("captured", "<", mktime(0, 0, 0, $display_month, ($display_day + 1), $display_year))
->find_all()
->count();
} else {
$day_count = ORM::factory("item")
->viewable()
->where("owner_id", "=", $display_user)
->where("type", "!=", "album")
->where("captured", ">=", mktime(0, 0, 0, $display_month, $display_day, $display_year))
->where("captured", "<", mktime(0, 0, 0, $display_month, ($display_day + 1), $display_year))
->find_all()
->count();
// Set up default search conditions for retrieving all photos from the specified day.
$where = array(array("type", "!=", "album"));
if ($display_user != "-1") {
$where[] = array("owner_id", "=", $display_user);
}
$where[] = array("captured", ">=", mktime(0, 0, 0, $display_month, $display_day, $display_year));
$where[] = array("captured", "<", mktime(0, 0, 0, $display_month, ($display_day + 1), $display_year));
// Figure out the total number of photos to display.
$day_count = calendarview::get_items_count($where);
// Figure out paging stuff.
$page_size = module::get_var("gallery", "page_size", 9);
@ -83,25 +69,7 @@ class CalendarView_Controller extends Controller {
}
// Figure out which photos go on this page.
$children = "";
if ($display_user == "-1") {
$children = ORM::factory("item")
->viewable()
->where("type", "!=", "album")
->where("captured", ">=", mktime(0, 0, 0, $display_month, $display_day, $display_year))
->where("captured", "<", mktime(0, 0, 0, $display_month, ($display_day + 1), $display_year))
->order_by("captured", "ASC")
->find_all($page_size, $offset);
} else {
$children = ORM::factory("item")
->viewable()
->where("owner_id", "=", $display_user)
->where("type", "!=", "album")
->where("captured", ">=", mktime(0, 0, 0, $display_month, $display_day, $display_year))
->where("captured", "<", mktime(0, 0, 0, $display_month, ($display_day + 1), $display_year))
->order_by("captured", "ASC")
->find_all($page_size, $offset);
}
$children = calendarview::get_items($page_size, $offset, $where);
// Create and display the page.
$root = item::root();
@ -121,31 +89,46 @@ class CalendarView_Controller extends Controller {
$template->content = new View("dynamic.html");
$template->content->title = t("Photos From ") . date("d", mktime(0, 0, 0, $display_month, $display_day, $display_year)) . " " . t(date("F", mktime(0, 0, 0, $display_month, $display_day, $display_year))) . " " . date("Y", mktime(0, 0, 0, $display_month, $display_day, $display_year));
print $template;
// Set breadcrumbs on the photo pages to point back to the calendar day view.
item::set_display_context_callback("CalendarView_Controller::get_display_day_context", $display_user, $display_year, $display_month, $display_day);
}
static function get_display_day_context($item, $display_user, $display_year, $display_month, $display_day) {
// Set up default search conditions for retrieving all photos from the specified day.
$where = array(array("type", "!=", "album"));
if ($display_user != "-1") {
$where[] = array("owner_id", "=", $display_user);
}
$where[] = array("captured", ">=", mktime(0, 0, 0, $display_month, $display_day, $display_year));
$where[] = array("captured", "<", mktime(0, 0, 0, $display_month, ($display_day + 1), $display_year));
// Generate breadcrumbs for the photo page.
$root = item::root();
$breadcrumbs = array(
Breadcrumb::instance($root->title, $root->url())->set_first(),
Breadcrumb::instance($display_year, url::site("calendarview/calendar/" . $display_year . "/" . $display_user)),
Breadcrumb::instance(t(date("F", mktime(0, 0, 0, $display_month, $display_day, $display_year))), url::site("calendarview/month/" . $display_year . "/" . $display_user . "/" . $display_month)),
Breadcrumb::instance($display_day, url::site("calendarview/month/" . $display_year . "/" . $display_user . "/" . $display_month . "/" . $display_day)),
Breadcrumb::instance($item->title, $item->url())->set_last()
);
return CalendarView_Controller::get_display_context($item, $where, $breadcrumbs);
}
public function month($display_year, $display_user, $display_month) {
// Display all images for the specified month.
// Figure out the total number of photos to display.
$day_count = 0;
if ($display_user == "-1") {
$day_count = ORM::factory("item")
->viewable()
->where("type", "!=", "album")
->where("captured", ">=", mktime(0, 0, 0, $display_month, 1, $display_year))
->where("captured", "<", mktime(0, 0, 0, $display_month+1, 1, $display_year))
->find_all()
->count();
} else {
$day_count = ORM::factory("item")
->viewable()
->where("owner_id", "=", $display_user)
->where("type", "!=", "album")
->where("captured", ">=", mktime(0, 0, 0, $display_month, 1, $display_year))
->where("captured", "<", mktime(0, 0, 0, $display_month+1, 1, $display_year))
->find_all()
->count();
// Set up default search conditions for retrieving all photos from the specified month.
$where = array(array("type", "!=", "album"));
if ($display_user != "-1") {
$where[] = array("owner_id", "=", $display_user);
}
$where[] = array("captured", ">=", mktime(0, 0, 0, $display_month, 1, $display_year));
$where[] = array("captured", "<", mktime(0, 0, 0, $display_month+1, 1, $display_year));
// Figure out the total number of photos to display.
$day_count = calendarview::get_items_count($where);
// Figure out paging stuff.
$page_size = module::get_var("gallery", "page_size", 9);
@ -159,25 +142,7 @@ class CalendarView_Controller extends Controller {
}
// Figure out which photos go on this page.
$children = "";
if ($display_user == "-1") {
$children = ORM::factory("item")
->viewable()
->where("type", "!=", "album")
->where("captured", ">=", mktime(0, 0, 0, $display_month, 1, $display_year))
->where("captured", "<", mktime(0, 0, 0, $display_month+1, 1, $display_year))
->order_by("captured", "ASC")
->find_all($page_size, $offset);
} else {
$children = ORM::factory("item")
->viewable()
->where("owner_id", "=", $display_user)
->where("type", "!=", "album")
->where("captured", ">=", mktime(0, 0, 0, $display_month, 1, $display_year))
->where("captured", "<", mktime(0, 0, 0, $display_month+1, 1, $display_year))
->order_by("captured", "ASC")
->find_all($page_size, $offset);
}
$children = calendarview::get_items($page_size, $offset, $where);
// Create and display the page.
$root = item::root();
@ -196,6 +161,53 @@ class CalendarView_Controller extends Controller {
$template->content = new View("dynamic.html");
$template->content->title = t("Photos From ") . t(date("F", mktime(0, 0, 0, $display_month, 1, $display_year))) . " " . date("Y", mktime(0, 0, 0, $display_month, 1, $display_year));
print $template;
// Set up breadcrumbs for the photo pages to point back to the calendar month view.
item::set_display_context_callback("CalendarView_Controller::get_display_month_context", $display_user, $display_year, $display_month);
}
static function get_display_month_context($item, $display_user, $display_year, $display_month) {
// Set up default search conditions for retrieving all photos from the specified month.
$where = array(array("type", "!=", "album"));
if ($display_user != "-1") {
$where[] = array("owner_id", "=", $display_user);
}
$where[] = array("captured", ">=", mktime(0, 0, 0, $display_month, 1, $display_year));
$where[] = array("captured", "<", mktime(0, 0, 0, $display_month+1, 1, $display_year));
// Generate breadcrumbs for the photo page.
$root = item::root();
$breadcrumbs = array(
Breadcrumb::instance($root->title, $root->url())->set_first(),
Breadcrumb::instance($display_year, url::site("calendarview/calendar/" . $display_year . "/" . $display_user)),
Breadcrumb::instance(t(date("F", mktime(0, 0, 0, $display_month, 1, $display_year))), url::site("calendarview/month/" . $display_year . "/" . $display_user . "/" . $display_month)),
Breadcrumb::instance($item->title, $item->url())->set_last()
);
return CalendarView_Controller::get_display_context($item, $where, $breadcrumbs);
}
private function get_display_context($item, $where=array(), $breadcrumbs=array()) {
// Set up previous / next / breadcrumbs / etc to point to CalendarView instead of the album.
// Figure out the photo's position.
$position = calendarview::get_position($item, $where);
// Figure out the previous and next items.
if ($position > 1) {
list ($previous_item, $ignore, $next_item) = calendarview::get_items(3, $position - 2, $where);
} else {
list ($next_item) = calendarview::get_items(1, $position, $where);
}
// Figure out the total number of photos.
$sibling_count = calendarview::get_items_count($where);
return array("position" => $position,
"previous_item" => $previous_item,
"next_item" => $next_item,
"sibling_count" => $sibling_count,
"breadcrumbs" => $breadcrumbs);
}
private function _get_calenderprefs_form($display_year, $display_user) {
@ -224,7 +236,6 @@ class CalendarView_Controller extends Controller {
$valid_years = Array();
$all_photos = ORM::factory("item")
->viewable()
//->where("owner_id", "=", $one_user->id)
->where("type", "!=", "album")
->where("captured", "!=", "")
->order_by("captured", "DESC")

View File

@ -0,0 +1,48 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2012 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class calendarview_Core {
static function get_items_count($where=array()) {
// Returns the number of viewable items identified by $where.
return ORM::factory("item")
->viewable()
->merge_where($where)
->order_by("captured", "ASC")
->count_all();
}
static function get_items($limit=null, $offset=null, $where=array()) {
// Returns the items identified by $where, up to $limit, and starting at $offset.
return ORM::factory("item")
->viewable()
->merge_where($where)
->order_by("captured", "ASC")
->find_all($limit, $offset);
}
static function get_position($item, $where=array()) {
// Get's $item's position within $where.
return ORM::factory("item")
->viewable()
->merge_where($where)
->where("items.id", "<=", $item->id)
->order_by("captured", "ASC")
->count_all();
}
}