aboutsummaryrefslogtreecommitdiffstats
path: root/include/calendar_monthly.class.php
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--include/calendar_monthly.class.php170
1 files changed, 90 insertions, 80 deletions
diff --git a/include/calendar_monthly.class.php b/include/calendar_monthly.class.php
index e628cd44b..3a4207076 100644
--- a/include/calendar_monthly.class.php
+++ b/include/calendar_monthly.class.php
@@ -36,6 +36,32 @@ define ('CDAY', 2);
class Calendar extends CalendarBase
{
+ /**
+ * Initialize the calendar
+ * @param string date_field db column on which this calendar works
+ * @param string inner_sql used for queries (INNER JOIN or normal)
+ * @param array date_components
+ */
+ function initialize($date_field, $inner_sql, $date_components)
+ {
+ parent::initialize($date_field, $inner_sql, $date_components);
+ global $lang;
+ $this->calendar_levels = array(
+ array(
+ 'sql'=> 'YEAR('.$this->date_field.')',
+ 'labels' => null
+ ),
+ array(
+ 'sql'=> 'MONTH('.$this->date_field.')',
+ 'labels' => $lang['month']
+ ),
+ array(
+ 'sql'=> 'DAYOFMONTH('.$this->date_field.')',
+ 'labels' => null
+ ),
+ );
+ }
+
/**
* Generate navigation bars for category page
* @return boolean false to indicate that thumbnails
@@ -43,7 +69,7 @@ class Calendar extends CalendarBase
*/
function generate_category_content($url_base, $view_type)
{
- global $lang, $conf;
+ global $conf;
$this->url_base = $url_base;
@@ -59,8 +85,7 @@ function generate_category_content($url_base, $view_type)
{//case B: year given - display all days in given year
if ($this->build_year_calendar())
{
- if ( $conf['calendar_multi_bar'] )
- $this->build_nav_bar2(CYEAR, 'YEAR'); // years
+ $this->build_nav_bar(CYEAR); // years
return true;
}
}
@@ -68,34 +93,30 @@ 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();
- if ( $conf['calendar_multi_bar'] )
- {
- $this->build_nav_bar2(CYEAR, 'YEAR'); // years
- }
- if (count($this->date_components)>=1 and
- ( $conf['calendar_multi_bar'] or count($this->date_components)==1 ) )
- {
- $this->build_nav_bar2(CMONTH, 'MONTH', $lang['month']); // month
- }
+ $this->build_nav_bar(CYEAR); // years
+ $this->build_nav_bar(CMONTH); // month
return true;
}
}
if ($view_type==CAL_VIEW_LIST or count($this->date_components)==3)
{
- if ( $conf['calendar_multi_bar'] or count($this->date_components)==0 )
+ if ( count($this->date_components)>=0 )
{
- $this->build_nav_bar2(CYEAR, 'YEAR'); // years
+ $this->build_nav_bar(CYEAR); // years
}
- if ( count($this->date_components)>=1 and
- ( $conf['calendar_multi_bar'] or count($this->date_components)==1 )
- )
+ if ( count($this->date_components)>=1)
{
- $this->build_nav_bar2(CMONTH, 'MONTH', $lang['month']); // month
+ $this->build_nav_bar(CMONTH); // month
}
if ( count($this->date_components)>=2 )
{
- $this->build_nav_bar2(CDAY, 'DAYOFMONTH' ); // days
+ $this->build_nav_bar(
+ CDAY,
+ $this->get_all_days_in_month(
+ $this->date_components[CYEAR] ,$this->date_components[CMONTH]
+ )
+ ); // days
}
}
return false;
@@ -141,11 +162,11 @@ function get_date_where($max_levels=3)
$e .= '12-31';
if (isset($date[CMONTH]) and $date[CMONTH]!='any')
{
- $res .= ' AND MONTH('.$this->date_field.')='.$date[CMONTH];
+ $res .= ' AND '.$this->calendar_levels[CMONTH]['sql'].'='.$date[CMONTH];
}
- if (isset($date[2]) and $date[2]!='any')
+ if (isset($date[CDAY]) and $date[CDAY]!='any')
{
- $res .= ' AND DAYOFMONTH('.$this->date_field.')='.$date[CDAY];
+ $res .= ' AND '.$this->calendar_levels[CDAY]['sql'].'='.$date[CDAY];
}
}
$res = " AND $this->date_field BETWEEN '$b' AND '$e 23:59:59'" . $res;
@@ -155,74 +176,56 @@ function get_date_where($max_levels=3)
$res = ' AND '.$this->date_field.' IS NOT NULL';
if (isset($date[CMONTH]) and $date[CMONTH]!='any')
{
- $res .= ' AND MONTH('.$this->date_field.')='.$date[CMONTH];
+ $res .= ' AND '.$this->calendar_levels[CMONTH]['sql'].'='.$date[CMONTH];
}
if (isset($date[CDAY]) and $date[CDAY]!='any')
{
- $res .= ' AND DAYOFMONTH('.$this->date_field.')='.$date[CDAY];
+ $res .= ' AND '.$this->calendar_levels[CDAY]['sql'].'='.$date[CDAY];
}
}
return $res;
}
-function get_display_name()
+
+//--------------------------------------------------------- private members ---
+
+// returns an array with alll the days in a given month
+function get_all_days_in_month($year, $month)
{
- global $conf, $lang;
- $res = '';
- $url = $this->url_base;
- if ( isset($this->date_components[CYEAR]) )
+ $md= array(1=>31,28,31,30,31,30,31,31,30,31,30,31);
+
+ if ( is_numeric($year) and $month==2)
{
- $res .= $conf['level_separator'];
- $url .= $this->date_components[CYEAR].'-';
- $res .=
- '<a href="'.$url.'">'
- .$this->get_date_component_label($this->date_components[CYEAR])
- .'</a>';
+ $nb_days = $md[2];
+ if ( ($year%4==0) and ( ($year%100!=0) or ($year%400!=0) ) )
+ {
+ $nb_days++;
+ }
}
- if ( isset($this->date_components[CMONTH]) )
+ elseif ( is_numeric($month) )
{
- $res .= $conf['level_separator'];
- $url .= $this->date_components[CMONTH].'-';
- $res .=
- '<a href="'.$url.'">'
- .$this->get_date_component_label(
- $this->date_components[CMONTH],
- $lang['month']
- )
- .'</a>';
+ $nb_days = $md[ $month ];
}
- if ( isset($this->date_components[CDAY]) )
+ else
{
- $res .= $conf['level_separator'];
- $url .= $this->date_components[CDAY].'-';
- $res .=
- '<a href="'.$url.'">'
- .$this->get_date_component_label($this->date_components[CDAY])
- .'</a>';
+ $nb_days = 31;
}
-
- return $res;
-}
-
-
-//--------------------------------------------------------- private members ---
-function build_nav_bar2($level, $sql_func, $labels=null)
-{
- parent::build_nav_bar($level, $sql_func, '', $labels);
+ return range(1, $nb_days);
}
function build_global_calendar()
{
assert( count($this->date_components) == 0 );
$query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%Y%m")) as period,
- COUNT(id) as count';
+ COUNT( DISTINCT(id) ) as count';
$query.= $this->inner_sql;
$query.= $this->get_date_where();
$query.= '
GROUP BY period';
$result = pwg_query($query);
+ $items=array();
while ($row = mysql_fetch_array($result))
{
$y = substr($row['period'], 0, 4);
@@ -252,8 +255,8 @@ function build_global_calendar()
$nav_bar .= '</span><br>';
$url_base .= '-';
- $nav_bar .= $this->get_nav_bar_from_items( $url_base,
- $year_data['children'], null, 'calCal', false, $lang['month'] );
+ $nav_bar .= $this->get_nav_bar_from_items( $url_base,
+ $year_data['children'], null, 'calCal', false, false, $lang['month'] );
$template->assign_block_vars( 'calendar.calbar',
array( 'BAR' => $nav_bar)
@@ -266,13 +269,14 @@ function build_year_calendar()
{
assert( count($this->date_components) == 1 );
$query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%m%d")) as period,
- COUNT(id) as count';
+ COUNT( DISTINCT(id) ) as count';
$query.= $this->inner_sql;
$query.= $this->get_date_where();
$query.= '
GROUP BY period';
$result = pwg_query($query);
+ $items=array();
while ($row = mysql_fetch_array($result))
{
$m = (int)substr($row['period'], 0, 2);
@@ -307,7 +311,7 @@ function build_year_calendar()
$nav_bar .= '</span><br>';
$url_base .= '-';
- $nav_bar .= $this->get_nav_bar_from_items( $url_base,
+ $nav_bar .= $this->get_nav_bar_from_items( $url_base,
$month_data['children'], null, 'calCal', false );
$template->assign_block_vars( 'calendar.calbar',
@@ -331,18 +335,11 @@ function build_month_calendar()
while ($row = mysql_fetch_array($result))
{
$d = $row['period'];
- $items[$d] = $row['count'];
+ $items[$d] = array('nb_images'=>$row['count']);
}
- global $lang, $template;
-
- $template->assign_block_vars('thumbnails', array());
- $template->assign_block_vars('thumbnails.line', array());
- foreach ( $items as $day=>$nb_images)
+ foreach ( $items as $day=>$data)
{
- $url_base = $this->url_base.
- $this->date_components[CYEAR].'-'.
- $this->date_components[CMONTH].'-'.$day;
$this->date_components[CDAY]=$day;
$query = '
SELECT file,tn_ext,path, DAYOFWEEK('.$this->date_field.')-1 as dw';
@@ -354,16 +351,28 @@ SELECT file,tn_ext,path, DAYOFWEEK('.$this->date_field.')-1 as dw';
unset ( $this->date_components[CDAY] );
$row = mysql_fetch_array(pwg_query($query));
+ $items[$day]['tn_path'] = get_thumbnail_src($row['path'], @$row['tn_ext']);
+ $items[$day]['tn_file'] = $row['file'];
+ $items[$day]['tn_dw'] = $row['dw'];
+ }
+
+ global $lang, $template;
+ $template->assign_block_vars('thumbnails', array());
+ $template->assign_block_vars('thumbnails.line', array());
+ foreach ( $items as $day=>$data)
+ {
+ $url_base = $this->url_base.
+ $this->date_components[CYEAR].'-'.
+ $this->date_components[CMONTH].'-'.$day;
- $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
- $thumbnail_title = $lang['day'][$row['dw']] . ' ' . $day;
- $name = $thumbnail_title .' ('.$nb_images.')';
+ $thumbnail_title = $lang['day'][$data['tn_dw']] . ' ' . $day;
+ $name = $thumbnail_title .' ('.$data['nb_images'].')';
$template->assign_block_vars(
'thumbnails.line.thumbnail',
array(
- 'IMAGE'=>$thumbnail_src,
- 'IMAGE_ALT'=>$row['file'],
+ 'IMAGE'=>$data['tn_path'],
+ 'IMAGE_ALT'=>$data['tn_file'],
'IMAGE_TITLE'=>$thumbnail_title,
'U_IMG_LINK'=>$url_base
)
@@ -375,6 +384,7 @@ SELECT file,tn_ext,path, DAYOFWEEK('.$this->date_field.')-1 as dw';
)
);
}
+
return true;
}