/** * downloads a file * * @return void */ function downloadFile() { $app = JFactory::getApplication(); $user = JFactory::getUser(); $productfile_id = $app->input->getInt('id', 0); //$productfile_id = intval( JRequest::getvar( 'id', '', 'request', 'int' ) ); $product_id = $app->input->getInt('product_id', 0); $link = 'index.php?option=com_citruscart&view=products&task=edit&id=' . $product_id; Citruscart::load('CitruscartHelperBase', 'helpers._base'); $helper = CitruscartHelperBase::getInstance('ProductDownload', 'CitruscartHelper'); JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_citruscart' . DS . 'tables'); $productfile = JTable::getInstance('ProductFiles', 'CitruscartTable'); $productfile->load($productfile_id); if (empty($productfile->productfile_id)) { $this->messagetype = 'notice'; $this->message = JText::_('COM_CITRUSCART_INVALID FILE'); $this->setRedirect($link, $this->message, $this->messagetype); return false; } // log and download Citruscart::load('CitruscartFile', '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 = CitruscartFile::download($productfile)) { $link = JRoute::_($link, false); $this->setRedirect($link); } }
/** * downloads a file * * @return void */ function downloadFile() { $input = JFactory::getApplication()->input; $user = JFactory::getUser(); $productfile_id = intval($input->getInt('id', 0)); $product_id = intval($input->getInt('product_id', 0)); $link = 'index.php?option=com_citruscart&controller=products&view=products&task=view&id=' . $product_id; Citruscart::load('CitruscartHelperBase', 'helpers._base'); $helper = CitruscartHelperBase::getInstance('ProductDownload', 'CitruscartHelper'); if (!($canView = $helper->canDownload($productfile_id, JFactory::getUser()->id))) { $this->messagetype = 'notice'; $this->message = JText::_('COM_CITRUSCART_NOT_AUTHORIZED_TO_DOWNLOAD_FILE'); $this->setRedirect($link, $this->message, $this->messagetype); return false; } JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); $productfile = JTable::getInstance('ProductFiles', 'CitruscartTable'); $productfile->load($productfile_id); if (empty($productfile->productfile_id)) { $this->messagetype = 'notice'; $this->message = JText::_('COM_CITRUSCART_INVALID_FILE'); $this->setRedirect($link, $this->message, $this->messagetype); return false; } // log and download Citruscart::load('CitruscartFile', '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', 'CitruscartTable'); $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 = CitruscartFile::download($productfile->productfile_path)) { $link = JRoute::_($link, false); $this->setRedirect($link); } }