FOSSology  4.4.0
Open Source License Compliance by Open Source Software
AjaxLicenseStdComments.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2019 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_std_comments";
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->licenseCommentDao = $this->getObject('dao.license.stdc');
47  }
48 
52  protected function handle(Request $request)
53  {
54  $toggleCommentPk = $request->get("toggle");
55  if ($toggleCommentPk !== null) {
56  $status = false;
57  try {
58  $status = $this->licenseCommentDao->toggleComment(intval($toggleCommentPk));
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->licenseCommentDao->getAllComments();
68  } else if (strcasecmp($reqScope, "visible") === 0) {
69  $responseArray = $this->licenseCommentDao->getAllComments(true);
70  } else {
71  try {
72  $responseArray = [
73  "comment" => $this->licenseCommentDao->getComment(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 AjaxLicenseStdComments());
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
handle(Request $request)
Load the license comments based on request type.