OXID eShop CE  4.10.7
 All Classes Namespaces Files Functions Variables Pages
article_list.php
Go to the documentation of this file.
1 <?php
2 
9 class Article_List extends oxAdminList
10 {
11 
17  protected $_sListClass = 'oxarticle';
18 
24  protected $_sListType = 'oxarticlelist';
25 
32  public function render()
33  {
34  $myConfig = $this->getConfig();
35  $sPwrSearchFld = oxRegistry::getConfig()->getRequestParameter("pwrsearchfld");
36  $sPwrSearchFld = $sPwrSearchFld ? strtolower($sPwrSearchFld) : "oxtitle";
37 
38  $oArticle = null;
39  $oList = $this->getItemList();
40  if ($oList) {
41  foreach ($oList as $key => $oArticle) {
42  $sFieldName = "oxarticles__{$sPwrSearchFld}";
43 
44  // formatting view
45  if (!$myConfig->getConfigParam('blSkipFormatConversion')) {
46  if ($oArticle->$sFieldName->fldtype == "datetime") {
47  oxRegistry::get("oxUtilsDate")->convertDBDateTime($oArticle->$sFieldName);
48  } elseif ($oArticle->$sFieldName->fldtype == "timestamp") {
49  oxRegistry::get("oxUtilsDate")->convertDBTimestamp($oArticle->$sFieldName);
50  } elseif ($oArticle->$sFieldName->fldtype == "date") {
51  oxRegistry::get("oxUtilsDate")->convertDBDate($oArticle->$sFieldName);
52  }
53  }
54 
55  $oArticle->pwrsearchval = $oArticle->$sFieldName->value;
56  $oList[$key] = $oArticle;
57  }
58  }
59 
61 
62  // load fields
63  if (!$oArticle && $oList) {
64  $oArticle = $oList->getBaseObject();
65  }
66  $this->_aViewData["pwrsearchfields"] = $oArticle ? $this->getSearchFields() : null;
67  $this->_aViewData["pwrsearchfld"] = strtoupper($sPwrSearchFld);
68 
69  $aFilter = $this->getListFilter();
70  if (isset($aFilter["oxarticles"][$sPwrSearchFld])) {
71  $this->_aViewData["pwrsearchinput"] = $aFilter["oxarticles"][$sPwrSearchFld];
72  }
73 
74  $sType = '';
75  $sValue = '';
76 
77  $sArtCat = oxRegistry::getConfig()->getRequestParameter("art_category");
78  if ($sArtCat && strstr($sArtCat, "@@") !== false) {
79  list($sType, $sValue) = explode("@@", $sArtCat);
80  }
81  $this->_aViewData["art_category"] = $sArtCat;
82 
83  // parent categorie tree
84  $this->_aViewData["cattree"] = $this->getCategoryList($sType, $sValue);
85 
86  // manufacturer list
87  $this->_aViewData["mnftree"] = $this->getManufacturerlist($sType, $sValue);
88 
89  // vendor list
90  $this->_aViewData["vndtree"] = $this->getVendorList($sType, $sValue);
91 
92  return "article_list.tpl";
93  }
94 
100  public function getSearchFields()
101  {
102  $aSkipFields = array("oxblfixedprice", "oxvarselect", "oxamitemid",
103  "oxamtaskid", "oxpixiexport", "oxpixiexported");
104  $oArticle = oxNew("oxarticle");
105 
106  return array_diff($oArticle->getFieldNames(), $aSkipFields);
107  }
108 
117  public function getCategoryList($sType, $sValue)
118  {
119  $myConfig = $this->getConfig();
120 
121  // parent categorie tree
122  $oCatTree = oxNew("oxCategoryList");
123  $oCatTree->loadList();
124  if ($sType === 'cat') {
125  foreach ($oCatTree as $oCategory) {
126  if ($oCategory->oxcategories__oxid->value == $sValue) {
127  $oCategory->selected = 1;
128  break;
129  }
130  }
131  }
132 
133  return $oCatTree;
134  }
135 
144  public function getManufacturerList($sType, $sValue)
145  {
146  $oMnfTree = oxNew("oxManufacturerList");
147  $oMnfTree->loadManufacturerList();
148  if ($sType === 'mnf') {
149  foreach ($oMnfTree as $oManufacturer) {
150  if ($oManufacturer->oxmanufacturers__oxid->value == $sValue) {
151  $oManufacturer->selected = 1;
152  break;
153  }
154  }
155  }
156 
157  return $oMnfTree;
158  }
159 
168  public function getVendorList($sType, $sValue)
169  {
170  $oVndTree = oxNew("oxVendorList");
171  $oVndTree->loadVendorList();
172  if ($sType === 'vnd') {
173  foreach ($oVndTree as $oVendor) {
174  if ($oVendor->oxvendor__oxid->value == $sValue) {
175  $oVendor->selected = 1;
176  break;
177  }
178  }
179  }
180 
181  return $oVndTree;
182  }
183 
191  protected function _buildSelectString($oListObject = null)
192  {
193  $sQ = parent::_buildSelectString($oListObject);
194  if ($sQ) {
195  $sTable = getViewName("oxarticles");
196  $sQ .= " and $sTable.oxparentid = '' ";
197 
198  $sType = false;
199  $sArtCat = oxRegistry::getConfig()->getRequestParameter("art_category");
200  if ($sArtCat && strstr($sArtCat, "@@") !== false) {
201  list($sType, $sValue) = explode("@@", $sArtCat);
202  }
203 
204  switch ($sType) {
205  // add category
206  case 'cat':
207  $oStr = getStr();
208  $sViewName = getViewName("oxobject2category");
209  $sInsert = "from $sTable left join {$sViewName} on {$sTable}.oxid = {$sViewName}.oxobjectid " .
210  "where {$sViewName}.oxcatnid = " . oxDb::getDb()->quote($sValue) . " and ";
211  $sQ = $oStr->preg_replace("/from\s+$sTable\s+where/i", $sInsert, $sQ);
212  break;
213  // add category
214  case 'mnf':
215  $sQ .= " and $sTable.oxmanufacturerid = " . oxDb::getDb()->quote($sValue);
216  break;
217  // add vendor
218  case 'vnd':
219  $sQ .= " and $sTable.oxvendorid = " . oxDb::getDb()->quote($sValue);
220  break;
221  }
222  }
223 
224  return $sQ;
225  }
226 
232  public function buildWhere()
233  {
234  // we override this to select only parent articles
235  $this->_aWhere = parent::buildWhere();
236 
237  // adding folder check
238  $sFolder = oxRegistry::getConfig()->getRequestParameter('folder');
239  if ($sFolder && $sFolder != '-1') {
240  $this->_aWhere[getViewName("oxarticles") . ".oxfolder"] = $sFolder;
241  }
242 
243  return $this->_aWhere;
244  }
245 
249  public function deleteEntry()
250  {
251  $sOxId = $this->getEditObjectId();
252  $oArticle = oxNew("oxarticle");
253  if ($sOxId && $oArticle->load($sOxId)) {
255  }
256  }
257 
258 }