eZ Publish  [4.0]
eznotificationschedule.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZNotificationSchedule class
00004 //
00005 // Created on: <16-May-2003 15:22:43 sp>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*! \file eznotificationschedule.php
00032 */
00033 
00034 /*!
00035   \class eZNotificationSchedule eznotificationschedule.php
00036   \brief The class eZNotificationSchedule does
00037 
00038 */
00039 //include_once( "lib/ezlocale/classes/ezdate.php" );
00040 
00041 
00042 class eZNotificationSchedule
00043 {
00044     /*!
00045      Constructor
00046     */
00047     function eZNotificationSchedule()
00048     {
00049     }
00050 
00051     function setDateForItem( $item, $settings )
00052     {
00053         if ( !is_array( $settings ) )
00054             return false;
00055 
00056         $dayNum = isset( $settings['day'] ) ? $settings['day'] : false;
00057         $hour = $settings['hour'];
00058         $currentDate = getdate();
00059         $hoursDiff = $hour - $currentDate['hours'];
00060 
00061         switch ( $settings['frequency'] )
00062         {
00063             case 'day':
00064             {
00065                 if ( $hoursDiff <= 0 )
00066                 {
00067                     $hoursDiff += 24;
00068                 }
00069 
00070                 $secondsDiff = 3600 * $hoursDiff
00071                      - $currentDate['seconds']
00072                      - 60 * $currentDate['minutes'];
00073             } break;
00074 
00075             case 'week':
00076             {
00077                 $daysDiff = $dayNum - $currentDate['wday'];
00078                 if ( $daysDiff < 0 or
00079                      ( $daysDiff == 0 and $hoursDiff <= 0 ) )
00080                 {
00081                     $daysDiff += 7;
00082                 }
00083 
00084                 $secondsDiff = 3600 * ( $daysDiff * 24 + $hoursDiff )
00085                      - $currentDate['seconds']
00086                      - 60 * $currentDate['minutes'];
00087             } break;
00088 
00089             case 'month':
00090             {
00091                 // If the daynum the user has chosen is larger than the number of days in this month,
00092                 // then reduce it to the number of days in this month.
00093                 $daysInMonth = intval( date( 't', mktime( 0, 0, 0, $currentDate['mon'], 1, $currentDate['year'] ) ) );
00094                 if ( $dayNum > $daysInMonth )
00095                 {
00096                     $dayNum = $daysInMonth;
00097                 }
00098 
00099                 $daysDiff = $dayNum - $currentDate['mday'];
00100                 if ( $daysDiff < 0 or
00101                      ( $daysDiff == 0 and $hoursDiff <= 0 ) )
00102                 {
00103                     $daysDiff += $daysInMonth;
00104                 }
00105 
00106                 $secondsDiff = 3600 * ( $daysDiff * 24 + $hoursDiff )
00107                      - $currentDate['seconds']
00108                      - 60 * $currentDate['minutes'];
00109             } break;
00110         }
00111 
00112         $sendDate = time() + $secondsDiff;
00113         eZDebugSetting::writeDebug( 'kernel-notification', getdate( $sendDate ), "item date"  );
00114         $item->setAttribute( 'send_date', $sendDate );
00115         return $sendDate;
00116     }
00117 }
00118 
00119 ?>