FOSSology  4.5.1
Open Source License Compliance by Open Source Software
AdminObligationToJSON.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2024 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 namespace Fossology\UI\Page;
9 
13 use Symfony\Component\HttpFoundation\Request;
14 use Symfony\Component\HttpFoundation\Response;
15 
17 {
18  const NAME = "admin_obligation_to_json";
19 
20  function __construct()
21  {
22  parent::__construct(self::NAME, array(
23  self::TITLE => "Admin Obligation JSON Export",
24  self::MENU_LIST => "Admin::Obligation Admin::JSON Export",
25  self::REQUIRES_LOGIN => true,
26  self::PERMISSION => Auth::PERM_ADMIN
27  ));
28  }
29 
34  protected function handle(Request $request)
35  {
36  $confirmed = $request->get('confirmed', false);
37  $referer = $request->headers->get('referer');
38  $fileName = "fossology-obligations-export-" . date("YMj-Gis") . '.json';
39 
40  if (!$confirmed) {
41  $downloadUrl = "?mod=" . self::NAME . "&rf=" . $request->get('rf') . "&confirmed=true";
42  return DownloadUtil::getDownloadConfirmationResponse($downloadUrl, $fileName, $referer);
43  }
44 
45  $obligationCsvExport = new \Fossology\Lib\Application\ObligationCsvExport($this->getObject('db.manager'));
46  $content = $obligationCsvExport->createCsv(intval($request->get('rf')), true);
47  return DownloadUtil::getDownloadResponse($content, $fileName, 'text/json');
48  }
49 }
50 
51 register_plugin(new AdminObligationToJSON());
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
static getDownloadConfirmationResponse($downloadUrl, $fileName, $referer)
static getDownloadResponse($content, $fileName, $contentType='text/csv')