Ejemplo n.º 1
0
<?php

require '../loader.php';
?>
{
    "Data" : [
<?php 
$language_items = array();
$TYPES = array(LanguageItem::SUBSTANTIV, LanguageItem::ADJEKTIV, LanguageItem::SUBSTANTIV, LanguageItem::SUBSTANTIV, LanguageItem::VERB, LanguageItem::SUBSTANTIV, LanguageItem::ADJEKTIV, LanguageItem::SUBSTANTIV, LanguageItem::VERB, LanguageItem::SUBSTANTIV);
for ($i = 0; $i < 10; $i++) {
    $language_items[] = LanguageItem::random($_GET['Scope'], null, $TYPES[$i]);
}
$first = true;
foreach ($language_items as $index => $word) {
    if ($first) {
        $first = false;
    } else {
        echo ",";
    }
    ?>
        { "<?php 
    echo $word->get_ID();
    ?>
" : "<?php 
    echo $word->get_text();
    ?>
" }
    <?php 
}
?>
    ],
Ejemplo n.º 2
0
require '../loader.php';
?>

{
    "Data" : [
        <?php 
$language_items = array();
if (isset($_GET['CompleteResponse'])) {
    $response = Response::random($_GET['Scope']);
    $response_items = ResponseItem::all($response->get_ID());
    foreach ($response_items as $response_item) {
        $language_items[] = LanguageItem::load($response_item->get_LanguageItemId());
    }
} else {
    for ($i = isset($_GET['Start']) ? $_GET['Start'] : 0; $i < $_GET['End']; $i++) {
        $language_items[] = LanguageItem::random($_GET['Scope'], $i);
    }
}
$first = true;
foreach ($language_items as $word) {
    if ($first) {
        $first = false;
    } else {
        echo ",";
    }
    ?>
                        { "<?php 
    echo $word->get_ID();
    ?>
" : "<?php 
    echo $word->get_text();
<?php

include '../loader.php';
$responses = Response::loop($_GET['Scope']);
$stats = array();
foreach ($responses as $response) {
    $items = $response->get_items();
    $key = "";
    foreach ($items as $item) {
        $key .= $item->get_LanguageItemId() . "-";
    }
    if (!array_key_exists($key, $stats)) {
        $stats[$key] = array('rating' => 0, 'count' => 0, 'words' => array());
        foreach ($items as $item) {
            $stats[$key]['words'][] = LanguageItem::load($item->get_LanguageItemId())->get_text();
        }
    }
    $stats[$key]['rating'] = ($stats[$key]['rating'] * $stats[$key]['count'] + $response->get_rating()) / ($stats[$key]['count'] + 1);
    $stats[$key]['count'] += 1;
}
$first = true;
?>
{
    "Ratings" : [
        <?php 
foreach ($stats as $stat) {
    if ($first) {
        $first = false;
    } else {
        echo ",";
    }
<?php

function fail()
{
    return '{ "success" : false }';
}
require '../loader.php';
if (!$_POST['Data']) {
    return fail();
}
$data = json_decode(str_replace('\\"', '"', $_POST['Data']), true);
$response = new Response($data['Rating'], $data['Scope']);
if (!$response->save()) {
    return fail();
}
foreach ($data['Data'] as $language_item) {
    $language_item['Text'] = trim($language_item['Text']);
    $new_item = new LanguageItem($language_item['Text'], $language_item['Scope'], $language_item['Position'], $language_item['Type']);
    if (!$new_item->checkExistence() && !$new_item->save()) {
        return fail();
    }
    $response_item = new ResponseItem($response->get_ID(), $new_item->get_ID());
    if (!$response_item->save()) {
        return fail();
    }
}
?>
{
    "success" : true
}