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

Last change on this file since 25018 was 25018, checked in by mistic100, 11 years ago

remove all array_push (50% slower than []) + some changes missing for feature:2978

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