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                         oxDb::getInstance()->convertDBDateTime( $oArticle->$sFieldName );
00047                     elseif ( $oArticle->$sFieldName->fldtype == "timestamp" )
00048                         oxDb::getInstance()->convertDBTimestamp( $oArticle->$sFieldName );
00049                     elseif ( $oArticle->$sFieldName->fldtype == "date" )
00050                         oxDb::getInstance()->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 ? $oArticle->getSearchableFields() : 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 
00101     public function getCategoryList($sType, $sValue)
00102     {
00103         $myConfig = $this->getConfig();
00104 
00105         // parent categorie tree
00106         $oCatTree = oxNew( "oxCategoryList");
00107         $oCatTree->buildList( $myConfig->getConfigParam( 'bl_perfLoadCatTree' ) );
00108         if ( $sType === 'cat' ) {
00109             foreach ($oCatTree as $oCategory ) {
00110                 if ( $oCategory->oxcategories__oxid->value == $sValue ) {
00111                     $oCategory->selected = 1;
00112                     break;
00113                 }
00114             }
00115         }
00116 
00117         return $oCatTree;
00118     }
00119 
00128     public function getManufacturerList($sType, $sValue)
00129     {
00130         $oMnfTree = oxNew( "oxManufacturerList");
00131         $oMnfTree->loadManufacturerList();
00132         if ( $sType === 'mnf' ) {
00133             foreach ($oMnfTree as $oManufacturer ) {
00134                 if ( $oManufacturer->oxmanufacturers__oxid->value == $sValue ) {
00135                     $oManufacturer->selected = 1;
00136                     break;
00137                 }
00138             }
00139         }
00140 
00141         return $oMnfTree;
00142     }
00143 
00152     public function getVendorList($sType, $sValue)
00153     {
00154         $oVndTree = oxNew( "oxVendorList");
00155         $oVndTree->loadVendorList();
00156         if ( $sType === 'vnd' ) {
00157             foreach ($oVndTree as $oVendor ) {
00158                 if ( $oVendor->oxvendor__oxid->value == $sValue ) {
00159                     $oVendor->selected = 1;
00160                     break;
00161                 }
00162             }
00163         }
00164 
00165         return $oVndTree;
00166     }
00167 
00175     protected function _changeselect( $sSql )
00176     {
00177         $sArtCat= oxConfig::getParameter("art_category");
00178         if ( $sArtCat && strstr($sArtCat, "@@") !== false ) {
00179             list($sType, $sValue) = explode("@@", $sArtCat);
00180         }
00181 
00182         $sTable = getViewName( "oxarticles" );
00183         switch ($sType) {
00184             // add category
00185             case 'cat':
00186                 $oStr = getStr();
00187                 $sO2CView = getViewName( "oxobject2category" );
00188                 $sInsert  = "from $sTable left join $sO2CView on $sTable.oxid = $sO2CView.oxobjectid where $sO2CView.oxcatnid = ".oxDb::getDb()->quote($sValue)." and ";
00189                 $sSql = $oStr->preg_replace( "/from\s+$sTable\s+where/i", $sInsert, $sSql);
00190                 break;
00191             // add category
00192             case 'mnf':
00193                 $sSql.= " and $sTable.oxmanufacturerid = ".oxDb::getDb()->quote($sValue);
00194                 break;
00195             // add vendor
00196             case 'vnd':
00197                 $sSql.= " and $sTable.oxvendorid = ".oxDb::getDb()->quote($sValue);
00198                 break;
00199         }
00200         return $sSql;
00201     }
00202 
00208     public function buildWhere()
00209     {
00210         // we override this to select only parent articles
00211         $this->_aWhere = parent::buildWhere();
00212 
00213         // adding folder check
00214         $sFolder = oxConfig::getParameter( 'folder' );
00215         if ( $sFolder && $sFolder != '-1' ) {
00216             $this->_aWhere[getViewName( "oxarticles" ).".oxfolder"] = $sFolder;
00217         }
00218 
00219         return $this->_aWhere;
00220     }
00221 
00230     protected function _prepareWhereQuery( $aWhere, $sQ )
00231     {
00232         $sQ = parent::_prepareWhereQuery( $aWhere, $sQ );
00233 
00234         return $sQ . " and ".getViewName( 'oxarticles' ).".oxparentid = '' ";
00235     }
00236 
00242     public function deleteEntry()
00243     {
00244         $sOxId = $this->getEditObjectId();
00245         $oArticle = oxNew( "oxarticle");
00246         if ( $sOxId && $oArticle->load( $sOxId ) ) {
00247             parent::deleteEntry();
00248         }
00249     }
00250 
00251 }