oxattributelist.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class oxAttributeList extends oxList
00007 {
00015     public function __construct( $sObjectsInListName = 'oxattribute')
00016     {
00017         parent::__construct( 'oxattribute');
00018     }
00019 
00027     public function loadAttributesByIds( $aIds )
00028     {
00029         if (!count($aIds)) {
00030             return;
00031         }
00032 
00033         foreach ($aIds as $iKey => $sVal) {
00034             $aIds[$iKey] = oxDb::getInstance()->escapeString($sVal);
00035         }
00036 
00037         $sAttrViewName = getViewName( 'oxattribute' );
00038         $sViewName     = getViewName( 'oxobject2attribute' );
00039 
00040         $sSelect  = "select $sAttrViewName.oxid, $sAttrViewName.oxtitle, {$sViewName}.oxvalue, {$sViewName}.oxobjectid ";
00041         $sSelect .= "from {$sViewName} left join $sAttrViewName on $sAttrViewName.oxid = {$sViewName}.oxattrid ";
00042         $sSelect .= "where {$sViewName}.oxobjectid in ( '".implode("','", $aIds)."' ) ";
00043         $sSelect .= "order by {$sViewName}.oxpos, $sAttrViewName.oxpos";
00044 
00045         return $this->_createAttributeListFromSql( $sSelect);
00046     }
00047 
00055     protected function _createAttributeListFromSql( $sSelect )
00056     {
00057         $aAttributes = array();
00058         $rs = oxDb::getDb()->select( $sSelect );
00059         if ($rs != false && $rs->recordCount() > 0) {
00060             while (!$rs->EOF) {
00061                 if ( !isset( $aAttributes[$rs->fields[0]])) {
00062                     $aAttributes[$rs->fields[0]] = new stdClass();
00063                 }
00064 
00065                 $aAttributes[$rs->fields[0]]->title = $rs->fields[1];
00066                 if ( !isset( $aAttributes[$rs->fields[0]]->aProd[$rs->fields[3]])) {
00067                     $aAttributes[$rs->fields[0]]->aProd[$rs->fields[3]] = new stdClass();
00068                 }
00069                 $aAttributes[$rs->fields[0]]->aProd[$rs->fields[3]]->value = $rs->fields[2];
00070                 $rs->moveNext();
00071             }
00072         }
00073         return $aAttributes;
00074     }
00075 
00083     public function loadAttributes( $sArtId )
00084     {
00085         if ( $sArtId ) {
00086 
00087             $sAttrViewName = getViewName( 'oxattribute' );
00088             $sViewName     = getViewName( 'oxobject2attribute' );
00089 
00090             $sSelect  = "select {$sAttrViewName}.*, o2a.* from {$sViewName} as o2a ";
00091             $sSelect .= "left join {$sAttrViewName} on {$sAttrViewName}.oxid = o2a.oxattrid ";
00092             $sSelect .= "where o2a.oxobjectid = '{$sArtId}' and o2a.oxvalue != '' ";
00093             $sSelect .= "order by o2a.oxpos, {$sAttrViewName}.oxpos";
00094 
00095             $this->selectString( $sSelect );
00096         }
00097     }
00098 
00108     public function getCategoryAttributes( $sCategoryId, $iLang )
00109     {
00110         $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00111 
00112         $oArtList = oxNew( "oxarticlelist");
00113         $oArtList->loadCategoryIDs( $sCategoryId, $aSessionFilter );
00114 
00115         // Only if we have articles
00116         if (count($oArtList) > 0 ) {
00117             $oDb = oxDb::getDb();
00118             $sArtIds = '';
00119             foreach (array_keys($oArtList->getArray()) as $sId ) {
00120                 if ($sArtIds) {
00121                     $sArtIds .= ',';
00122                 }
00123                 $sArtIds .= $oDb->quote($sId);
00124             }
00125 
00126             $sActCatQuoted = $oDb->quote( $sCategoryId );
00127             $sAttTbl = getViewName( 'oxattribute', $iLang );
00128             $sO2ATbl = getViewName( 'oxobject2attribute', $iLang );
00129             $sC2ATbl = getViewName( 'oxcategory2attribute', $iLang );
00130 
00131             $sSelect = "SELECT DISTINCT att.oxid, att.oxtitle, o2a.oxvalue ".
00132                        "FROM $sAttTbl as att, $sO2ATbl as o2a ,$sC2ATbl as c2a ".
00133                        "WHERE att.oxid = o2a.oxattrid AND c2a.oxobjectid = $sActCatQuoted AND c2a.oxattrid = att.oxid AND o2a.oxvalue !='' AND o2a.oxobjectid IN ($sArtIds) ".
00134                        "ORDER BY c2a.oxsort , att.oxpos, att.oxtitle, o2a.oxvalue";
00135 
00136             $rs = $oDb->select( $sSelect );
00137 
00138             if ( $rs != false && $rs->recordCount() > 0 ) {
00139                 while ( !$rs->EOF && list( $sAttId, $sAttTitle, $sAttValue ) = $rs->fields ) {
00140 
00141                     if ( !$this->offsetExists( $sAttId ) ) {
00142 
00143                         $oAttribute = oxNew( "oxattribute" );
00144                         $oAttribute->setTitle( $sAttTitle );
00145 
00146                         $this->offsetSet( $sAttId, $oAttribute );
00147                         $iLang = oxLang::getInstance()->getBaseLanguage();
00148                         if ( isset( $aSessionFilter[$sCategoryId][$iLang][$sAttId] ) ) {
00149                             $oAttribute->setActiveValue( $aSessionFilter[$sCategoryId][$iLang][$sAttId] );
00150                         }
00151 
00152                     } else {
00153                         $oAttribute = $this->offsetGet( $sAttId );
00154                     }
00155 
00156                     $oAttribute->addValue( $sAttValue );
00157                     $rs->moveNext();
00158                 }
00159             }
00160         }
00161 
00162         return $this;
00163     }
00164 }