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

Last change on this file since 25812 was 25507, checked in by mistic100, 10 years ago

feature 2999 : documentation of include/functions_calendar.inc.php and Calendar classes

  • Property svn:eol-style set to LF
File size: 4.6 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
24/**
25 * @package functions\calendar
26 */
27
28include_once(PHPWG_ROOT_PATH.'include/calendar_base.class.php');
29
30/** level of year view */
31define('CYEAR', 0);
32/** level of week view */
33define('CWEEK', 1);
34/** level of day view */
35define('CDAY',  2);
36
37
38/**
39 * Weekly calendar style (composed of years/week in years and days in week)
40 */
41class Calendar extends CalendarBase
42{
43  /**
44   * Initialize the calendar
45   * @param string $inner_sql
46   */
47  function initialize($inner_sql)
48  {
49    parent::initialize($inner_sql);
50    global $lang, $conf;
51    $week_no_labels=array();
52    for ($i=1; $i<=53; $i++)
53    {
54      $week_no_labels[$i] = l10n('Week %d', $i);
55      //$week_no_labels[$i] = $i;
56    }
57
58    $this->calendar_levels = array(
59      array(
60          'sql'=> pwg_db_get_year($this->date_field),
61          'labels' => null
62        ),
63      array(
64          'sql'=> pwg_db_get_week($this->date_field).'+1',
65          'labels' => $week_no_labels,
66        ),
67      array(
68          'sql'=> pwg_db_get_dayofweek($this->date_field).'-1',
69          'labels' => $lang['day']
70        ),
71     );
72    //Comment next lines for week starting on Sunday or if MySQL version<4.0.17
73    //WEEK(date,5) = "0-53 - Week 1=the first week with a Monday in this year"
74    if ('monday' == $conf['week_starts_on'])
75    {
76      $this->calendar_levels[CWEEK]['sql'] = pwg_db_get_week($this->date_field, 5).'+1';
77      $this->calendar_levels[CDAY]['sql'] = pwg_db_get_weekday($this->date_field);
78      $this->calendar_levels[CDAY]['labels'][] = array_shift($this->calendar_levels[CDAY]['labels']);
79    }
80  }
81
82  /**
83   * Generate navigation bars for category page.
84   *
85   * @return boolean false indicates that thumbnails where not included
86   */
87  function generate_category_content()
88  {
89    global $conf, $page;
90
91    if ( count($page['chronology_date'])==0 )
92    {
93      $this->build_nav_bar(CYEAR); // years
94    }
95    if ( count($page['chronology_date'])==1 )
96    {
97      $this->build_nav_bar(CWEEK, array()); // week nav bar 1-53
98    }
99    if ( count($page['chronology_date'])==2 )
100    {
101      $this->build_nav_bar(CDAY); // days nav bar Mon-Sun
102    }
103    $this->build_next_prev();
104    return false;
105  }
106
107  /**
108   * Returns a sql WHERE subquery for the date field.
109   *
110   * @param int $max_levels (e.g. 2=only year and month)
111   * @return string
112   */
113  function get_date_where($max_levels=3)
114  {
115    global $page;
116    $date = $page['chronology_date'];
117    while (count($date)>$max_levels)
118    {
119      array_pop($date);
120    }
121    $res = '';
122    if (isset($date[CYEAR]) and $date[CYEAR]!=='any')
123    {
124      $y = $date[CYEAR];
125      $res = " AND $this->date_field BETWEEN '$y-01-01' AND '$y-12-31 23:59:59'";
126    }
127
128    if (isset($date[CWEEK]) and $date[CWEEK]!=='any')
129    {
130      $res .= ' AND '.$this->calendar_levels[CWEEK]['sql'].'='.$date[CWEEK];
131    }
132    if (isset($date[CDAY]) and $date[CDAY]!=='any')
133    {
134      $res .= ' AND '.$this->calendar_levels[CDAY]['sql'].'='.$date[CDAY];
135    }
136    if (empty($res))
137    {
138      $res = ' AND '.$this->date_field.' IS NOT NULL';
139    }
140    return $res;
141  }
142}
143
144?>
Note: See TracBrowser for help on using the repository browser.