oxlist.php

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         foreach ( $this->_aArray as $key => $sValue) {
00188             unset( $this->_aArray[$key]);
00189         }
00190         reset( $this->_aArray);*/
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 
00246     protected $_aAssignCallbackPrepend  = null;
00247 
00253     protected $_aAssignCallback = null;
00254 
00258     protected $_aSqlLimit = array();
00259 
00265     public function __construct( $sObjectName = null )
00266     {
00267         $myConfig = $this->getConfig();
00268         $this->_aSqlLimit[0] = 0;
00269         $this->_aSqlLimit[1] = 0;
00270         $this->_sShopID   = $myConfig->getShopId();
00271 
00272         if ( $sObjectName ) {
00273             $this->init( $sObjectName );
00274         }
00275     }
00276 
00284     public function __get( $sName)
00285     {
00286         //throw new Exception( 'oxList Access to undefined variable '. $sName);
00287         //echo( "Access to ".$sName.PHP_EOL);
00288 
00289         // TMP
00290         if ( $sName == 'aList') {
00291             return $this->_aArray;
00292         }
00293     }
00294 
00300     public function getArray()
00301     {
00302         return $this->_aArray;
00303     }
00304 
00313     public function init($sObjectName, $sCoreTable = null)
00314     {
00315         $this->_sObjectsInListName = $sObjectName;
00316         if ($sCoreTable) {
00317             $this->_sCoreTable = $sCoreTable;
00318         }
00319     }
00320 
00328     public function setAssignCallbackPrepend($aAssignCallbackPrepend)
00329     {
00330         $this->_aAssignCallbackPrepend = $aAssignCallbackPrepend;
00331     }
00332 
00340     public function setAssignCallback( $aAssignCallBack)
00341     {
00342         $this->_aAssignCallback = $aAssignCallBack;
00343     }
00344 
00350     public function getBaseObject()
00351     {
00352         if ( !$this->_oBaseObject ) {
00353             $this->_oBaseObject = oxNew( $this->_sObjectsInListName );
00354             $this->_oBaseObject->setInList();
00355             $this->_oBaseObject->init( $this->_sCoreTable );
00356         }
00357 
00358         return $this->_oBaseObject;
00359     }
00360 
00368     public function selectString( $sSql)
00369     {
00370         //echo $sSql."<br><br>\n"; // DONT COMMIT
00371 
00372         $this->clear();
00373 
00374         if ( $this->_aSqlLimit[0] || $this->_aSqlLimit[1]) {
00375             $rs = oxDb::getDb(true)->SelectLimit( $sSql, $this->_aSqlLimit[1], $this->_aSqlLimit[0]);
00376         } else {
00377             $rs = oxDb::getDb(true)->Execute( $sSql);
00378         }
00379 
00380         //$blFirstLoop = true;
00381         $oListObject = $this->getBaseObject();
00382         $oSaved = oxNew( $this->_sObjectsInListName);
00383         $oSaved->setInList();
00384         $oSaved->init( $oListObject->getCoreTableName() );
00385 
00386         if ( $oSaved->isMultilang() ) {
00387             $oSaved->setLanguage( $oListObject->getLanguage() );
00388         }
00389 
00390         if ( $this->_aAssignCallbackPrepend && is_callable($this->_aAssignCallbackPrepend)) {
00391             call_user_func( $this->_aAssignCallbackPrepend, $oSaved);
00392         }
00393 
00394         if ($rs != false && $rs->recordCount() > 0) {
00395             while (!$rs->EOF) {
00396 
00397                 $oListObject = clone $oSaved;
00398 
00399                 $this->_assignElement($oListObject, $rs->fields);
00400                 //$oListObject->assign( $rs->fields);
00401 
00402                 if ( $this->_aAssignCallback ) {
00403                     call_user_func( $this->_aAssignCallback, $oListObject );
00404                 }
00405 
00406                 if ($oListObject->getId()) {
00407                     $this->_aArray[$oListObject->getId()] = $oListObject;
00408                 } else {
00409                     $this->_aArray[] = $oListObject;
00410                 }
00411 
00412                 $rs->moveNext();
00413             }
00414         }
00415     }
00416 
00425     public function setSqlLimit( $iStart, $iRecords)
00426     {
00427         $this->_aSqlLimit[0] = $iStart;
00428         $this->_aSqlLimit[1] = $iRecords;
00429     }
00430 
00439     public function containsFieldValue($oVal, $sFieldName)
00440     {
00441         $sFieldName = $this->_getFieldLongName($sFieldName);
00442         foreach ($this->_aArray as $obj) {
00443             if ($obj->{$sFieldName}->value == $oVal) {
00444                 return true;
00445             }
00446         }
00447 
00448         return false;
00449     }
00450 
00456     public function getList()
00457     {
00458         $oListObject =$this->getBaseObject();
00459         $sFieldList = $oListObject->getSelectFields();
00460         $sQ = "select $sFieldList from " . $oListObject->getViewName();
00461         if ( $sActiveSnippet = $oListObject->getSqlActiveSnippet() ) {
00462             $sQ .= " where $sActiveSnippet ";
00463         }
00464         $this->selectString($sQ);
00465 
00466         return $this;
00467     }
00468 
00478     protected function _assignElement($oListObject, $aDbFields)
00479     {
00480         $oListObject->assign($aDbFields);
00481     }
00482 
00490     protected function _getFieldLongName($sFieldName)
00491     {
00492         if ($this->_sCoreTable) {
00493             return $this->_sCoreTable . '__' . $sFieldName;
00494         }
00495 
00496         return $sFieldName;
00497     }
00498 
00499 }

Generated on Wed May 13 13:25:51 2009 for OXID eShop CE by  doxygen 1.5.5