1
0

Check and see if there are any photo's to display for a given day or month before displaying the sidebar block.

This commit is contained in:
rWatcher 2010-03-16 13:40:31 +08:00 committed by Tim Almdal
parent d29fc6f252
commit c24003fc9e
2 changed files with 23 additions and 1 deletions

View File

@ -38,14 +38,32 @@ class calendarview_block_Core {
$display_date = $item->created;
}
// Make sure there are photo's to display.
$day_count = ORM::factory("item")
->viewable()
->where("type", "!=", "album")
->where("captured", ">=", mktime(0, 0, 0, date("n", $display_date), date("j", $display_date), date("Y", $display_date)))
->where("captured", "<", mktime(0, 0, 0, date("n", $display_date), date("j", $display_date)+1, date("Y", $display_date)))
->find_all()
->count();
$month_count = ORM::factory("item")
->viewable()
->where("type", "!=", "album")
->where("captured", ">=", mktime(0, 0, 0, date("n", $display_date), 1, date("Y", $display_date)))
->where("captured", "<", mktime(0, 0, 0, date("n", $display_date)+1, 1, date("Y", $display_date)))
->find_all()
->count();
switch ($block_id) {
case "calendarview_photo":
if ($display_date != "") {
if ( ($display_date != "") && (($day_count > 0) || ($month_count > 0)) ) {
$block = new Block();
$block->css_id = "g-calendarview-sidebar";
$block->title = t("Calendar");
$block->content = new View("calendarview_sidebar.html");
$block->content->date = $display_date;
$block->content->day_count = $day_count;
$block->content->month_count = $month_count;
}
break;
}

View File

@ -1,5 +1,9 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<ul>
<? if ($day_count > 0): ?>
<li><a href="<?=url::site("calendarview/day/" . date("Y", $date) . "/-1/" . date("n", $date) . "/" . date("j", $date)); ?>"><?=t("More from"); ?> <?=date("F", $date); ?> <?=date("j", $date); ?><?=date("S", $date); ?></a></li>
<? endif ?>
<? if ($month_count > 0): ?>
<li><a href="<?=url::site("calendarview/month/" . date("Y", $date) . "/-1/" . date("n", $date)); ?>"><?=t("More from"); ?> <?=date("F", $date); ?></a></li>
<? endif ?>
</ul>