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