Go to the documentation of this file.00001 <?php
00002
00007 class oxList extends oxSuperCfg implements ArrayAccess, Iterator, Countable
00008 {
00014 protected $_aArray = array();
00015
00021 private $_oBaseObject = null;
00022
00028 private $_blValid = true;
00029
00048 public function offsetExists( $offset )
00049 {
00050 if ( isset( $this->_aArray[$offset] ) ) {
00051 return true;
00052 } else {
00053 return false;
00054 }
00055 }
00056
00064 public function offsetGet( $offset )
00065 {
00066 if ( $this->offsetExists( $offset ) ) {
00067 return $this->_aArray[$offset];
00068 } else {
00069 return false;
00070 }
00071 }
00072
00081 public function offsetSet( $offset, $oBase )
00082 {
00083 if ( isset( $offset ) ) {
00084 $this->_aArray[$offset] = & $oBase;
00085 } else {
00086 $sLongFieldName = $this->_getFieldLongName( 'oxid' );
00087 if ( isset( $oBase->$sLongFieldName->value ) ) {
00088 $sOxid = $oBase->$sLongFieldName->value;
00089 $this->_aArray[$sOxid] = & $oBase;
00090 } else {
00091 $this->_aArray[] = & $oBase;
00092 }
00093 }
00094
00095 }
00096
00104 public function offsetUnset( $offset )
00105 {
00106 unset( $this->_aArray[$offset] );
00107 }
00108
00114 public function arrayKeys()
00115 {
00116 return array_keys( $this->_aArray );
00117 }
00118
00124 public function rewind()
00125 {
00126 $this->_blValid = ( false !== reset( $this->_aArray ) );
00127 }
00128
00134 public function current()
00135 {
00136 return current( $this->_aArray );
00137 }
00138
00144 public function key()
00145 {
00146 return key( $this->_aArray );
00147 }
00148
00154 public function next()
00155 {
00156 $this->_blValid = ( false !== next( $this->_aArray ) );
00157 }
00158
00164 public function valid()
00165 {
00166 return $this->_blValid;
00167 }
00168
00174 public function count()
00175 {
00176 return count( $this->_aArray );
00177 }
00178
00184 public function clear()
00185 {
00186
00187
00188
00189
00190
00191 $this->_aArray = array();
00192 }
00193
00201 public function assign( $aArray )
00202 {
00203 $this->_aArray = $aArray;
00204 }
00205
00211 public function reverse()
00212 {
00213 return array_reverse( $this->_aArray );
00214 }
00215
00227 protected $_sObjectsInListName = 'oxBase';
00228
00234 protected $_sCoreTable = null;
00235
00239 protected $_sShopID = null;
00240
00244 protected $_aSqlLimit = array();
00245
00251 public function __construct( $sObjectName = null )
00252 {
00253 $myConfig = $this->getConfig();
00254 $this->_aSqlLimit[0] = 0;
00255 $this->_aSqlLimit[1] = 0;
00256 $this->_sShopID = $myConfig->getShopId();
00257
00258 if ( $sObjectName ) {
00259 $this->init( $sObjectName );
00260 }
00261 }
00262
00270 public function __get( $sName)
00271 {
00272
00273
00274
00275
00276 if ( $sName == 'aList') {
00277 return $this->_aArray;
00278 }
00279 }
00280
00286 public function getArray()
00287 {
00288 return $this->_aArray;
00289 }
00290
00299 public function init($sObjectName, $sCoreTable = null)
00300 {
00301 $this->_sObjectsInListName = $sObjectName;
00302 if ($sCoreTable) {
00303 $this->_sCoreTable = $sCoreTable;
00304 }
00305 }
00306
00312 public function getBaseObject()
00313 {
00314 if ( !$this->_oBaseObject ) {
00315 $this->_oBaseObject = oxNew( $this->_sObjectsInListName );
00316 $this->_oBaseObject->setInList();
00317 $this->_oBaseObject->init( $this->_sCoreTable );
00318 }
00319
00320 return $this->_oBaseObject;
00321 }
00322
00330 public function selectString( $sSql)
00331 {
00332 $this->clear();
00333
00334 if ( $this->_aSqlLimit[0] || $this->_aSqlLimit[1]) {
00335 $rs = oxDb::getDb(true)->SelectLimit( $sSql, $this->_aSqlLimit[1], $this->_aSqlLimit[0]);
00336 } else {
00337 $rs = oxDb::getDb(true)->Execute( $sSql);
00338 }
00339
00340 if ($rs != false && $rs->recordCount() > 0) {
00341
00342 $oSaved = clone $this->getBaseObject();
00343
00344 while (!$rs->EOF) {
00345
00346 $oListObject = clone $oSaved;
00347
00348 $this->_assignElement($oListObject, $rs->fields);
00349
00350 if ($oListObject->getId()) {
00351 $this->_aArray[$oListObject->getId()] = $oListObject;
00352 } else {
00353 $this->_aArray[] = $oListObject;
00354 }
00355
00356 $rs->moveNext();
00357 }
00358 }
00359 }
00360
00369 public function setSqlLimit( $iStart, $iRecords)
00370 {
00371 $this->_aSqlLimit[0] = $iStart;
00372 $this->_aSqlLimit[1] = $iRecords;
00373 }
00374
00383 public function containsFieldValue($oVal, $sFieldName)
00384 {
00385 $sFieldName = $this->_getFieldLongName($sFieldName);
00386 foreach ($this->_aArray as $obj) {
00387 if ($obj->{$sFieldName}->value == $oVal) {
00388 return true;
00389 }
00390 }
00391
00392 return false;
00393 }
00394
00400 public function getList()
00401 {
00402 $oListObject =$this->getBaseObject();
00403 $sFieldList = $oListObject->getSelectFields();
00404 $sQ = "select $sFieldList from " . $oListObject->getViewName();
00405 if ( $sActiveSnippet = $oListObject->getSqlActiveSnippet() ) {
00406 $sQ .= " where $sActiveSnippet ";
00407 }
00408 $this->selectString($sQ);
00409
00410 return $this;
00411 }
00412
00422 protected function _assignElement($oListObject, $aDbFields)
00423 {
00424 $oListObject->assign($aDbFields);
00425 }
00426
00434 protected function _getFieldLongName($sFieldName)
00435 {
00436 if ($this->_sCoreTable) {
00437 return $this->_sCoreTable . '__' . $sFieldName;
00438 }
00439
00440 return $sFieldName;
00441 }
00442
00443 }