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_base.class.php

    r1057 r1059  
    3838  // array of date components e.g. (2005,10,12) ...
    3939  var $date_components;
    40 
     40  //
     41  var $calendar_levels;
    4142
    4243  /**
     
    5354  }
    5455
     56  function get_display_name()
     57  {
     58    global $conf;
     59    $res = '';
     60    $url = $this->url_base;
     61
     62    for ($i=0; $i<count($this->date_components); $i++)
     63    {
     64      $res .= $conf['level_separator'];
     65
     66      $url .= $this->date_components[$i].'-';
     67      if ( isset($this->date_components[$i+1]) )
     68      {
     69        $res .=
     70          '<a href="'.$url.'">'
     71          .$this->get_date_component_label($i, $this->date_components[$i])
     72          .'</a>';
     73      }
     74      else
     75      {
     76        $res .=
     77          '<span class="calInHere">'
     78          .$this->get_date_component_label($i, $this->date_components[$i])
     79          .'</span>';
     80      }
     81    }
     82    return $res;
     83  }
     84
    5585//--------------------------------------------------------- private members ---
    5686  /**
    5787   * Returns a display name for a date component optionally using labels
    5888  */
    59   function get_date_component_label($date_component, $labels=null)
     89  function get_date_component_label($level, $date_component)
    6090  {
    6191    $label = $date_component;
    62     if (isset($labels[$date_component]))
    63     {
    64       $label = $labels[$date_component];
     92    if (isset($this->calendar_levels[$level]['labels'][$date_component]))
     93    {
     94      $label = $this->calendar_levels[$level]['labels'][$date_component];
    6595    }
    6696    elseif ($date_component == 'any' )
     
    70100    return $label;
    71101  }
    72  
     102
    73103  /**
    74104   * Creates a calendar navigation bar.
     
    78108   * @param array selected_item - item currently selected (e.g. 2005)
    79109   * @param string class_prefix - html class attribute prefix for span elements
    80    * @param bool allow_any - adds any to the end of the bar
     110   * @param bool show_any - adds any link to the end of the bar
     111   * @param bool show_empty - shows all labels even those without items
    81112   * @param array labels - optional labels for items (e.g. Jan,Feb,...)
    82113   * @return string the navigation bar
    83114   */
    84115  function get_nav_bar_from_items($url_base, $items, $selected_item,
    85                                   $class_prefix, $allow_any, $labels=null)
    86   {
     116                                  $class_prefix, $show_any,
     117                                  $show_empty=false, $labels=null)
     118  {
     119    global $conf;
     120
    87121    $nav_bar = '';
    88      
     122
     123    if ($conf['calendar_show_empty'] and $show_empty and !empty($labels) )
     124    {
     125      foreach ($labels as $item => $label)
     126      {
     127        if ( ! isset($items[$item]) )
     128        {
     129          $items[$item] = -1;
     130        }
     131      }
     132      ksort($items);
     133    }
     134
    89135    foreach ($items as $item => $nb_images)
    90136    {
     
    97143      {
    98144        $nav_bar .= '<span class="'.$class_prefix.'Sel">';
     145        $nav_bar .= $label;
     146      }
     147      elseif ($nb_images==-1)
     148      {
     149        $nav_bar .= '<span class="'.$class_prefix.'Empty">';
    99150        $nav_bar .= $label;
    100151      }
     
    113164      $nav_bar.= '</span>';
    114165    }
    115     global $conf;
    116     if ($conf['calendar_show_any'] and $allow_any and count($items) > 1)
     166
     167    if ($conf['calendar_show_any'] and $show_any and count($items) > 1)
    117168    {
    118169      $label = l10n('calendar_any');
     
    138189   * Creates a calendar navigation bar for a given level.
    139190   *
    140    * @param string sql_func - YEAR/MONTH/DAY/WEEK/DAYOFWEEK ...
    141    * @param string sql_offset - (e.g. +1 for WEEK - first in year is 1)
    142    * @param array labels - optional labels to show in the navigation bar
     191   * @param int level - the level (0-year,1-month/week,2-day)
    143192   * @return void
    144193   */
    145   function build_nav_bar($level, $sql_func,
    146                          $sql_offset='', $labels=null)
    147   {
    148     global $template;
    149    
     194  function build_nav_bar($level, $labels=null)
     195  {
     196    global $template, $conf;
     197
    150198    $query = '
    151 SELECT DISTINCT('.$sql_func.'('.$this->date_field.')'.$sql_offset
     199SELECT DISTINCT('.$this->calendar_levels[$level]['sql']
    152200      .') as period';
    153201    $query.= $this->inner_sql;
     
    164212    }
    165213
     214    if ( count($level_items)==1 )
     215    {
     216      if ( ! isset($this->date_components[$level]) )
     217      {
     218        list($key) = array_keys($level_items);
     219        $this->date_components[$level] = (int)$key;
     220      }
     221    }
     222
     223    if ( $conf['calendar_multi_bar']==false )
     224    {
     225      if ( $level<count($this->date_components) and
     226           $level!=count($this->calendar_levels)-1 )
     227      {
     228        return;
     229      }
     230    }
     231
    166232    $url_base = $this->url_base;
    167233    for ($i=0; $i<$level; $i++)
     
    181247      $level_items,
    182248      $selected,
    183       'cal',
     249      'calItem',
    184250      true,
    185       $labels
     251      true,
     252      isset($labels) ? $labels : $this->calendar_levels[$level]['labels']
    186253      );
    187254
Note: See TracChangeset for help on using the changeset viewer.