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

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

calendar improvements: week on weekly list starts on Monday,
ability to show grayed months/weeks/days (without any picture in it),
added icons for created/posted fields
language uniformization

calendar fixes: correct number of pictures in calendar view,
code simplification (I hope so)

  • Property svn:eol-style set to native
File size: 4.4 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 date_field db column on which this calendar works
42   * @param string inner_sql used for queries (INNER JOIN or normal)
43   * @param array date_components
44   */
45  function initialize($date_field, $inner_sql, $date_components)
46  {
47    parent::initialize($date_field, $inner_sql, $date_components);
48    global $lang;
49    $this->calendar_levels = array(
50      array(
51          'sql'=> 'YEAR('.$this->date_field.')',
52          'labels' => null
53        ),
54      array(
55          'sql'=> 'WEEK('.$this->date_field.')+1',
56          'labels' => null
57        ),
58      array(
59          'sql'=> 'DAYOFWEEK('.$this->date_field.')-1',
60          'labels' => $lang['day']
61        ),
62     );
63    //Comment next lines for week starting on Sunday or if MySQL version<4.0.17
64    //WEEK(date,5) = "0-53 - Week 1=the first week with a Monday in this year"
65    $this->calendar_levels[CWEEK]['sql'] = 'WEEK('.$this->date_field.',5)+1';
66    $this->calendar_levels[CDAY]['sql'] = 'WEEKDAY('.$this->date_field.')';
67    array_push( $this->calendar_levels[CDAY]['labels'],
68                array_shift( $this->calendar_levels[CDAY]['labels'] ) );
69  }
70
71/**
72 * Generate navigation bars for category page
73 * @return boolean false to indicate that thumbnails where not included here
74 */
75function generate_category_content($url_base, $view_type)
76{
77  global $conf;
78
79  $this->url_base = $url_base;
80
81  assert($view_type==CAL_VIEW_LIST);
82
83  $this->build_nav_bar(CYEAR); // years
84  if ( count($this->date_components)>=1 )
85  {
86    $this->build_nav_bar(CWEEK); // week nav bar 1-53
87  }
88  if ( count($this->date_components)>=2 )
89  {
90    $this->build_nav_bar(CDAY); // days nav bar Mon-Sun
91  }
92  return false;
93}
94
95
96/**
97 * Returns a sql where subquery for the date field
98 * @param int max_levels return the where up to this level
99 * (e.g. 2=only year and week in year)
100 * @return string
101 */
102function get_date_where($max_levels=3)
103{
104  $date = $this->date_components;
105  while (count($date)>$max_levels)
106  {
107    array_pop($date);
108  }
109  $res = '';
110  if (isset($date[CYEAR]) and $date[CYEAR]!='any')
111  {
112    $y = $date[CYEAR];
113    $res = " AND $this->date_field BETWEEN '$y-01-01' AND '$y-12-31 23:59:59'";
114  }
115
116  if (isset($date[CWEEK]) and $date[CWEEK]!='any')
117  {
118    $res .= ' AND '.$this->calendar_levels[CWEEK]['sql'].'='.$date[CWEEK];
119  }
120  if (isset($date[CDAY]) and $date[CDAY]!='any')
121  {
122    $res .= ' AND '.$this->calendar_levels[CDAY]['sql'].'='.$date[CDAY];
123  }
124  if (empty($res))
125  {
126    $res = ' AND '.$this->date_field.' IS NOT NULL';
127  }
128  return $res;
129}
130
131}
132
133?>
Note: See TracBrowser for help on using the repository browser.