survey/auswertung.php

96 lines
3.4 KiB
PHP

<?php
use ArangoDBClient\CollectionHandler;
use ArangoDBClient\Connection;
use ArangoDBClient\ConnectionOptions;
use ArangoDBClient\DocumentHandler;
use ArangoDBClient\Statement;
use ArangoDBClient\UpdatePolicy;
include "config.php";
include "Seite.php";
require "vendor/autoload.php";
$connectionOptions = array(
// server endpoint to connect to
//ConnectionOptions::OPTION_ENDPOINT => 'tcp://10.16.17.154:8529',
ConnectionOptions::OPTION_ENDPOINT => 'tcp://' . $server . ':8529',
// authorization type to use (currently supported: 'Basic')
ConnectionOptions::OPTION_AUTH_TYPE => 'Basic',
// user for basic authorization
ConnectionOptions::OPTION_AUTH_USER => $dbuser,
// password for basic authorization
ConnectionOptions::OPTION_AUTH_PASSWD => $passwd,
// connection persistence on server. can use either 'Close' (one-time connections) or 'Keep-Alive' (re-used connections)
ConnectionOptions::OPTION_CONNECTION => 'Close',
// connect timeout in seconds
ConnectionOptions::OPTION_TIMEOUT => 3,
// whether or not to reconnect when a keep-alive connection has timed out on server
ConnectionOptions::OPTION_RECONNECT => true,
// optionally create new collections when inserting documents
ConnectionOptions::OPTION_CREATE => true,
// optionally create new collections when inserting documents
ConnectionOptions::OPTION_UPDATE_POLICY => UpdatePolicy::LAST,
ConnectionOptions::OPTION_DATABASE => $database,
);
// open connection
$connection = new Connection($connectionOptions);
$collectionHandler = new CollectionHandler($connection);
$documentHandler = new DocumentHandler($connection);
if (isset($_GET['pwd'])){
if ($_GET['pwd'] == 123){
$statement = new Statement($connection, [
'query' => 'for user in users
let name = (
for v, e, p in 1..1 outbound user answered
filter v._key==\'29551\'
return e.answer
)
let answers = (
for v, e, p in 1..1 outbound user answered
filter v.type==\'personal\' or v.type==\'aux\'
return {qkey: v._key, question: v.question, answer: e.answer}
)
return {user: user._key, name: name[0], answers: answers}',
'count' => true,
'batchSize' => 1000,
'bindVars' => null,
'sanitize' => true,
]
);
$cursor = $statement->execute();
$users = array();
foreach ($cursor->getAll() as $doc) {
$users[] = json_decode(json_encode($doc));
}
$seite = new \goeranh\Seite('Antworten');
$inhalt = '
<style>
table{
border-collapse: collapse;
}
tr{
border-collapse: collapse;
}
td{
border-bottom: 1px solid black;
border-collapse: collapse;
}
</style>
<table>';
foreach ($users as $user){
$inhalt .= '<tr><td colspan="2"><h2>'.$user->name.'</h2></td></tr>';
foreach ($user->answers as $answers){
$inhalt .= '<tr><td>'.$answers->question.'</td><td>'.$answers->answer.'</td></tr>';
}
}
$inhalt .= '</table>';
$seite->addInhalt($inhalt);
$seite->augeben();
}
}