article_list.php

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