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 
23 use Psr\Http\Message\ServerRequestInterface;
24 
25 
27 {
32  private $sysconfigDao;
33 
34 
35  public function __construct($container)
36  {
37  parent::__construct($container);
38  $this->sysconfigDao = $this->container->get('dao.sys_config');
39  }
40 
50  public function getCustomiseData($request, $response, $args)
51  {
52  $this->throwNotAdminException();
53  $returnVal = $this->sysconfigDao->getConfigData();
54  $finalVal = $this->sysconfigDao->getCustomiseData($returnVal);
55  return $response->withJson($finalVal, 200);
56  }
57 
67  public function updateCustomiseData($request, $response, $args)
68  {
69  $this->throwNotAdminException();
70  $body = $this->getParsedBody($request);
71  if (empty($body) || !array_key_exists("key", $body) || !array_key_exists("value", $body)) {
72  throw new HttpBadRequestException("Invalid request body.");
73  }
74  list($success, $msg) = $this->sysconfigDao->UpdateConfigData($body);
75  if (!$success) {
76  throw new HttpBadRequestException($msg);
77  }
78  $info = new Info(200, "Successfully updated $msg.",
79  InfoType::INFO);
80  return $response->withJson($info->getArray(), $info->getCode());
81  }
82 
91  public function getBannerMessage($request, $response, $args)
92  {
93  $returnVal = $this->sysconfigDao->getBannerData();
94  return $response->withJson($returnVal, 200);
95  }
96 }
Base controller for REST calls.
getParsedBody(ServerRequestInterface $request)
Parse request body as JSON and return associative PHP array.
Override Slim response for withJson function.
Different type of infos provided by REST.
Definition: InfoType.php:16
Info model to contain general error and return values.
Definition: Info.php:19