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

Last change on this file since 2315 was 2299, checked in by plg, 17 years ago

Bug fixed: as rvelices notified me by email, my header replacement script was
bugged (r2297 was repeating new and old header).

By the way, I've also removed the replacement keywords. We were using them
because it was a common usage with CVS but it is advised not to use them with
Subversion. Personnaly, it is a problem when I search differences between 2
Piwigo installations outside Subversion.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 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
24include_once(PHPWG_ROOT_PATH.'include/calendar_base.class.php');
25
26define ('CYEAR', 0);
27define ('CWEEK', 1);
28define ('CDAY',  2);
29
30/**
31 * Weekly calendar style (composed of years/week in years and days in week)
32 */
33class Calendar extends CalendarBase
34{
35
36  /**
37   * Initialize the calendar
38   * @param string inner_sql used for queries (INNER JOIN or normal)
39   */
40  function initialize($inner_sql)
41  {
42    parent::initialize($inner_sql);
43    global $lang;
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
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',
58          'labels' => $week_no_labels,
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
73/**
74 * Generate navigation bars for category page
75 * @return boolean false to indicate that thumbnails where not included here
76 */
77function generate_category_content()
78{
79  global $conf, $page;
80
81  if ( count($page['chronology_date'])==0 )
82  {
83    $this->build_nav_bar(CYEAR); // years
84  }
85  if ( count($page['chronology_date'])==1 )
86  {
87    $this->build_nav_bar(CWEEK, array()); // week nav bar 1-53
88  }
89  if ( count($page['chronology_date'])==2 )
90  {
91    $this->build_nav_bar(CDAY); // days nav bar Mon-Sun
92  }
93  $this->build_next_prev();
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 */
104function get_date_where($max_levels=3)
105{
106  global $page;
107  $date = $page['chronology_date'];
108  while (count($date)>$max_levels)
109  {
110    array_pop($date);
111  }
112  $res = '';
113  if (isset($date[CYEAR]) and $date[CYEAR]!=='any')
114  {
115    $y = $date[CYEAR];
116    $res = " AND $this->date_field BETWEEN '$y-01-01' AND '$y-12-31 23:59:59'";
117  }
118
119  if (isset($date[CWEEK]) and $date[CWEEK]!=='any')
120  {
121    $res .= ' AND '.$this->calendar_levels[CWEEK]['sql'].'='.$date[CWEEK];
122  }
123  if (isset($date[CDAY]) and $date[CDAY]!=='any')
124  {
125    $res .= ' AND '.$this->calendar_levels[CDAY]['sql'].'='.$date[CDAY];
126  }
127  if (empty($res))
128  {
129    $res = ' AND '.$this->date_field.' IS NOT NULL';
130  }
131  return $res;
132}
133
134}
135
136?>
Note: See TracBrowser for help on using the repository browser.