forked from cultuurnet/udb3-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.php
59 lines (47 loc) · 1.75 KB
/
debug.php
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
<?php
/**
* @file
*/
use \Symfony\Component\HttpFoundation\JsonResponse;
use \Symfony\Component\HttpFoundation\Request;
use \Silex\Application;
use \CultuurNet\UDB3\UDB2\EntryAPIFactory;
use \CultuurNet\Auth\User;
/** @var Application $app */
$app['udb2_entry_api_factory'] = $app->share(
function ($app) {
$uitidConfig = $app['config']['uitid'];
$baseUrl =
$uitidConfig['base_url'] .
$uitidConfig['apis']['entry'];
return new \CultuurNet\UDB3\UDB2\EntryAPIFactory(
new \CultuurNet\UDB3\UDB2\Consumer(
$baseUrl,
$app['uitid_consumer_credentials']
)
);
}
);
$app->get(
'api/1.0/entry/search',
function (Request $request, Application $app) {
/** @var EntryAPIFactory $entryAPIFactory */
$entryAPIFactory = $app['udb2_entry_api_factory'];
/** @var \Symfony\Component\HttpFoundation\Session\Session $session */
$session = $app['session'];
/** @var User $minimalUserData */
$minimalUserData = $session->get('culturefeed_user');
$tokenCredentials = $minimalUserData->getTokenCredentials();
$entryAPI = $entryAPIFactory->withTokenCredentials($tokenCredentials);
$query = $request->query->get('query', '');
$page = $request->query->get('page', 1);
$pageLength = $request->query->get('pagelength', 50);
$results = $entryAPI->getEvents($query, $page, $pageLength);
$content = array();
/** @var CultureFeed_Cdb_List_Item $item */
foreach ($results as $item) {
$content[] = $app['iri_generator']->iri($item->getCdbId());
}
return JsonResponse::create()->setData($content);
}
)->before($checkAuthenticated);