OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
oxselectlist.php
Go to the documentation of this file.
1 <?php
2 
7 class oxSelectlist extends oxI18n implements oxISelectList
8 {
13  protected $_aFieldList = null;
14 
19  protected $_sClassName = 'oxselectlist';
20 
26  protected $_aList = null;
27 
32  protected $_dVat = null;
33 
38  protected $_oActiveSelection = null;
39 
48  public function __construct( $sObjectsInListName = 'oxselectlist')
49  {
51  $this->init( 'oxselectlist' );
52  }
53 
61  public function getFieldList( $dVat = null )
62  {
63  if ( $this->_aFieldList == null && $this->oxselectlist__oxvaldesc->value ) {
64  $this->_aFieldList = oxRegistry::getUtils()->assignValuesFromText( $this->oxselectlist__oxvaldesc->value, $dVat );
65  foreach ( $this->_aFieldList as $sKey => $oField ) {
66  $this->_aFieldList[$sKey]->name = getStr()->strip_tags( $this->_aFieldList[$sKey]->name );
67  }
68  }
69  return $this->_aFieldList;
70  }
71 
79  public function delete( $sOXID = null )
80  {
81  if ( !$sOXID ) {
82  $sOXID = $this->getId();
83  }
84  if ( !$sOXID ) {
85  return false;
86  }
87 
88  // remove selectlists from articles also
89  if ( $blRemove = parent::delete( $sOXID ) ) {
90  $oDb = oxDb::getDb();
91  $oDb->execute( "delete from oxobject2selectlist where oxselnid = " . $oDb->quote( $sOXID ) . " " );
92  }
93 
94  return $blRemove;
95  }
96 
104  public function setVat( $dVat )
105  {
106  $this->_dVat = $dVat;
107  }
108 
114  public function getVat()
115  {
116  return $this->_dVat;
117  }
118 
124  public function getLabel()
125  {
126  return $this->oxselectlist__oxtitle->value;
127  }
128 
134  public function getSelections()
135  {
136  if ( $this->_aList === null && $this->oxselectlist__oxvaldesc->value ) {
137  $this->_aList = false;
138  $aList = oxRegistry::getUtils()->assignValuesFromText( $this->oxselectlist__oxvaldesc->getRawValue(), $this->getVat() );
139  foreach ( $aList as $sKey => $oField ) {
140  if ( $oField->name ) {
141  $this->_aList[$sKey] = oxNew( "oxSelection", getStr()->strip_tags( $oField->name ), $sKey, false, $this->_aList === false ? true : false );
142  }
143  }
144  }
145  return $this->_aList;
146  }
147 
153  public function getActiveSelection()
154  {
155  if ( $this->_oActiveSelection === null ) {
156  if ( ( $aSelections = $this->getSelections() ) ) {
157  // first is allways active
158  $this->_oActiveSelection = reset( $aSelections );
159  }
160  }
161 
163  }
164 
172  public function setActiveSelectionByIndex( $iIdx )
173  {
174  if ( ( $aSelections = $this->getSelections() ) ) {
175  $iSelIdx = 0;
176  foreach ( $aSelections as $oSelection ) {
177  $oSelection->setActiveState( $iSelIdx == $iIdx );
178  if ( $iSelIdx == $iIdx ) {
179  $this->_oActiveSelection = $oSelection;
180  }
181  $iSelIdx++;
182  }
183  }
184  }
185 
186 
187 
188 
189 }