improvement: calendar navigation now uses at maximum one navigation bar

together with a next/previous date links 

improvement: calendar view styles now shown in DIV.titrePage (I still need 
to move padding from H2 to DIV.titrePage ...)

fix: moved all calendar css colors from template to the theme

git-svn-id: http://piwigo.org/svn/trunk@1062 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
rvelices
2006-03-03 01:57:39 +00:00
parent 8f33338fed
commit 2a3d501213
9 changed files with 176 additions and 96 deletions
+101 -16
View File
@@ -40,6 +40,8 @@ class CalendarBase
//
var $calendar_levels;
var $has_nav_bar;
/**
* Initialize the calendar
* @param string date_field db column on which this calendar works
@@ -51,6 +53,7 @@ class CalendarBase
$this->date_field = $date_field;
$this->inner_sql = $inner_sql;
$this->date_components = $date_components;
$this->has_nav_bar = false;
}
function get_display_name()
@@ -100,6 +103,28 @@ class CalendarBase
return $label;
}
/**
* Gets a nice display name for a date to be shown in previos/next links.
*/
function get_date_nice_name($date)
{
$date_components = explode('-', $date);
$res = '';
for ($i=count($date_components)-1; $i>=0; $i--)
{
if ($date_components[$i]!='any')
{
$label = $date_components[$i];
if (isset($this->calendar_levels[$i]['labels'][$date_components[$i]]))
{
$label = $this->calendar_levels[$i]['labels'][$date_components[$i]];
}
$res .= $label.' ';
}
}
return $res;
}
/**
* Creates a calendar navigation bar.
*
@@ -211,21 +236,19 @@ SELECT DISTINCT('.$this->calendar_levels[$level]['sql']
$level_items[$row['period']] = 0;
}
if ( count($level_items)==1 )
if ( count($level_items)==1 and
count($this->date_components)<count($this->calendar_levels)-1)
{
if ( ! isset($this->date_components[$level]) )
{
list($key) = array_keys($level_items);
$this->date_components[$level] = (int)$key;
}
}
if ( $conf['calendar_multi_bar']==false )
{
if ( $level<count($this->date_components) and
$level!=count($this->calendar_levels)-1 )
{
return;
if ( $level<count($this->date_components) and
$level!=count($this->calendar_levels)-1 )
{
return;
}
}
}
@@ -237,15 +260,10 @@ SELECT DISTINCT('.$this->calendar_levels[$level]['sql']
$url_base .= $this->date_components[$i].'-';
}
}
$selected = null;
if ( isset($this->date_components[$level]) )
{
$selected = $this->date_components[$level];
}
$nav_bar = $this->get_nav_bar_from_items(
$url_base,
$level_items,
$selected,
null,
'calItem',
true,
true,
@@ -255,9 +273,76 @@ SELECT DISTINCT('.$this->calendar_levels[$level]['sql']
$template->assign_block_vars(
'calendar.navbar',
array(
'BAR' => $nav_bar
'BAR' => $nav_bar,
)
);
$this->has_nav_bar = true;
}
/**
* Assigns the next/previous link to the template with regards to
* the currently choosen date.
*/
function build_next_prev()
{
global $template;
$prev = $next =null;
if ( empty($this->date_components) )
return;
$current = '';
$query = 'SELECT CONCAT_WS("-"';
for ($i=0; $i<count($this->date_components); $i++)
{
if ( $this->date_components[$i] != 'any' )
{
$query .= ','.$this->calendar_levels[$i]['sql'];
}
else
{
$query .= ','.'"any"';
}
$current .= '-' . $this->date_components[$i];
}
$current = substr($current, 1);
$query.=') as period' . $this->inner_sql .'
AND ' . $this->date_field . ' IS NOT NULL
GROUP BY period';
$upper_items = array_from_query( $query, 'period');
usort($upper_items, 'version_compare');
//echo ('<pre>'. var_export($upper_items, true) . '</pre>');
$upper_items_rank = array_flip($upper_items);
$current_rank = $upper_items_rank[$current];
if (!$this->has_nav_bar and
($current_rank>0 or $current_rank < count($upper_items)-1 ) )
{
$template->assign_block_vars( 'calendar.navbar', array() );
}
if ( $current_rank>0 )
{ // has previous
$prev = $upper_items[$current_rank-1];
$template->assign_block_vars(
'calendar.navbar.prev',
array(
'LABEL' => $this->get_date_nice_name($prev),
'URL' => $this->url_base . $prev,
)
);
}
if ( $current_rank < count($upper_items)-1 )
{
// has next
$next = $upper_items[$current_rank+1];
$template->assign_block_vars(
'calendar.navbar.next',
array(
'LABEL' => $this->get_date_nice_name($next),
'URL' => $this->url_base . $next,
)
);
}
}
}
?>
+13 -16
View File
@@ -93,31 +93,33 @@ function generate_category_content($url_base, $view_type)
if ( count($this->date_components)==2 )
{//case C: year+month given - display a nice month calendar
$this->build_month_calendar();
$this->build_nav_bar(CYEAR); // years
$this->build_nav_bar(CMONTH); // month
//$this->build_nav_bar(CYEAR); // years
//$this->build_nav_bar(CMONTH); // month
$this->build_next_prev();
return true;
}
}
if ($view_type==CAL_VIEW_LIST or count($this->date_components)==3)
{
if ( count($this->date_components)>=0 )
$has_nav_bar = false;
if ( count($this->date_components)==0 )
{
$this->build_nav_bar(CYEAR); // years
}
if ( count($this->date_components)>=1)
if ( count($this->date_components)==1)
{
$this->build_nav_bar(CMONTH); // month
}
if ( count($this->date_components)>=2 )
if ( count($this->date_components)==2 )
{
$this->build_nav_bar(
CDAY,
range( 1, $this->get_all_days_in_month(
$this->date_components[CYEAR] ,$this->date_components[CMONTH] )
)
); // days
$day_labels = range( 1, $this->get_all_days_in_month(
$this->date_components[CYEAR] ,$this->date_components[CMONTH] ) );
array_unshift($day_labels, 0);
unset( $day_labels[0] );
$this->build_nav_bar( CDAY, $day_labels ); // days
}
$this->build_next_prev();
}
return false;
}
@@ -293,11 +295,6 @@ function build_year_calendar()
{ // only one month exists so bail out to month view
list($m) = array_keys($items);
$this->date_components[CMONTH] = $m;
if (count($items[$m]['children'])==1)
{ // or even to day view if everything occured in one day
list($d) = array_keys($items[$m]['children']);
$this->date_components[CDAY] = $d;
}
return false;
}
global $lang, $template;
+7 -3
View File
@@ -80,15 +80,19 @@ function generate_category_content($url_base, $view_type)
assert($view_type==CAL_VIEW_LIST);
$this->build_nav_bar(CYEAR); // years
if ( count($this->date_components)>=1 )
if ( count($this->date_components)==0 )
{
$this->build_nav_bar(CYEAR); // years
}
if ( count($this->date_components)==1 )
{
$this->build_nav_bar(CWEEK); // week nav bar 1-53
}
if ( count($this->date_components)>=2 )
if ( count($this->date_components)==2 )
{
$this->build_nav_bar(CDAY); // days nav bar Mon-Sun
}
$this->build_next_prev();
return false;
}
-4
View File
@@ -90,10 +90,6 @@ $conf['anti-flood_time'] = 60;
// catgory
$conf['calendar_datefield'] = 'date_creation';
// calendar_multi_bar : the calendar shows a maximum number of
// year/month/week/day navigation bars
$conf['calendar_multi_bar'] = true;
// calendar_show_any : the calendar shows an aditional 'any' button in the
// year/month/week/day navigation bars
$conf['calendar_show_any'] = true;
+11 -14
View File
@@ -260,24 +260,20 @@ WHERE id IN (' . implode(',',$page['items']) .')';
}
}
}
$calendar_title =
'<a href="'.$url_base.$cal_style.'-'.$cal_view.'">'
.$fields[$cal_field]['label'].'</a>';
$calendar_title.= $calendar->get_display_name();
//this should be an assign_block_vars, but I need to assign 'calendar'
//above and at that point I don't have the title yet.
$template->_tpldata['calendar.'][0]['TITLE'] = $calendar_title;
} // end category calling
$calendar_title =
'<a href="'.$url_base.$cal_style.'-'.$cal_view.'">'
.$fields[$cal_field]['label'].'</a>';
$calendar_title.= $calendar->get_display_name();
$template->assign_block_vars(
'calendar',
array(
'TITLE' => '<br/>'.$calendar_title,
)
);
if ($must_show_list)
{
$query = 'SELECT DISTINCT(id)';
$query .= $calendar->inner_sql;
$query .= $calendar->get_date_where();
$query .= $calendar->inner_sql.'
'.$calendar->get_date_where();
if ( isset($page['super_order_by']) )
{
$query .= '
@@ -289,7 +285,8 @@ WHERE id IN (' . implode(',',$page['items']) .')';
'ORDER BY ',
'ORDER BY '.$calendar->date_field.' DESC,', $conf['order_by']
);
$query .= $order_by;
$query .= '
'.$order_by;
}
$page['items'] = array_from_query($query, 'id');