OXID eShop CE  4.8.10
 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  $oArticleFile->save();
72  }
73  }
74  }
75 
83  public function getArticle($blReset = false)
84  {
85  if ($this->_oArticle !== null && !$blReset) {
86  return $this->_oArticle;
87  }
88  $sProductId = $this->getEditObjectId();
89 
90  $oProduct = oxNew( 'oxArticle' );
91  $oProduct->load( $sProductId );
92  $this->_oArticle = $oProduct;
93 
94  return $this->_oArticle;
95  }
96 
102  public function upload()
103  {
104  $myConfig = $this->getConfig();
105 
106  if ( $myConfig->isDemoShop() ) {
107  $oEx = oxNew( "oxExceptionToDisplay" );
108  $oEx->setMessage( 'ARTICLE_EXTEND_UPLOADISDISABLED' );
109  oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false );
110 
111  return;
112  }
113 
114  $soxId = $this->getEditObjectId();
115 
116  $aParams = oxConfig::getParameter( "newfile");
117  $aParams = $this->_processOptions($aParams);
118  $aNewFile = $this->getConfig()->getUploadedFile( "newArticleFile");
119 
120  $sExistingFilename = trim(oxConfig::getParameter( "existingFilename"));
121 
122  //uploading and processing supplied file
123  $oArticleFile = oxNew( "oxFile" );
124  $oArticleFile->assign($aParams);
125 
126  if (!$aNewFile['name'] && !$oArticleFile->oxfiles__oxfilename->value) {
127  return oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'EXCEPTION_NOFILE' );
128  }
129 
130  if ($aNewFile['name']) {
131  $oArticleFile->oxfiles__oxfilename = new oxField($aNewFile['name'], oxField::T_RAW);
132  try {
133  $oArticleFile->processFile( 'newArticleFile' );
134  } catch (Exception $e) {
135  return oxRegistry::get("oxUtilsView")->addErrorToDisplay( $e->getMessage() );
136  }
137  }
138 
139  //save media url
140  $oArticleFile->oxfiles__oxartid = new oxField($soxId, oxField::T_RAW);
141  $oArticleFile->save();
142  }
143 
149  public function deletefile()
150  {
151  $myConfig = $this->getConfig();
152 
153  if ( $myConfig->isDemoShop() ) {
154  $oEx = oxNew( "oxExceptionToDisplay" );
155  $oEx->setMessage( 'ARTICLE_EXTEND_UPLOADISDISABLED' );
156  oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false );
157 
158  return;
159  }
160 
161  $sArticleId = $this->getEditObjectId();
162  $sArticleFileId = oxConfig::getParameter('fileid');
163  $oArticleFile = oxNew('oxFile');
164  $oArticleFile->load($sArticleFileId);
165  if ($oArticleFile->hasValidDownloads()) {
166  return oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'EXCEPTION_DELETING_VALID_FILE' );
167  }
168  if ($oArticleFile->oxfiles__oxartid->value == $sArticleId) {
169  $oArticleFile->delete();
170  }
171  }
172 
180  public function getConfigOptionValue( $iOption )
181  {
182  $iOption = ( $iOption < 0 ) ? "" : $iOption;
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  return $aParams;
212  }
213 }