1
|
<?php
|
2
|
|
3
|
namespace App\OpenData;
|
4
|
|
5
|
use MongoDB\Driver\Query;
|
6
|
use MongoDB\Driver\Manager;
|
7
|
|
8
|
class OpenDataManager implements IOpenDataManager {
|
9
|
private $manager;
|
10
|
|
11
|
public function __construct() {
|
12
|
$this->manager = new Manager(
|
13
|
$_ENV['DATABASE_CONNECTION_STRING']
|
14
|
);
|
15
|
}
|
16
|
|
17
|
public function getCollectionDataByName($name, $date, $hour) {
|
18
|
$openData = $this->manager->executeQuery('open-data-db.'.$name.$date, new Query(['date' => $date.$hour], []));
|
19
|
|
20
|
$openData->setTypeMap([
|
21
|
'array' => 'array',
|
22
|
'document' => 'array',
|
23
|
'root' => 'array',
|
24
|
]);
|
25
|
|
26
|
return $openData->toArray();
|
27
|
}
|
28
|
|
29
|
public function getAvailableCollections() {
|
30
|
$openData = $this->manager->executeQuery('open-data-db.DATASETS', new Query([], ['projection' => ['name' => 1, '_id' => 0]]));
|
31
|
|
32
|
$openData->setTypeMap([
|
33
|
'array' => 'array',
|
34
|
'document' => 'array',
|
35
|
'root' => 'array',
|
36
|
]);
|
37
|
|
38
|
return $openData->toArray();
|
39
|
}
|
40
|
|
41
|
public function getAvailableCollectionsByDay($date) {
|
42
|
$availableInDate = [];
|
43
|
$available = $this->getAvailableCollections();
|
44
|
$index = 0;
|
45
|
foreach ($available as $key => $value) {
|
46
|
$openData = $this->manager->executeQuery('open-data-db.'.$value['name'].$date, new Query([], []));
|
47
|
|
48
|
$openData->setTypeMap([
|
49
|
'array' => 'array',
|
50
|
'document' => 'array',
|
51
|
'root' => 'array',
|
52
|
]);
|
53
|
|
54
|
if (false == empty($openData->toArray())) {
|
55
|
$availableInDate[$value['name']] = $index++;
|
56
|
}
|
57
|
}
|
58
|
|
59
|
return $availableInDate;
|
60
|
}
|
61
|
}
|