OXID eShop CE  4.9.7
 All Classes 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  $oArticleFile->save();
71  }
72  }
73  }
74 
82  public function getArticle($blReset = false)
83  {
84  if ($this->_oArticle !== null && !$blReset) {
85  return $this->_oArticle;
86  }
87  $sProductId = $this->getEditObjectId();
88 
89  $oProduct = oxNew('oxArticle');
90  $oProduct->load($sProductId);
91  $this->_oArticle = $oProduct;
92 
93  return $this->_oArticle;
94  }
95 
101  public function upload()
102  {
103  $myConfig = $this->getConfig();
104 
105  if ($myConfig->isDemoShop()) {
106  $oEx = oxNew("oxExceptionToDisplay");
107  $oEx->setMessage('ARTICLE_EXTEND_UPLOADISDISABLED');
108  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false);
109 
110  return;
111  }
112 
113  $soxId = $this->getEditObjectId();
114 
115  $aParams = oxRegistry::getConfig()->getRequestParameter("newfile");
116  $aParams = $this->_processOptions($aParams);
117  $aNewFile = $this->getConfig()->getUploadedFile("newArticleFile");
118 
119  $sExistingFilename = trim(oxRegistry::getConfig()->getRequestParameter("existingFilename"));
120 
121  //uploading and processing supplied file
122  $oArticleFile = oxNew("oxFile");
123  $oArticleFile->assign($aParams);
124 
125  if (!$aNewFile['name'] && !$oArticleFile->oxfiles__oxfilename->value) {
126  return oxRegistry::get("oxUtilsView")->addErrorToDisplay('EXCEPTION_NOFILE');
127  }
128 
129  if ($aNewFile['name']) {
130  $oArticleFile->oxfiles__oxfilename = new oxField($aNewFile['name'], oxField::T_RAW);
131  try {
132  $oArticleFile->processFile('newArticleFile');
133  } catch (Exception $e) {
134  return oxRegistry::get("oxUtilsView")->addErrorToDisplay($e->getMessage());
135  }
136  }
137 
138  //save media url
139  $oArticleFile->oxfiles__oxartid = new oxField($soxId, oxField::T_RAW);
140  $oArticleFile->save();
141  }
142 
148  public function deletefile()
149  {
150  $myConfig = $this->getConfig();
151 
152  if ($myConfig->isDemoShop()) {
153  $oEx = oxNew("oxExceptionToDisplay");
154  $oEx->setMessage('ARTICLE_EXTEND_UPLOADISDISABLED');
155  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false);
156 
157  return;
158  }
159 
160  $sArticleId = $this->getEditObjectId();
161  $sArticleFileId = oxRegistry::getConfig()->getRequestParameter('fileid');
162  $oArticleFile = oxNew('oxFile');
163  $oArticleFile->load($sArticleFileId);
164  if ($oArticleFile->hasValidDownloads()) {
165  return oxRegistry::get("oxUtilsView")->addErrorToDisplay('EXCEPTION_DELETING_VALID_FILE');
166  }
167  if ($oArticleFile->oxfiles__oxartid->value == $sArticleId) {
168  $oArticleFile->delete();
169  }
170  }
171 
179  public function getConfigOptionValue($iOption)
180  {
181  $iOption = ($iOption < 0) ? "" : $iOption;
182 
183  return $iOption;
184  }
185 
193  protected function _processOptions($aParams)
194  {
195  if (!is_array($aParams)) {
196  $aParams = array();
197  }
198 
199  if (!isset($aParams["oxfiles__oxdownloadexptime"]) || $aParams["oxfiles__oxdownloadexptime"] == "") {
200  $aParams["oxfiles__oxdownloadexptime"] = -1;
201  }
202  if (!isset($aParams["oxfiles__oxlinkexptime"]) || $aParams["oxfiles__oxlinkexptime"] == "") {
203  $aParams["oxfiles__oxlinkexptime"] = -1;
204  }
205  if (!isset($aParams["oxfiles__oxmaxunregdownloads"]) || $aParams["oxfiles__oxmaxunregdownloads"] == "") {
206  $aParams["oxfiles__oxmaxunregdownloads"] = -1;
207  }
208  if (!isset($aParams["oxfiles__oxmaxdownloads"]) || $aParams["oxfiles__oxmaxdownloads"] == "") {
209  $aParams["oxfiles__oxmaxdownloads"] = -1;
210  }
211 
212  return $aParams;
213  }
214 }