FOSSology  4.4.0
Open Source License Compliance by Open Source Software
AjaxLicenseAcknowledgements.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2022 Siemens AG
4  Author: Gaurav Mishra <mishra.gaurav@siemens.com>
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
12 namespace Fossology\UI\Ajax;
13 
17 use Symfony\Component\HttpFoundation\Request;
18 use Symfony\Component\HttpFoundation\JsonResponse;
19 
25 {
26 
31  const NAME = "ajax_license_acknowledgements";
32 
38 
39  function __construct()
40  {
41  parent::__construct(self::NAME,
42  array(
43  self::REQUIRES_LOGIN => true,
44  self::PERMISSION => Auth::PERM_READ
45  ));
46  $this->licenseAcknowledgementDao = $this->getObject('dao.license.acknowledgement');
47  }
48 
52  protected function handle(Request $request)
53  {
54  $toggleAcknowledgementPk = $request->get("toggle");
55  if ($toggleAcknowledgementPk !== null) {
56  $status = false;
57  try {
58  $status = $this->licenseAcknowledgementDao->toggleAcknowledgement(intval($toggleAcknowledgementPk));
59  } catch (\UnexpectedValueException $e) {
60  $status = $e->getMessage();
61  }
62  return new JsonResponse(["status" => $status]);
63  }
64  $reqScope = $request->get("scope", "all");
65  $responseArray = null;
66  if (strcasecmp($reqScope, "all") === 0) {
67  $responseArray = $this->licenseAcknowledgementDao->getAllAcknowledgements();
68  } else if (strcasecmp($reqScope, "visible") === 0) {
69  $responseArray = $this->licenseAcknowledgementDao->getAllAcknowledgements(true);
70  } else {
71  try {
72  $responseArray = [
73  "acknowledgement" => $this->licenseAcknowledgementDao->getAcknowledgement(intval($reqScope))
74  ];
75  } catch (\UnexpectedValueException $e) {
76  $responseArray = [
77  "status" => false,
78  "error" => $e->getMessage()
79  ];
80  return new JsonResponse($responseArray, JsonResponse::HTTP_NOT_FOUND);
81  }
82  }
83  return new JsonResponse($responseArray, JsonResponse::HTTP_OK);
84  }
85 }
86 
87 register_plugin(new AjaxLicenseStdAcknowledgements());
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
handle(Request $request)
Load the license acknowledgements based on request type.