Ignore:
Timestamp:
Mar 3, 2006, 2:57:39 AM (18 years ago)
Author:
rvelices
Message:

improvement: calendar navigation now uses at maximum one navigation bar
together with a next/previous date links

improvement: calendar view styles now shown in DIV.titrePage (I still need
to move padding from H2 to DIV.titrePage ...)

fix: moved all calendar css colors from template to the theme

File:
1 edited

Legend:

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

    r1059 r1062  
    4141  var $calendar_levels;
    4242
     43  var $has_nav_bar;
     44
    4345  /**
    4446   * Initialize the calendar
     
    5254    $this->inner_sql = $inner_sql;
    5355    $this->date_components = $date_components;
     56    $this->has_nav_bar = false;
    5457  }
    5558
     
    99102    }
    100103    return $label;
     104  }
     105
     106  /**
     107   * Gets a nice display name for a date to be shown in previos/next links.
     108   */
     109  function get_date_nice_name($date)
     110  {
     111    $date_components = explode('-', $date);
     112    $res = '';
     113    for ($i=count($date_components)-1; $i>=0; $i--)
     114    {
     115      if ($date_components[$i]!='any')
     116      {
     117        $label = $date_components[$i];
     118        if (isset($this->calendar_levels[$i]['labels'][$date_components[$i]]))
     119        {
     120          $label = $this->calendar_levels[$i]['labels'][$date_components[$i]];
     121        }
     122        $res .= $label.' ';
     123      }
     124    }
     125    return $res;
    101126  }
    102127
     
    212237    }
    213238
    214     if ( count($level_items)==1 )
     239    if ( count($level_items)==1 and
     240         count($this->date_components)<count($this->calendar_levels)-1)
    215241    {
    216242      if ( ! isset($this->date_components[$level]) )
     
    218244        list($key) = array_keys($level_items);
    219245        $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;
     246
     247        if ( $level<count($this->date_components) and
     248             $level!=count($this->calendar_levels)-1 )
     249        {
     250          return;
     251        }
    229252      }
    230253    }
     
    237260        $url_base .= $this->date_components[$i].'-';
    238261      }
    239     }
    240     $selected = null;
    241     if ( isset($this->date_components[$level]) )
    242     {
    243       $selected = $this->date_components[$level];
    244262    }
    245263    $nav_bar = $this->get_nav_bar_from_items(
    246264      $url_base,
    247265      $level_items,
    248       $selected,
     266      null,
    249267      'calItem',
    250268      true,
     
    256274      'calendar.navbar',
    257275      array(
    258         'BAR' => $nav_bar
     276        'BAR' => $nav_bar,
    259277        )
    260278      );
     279    $this->has_nav_bar = true;
     280  }
     281
     282  /**
     283   * Assigns the next/previous link to the template with regards to
     284   * the currently choosen date.
     285   */
     286  function build_next_prev()
     287  {
     288    global $template;
     289    $prev = $next =null;
     290    if ( empty($this->date_components) )
     291      return;
     292
     293    $current = '';
     294    $query = 'SELECT CONCAT_WS("-"';
     295    for ($i=0; $i<count($this->date_components); $i++)
     296    {
     297      if ( $this->date_components[$i] != 'any' )
     298      {
     299        $query .= ','.$this->calendar_levels[$i]['sql'];
     300      }
     301      else
     302      {
     303        $query .= ','.'"any"';
     304      }
     305      $current .= '-' . $this->date_components[$i];
     306    }
     307    $current = substr($current, 1);
     308
     309    $query.=') as period' . $this->inner_sql .'
     310AND ' . $this->date_field . ' IS NOT NULL
     311GROUP BY period';
     312    $upper_items = array_from_query( $query, 'period');
     313    usort($upper_items, 'version_compare');
     314    //echo ('<pre>'. var_export($upper_items, true) . '</pre>');
     315    $upper_items_rank = array_flip($upper_items);
     316    $current_rank = $upper_items_rank[$current];
     317    if (!$this->has_nav_bar and
     318        ($current_rank>0 or $current_rank < count($upper_items)-1 ) )
     319    {
     320      $template->assign_block_vars( 'calendar.navbar', array() );
     321    }
     322
     323    if ( $current_rank>0 )
     324    { // has previous
     325      $prev = $upper_items[$current_rank-1];
     326      $template->assign_block_vars(
     327        'calendar.navbar.prev',
     328        array(
     329          'LABEL' => $this->get_date_nice_name($prev),
     330          'URL' => $this->url_base . $prev,
     331          )
     332        );
     333    }
     334    if ( $current_rank < count($upper_items)-1 )
     335    {
     336      // has next
     337      $next = $upper_items[$current_rank+1];
     338      $template->assign_block_vars(
     339        'calendar.navbar.next',
     340        array(
     341          'LABEL' => $this->get_date_nice_name($next),
     342          'URL' => $this->url_base . $next,
     343          )
     344        );
     345    }
    261346  }
    262347}
Note: See TracChangeset for help on using the changeset viewer.