aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2006-03-03 01:57:39 +0000
committerrvelices <rv-github@modusoptimus.com>2006-03-03 01:57:39 +0000
commit2a3d5012138715952add2f69e9b3253353ea419d (patch)
tree0edda816004ca51c4781bf12517f0c95ad422eae /include
parent8f33338fed3809c2b964cbe610658b143c96b6c9 (diff)
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
Diffstat (limited to 'include')
-rw-r--r--include/calendar_base.class.php117
-rw-r--r--include/calendar_monthly.class.php29
-rw-r--r--include/calendar_weekly.class.php10
-rw-r--r--include/config_default.inc.php4
-rw-r--r--include/functions_calendar.inc.php25
5 files changed, 132 insertions, 53 deletions
diff --git a/include/calendar_base.class.php b/include/calendar_base.class.php
index 8f9ec4bb7..c71940830 100644
--- a/include/calendar_base.class.php
+++ b/include/calendar_base.class.php
@@ -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()
@@ -101,6 +104,28 @@ class CalendarBase
}
/**
+ * 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.
*
* @param string url_base - links start with this root
@@ -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,
+ )
+ );
+ }
}
}
?> \ No newline at end of file
diff --git a/include/calendar_monthly.class.php b/include/calendar_monthly.class.php
index 107c98634..81978f963 100644
--- a/include/calendar_monthly.class.php
+++ b/include/calendar_monthly.class.php
@@ -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;
diff --git a/include/calendar_weekly.class.php b/include/calendar_weekly.class.php
index 786f90c68..817acb1b0 100644
--- a/include/calendar_weekly.class.php
+++ b/include/calendar_weekly.class.php
@@ -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;
}
diff --git a/include/config_default.inc.php b/include/config_default.inc.php
index 5a61c12e3..c9c0f80af 100644
--- a/include/config_default.inc.php
+++ b/include/config_default.inc.php
@@ -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;
diff --git a/include/functions_calendar.inc.php b/include/functions_calendar.inc.php
index 1606b4307..f9404467a 100644
--- a/include/functions_calendar.inc.php
+++ b/include/functions_calendar.inc.php
@@ -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');