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('sample.php'); 0011 require_once('survey.php'); 0012 require_once('utils.php'); 0013 0014 /** Command handler for the analytics interface. */ 0015 class Analytics 0016 { 0017 0018 /** Schema check and update. */ 0019 public function get_check_schema() 0020 { 0021 // check PHP version 0022 if (PHP_VERSION_ID < 50400) 0023 throw new RESTException('Minium required PHP version is 5.4, found ' . PHP_VERSION, 500); 0024 0025 // check database layout 0026 $db = new DataStore(); 0027 $res = $db->checkSchema(); 0028 $res['protocolVersion'] = 2; 0029 0030 header('Content-Type: text/json'); 0031 echo(json_encode($res)); 0032 } 0033 0034 /** List all products. */ 0035 public function get_products() 0036 { 0037 $db = new DataStore(); 0038 $products = Product::allProducts($db); 0039 $json = json_encode($products); 0040 0041 header('Content-Type: text/json'); 0042 echo($json); 0043 } 0044 0045 /** List data for a product. */ 0046 public function get_data($productName) 0047 { 0048 $db = new DataStore(); 0049 $product = Product::productByName($db, $productName); 0050 if (is_null($product)) 0051 throw new RESTException('Product not found.', 404); 0052 0053 header('Content-Type: text/json'); 0054 Sample::echoDataAsJson($db, $product); 0055 } 0056 0057 /** List all surveys for a product. */ 0058 public function get_surveys($productName) 0059 { 0060 if ($productName == "") 0061 Utils::httpError(400, "No product id specified."); 0062 0063 $db = new DataStore(); 0064 $surveys = Survey::surveysForProduct($db, $productName); 0065 0066 header('Content-Type: text/json'); 0067 echo(json_encode($surveys)); 0068 } 0069 0070 } 0071 0072 ?>