[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/common/ -> ezdateoperatorcollection.php (source)

   1  <?php
   2  //
   3  // Definition of eZDateOperatorCollection class
   4  //
   5  // Created on: <07-Feb-2003 09:39:55 bf>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  class eZDateOperatorCollection
  30  {
  31      /*!
  32       */
  33      function eZDateOperatorCollection( $monthName = 'month_overview' )
  34      {
  35          $this->MonthOverviewName = $monthName;
  36          $this->Operators = array( $monthName );
  37      }
  38  
  39      /*!
  40       Returns the operators in this class.
  41      */
  42      function &operatorList()
  43      {
  44          return $this->Operators;
  45      }
  46  
  47      /*!
  48       \return true to tell the template engine that the parameter list exists per operator type.
  49      */
  50      function namedParameterPerOperator()
  51      {
  52          return true;
  53      }
  54  
  55      /*!
  56       See eZTemplateOperator::namedParameterList()
  57      */
  58      function namedParameterList()
  59      {
  60          return array( 'month_overview' => array( 'field' => array( 'type' => 'string',
  61                                                                     'required' => true,
  62                                                                     'default' => false ),
  63                                                   'date' => array( 'type' => 'integer',
  64                                                                    'required' => true,
  65                                                                    'default' => false ),
  66                                                   'optional' => array( 'type' => 'array',
  67                                                                        'required' => false,
  68                                                                        'default' => false ) ) );
  69      }
  70  
  71      /*!
  72       \reimp
  73      */
  74      function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters )
  75      {
  76          $locale =& eZLocale::instance();
  77          if ( $operatorName == $this->MonthOverviewName )
  78          {
  79              $field = $namedParameters['field'];
  80              $date = $namedParameters['date'];
  81              if ( !$field )
  82                  return $tpl->missingParameter( $operatorName, 'field' );
  83              if ( !$date )
  84                  return $tpl->missingParameter( $operatorName, 'date' );
  85              $optional = $namedParameters['optional'];
  86              $dateInfo = getdate( $date );
  87              if ( is_array( $operatorValue ) )
  88              {
  89                  $month = array();
  90                  $month['year'] = $dateInfo['year'];
  91                  $month['month'] = $locale->longMonthName( $dateInfo['mon'] );
  92                  $weekDays = $locale->weekDays();
  93                  $weekDaysMap = array();
  94                  $i = 0;
  95                  $dayNames = array( 0 => 'sun', 1 => 'mon', 2 => 'tue',
  96                                     3 => 'wed', 4 => 'thu', 5 => 'fri', 6 => 'sat' );
  97                  foreach ( $weekDays as $weekDay )
  98                  {
  99                      $weekDaysMap[$weekDay] = $i;
 100                      $weekDayName = $locale->shortDayName( $weekDay );
 101                      $weekDayIdentifier = $dayNames[$weekDay];
 102                      $month['weekdays'][] = array( 'day' => $weekDayName,
 103                                                    'class' => $weekDayIdentifier );
 104                      ++$i;
 105                  }
 106                  $days = array();
 107                  $lastDay = getdate( mktime( 0, 0, 0, $dateInfo['mon']+1, 0, $dateInfo['year'] ) );
 108                  $lastDay = $lastDay['mday'];
 109                  for ( $day = 1; $day <= $lastDay; ++$day )
 110                  {
 111                      $days[$day] = false;
 112                  }
 113                  foreach ( array_keys( $operatorValue ) as $key )
 114                  {
 115                      $item =& $operatorValue[$key];
 116                      $value = null;
 117                      if ( is_object( $item ) and
 118                           method_exists( $item, 'hasattribute' ) and
 119                           method_exists( $item, 'attribute' ) )
 120                      {
 121                          if ( $item->hasAttribute( $field ) )
 122                              $value = $item->attribute( $field );
 123                      }
 124                      else if ( is_array( $item ) )
 125                      {
 126                          if ( array_key_exists( $field, $item ) )
 127                              $value = $item[$field];
 128                      }
 129                      if ( $value !== null )
 130                      {
 131                          $info = getdate( $value );
 132                          if ( $info['year'] == $dateInfo['year'] and
 133                               $info['mon'] == $dateInfo['mon'] )
 134                          {
 135                              $days[$info['mday']] = true;
 136                          }
 137                      }
 138                  }
 139                  $currentDay = false;
 140                  if ( isset( $optional['current'] ) and $optional['current'] !== false )
 141                  {
 142                      $info = getdate( $optional['current'] );
 143                      $currentDay = $info['yday'];
 144                  }
 145                  $today = mktime();
 146                  $todayInfo = getdate( $today );
 147                  $todayClass = false;
 148                  if ( isset( $optional['today_class'] ) )
 149                      $todayClass = $optional['today_class'];
 150                  $dayClass = false;
 151                  if ( isset( $optional['day_class'] ) )
 152                      $dayClass = $optional['day_class'];
 153                  $link = false;
 154                  if ( isset( $optional['link'] ) )
 155                      $link = $optional['link'];
 156                  $yearLinkParameter = false;
 157                  $monthLinkParameter = false;
 158                  $dayLinkParameter = false;
 159                  if ( isset( $optional['year_link'] ) )
 160                      $yearLinkParameter = $optional['year_link'];
 161                  if ( isset( $optional['month_link'] ) )
 162                      $monthLinkParameter = $optional['month_link'];
 163                  if ( isset( $optional['day_link'] ) )
 164                      $dayLinkParameter = $optional['day_link'];
 165                  $weeks = array();
 166                  $lastWeek = 0;
 167                  for ( $day = 1; $day <= $lastDay; ++$day )
 168                  {
 169                      $timestamp = mktime( 0, 0, 0, $dateInfo['mon'], $day, $dateInfo['year'] );
 170                      $info = getdate( $timestamp );
 171                      $weekDay = $weekDaysMap[$info['wday']];
 172  
 173                      /*
 174                       * Attention: date('W') returns the week number according to
 175                       * ISO, which states that the week with the first Thursday
 176                       * in the new year is week 1.
 177                       */
 178                      $week = date( 'W', $timestamp );
 179  
 180                      if ( $weekDay == 0 && $weekDaysMap[0] == 0 )
 181                      {
 182                          ++$week;
 183                      }
 184  
 185                      /*
 186                       * This checks for a year switch within a week. Routine
 187                       * takes care that first days in January might still belong
 188                       * to the last week of the old year (according to ISO week
 189                       * number), thus be part of week 52 or 53.
 190                       */
 191                      if ($week >= 52 || $week == 1)
 192                      {
 193                          // See if it's a new year by comparing the year of the previous week with the
 194                          // current one.
 195                          $timestampPrevWeek = mktime( 0, 0, 0, $dateInfo['mon'], $day-7, $dateInfo['year'] );
 196                          $isNewYear = date('Y', $timestampPrevWeek) < date('Y', $timestamp);
 197                          if ($isNewYear && $week != 1)
 198                          {
 199                              // A new year with the first week having last year's final week number (52 or 53),
 200                              // because the week's Thursday lies in the old year.
 201                              $week = $lastWeek;
 202                          }
 203                          else
 204                          {
 205                              // The last week of December having the week number 1, because
 206                              // the week's Thursday lies in the new year.
 207                              $week = $lastWeek;
 208                          }
 209                          if ($weekDay == 0)
 210                          {
 211                              ++$week;
 212                          }
 213                      }
 214  
 215                      $lastWeek = $week;
 216  
 217                      if ( !isset( $weeks[$week] ) )
 218                      {
 219                          for ( $i = 0; $i < 7; ++$i )
 220                          {
 221                              $weeks[$week][] = false;
 222                          }
 223                      }
 224                      $dayData = array( 'day' => $day,
 225                                        'link' => false,
 226                                        'class' => $dayClass,
 227                                        'highlight' => false );
 228                      if ( $currentDay == $info['yday'] )
 229                      {
 230                          if ( isset( $optional['current_class'] ) )
 231                              $dayData['class'] = $optional['current_class'];
 232                          $dayData['highlight'] = true;
 233                      }
 234                      if ( $dateInfo['year'] == $todayInfo['year'] and
 235                           $dateInfo['mon'] == $todayInfo['mon'] and
 236                           $day == $todayInfo['mday'] )
 237                      {
 238                          if ( $dayData['class'] )
 239                              $dayData['class'] .= '-' . $todayClass;
 240                          else
 241                              $dayData['class'] = $todayClass;
 242                      }
 243                      if ( $days[$day] )
 244                      {
 245                          $dayLink = $link;
 246                          if ( $dayLink )
 247                          {
 248                              $dayLink .= '/(year)/' . $info['year'];
 249                              $dayLink .= '/(month)/' . $info['mon'];
 250                              $dayLink .= '/(day)/' . $info['mday'];
 251                          }
 252                          $dayData['link'] = $dayLink;
 253                      }
 254                      $weeks[$week][$weekDay] = $dayData;
 255                  }
 256  
 257                  $next = false;
 258                  if ( isset( $optional['next'] ) )
 259                      $next = $optional['next'];
 260                  if ( $next )
 261                  {
 262                      $nextTimestamp = mktime( 0, 0, 0, $dateInfo['mon'] + 1, 1, $dateInfo['year'] );
 263                      $nextInfo = getdate( $nextTimestamp );
 264                      $month['next'] = array( 'month' => $locale->longMonthName( $nextInfo['mon'] ),
 265                                              'year' => $nextInfo['year'] );
 266                      $nextLink = $next['link'];
 267                      $nextLink .= '/(year)/' . $nextInfo['year'];
 268                      $nextLink .= '/(month)/' . $nextInfo['mon'];
 269                      $month['next']['link'] = $nextLink;
 270                  }
 271                  else
 272                      $month['next'] = false;
 273  
 274                  $month['current'] = array( 'month' => $locale->longMonthName( $info['mon'] ),
 275                                             'year' => $info['year'] );
 276                  $currentLink = $next['link'];
 277                  $currentLink .= '/(year)/' . $info['year'];
 278                  $currentLink .= '/(month)/' . $info['mon'];
 279                  $month['current']['link'] = $currentLink;
 280  
 281                  $previous = false;
 282                  if ( isset( $optional['previous'] ) )
 283                  {
 284                      $previous = $optional['previous'];
 285                  }
 286                  if ( $previous )
 287                  {
 288                      $previousTimestamp = mktime( 0, 0, 0, $dateInfo['mon'] - 1, 1, $dateInfo['year'] );
 289                      $previousInfo = getdate( $previousTimestamp );
 290                      $month['previous'] = array( 'month' => $locale->longMonthName( $previousInfo['mon'] ),
 291                                                  'year' => $previousInfo['year'] );
 292                      $previousLink = $previous['link'];
 293                      $previousLink .= '/(year)/' . $previousInfo['year'];
 294                      $previousLink .= '/(month)/' . $previousInfo['mon'];
 295                      $month['previous']['link'] = $previousLink;
 296                  }
 297                  else
 298                  {
 299                      $month['previous'] = false;
 300                  }
 301                  $month['weeks'] = $weeks;
 302                  $operatorValue = $month;
 303              }
 304          }
 305      }
 306  
 307      /// \privatesection
 308      var $Operators;
 309  };
 310  
 311  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7