Ignore:
Timestamp:
Mar 17, 2006, 5:13:19 AM (18 years ago)
Author:
rvelices
Message:

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

File:
1 edited

Legend:

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

    r1069 r1086  
    3434  // used for queries (INNER JOIN or normal)
    3535  var $inner_sql;
    36   // base url used when generating html links
    37   var $url_base;
    38   // array of date components e.g. (2005,10,12) ...
    39   var $date_components;
    4036  //
    4137  var $calendar_levels;
     
    4541  /**
    4642   * Initialize the calendar
    47    * @param string date_field db column on which this calendar works
    4843   * @param string inner_sql used for queries (INNER JOIN or normal)
    49    * @param array date_components
    50    */
    51   function initialize($date_field, $inner_sql, $date_components)
    52   {
    53     $this->date_field = $date_field;
     44   */
     45  function initialize($inner_sql)
     46  {
     47    global $page;
     48    if ($page['chronology']['field']=='posted')
     49    {
     50      $this->date_field = 'date_available';
     51    }
     52    else
     53    {
     54      $this->date_field = 'date_creation';
     55    }
    5456    $this->inner_sql = $inner_sql;
    55     $this->date_components = $date_components;
    5657    $this->has_nav_bar = false;
    5758  }
     
    5960  function get_display_name()
    6061  {
    61     global $conf;
     62    global $conf, $page;
    6263    $res = '';
    63     $url = $this->url_base;
    64 
    65     for ($i=0; $i<count($this->date_components); $i++)
     64
     65    for ($i=0; $i<count($page['chronology_date']); $i++)
    6666    {
    6767      $res .= $conf['level_separator'];
    68       if ($i>0)
    69       {
    70         $url .= '-';
    71       }
    72       $url .= $this->date_components[$i];
    73       if ( isset($this->date_components[$i+1]) )
    74       {
     68      if ( isset($page['chronology_date'][$i+1]) )
     69      {
     70        $chronology_date = array_slice($page['chronology_date'],0, $i+1);
     71        $url = duplicate_index_url(
     72            array( 'chronology_date'=>$chronology_date ),
     73            array( 'start' )
     74            );
    7575        $res .=
    7676          '<a href="'.$url.'">'
    77           .$this->get_date_component_label($i, $this->date_components[$i])
     77          .$this->get_date_component_label($i, $page['chronology_date'][$i])
    7878          .'</a>';
    7979      }
     
    8282        $res .=
    8383          '<span class="calInHere">'
    84           .$this->get_date_component_label($i, $this->date_components[$i])
     84          .$this->get_date_component_label($i, $page['chronology_date'][$i])
    8585          .'</span>';
    8686      }
     
    132132   * Creates a calendar navigation bar.
    133133   *
    134    * @param string url_base - links start with this root
     134   * @param array date_components
    135135   * @param array items - hash of items to put in the bar (e.g. 2005,2006)
    136136   * @param array selected_item - item currently selected (e.g. 2005)
     
    141141   * @return string the navigation bar
    142142   */
    143   function get_nav_bar_from_items($url_base, $items, $selected_item,
     143  function get_nav_bar_from_items($date_components, $items, $selected_item,
    144144                                  $class_prefix, $show_any,
    145145                                  $show_empty=false, $labels=null)
    146146  {
    147     global $conf;
     147    global $conf, $page;
    148148
    149149    $nav_bar = '';
     
    181181      {
    182182        $nav_bar .= '<span class="'.$class_prefix.'">';
    183         $url = $url_base . $item;
     183        $url = duplicate_index_url(
     184          array('chronology_date'=>array_merge($date_components,$item)),
     185          array( 'start' )
     186            );
    184187        $nav_bar .= '<a href="'.$url.'">';
    185188        $nav_bar .= $label;
     
    204207      {
    205208        $nav_bar .= '<span class="'.$class_prefix.'">';
    206         $url = $url_base . 'any';
     209        $url = duplicate_index_url(
     210          array('chronology_date'=>array_merge($date_components,'any')),
     211          array( 'start' )
     212            );
    207213        $nav_bar .= '<a href="'.$url.'">';
    208214        $nav_bar .= $label;
     
    222228  function build_nav_bar($level, $labels=null)
    223229  {
    224     global $template, $conf;
     230    global $template, $conf, $page;
    225231
    226232    $query = '
     
    241247
    242248    if ( count($level_items)==1 and
    243          count($this->date_components)<count($this->calendar_levels)-1)
    244     {
    245       if ( ! isset($this->date_components[$level]) )
     249         count($page['chronology_date'])<count($this->calendar_levels)-1)
     250    {
     251      if ( ! isset($page['chronology_date'][$level]) )
    246252      {
    247253        list($key) = array_keys($level_items);
    248         $this->date_components[$level] = (int)$key;
    249 
    250         if ( $level<count($this->date_components) and
     254        $page['chronology_date'][$level] = (int)$key;
     255
     256        if ( $level<count($page['chronology_date']) and
    251257             $level!=count($this->calendar_levels)-1 )
    252258        {
     
    256262    }
    257263
    258     $url_base = $this->url_base;
    259     for ($i=0; $i<$level; $i++)
    260     {
    261       if (isset($this->date_components[$i]))
    262       {
    263         $url_base .= $this->date_components[$i].'-';
    264       }
    265     }
    266264    $nav_bar = $this->get_nav_bar_from_items(
    267       $url_base,
     265      $page['chronology_date'],
    268266      $level_items,
    269267      null,
     
    289287  function build_next_prev()
    290288  {
    291     global $template;
     289    global $template, $page;
    292290    $prev = $next =null;
    293     if ( empty($this->date_components) )
     291    if ( empty($page['chronology_date']) )
    294292      return;
    295293    $query = 'SELECT CONCAT_WS("-"';
    296     for ($i=0; $i<count($this->date_components); $i++)
    297     {
    298       if ( 'any' === $this->date_components[$i] )
     294    for ($i=0; $i<count($page['chronology_date']); $i++)
     295    {
     296      if ( 'any' === $page['chronology_date'] )
    299297      {
    300298        $query .= ','.'"any"';
     
    305303      }
    306304    }
    307     $current = implode('-', $this->date_components );
     305    $current = implode('-', $page['chronology_date'] );
    308306
    309307    $query.=') as period' . $this->inner_sql .'
     
    328326      $template->assign_block_vars( 'calendar.navbar', array() );
    329327    }
     328
    330329    if ( $current_rank>0 )
    331330    { // has previous
    332331      $prev = $upper_items[$current_rank-1];
     332      $chronology_date = explode('-', $prev);
    333333      $template->assign_block_vars(
    334334        'calendar.navbar.prev',
    335335        array(
    336336          'LABEL' => $this->get_date_nice_name($prev),
    337           'URL' => $this->url_base . $prev,
     337          'URL' => duplicate_index_url(
     338                array('chronology_date'=>$chronology_date), array('start')
     339                )
    338340          )
    339341        );
    340342    }
    341343    if ( $current_rank < count($upper_items)-1 )
    342     {
    343       // has next
     344    { // has next
    344345      $next = $upper_items[$current_rank+1];
     346      $chronology_date = explode('-', $next);
    345347      $template->assign_block_vars(
    346348        'calendar.navbar.next',
    347349        array(
    348350          'LABEL' => $this->get_date_nice_name($next),
    349           'URL' => $this->url_base . $next,
     351          'URL' => duplicate_index_url(
     352                array('chronology_date'=>$chronology_date), array('start')
     353                )
    350354          )
    351355        );
Note: See TracChangeset for help on using the changeset viewer.