Exemplo n.º 1
0
 /**
  * downloads a file
  *
  * @return void
  */
 function downloadFile()
 {
     $user = JFactory::getUser();
     $productfile_id = intval(JRequest::getvar('id', '', 'request', 'int'));
     $product_id = intval(JRequest::getvar('product_id', '', 'request', 'int'));
     $link = 'index.php?option=com_tienda&view=products&task=edit&id=' . $product_id;
     Tienda::load('TiendaHelperBase', 'helpers._base');
     $helper = TiendaHelperBase::getInstance('ProductDownload', 'TiendaHelper');
     JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_tienda' . DS . 'tables');
     $productfile = JTable::getInstance('ProductFiles', 'TiendaTable');
     $productfile->load($productfile_id);
     if (empty($productfile->productfile_id)) {
         $this->messagetype = 'notice';
         $this->message = JText::_('COM_TIENDA_INVALID FILE');
         $this->setRedirect($link, $this->message, $this->messagetype);
         return false;
     }
     // log and download
     Tienda::load('TiendaFile', 'library.file');
     // geting the ProductDownloadId to updated for which productdownload_max  is greater then 0
     $productToDownload = $helper->getProductDownloadInfo($productfile->productfile_id, $user->id);
     if ($downloadFile = TiendaFile::download($productfile)) {
         $link = JRoute::_($link, false);
         $this->setRedirect($link);
     }
 }
Exemplo n.º 2
0
 /**
  * downloads a file
  *
  * @return void
  */
 function downloadFile()
 {
     $user = JFactory::getUser();
     $productfile_id = intval(JRequest::getvar('id', '', 'request', 'int'));
     $product_id = intval(JRequest::getvar('product_id', '', 'request', 'int'));
     $link = 'index.php?option=com_tienda&controller=products&view=products&task=view&id=' . $product_id;
     Tienda::load('TiendaHelperBase', 'helpers._base');
     $helper = TiendaHelperBase::getInstance('ProductDownload', 'TiendaHelper');
     if (!($canView = $helper->canDownload($productfile_id, JFactory::getUser()->id))) {
         $this->messagetype = 'notice';
         $this->message = JText::_('COM_TIENDA_NOT_AUTHORIZED_TO_DOWNLOAD_FILE');
         $this->setRedirect($link, $this->message, $this->messagetype);
         return false;
     }
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     $productfile = JTable::getInstance('ProductFiles', 'TiendaTable');
     $productfile->load($productfile_id);
     if (empty($productfile->productfile_id)) {
         $this->messagetype = 'notice';
         $this->message = JText::_('COM_TIENDA_INVALID FILE');
         $this->setRedirect($link, $this->message, $this->messagetype);
         return false;
     }
     // log and download
     Tienda::load('TiendaFile', 'library.file');
     // Log the download
     $productfile->logDownload($user->id);
     // After download complete it will update the productdownloads on the basis of the user
     // geting the ProductDownloadId to updated for which productdownload_max  is greater then 0
     $productToDownload = $helper->getProductDownloadInfo($productfile->productfile_id, $user->id);
     if (!empty($productToDownload)) {
         $productDownload = JTable::getInstance('ProductDownloads', 'TiendaTable');
         $productDownload->load($productToDownload->productdownload_id);
         $productDownload->productdownload_max = $productDownload->productdownload_max - 1;
         if (!$productDownload->save()) {
             // TODO in case product Download is not updating properly .
         }
     }
     if ($downloadFile = TiendaFile::download($productfile)) {
         $link = JRoute::_($link, false);
         $this->setRedirect($link);
     }
 }