FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
AjaxLicenseStdComments.php
Go to the documentation of this file.
1 <?php
25 namespace Fossology\UI\Ajax;
26 
32 
38 {
39 
44  const NAME = "ajax_license_std_comments";
45 
51 
52  function __construct()
53  {
54  parent::__construct(self::NAME,
55  array(
56  self::REQUIRES_LOGIN => true,
57  self::PERMISSION => Auth::PERM_READ
58  ));
59  $this->licenseCommentDao = $this->getObject('dao.license.stdc');
60  }
61 
65  protected function handle(Request $request)
66  {
67  $toggleCommentPk = $request->get("toggle");
68  if ($toggleCommentPk !== null) {
69  $status = false;
70  try {
71  $status = $this->licenseCommentDao->toggleComment(intval($toggleCommentPk));
72  } catch (\UnexpectedValueException $e) {
73  $status = $e->getMessage();
74  }
75  return new JsonResponse(["status" => $status]);
76  }
77  $reqScope = $request->get("scope", "all");
78  $responseArray = null;
79  if (strcasecmp($reqScope, "all") === 0) {
80  $responseArray = $this->licenseCommentDao->getAllComments();
81  } else if (strcasecmp($reqScope, "visible") === 0) {
82  $responseArray = $this->licenseCommentDao->getAllComments(true);
83  } else {
84  try {
85  $responseArray = [
86  "comment" => $this->licenseCommentDao->getComment(intval($reqScope))
87  ];
88  } catch (\UnexpectedValueException $e) {
89  $responseArray = [
90  "status" => false,
91  "error" => $e->getMessage()
92  ];
93  return new JsonResponse($responseArray, JsonResponse::HTTP_NOT_FOUND);
94  }
95  }
96  return new JsonResponse($responseArray, JsonResponse::HTTP_OK);
97  }
98 }
99 
100 register_plugin(new AjaxLicenseStdComments());
handle(Request $request)
Load the license comments based on request type.