1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
<?php
namespace App\Controller;
use Gedcomx\Conclusion\Event;
use Gedcomx\Rs\Client\Rel;
use GeniBase\Common\Statistic;
use GeniBase\Storager\StoragerFactory;
use Silex\Application;
use Symfony\Bridge\Twig\Extension\WebLinkExtension;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class EventsController extends BaseController
{
public function statistic(Application $app)
{
$t_cons = $app['gb.db']->getTableName('conclusions');
$t_events = $app['gb.db']->getTableName('events');
$query = "SELECT COUNT(*) AS events, MAX(att_modified) AS events_modified FROM $t_events AS ev " .
"LEFT JOIN $t_cons AS cs ON ( ev.id = cs.id )";
$result = $app['db']->fetchAssoc($query);
if (false !== $result) {
$result = new Statistic($result);
}
return $result;
}
public static function bindApiRoutes($app, $base)
{
$app->get($base, "events.controller:statistic");
$app->get($base.'/{id}', "events.controller:getOne");
}
public function getOne(Application $app, Request $request, $id)
{
$gedcomx = StoragerFactory::newStorager($app['gb.db'], Event::class)
->loadGedcomx(
[
'id' => $id,
]
);
if (false === $gedcomx) {
return new Response(null, 204);
}
if (class_exists(WebLinkExtension::class)) {
(new WebLinkExtension($app['request_stack']))->link($request->getUri(), Rel::DESCRIPTION);
}
return $gedcomx;
}
}