FOSSology  4.4.0
Open Source License Compliance by Open Source Software
CustomiseController.php
Go to the documentation of this file.
1 <?php
2 /*
3  Author: Soham Banerjee <sohambanerjee4abc@hotmail.com>
4  SPDX-FileCopyrightText: © 2023 Soham Banerjee <sohambanerjee4abc@hotmail.com>
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
14 namespace Fossology\UI\Api\Controllers;
15 
24 use Psr\Http\Message\ServerRequestInterface;
25 
26 
28 {
33  private $sysconfigDao;
34 
35 
36  public function __construct($container)
37  {
38  parent::__construct($container);
39  $this->sysconfigDao = $this->container->get('dao.sys_config');
40  }
41 
51  public function getCustomiseData($request, $response, $args)
52  {
53  $this->throwNotAdminException();
54  $apiVersion = ApiVersion::getVersion($request);
55  $returnVal = $this->sysconfigDao->getConfigData();
56  $finalVal = $this->sysconfigDao->getCustomiseData($returnVal, $apiVersion);
57  return $response->withJson($finalVal, 200);
58  }
59 
69  public function updateCustomiseData($request, $response, $args)
70  {
71  $this->throwNotAdminException();
72  $body = $this->getParsedBody($request);
73  if (empty($body) || !array_key_exists("key", $body) || !array_key_exists("value", $body)) {
74  throw new HttpBadRequestException("Invalid request body.");
75  }
76  list($success, $msg) = $this->sysconfigDao->UpdateConfigData($body);
77  if (!$success) {
78  throw new HttpBadRequestException($msg);
79  }
80  $info = new Info(200, "Successfully updated $msg.",
81  InfoType::INFO);
82  return $response->withJson($info->getArray(), $info->getCode());
83  }
84 
93  public function getBannerMessage($request, $response, $args)
94  {
95  $returnVal = $this->sysconfigDao->getBannerData();
96  return $response->withJson($returnVal, 200);
97  }
98 }
Base controller for REST calls.
getParsedBody(ServerRequestInterface $request)
Parse request body as JSON and return associative PHP array.
Override Slim response for withJson function.
static getVersion(ServerRequestInterface $request)
Definition: ApiVersion.php:29
Different type of infos provided by REST.
Definition: InfoType.php:16
Info model to contain general error and return values.
Definition: Info.php:19