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