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] = mysql_real_escape_string($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()->execute( $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             $sAttrViewName = getViewName( 'oxattribute' );
00087             $sViewName     = getViewName( 'oxobject2attribute' );
00088 
00089             $sSelect  = "select {$sAttrViewName}.*, o2a.* from {$sViewName} as o2a ";
00090             $sSelect .= "left join {$sAttrViewName} on {$sAttrViewName}.oxid = o2a.oxattrid ";
00091             $sSelect .= "where o2a.oxobjectid = '{$sArtId}' and o2a.oxvalue != '' ";
00092             $sSelect .= "order by o2a.oxpos, {$sAttrViewName}.oxpos";
00093 
00094             $this->selectString( $sSelect );
00095         }
00096     }
00097 
00107     public function getCategoryAttributes( $sCategoryId, $iLang )
00108     {
00109         $aSessionFilter = oxSession::getVar( 'session_attrfilter' );
00110 
00111         $oArtList = oxNew( "oxarticlelist");
00112         $oArtList->loadCategoryIDs( $sCategoryId, $aSessionFilter );
00113 
00114         // Only if we have articles
00115         if (count($oArtList) > 0 ) {
00116             $oDb = oxDb::getDb();
00117             $sArtIds = '';
00118             foreach (array_keys($oArtList->getArray()) as $sId ) {
00119                 if ($sArtIds) {
00120                     $sArtIds .= ',';
00121                 }
00122                 $sArtIds .= $oDb->quote($sId);
00123             }
00124 
00125             $sActCatQuoted = $oDb->quote( $sCategoryId );
00126             $sAttTbl = getViewName( 'oxattribute', $iLang );
00127             $sO2ATbl = getViewName( 'oxobject2attribute', $iLang );
00128             $sC2ATbl = getViewName( 'oxcategory2attribute', $iLang );
00129 
00130             $sSelect = "SELECT DISTINCT att.oxid, att.oxtitle, o2a.oxvalue ".
00131                        "FROM $sAttTbl as att, $sO2ATbl as o2a ,$sC2ATbl as c2a ".
00132                        "WHERE att.oxid = o2a.oxattrid AND c2a.oxobjectid = $sActCatQuoted AND c2a.oxattrid = att.oxid AND o2a.oxvalue !='' AND o2a.oxobjectid IN ($sArtIds) ".
00133                        "ORDER BY c2a.oxsort , att.oxpos, att.oxtitle, o2a.oxvalue";
00134 
00135 
00136             $rs = $oDb->execute( $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 }