eZ Publish  [4.0]
ezrandomtranslator.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZRandomTranslator class
00004 //
00005 // Created on: <10-Jun-2002 11:05:00 amos>
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 eztranslatorgroup.php
00032 */
00033 
00034 /*!
00035   \class eZRandomTranslator eztranslatorgroup.php
00036   \ingroup eZTranslation
00037   \brief Translates text by picking randomly among it's sub handlers
00038 
00039 */
00040 
00041 //include_once( "lib/ezi18n/classes/eztranslatorgroup.php" );
00042 
00043 class eZRandomTranslator extends eZTranslatorGroup
00044 {
00045     /*!
00046      Constructor
00047     */
00048     function eZRandomTranslator( $is_key_based )
00049     {
00050         $this->eZTranslatorGroup( $is_key_based );
00051         srand( $this->makeSeed() );
00052     }
00053 
00054     /*!
00055      \reimp
00056      Returns a random pick from the registered handlers.
00057     */
00058     function keyPick( $key )
00059     {
00060         if ( $this->handlerCount() == 0 )
00061             return -1;
00062         return rand( 0, $this->handlerCount() - 1 );
00063     }
00064 
00065     /*!
00066      \reimp
00067      Returns a random pick from the registered handlers.
00068     */
00069     function pick( $context, $source, $comment )
00070     {
00071         if ( $this->handlerCount() == 0 )
00072             return -1;
00073         return rand( 0, $this->handlerCount() - 1 );
00074     }
00075 
00076     /*!
00077      \private
00078      Generates a seed usable for srand() and returns it.
00079     */
00080     function makeSeed()
00081     {
00082         $seed = microtime( true ) * 100000;
00083         return $seed;
00084     }
00085 }
00086 
00087 ?>