source: trunk/include/calendar_weekly.class.php @ 4303

Last change on this file since 4303 was 3282, checked in by plg, 16 years ago

change: according to topic:15067, svn:keywords property was removed

  • Property svn:eol-style set to LF
File size: 4.4 KB
RevLine 
[1055]1<?php
2// +-----------------------------------------------------------------------+
[2297]3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
[3049]5// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
[2297]6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
[1055]23
24include_once(PHPWG_ROOT_PATH.'include/calendar_base.class.php');
25
[1057]26define ('CYEAR', 0);
27define ('CWEEK', 1);
28define ('CDAY',  2);
29
[1055]30/**
31 * Weekly calendar style (composed of years/week in years and days in week)
32 */
33class Calendar extends CalendarBase
34{
35
[1059]36  /**
37   * Initialize the calendar
38   * @param string inner_sql used for queries (INNER JOIN or normal)
39   */
[1086]40  function initialize($inner_sql)
[1059]41  {
[1086]42    parent::initialize($inner_sql);
[1059]43    global $lang;
[1069]44    $week_no_labels=array();
45    for ($i=1; $i<=53; $i++)
46    {
47      $week_no_labels[$i] = sprintf( l10n("Week %d"), $i);
48      //$week_no_labels[$i] = $i;
49    }
50
[1059]51    $this->calendar_levels = array(
52      array(
53          'sql'=> 'YEAR('.$this->date_field.')',
54          'labels' => null
55        ),
56      array(
57          'sql'=> 'WEEK('.$this->date_field.')+1',
[1069]58          'labels' => $week_no_labels,
[1059]59        ),
60      array(
61          'sql'=> 'DAYOFWEEK('.$this->date_field.')-1',
62          'labels' => $lang['day']
63        ),
64     );
65    //Comment next lines for week starting on Sunday or if MySQL version<4.0.17
66    //WEEK(date,5) = "0-53 - Week 1=the first week with a Monday in this year"
67    $this->calendar_levels[CWEEK]['sql'] = 'WEEK('.$this->date_field.',5)+1';
68    $this->calendar_levels[CDAY]['sql'] = 'WEEKDAY('.$this->date_field.')';
69    array_push( $this->calendar_levels[CDAY]['labels'],
70                array_shift( $this->calendar_levels[CDAY]['labels'] ) );
71  }
72
[1055]73/**
74 * Generate navigation bars for category page
75 * @return boolean false to indicate that thumbnails where not included here
76 */
[1086]77function generate_category_content()
[1055]78{
[1086]79  global $conf, $page;
[1055]80
[1086]81  if ( count($page['chronology_date'])==0 )
[1057]82  {
[1062]83    $this->build_nav_bar(CYEAR); // years
84  }
[1086]85  if ( count($page['chronology_date'])==1 )
[1062]86  {
[1069]87    $this->build_nav_bar(CWEEK, array()); // week nav bar 1-53
[1057]88  }
[1086]89  if ( count($page['chronology_date'])==2 )
[1057]90  {
[1059]91    $this->build_nav_bar(CDAY); // days nav bar Mon-Sun
[1057]92  }
[1062]93  $this->build_next_prev();
[1055]94  return false;
95}
96
97
98/**
99 * Returns a sql where subquery for the date field
100 * @param int max_levels return the where up to this level
101 * (e.g. 2=only year and week in year)
102 * @return string
103 */
[1057]104function get_date_where($max_levels=3)
[1055]105{
[1086]106  global $page;
107  $date = $page['chronology_date'];
[1059]108  while (count($date)>$max_levels)
[1055]109  {
[1059]110    array_pop($date);
[1055]111  }
112  $res = '';
[1069]113  if (isset($date[CYEAR]) and $date[CYEAR]!=='any')
[1055]114  {
[1059]115    $y = $date[CYEAR];
[1055]116    $res = " AND $this->date_field BETWEEN '$y-01-01' AND '$y-12-31 23:59:59'";
117  }
118
[1069]119  if (isset($date[CWEEK]) and $date[CWEEK]!=='any')
[1055]120  {
[1059]121    $res .= ' AND '.$this->calendar_levels[CWEEK]['sql'].'='.$date[CWEEK];
[1055]122  }
[1069]123  if (isset($date[CDAY]) and $date[CDAY]!=='any')
[1055]124  {
[1059]125    $res .= ' AND '.$this->calendar_levels[CDAY]['sql'].'='.$date[CDAY];
[1055]126  }
127  if (empty($res))
128  {
129    $res = ' AND '.$this->date_field.' IS NOT NULL';
130  }
131  return $res;
132}
133
134}
135
[1903]136?>
Note: See TracBrowser for help on using the repository browser.