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

Last change on this file since 1748 was 1086, checked in by rvelices, 19 years ago

URL rewrite for chronology: uses $pagechronology and
$pagechronology_date. $pagechronology is an array with 'field',
'style' and 'view' keys. This is step 1.

  • Property svn:eol-style set to native
File size: 4.5 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
5// +-----------------------------------------------------------------------+
6// | branch        : BSF (Best So Far)
7// | file          : $RCSfile$
8// | last update   : $Date: 2006-01-27 02:11:43 +0100 (ven, 27 jan 2006) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 1014 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
26
27include_once(PHPWG_ROOT_PATH.'include/calendar_base.class.php');
28
29define ('CYEAR', 0);
30define ('CWEEK', 1);
31define ('CDAY',  2);
32
33/**
34 * Weekly calendar style (composed of years/week in years and days in week)
35 */
36class Calendar extends CalendarBase
37{
38
39  /**
40   * Initialize the calendar
41   * @param string inner_sql used for queries (INNER JOIN or normal)
42   */
43  function initialize($inner_sql)
44  {
45    parent::initialize($inner_sql);
46    global $lang;
47    $week_no_labels=array();
48    for ($i=1; $i<=53; $i++)
49    {
50      $week_no_labels[$i] = sprintf( l10n("Week %d"), $i);
51      //$week_no_labels[$i] = $i;
52    }
53
54    $this->calendar_levels = array(
55      array(
56          'sql'=> 'YEAR('.$this->date_field.')',
57          'labels' => null
58        ),
59      array(
60          'sql'=> 'WEEK('.$this->date_field.')+1',
61          'labels' => $week_no_labels,
62        ),
63      array(
64          'sql'=> 'DAYOFWEEK('.$this->date_field.')-1',
65          'labels' => $lang['day']
66        ),
67     );
68    //Comment next lines for week starting on Sunday or if MySQL version<4.0.17
69    //WEEK(date,5) = "0-53 - Week 1=the first week with a Monday in this year"
70    $this->calendar_levels[CWEEK]['sql'] = 'WEEK('.$this->date_field.',5)+1';
71    $this->calendar_levels[CDAY]['sql'] = 'WEEKDAY('.$this->date_field.')';
72    array_push( $this->calendar_levels[CDAY]['labels'],
73                array_shift( $this->calendar_levels[CDAY]['labels'] ) );
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.