Ignore:
Timestamp:
Feb 28, 2006, 5:28:06 AM (18 years ago)
Author:
rvelices
Message:

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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/calendar_weekly.class.php

    r1057 r1059  
    3737{
    3838
     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
    3971/**
    4072 * Generate navigation bars for category page
     
    4375function generate_category_content($url_base, $view_type)
    4476{
    45   global $lang, $conf;
     77  global $conf;
    4678
    4779  $this->url_base = $url_base;
     
    4981  assert($view_type==CAL_VIEW_LIST);
    5082
    51   if ( $conf['calendar_multi_bar'] or count($this->date_components)==0 )
     83  $this->build_nav_bar(CYEAR); // years
     84  if ( count($this->date_components)>=1 )
    5285  {
    53     $this->build_nav_bar(CYEAR, 'YEAR'); // years
    54   }
    55   if ( count($this->date_components)>=1 and
    56       ( $conf['calendar_multi_bar'] or count($this->date_components)==1 )
    57      )
    58   {
    59     $this->build_nav_bar(CWEEK, 'WEEK', '+1' ); // month
     86    $this->build_nav_bar(CWEEK); // week nav bar 1-53
    6087  }
    6188  if ( count($this->date_components)>=2 )
    6289  {
    63     $this->build_nav_bar(CDAY, 'DAYOFWEEK', '-1',
    64                          $lang['day'] ); // days
     90    $this->build_nav_bar(CDAY); // days nav bar Mon-Sun
    6591  }
    6692  return false;
     
    76102function get_date_where($max_levels=3)
    77103{
    78   $date_components = $this->date_components;
    79   while (count($date_components)>$max_levels)
     104  $date = $this->date_components;
     105  while (count($date)>$max_levels)
    80106  {
    81     array_pop($date_components);
     107    array_pop($date);
    82108  }
    83109  $res = '';
    84   if (isset($date_components[CYEAR]) and $date_components[CYEAR]!='any')
     110  if (isset($date[CYEAR]) and $date[CYEAR]!='any')
    85111  {
    86     $y = $date_components[CYEAR];
     112    $y = $date[CYEAR];
    87113    $res = " AND $this->date_field BETWEEN '$y-01-01' AND '$y-12-31 23:59:59'";
    88114  }
    89115
    90   if (isset($date_components[CWEEK]) and $date_components[CWEEK]!='any')
     116  if (isset($date[CWEEK]) and $date[CWEEK]!='any')
    91117  {
    92     $res .= ' AND WEEK('.$this->date_field.')+1='.$date_components[CWEEK];
     118    $res .= ' AND '.$this->calendar_levels[CWEEK]['sql'].'='.$date[CWEEK];
    93119  }
    94   if (isset($date_components[CDAY]) and $date_components[CDAY]!='any')
     120  if (isset($date[CDAY]) and $date[CDAY]!='any')
    95121  {
    96     $res .= ' AND DAYOFWEEK('.$this->date_field.')-1='
    97             .$date_components[CDAY];
     122    $res .= ' AND '.$this->calendar_levels[CDAY]['sql'].'='.$date[CDAY];
    98123  }
    99124  if (empty($res))
     
    104129}
    105130
    106 function get_display_name()
    107 {
    108   global $conf,$lang;
    109   $res = '';
    110   $url = $this->url_base;
    111   if ( isset($this->date_components[CYEAR]) )
    112   {
    113     $res .= $conf['level_separator'];
    114     $url .= $this->date_components[CYEAR].'-';
    115     $res .=
    116       '<a href="'.$url.'">'
    117       .$this->get_date_component_label($this->date_components[CYEAR])
    118       .'</a>';
    119   }
    120   if ( isset($this->date_components[CWEEK]) )
    121   {
    122     $res .= $conf['level_separator'];
    123     $url .= $this->date_components[CWEEK].'-';
    124     $res .=
    125       '<a href="'.$url.'">'
    126       .$this->get_date_component_label($this->date_components[CWEEK])
    127       .'</a>';
    128   }
    129   if ( isset($this->date_components[CDAY]) )
    130   {
    131     $res .= $conf['level_separator'];
    132     $url .= $this->date_components[CDAY].'-';
    133     $res .=
    134       '<a href="'.$url.'">'
    135       .$this->get_date_component_label(
    136                     $this->date_components[CDAY],
    137                     $lang['day']
    138                     )
    139       .'</a>';
    140   }
    141   return $res;
    142 }
    143 
    144131}
    145132
Note: See TracChangeset for help on using the changeset viewer.