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
00248 protected $_aAssignCallbackPrepend = null;
00249
00257 protected $_aAssignCallback = null;
00258
00262 protected $_aSqlLimit = array();
00263
00269 public function __construct( $sObjectName = null )
00270 {
00271 $myConfig = $this->getConfig();
00272 $this->_aSqlLimit[0] = 0;
00273 $this->_aSqlLimit[1] = 0;
00274 $this->_sShopID = $myConfig->getShopId();
00275
00276 if ( $sObjectName ) {
00277 $this->init( $sObjectName );
00278 }
00279 }
00280
00288 public function __get( $sName)
00289 {
00290
00291
00292
00293
00294 if ( $sName == 'aList') {
00295 return $this->_aArray;
00296 }
00297 }
00298
00304 public function getArray()
00305 {
00306 return $this->_aArray;
00307 }
00308
00317 public function init($sObjectName, $sCoreTable = null)
00318 {
00319 $this->_sObjectsInListName = $sObjectName;
00320 if ($sCoreTable) {
00321 $this->_sCoreTable = $sCoreTable;
00322 }
00323 }
00324
00334 public function setAssignCallbackPrepend($aAssignCallbackPrepend)
00335 {
00336 $this->_aAssignCallbackPrepend = $aAssignCallbackPrepend;
00337 }
00338
00348 public function setAssignCallback( $aAssignCallBack)
00349 {
00350 $this->_aAssignCallback = $aAssignCallBack;
00351 }
00352
00358 public function getBaseObject()
00359 {
00360 if ( !$this->_oBaseObject ) {
00361 $this->_oBaseObject = oxNew( $this->_sObjectsInListName );
00362 $this->_oBaseObject->setInList();
00363 $this->_oBaseObject->init( $this->_sCoreTable );
00364 }
00365
00366 return $this->_oBaseObject;
00367 }
00368
00376 public function selectString( $sSql)
00377 {
00378 $this->clear();
00379
00380 if ( $this->_aSqlLimit[0] || $this->_aSqlLimit[1]) {
00381 $rs = oxDb::getDb(true)->SelectLimit( $sSql, $this->_aSqlLimit[1], $this->_aSqlLimit[0]);
00382 } else {
00383 $rs = oxDb::getDb(true)->Execute( $sSql);
00384 }
00385
00386 if ($rs != false && $rs->recordCount() > 0) {
00387
00388 $oSaved = clone $this->getBaseObject();
00389
00390
00391 if ( $this->_aAssignCallbackPrepend && is_callable($this->_aAssignCallbackPrepend)) {
00392 call_user_func( $this->_aAssignCallbackPrepend, $oSaved);
00393 }
00394
00395
00396 while (!$rs->EOF) {
00397
00398 $oListObject = clone $oSaved;
00399
00400 $this->_assignElement($oListObject, $rs->fields);
00401
00402
00403 if ( $this->_aAssignCallback ) {
00404 call_user_func( $this->_aAssignCallback, $oListObject );
00405 }
00406
00407
00408 if ($oListObject->getId()) {
00409 $this->_aArray[$oListObject->getId()] = $oListObject;
00410 } else {
00411 $this->_aArray[] = $oListObject;
00412 }
00413
00414 $rs->moveNext();
00415 }
00416 }
00417 }
00418
00427 public function setSqlLimit( $iStart, $iRecords)
00428 {
00429 $this->_aSqlLimit[0] = $iStart;
00430 $this->_aSqlLimit[1] = $iRecords;
00431 }
00432
00441 public function containsFieldValue($oVal, $sFieldName)
00442 {
00443 $sFieldName = $this->_getFieldLongName($sFieldName);
00444 foreach ($this->_aArray as $obj) {
00445 if ($obj->{$sFieldName}->value == $oVal) {
00446 return true;
00447 }
00448 }
00449
00450 return false;
00451 }
00452
00458 public function getList()
00459 {
00460 $oListObject =$this->getBaseObject();
00461 $sFieldList = $oListObject->getSelectFields();
00462 $sQ = "select $sFieldList from " . $oListObject->getViewName();
00463 if ( $sActiveSnippet = $oListObject->getSqlActiveSnippet() ) {
00464 $sQ .= " where $sActiveSnippet ";
00465 }
00466 $this->selectString($sQ);
00467
00468 return $this;
00469 }
00470
00480 protected function _assignElement($oListObject, $aDbFields)
00481 {
00482 $oListObject->assign($aDbFields);
00483 }
00484
00492 protected function _getFieldLongName($sFieldName)
00493 {
00494 if ($this->_sCoreTable) {
00495 return $this->_sCoreTable . '__' . $sFieldName;
00496 }
00497
00498 return $sFieldName;
00499 }
00500
00501 }