[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

/kernel/classes/datatypes/ezrangeoption/ -> ezrangeoption.php (source)

   1  <?php
   2  //
   3  // Definition of eZRangeOption class
   4  //
   5  // Created on: <17-æÅ×-2003 16:17:18 sp>
   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  /*! \file ezrangeoption.php
  30  */
  31  
  32  /*!
  33    \class eZRangeOption ezrangeoption.php
  34    \ingroup eZDatatype
  35    \brief The class eZRangeOption does
  36  
  37  */
  38  
  39  class eZRangeOption
  40  {
  41      /*!
  42       Constructor
  43      */
  44      function eZRangeOption( $name )
  45      {
  46          $this->Name = $name;
  47          $this->Options = array();
  48          $this->OptionCount = 0;
  49      }
  50  
  51      /*!
  52       Sets the name of the option
  53      */
  54      function setName( $name )
  55      {
  56          $this->Name = $name;
  57      }
  58  
  59      /*!
  60       Returns the name of the option set.
  61      */
  62      function &name()
  63      {
  64          return $this->Name;
  65      }
  66  
  67      /*!
  68       \return list of supported attributes
  69      */
  70      function attributes()
  71      {
  72          return array( 'name',
  73                        'start_value',
  74                        'stop_value',
  75                        'step_value',
  76                        'option_list' );
  77      }
  78  
  79      function hasAttribute( $name )
  80      {
  81          return in_array( $name, $this->attributes() );
  82      }
  83  
  84      function &attribute( $name )
  85      {
  86          switch ( $name )
  87          {
  88              case "name" :
  89              {
  90                  return $this->Name;
  91              }break;
  92              case "start_value" :
  93              {
  94                  return $this->StartValue;
  95              }break;
  96              case "stop_value" :
  97              {
  98                  return $this->StopValue;
  99              }break;
 100              case "step_value" :
 101              {
 102                  return $this->StepValue;
 103              }break;
 104              case "option_list" :
 105              {
 106                  return $this->Options;
 107              }break;
 108              default:
 109              {
 110                  eZDebug::writeError( "Attribute '$name' does not exist", 'eZRangeOption::attribute' );
 111                  $retValue = null;
 112                  return $retValue;
 113              }break;
 114          }
 115      }
 116  
 117      function addOption( $valueArray )
 118      {
 119          $this->Options[] = array( "id" => $this->OptionCount,
 120                                    "value" => $valueArray['value'],
 121                                    'additional_price' => 0,
 122                                    "is_default" => false );
 123  
 124          $this->OptionCount += 1;
 125      }
 126  
 127      function decodeXML( $xmlString )
 128      {
 129          include_once ( 'lib/ezxml/classes/ezxml.php' );
 130  
 131          $xml = new eZXML();
 132  
 133  
 134          $dom =& $xml->domTree( $xmlString );
 135  
 136          if ( $xmlString != "" )
 137          {
 138              // set the name of the node
 139              $rangeOptionElement =& $dom->root( );
 140  //            $rangeOptionElement =& $rangeoptionElements[0];
 141              $startValue = $rangeOptionElement->attributeValue( 'start_value' );
 142              $stopValue = $rangeOptionElement->attributeValue( 'stop_value' );
 143              $stepValue = $rangeOptionElement->attributeValue( 'step_value' );
 144              if ( $stepValue == 0 )
 145                  $stepValue = 1;
 146              $this->StartValue = $startValue;
 147              $this->StopValue = $stopValue;
 148              $this->StepValue = $stepValue;
 149  
 150  
 151              $nameArray =& $dom->elementsByName( "name" );
 152              $this->setName( $nameArray[0]->textContent() );
 153  
 154              for ( $i=$startValue;$i<=$stopValue;$i+=$stepValue )
 155              {
 156                  $this->addOption( array( 'value' => $i,
 157                                           'additional_price' => 0 ) );
 158              }
 159          }
 160          else
 161          {
 162              $this->StartValue = 0;
 163              $this->StopValue = 0;
 164              $this->StepValue = 0;
 165          }
 166      }
 167  
 168      /*!
 169       Will return the XML string for this option set.
 170      */
 171      function &xmlString( )
 172      {
 173          include_once ( 'lib/ezxml/classes/ezdomdocument.php' );
 174  
 175          $doc = new eZDOMDocument( "Option" );
 176  
 177          $root = $doc->createElementNode( "ezrangeoption" );
 178          $root->appendAttribute( $doc->createAttributeNode( "start_value", $this->StartValue ) );
 179          $root->appendAttribute( $doc->createAttributeNode( "stop_value", $this->StopValue ) );
 180          $root->appendAttribute( $doc->createAttributeNode( "step_value", $this->StepValue ) );
 181          $doc->setRoot( $root );
 182  
 183          $name = $doc->createElementNode( "name" );
 184          $nameValue = $doc->createTextNode( $this->Name );
 185          $name->appendChild( $nameValue );
 186  
 187          $name->setContent( $this->Name() );
 188  
 189          $root->appendChild( $name );
 190  
 191          $xml = $doc->toString();
 192  
 193          return $xml;
 194      }
 195  
 196      function setStartValue( $value )
 197      {
 198          $this->StartValue = $value;
 199      }
 200  
 201      function setStopValue( $value )
 202      {
 203          $this->StopValue = $value;
 204      }
 205  
 206      function setStepValue( $value )
 207      {
 208          $this->StepValue = $value;
 209      }
 210  
 211  
 212          /// Contains the Option name
 213      var $Name;
 214  
 215      /// Contains the Options
 216      var $Options;
 217  
 218      /// Contains the option counter value
 219      var $OptionCount;
 220      var $StartValue;
 221      var $StopValue;
 222      var $StepValue;
 223  }
 224  
 225  ?>


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