OXID eShop CE  4.10.5
 All Classes Namespaces Files Functions Variables Pages
article_files.php
Go to the documentation of this file.
1 <?php
2 
9 {
10 
16  protected $_sThisTemplate = 'article_files.tpl';
17 
23  protected $_oArticle = null;
24 
31  public function render()
32  {
34 
35  if (!$this->getConfig()->getConfigParam('blEnableDownloads')) {
36  oxRegistry::get("oxUtilsView")->addErrorToDisplay('EXCEPTION_DISABLED_DOWNLOADABLE_PRODUCTS');
37  }
38  $oArticle = $this->getArticle();
39  // variant handling
40  if ($oArticle->oxarticles__oxparentid->value) {
41  $oParentArticle = oxNew('oxarticle');
42  $oParentArticle->load($oArticle->oxarticles__oxparentid->value);
43  $oArticle->oxarticles__oxisdownloadable = new oxField($oParentArticle->oxarticles__oxisdownloadable->value);
44  $this->_aViewData["oxparentid"] = $oArticle->oxarticles__oxparentid->value;
45  }
46 
47  return $this->_sThisTemplate;
48  }
49 
54  public function save()
55  {
56  // save article changes
57  $aArticleChanges = oxRegistry::getConfig()->getRequestParameter('editval');
58  $oArticle = $this->getArticle();
59  $oArticle->assign($aArticleChanges);
60  $oArticle->save();
61 
62  //update article files
63  $aArticleFiles = oxRegistry::getConfig()->getRequestParameter('article_files');
64  if (count($aArticleFiles) > 0) {
65  foreach ($aArticleFiles as $sArticleFileId => $aArticleFileUpdate) {
66  $oArticleFile = oxNew('oxFile');
67  $oArticleFile->load($sArticleFileId);
68  $aArticleFileUpdate = $this->_processOptions($aArticleFileUpdate);
69  $oArticleFile->assign($aArticleFileUpdate);
70 
71  if ($oArticleFile->isUnderDownloadFolder()) {
72  $oArticleFile->save();
73  } else {
74  oxRegistry::get("oxUtilsView")->addErrorToDisplay('EXCEPTION_NOFILE');
75  }
76  }
77  }
78  }
79 
87  public function getArticle($blReset = false)
88  {
89  if ($this->_oArticle !== null && !$blReset) {
90  return $this->_oArticle;
91  }
92  $sProductId = $this->getEditObjectId();
93 
94  $oProduct = oxNew('oxArticle');
95  $oProduct->load($sProductId);
96  $this->_oArticle = $oProduct;
97 
98  return $this->_oArticle;
99  }
100 
106  public function upload()
107  {
108  $myConfig = $this->getConfig();
109 
110  if ($myConfig->isDemoShop()) {
111  $oEx = oxNew("oxExceptionToDisplay");
112  $oEx->setMessage('ARTICLE_EXTEND_UPLOADISDISABLED');
113  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false);
114 
115  return;
116  }
117 
118  $soxId = $this->getEditObjectId();
119 
120  $aParams = oxRegistry::getConfig()->getRequestParameter("newfile");
121  $aParams = $this->_processOptions($aParams);
122  $aNewFile = $this->getConfig()->getUploadedFile("newArticleFile");
123 
124  //uploading and processing supplied file
125  $oArticleFile = oxNew("oxFile");
126  $oArticleFile->assign($aParams);
127 
128  if (!$aNewFile['name'] && !$oArticleFile->oxfiles__oxfilename->value) {
129  return oxRegistry::get("oxUtilsView")->addErrorToDisplay('EXCEPTION_NOFILE');
130  }
131 
132  if ($aNewFile['name']) {
133  $oArticleFile->oxfiles__oxfilename = new oxField($aNewFile['name'], oxField::T_RAW);
134  try {
135  $oArticleFile->processFile('newArticleFile');
136  } catch (Exception $e) {
137  return oxRegistry::get("oxUtilsView")->addErrorToDisplay($e->getMessage());
138  }
139  }
140 
141  if (!$oArticleFile->isUnderDownloadFolder()) {
142  return oxRegistry::get("oxUtilsView")->addErrorToDisplay('EXCEPTION_NOFILE');
143  }
144 
145  //save media url
146  $oArticleFile->oxfiles__oxartid = new oxField($soxId, oxField::T_RAW);
147  $oArticleFile->save();
148  }
149 
155  public function deletefile()
156  {
157  $myConfig = $this->getConfig();
158 
159  if ($myConfig->isDemoShop()) {
160  $oEx = oxNew("oxExceptionToDisplay");
161  $oEx->setMessage('ARTICLE_EXTEND_UPLOADISDISABLED');
162  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false);
163 
164  return;
165  }
166 
167  $sArticleId = $this->getEditObjectId();
168  $sArticleFileId = oxRegistry::getConfig()->getRequestParameter('fileid');
169  $oArticleFile = oxNew('oxFile');
170  $oArticleFile->load($sArticleFileId);
171  if ($oArticleFile->hasValidDownloads()) {
172  return oxRegistry::get("oxUtilsView")->addErrorToDisplay('EXCEPTION_DELETING_VALID_FILE');
173  }
174  if ($oArticleFile->oxfiles__oxartid->value == $sArticleId) {
175  $oArticleFile->delete();
176  }
177  }
178 
186  public function getConfigOptionValue($iOption)
187  {
188  $iOption = ($iOption < 0) ? "" : $iOption;
189 
190  return $iOption;
191  }
192 
200  protected function _processOptions($aParams)
201  {
202  if (!is_array($aParams)) {
203  $aParams = array();
204  }
205 
206  if (!isset($aParams["oxfiles__oxdownloadexptime"]) || $aParams["oxfiles__oxdownloadexptime"] == "") {
207  $aParams["oxfiles__oxdownloadexptime"] = -1;
208  }
209  if (!isset($aParams["oxfiles__oxlinkexptime"]) || $aParams["oxfiles__oxlinkexptime"] == "") {
210  $aParams["oxfiles__oxlinkexptime"] = -1;
211  }
212  if (!isset($aParams["oxfiles__oxmaxunregdownloads"]) || $aParams["oxfiles__oxmaxunregdownloads"] == "") {
213  $aParams["oxfiles__oxmaxunregdownloads"] = -1;
214  }
215  if (!isset($aParams["oxfiles__oxmaxdownloads"]) || $aParams["oxfiles__oxmaxdownloads"] == "") {
216  $aParams["oxfiles__oxmaxdownloads"] = -1;
217  }
218 
219  return $aParams;
220  }
221 }