article_list.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Article_List extends oxAdminList
00010 {
00016     protected $_sListClass = 'oxarticle';
00017 
00023     protected $_sListType = 'oxarticlelist';
00024 
00031     public function render()
00032     {
00033         $myConfig = $this->getConfig();
00034         $sPwrSearchFld = oxConfig::getParameter( "pwrsearchfld" );
00035         $sPwrSearchFld = $sPwrSearchFld ? strtolower( $sPwrSearchFld ) : "oxtitle";
00036 
00037         $oArticle = null;
00038         $oList = $this->getItemList();
00039         if ( $oList) {
00040             foreach ( $oList as $key => $oArticle ) {
00041                 $sFieldName = "oxarticles__{$sPwrSearchFld}";
00042 
00043                 // formatting view
00044                 if ( !$myConfig->getConfigParam( 'blSkipFormatConversion' ) ) {
00045                     if ( $oArticle->$sFieldName->fldtype == "datetime" )
00046                         oxRegistry::get("oxUtilsDate")->convertDBDateTime( $oArticle->$sFieldName );
00047                     elseif ( $oArticle->$sFieldName->fldtype == "timestamp" )
00048                         oxRegistry::get("oxUtilsDate")->convertDBTimestamp( $oArticle->$sFieldName );
00049                     elseif ( $oArticle->$sFieldName->fldtype == "date" )
00050                         oxRegistry::get("oxUtilsDate")->convertDBDate( $oArticle->$sFieldName );
00051                 }
00052 
00053                 $oArticle->pwrsearchval = $oArticle->$sFieldName->value;
00054                 $oList[$key] = $oArticle;
00055             }
00056         }
00057 
00058         parent::render();
00059 
00060         // load fields
00061         if ( !$oArticle && $oList ) {
00062             $oArticle = $oList->getBaseObject();
00063         }
00064         $this->_aViewData["pwrsearchfields"] = $oArticle ? $this->getSearchFields() : null;
00065         $this->_aViewData["pwrsearchfld"]    = strtoupper( $sPwrSearchFld );
00066 
00067         $aFilter = $this->getListFilter();
00068         if ( isset( $aFilter["oxarticles"][$sPwrSearchFld] ) ) {
00069             $this->_aViewData["pwrsearchinput"] = $aFilter["oxarticles"][$sPwrSearchFld];
00070         }
00071 
00072         $sType  = '';
00073         $sValue = '';
00074 
00075         $sArtCat= oxConfig::getParameter( "art_category" );
00076         if ( $sArtCat && strstr( $sArtCat, "@@" ) !== false ) {
00077             list( $sType, $sValue ) = explode( "@@", $sArtCat );
00078         }
00079         $this->_aViewData["art_category"] = $sArtCat;
00080 
00081         // parent categorie tree
00082         $this->_aViewData["cattree"] = $this->getCategoryList($sType, $sValue);
00083 
00084         // manufacturer list
00085         $this->_aViewData["mnftree"] = $this->getManufacturerlist($sType, $sValue);
00086 
00087         // vendor list
00088         $this->_aViewData["vndtree"] = $this->getVendorList($sType, $sValue);
00089 
00090         return "article_list.tpl";
00091     }
00092 
00098     public function getSearchFields()
00099     {
00100         $aSkipFields = array("oxblfixedprice", "oxvarselect", "oxamitemid", "oxamtaskid", "oxpixiexport", "oxpixiexported") ;
00101         $oArticle = oxNew( "oxarticle" );
00102         return array_diff( $oArticle->getFieldNames(), $aSkipFields );
00103     }
00104 
00113     public function getCategoryList($sType, $sValue)
00114     {
00115         $myConfig = $this->getConfig();
00116 
00117         // parent categorie tree
00118         $oCatTree = oxNew( "oxCategoryList");
00119         $oCatTree->buildList( $myConfig->getConfigParam( 'bl_perfLoadCatTree' ) );
00120         if ( $sType === 'cat' ) {
00121             foreach ($oCatTree as $oCategory ) {
00122                 if ( $oCategory->oxcategories__oxid->value == $sValue ) {
00123                     $oCategory->selected = 1;
00124                     break;
00125                 }
00126             }
00127         }
00128 
00129         return $oCatTree;
00130     }
00131 
00140     public function getManufacturerList($sType, $sValue)
00141     {
00142         $oMnfTree = oxNew( "oxManufacturerList");
00143         $oMnfTree->loadManufacturerList();
00144         if ( $sType === 'mnf' ) {
00145             foreach ($oMnfTree as $oManufacturer ) {
00146                 if ( $oManufacturer->oxmanufacturers__oxid->value == $sValue ) {
00147                     $oManufacturer->selected = 1;
00148                     break;
00149                 }
00150             }
00151         }
00152 
00153         return $oMnfTree;
00154     }
00155 
00164     public function getVendorList($sType, $sValue)
00165     {
00166         $oVndTree = oxNew( "oxVendorList");
00167         $oVndTree->loadVendorList();
00168         if ( $sType === 'vnd' ) {
00169             foreach ($oVndTree as $oVendor ) {
00170                 if ( $oVendor->oxvendor__oxid->value == $sValue ) {
00171                     $oVendor->selected = 1;
00172                     break;
00173                 }
00174             }
00175         }
00176 
00177         return $oVndTree;
00178     }
00179 
00187     protected function _buildSelectString( $oListObject = null )
00188     {
00189         $sQ = parent::_buildSelectString( $oListObject );
00190         if ( $sQ ) {
00191             $sTable = getViewName( "oxarticles" );
00192             $sQ .= " and $sTable.oxparentid = '' ";
00193 
00194             $sType   = false;
00195             $sArtCat = oxConfig::getParameter( "art_category" );
00196             if ( $sArtCat && strstr( $sArtCat, "@@" ) !== false ) {
00197                 list( $sType, $sValue ) = explode("@@", $sArtCat );
00198             }
00199 
00200             switch ( $sType ) {
00201                 // add category
00202                 case 'cat':
00203                     $oStr = getStr();
00204                     $sO2CView = getViewName( "oxobject2category" );
00205                     $sInsert  = "from $sTable left join $sO2CView on $sTable.oxid = $sO2CView.oxobjectid where $sO2CView.oxcatnid = ".oxDb::getDb()->quote($sValue)." and ";
00206                     $sQ = $oStr->preg_replace( "/from\s+$sTable\s+where/i", $sInsert, $sQ);
00207                     break;
00208                 // add category
00209                 case 'mnf':
00210                     $sQ.= " and $sTable.oxmanufacturerid = ".oxDb::getDb()->quote($sValue);
00211                     break;
00212                 // add vendor
00213                 case 'vnd':
00214                     $sQ.= " and $sTable.oxvendorid = ".oxDb::getDb()->quote($sValue);
00215                     break;
00216             }
00217         }
00218 
00219         return $sQ;
00220     }
00221 
00227     public function buildWhere()
00228     {
00229         // we override this to select only parent articles
00230         $this->_aWhere = parent::buildWhere();
00231 
00232         // adding folder check
00233         $sFolder = oxConfig::getParameter( 'folder' );
00234         if ( $sFolder && $sFolder != '-1' ) {
00235             $this->_aWhere[getViewName( "oxarticles" ).".oxfolder"] = $sFolder;
00236         }
00237 
00238         return $this->_aWhere;
00239     }
00240 
00246     public function deleteEntry()
00247     {
00248         $sOxId = $this->getEditObjectId();
00249         $oArticle = oxNew( "oxarticle");
00250         if ( $sOxId && $oArticle->load( $sOxId ) ) {
00251             parent::deleteEntry();
00252         }
00253     }
00254 
00255 }