oxselectlist.php

Go to the documentation of this file.
00001 <?php
00002 
00005 class oxSelectlist extends oxI18n implements oxISelectList
00006 {
00011     protected $_aFieldList = null;
00012 
00017     protected $_sClassName = 'oxselectlist';
00018 
00024     protected $_aList = null;
00025 
00030     protected $_dVat = null;
00031 
00036     protected $_oActiveSelection = null;
00037 
00046     public function __construct( $sObjectsInListName = 'oxselectlist')
00047     {
00048         parent::__construct();
00049         $this->init( 'oxselectlist' );
00050     }
00051 
00059     public function getFieldList( $dVat = null )
00060     {
00061         if ( $this->_aFieldList == null && $this->oxselectlist__oxvaldesc->value ) {
00062             $this->_aFieldList = oxUtils::getInstance()->assignValuesFromText( $this->oxselectlist__oxvaldesc->value, $dVat );
00063             foreach ( $this->_aFieldList as $sKey => $oField ) {
00064                 $this->_aFieldList[$sKey]->name = strip_tags( $this->_aFieldList[$sKey]->name );
00065             }
00066         }
00067         return $this->_aFieldList;
00068     }
00069 
00077     public function delete( $sOXID = null )
00078     {
00079         if ( !$sOXID ) {
00080             $sOXID = $this->getId();
00081         }
00082         if ( !$sOXID ) {
00083             return false;
00084         }
00085 
00086         // remove selectlists from articles also
00087         if ( $blRemove = parent::delete( $sOXID ) ) {
00088             $oDb = oxDb::getDb();
00089             $oDb->execute( "delete from oxobject2selectlist where oxselnid = " . $oDb->quote( $sOXID ) . " " );
00090         }
00091 
00092         return $blRemove;
00093     }
00094 
00102     public function setVat( $dVat )
00103     {
00104         $this->_dVat = $dVat;
00105     }
00106 
00112     public function getVat()
00113     {
00114         return $this->_dVat;
00115     }
00116 
00122     public function getLabel()
00123     {
00124         return $this->oxselectlist__oxtitle->value;
00125     }
00126 
00132     public function getSelections()
00133     {
00134         if ( $this->_aList === null && $this->oxselectlist__oxvaldesc->value ) {
00135             $this->_aList = false;
00136             $aList = oxUtils::getInstance()->assignValuesFromText( $this->oxselectlist__oxvaldesc->value, $this->getVat() );
00137             foreach ( $aList as $sKey => $oField ) {
00138                 if ( $oField->name ) {
00139                    $this->_aList[$sKey] = oxNew( "oxSelection", getStr()->htmlspecialchars( strip_tags( $oField->name ) ), $sKey, false, $this->_aList === false ? true : false );
00140                 }
00141             }
00142         }
00143         return $this->_aList;
00144     }
00145 
00151     public function getActiveSelection()
00152     {
00153         if ( $this->_oActiveSelection === null ) {
00154             if ( ( $aSelections = $this->getSelections() ) ) {
00155                 // first is allways active
00156                 $this->_oActiveSelection = reset( $aSelections );
00157             }
00158         }
00159 
00160         return $this->_oActiveSelection;
00161     }
00162 
00170     public function setActiveSelectionByIndex( $iIdx )
00171     {
00172         if ( ( $aSelections = $this->getSelections() ) ) {
00173             $iSelIdx = 0;
00174             foreach ( $aSelections as $oSelection ) {
00175                 $oSelection->setActiveState( $iSelIdx == $iIdx );
00176                 if ( $iSelIdx == $iIdx ) {
00177                     $this->_oActiveSelection = $oSelection;
00178                 }
00179                 $iSelIdx++;
00180             }
00181         }
00182     }
00183 }