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

Last change on this file since 24940 was 19703, checked in by plg, 12 years ago

update Piwigo headers to 2013 (the end of the world didn't occur as expected on r12922)

  • Property svn:eol-style set to LF
File size: 4.5 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2013 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, $conf;
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'=> pwg_db_get_year($this->date_field),
54          'labels' => null
55        ),
56      array(
57          'sql'=> pwg_db_get_week($this->date_field).'+1',
58          'labels' => $week_no_labels,
59        ),
60      array(
61          'sql'=> pwg_db_get_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    if ('monday' == $conf['week_starts_on'])
68    {
69      $this->calendar_levels[CWEEK]['sql'] = pwg_db_get_week($this->date_field, 5).'+1';
70      $this->calendar_levels[CDAY]['sql'] = pwg_db_get_weekday($this->date_field);
71      array_push( $this->calendar_levels[CDAY]['labels'],
72                  array_shift( $this->calendar_levels[CDAY]['labels'] ) );
73    }
74  }
75
76/**
77 * Generate navigation bars for category page
78 * @return boolean false to indicate that thumbnails where not included here
79 */
80function generate_category_content()
81{
82  global $conf, $page;
83
84  if ( count($page['chronology_date'])==0 )
85  {
86    $this->build_nav_bar(CYEAR); // years
87  }
88  if ( count($page['chronology_date'])==1 )
89  {
90    $this->build_nav_bar(CWEEK, array()); // week nav bar 1-53
91  }
92  if ( count($page['chronology_date'])==2 )
93  {
94    $this->build_nav_bar(CDAY); // days nav bar Mon-Sun
95  }
96  $this->build_next_prev();
97  return false;
98}
99
100
101/**
102 * Returns a sql where subquery for the date field
103 * @param int max_levels return the where up to this level
104 * (e.g. 2=only year and week in year)
105 * @return string
106 */
107function get_date_where($max_levels=3)
108{
109  global $page;
110  $date = $page['chronology_date'];
111  while (count($date)>$max_levels)
112  {
113    array_pop($date);
114  }
115  $res = '';
116  if (isset($date[CYEAR]) and $date[CYEAR]!=='any')
117  {
118    $y = $date[CYEAR];
119    $res = " AND $this->date_field BETWEEN '$y-01-01' AND '$y-12-31 23:59:59'";
120  }
121
122  if (isset($date[CWEEK]) and $date[CWEEK]!=='any')
123  {
124    $res .= ' AND '.$this->calendar_levels[CWEEK]['sql'].'='.$date[CWEEK];
125  }
126  if (isset($date[CDAY]) and $date[CDAY]!=='any')
127  {
128    $res .= ' AND '.$this->calendar_levels[CDAY]['sql'].'='.$date[CDAY];
129  }
130  if (empty($res))
131  {
132    $res = ' AND '.$this->date_field.' IS NOT NULL';
133  }
134  return $res;
135}
136
137}
138
139?>
Note: See TracBrowser for help on using the repository browser.