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

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

Modification: new header on PHP files, PhpWebGallery renamed Piwigo.

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