File indexing completed on 2024-12-15 03:45:05
0001 <?php 0002 /* 0003 SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org> 0004 0005 SPDX-License-Identifier: MIT 0006 */ 0007 0008 require_once('datastore.php'); 0009 require_once('product.php'); 0010 require_once('restexception.php'); 0011 require_once('utils.php'); 0012 require_once('sample.php'); 0013 require_once('survey.php'); 0014 0015 /** Command handler for the data receiver. */ 0016 class Receiver 0017 { 0018 0019 /** Dummy command for probing for redirects. */ 0020 function get_submit($productName) 0021 { 0022 } 0023 0024 /** Data submission command. */ 0025 function post_submit($productName) 0026 { 0027 // load JSON data sent by the client 0028 $rawPostData = file_get_contents('php://input'); 0029 0030 // look up product 0031 $db = new DataStore(); 0032 $db->beginTransaction(); 0033 $product = Product::productByName($db, $productName); 0034 if (is_null($product)) 0035 throw new RESTException('Unknown product.', 404); 0036 0037 Sample::insert($db, $rawPostData, $product); 0038 0039 // read survey from db 0040 $responseData = array(); 0041 $surveys = Survey::activeSurveysForProduct($db, $product); 0042 $responseData['surveys'] = $surveys; 0043 $db->commit(); 0044 0045 header('Content-Type: text/json'); 0046 echo(json_encode($responseData)); 0047 } 0048 0049 } 0050 0051 ?>