Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 72a438f3

Přidáno uživatelem Jakub Vašta před asi 4 roky(ů)

+ location persistence
+ last available collections
+ available collections code rework

Zobrazit rozdíly:

website/src/OpenDataManager.php
3 3
namespace App\OpenData;
4 4

  
5 5
use MongoDB\Driver\Query;
6
use MongoDB\Driver\Command;
7 6
use MongoDB\Driver\Manager;
8 7

  
9 8
class OpenDataManager implements IOpenDataManager {
......
54 53
    }
55 54

  
56 55
    public function isCollectionAvailable($name, $date) {
57
        $command = new Command(['listCollections' => 1, 'filter' => ['name' => $name.$date]]);
58
        $result = $this->manager->executeCommand('open-data-db', $command)->toArray();
56
        $result = $this->manager->executeQuery('open-data-db.'.$name, new Query(['date' => $date], []));
59 57

  
60
        return !empty($result);
58
        return !empty($result->toArray());
61 59
    }
62 60

  
63 61
    public function getDatesWithAvailableCollection() {
64
        $command = new Command(['listCollections' => 1]);
65
        $result = $this->manager->executeCommand('open-data-db', $command)->toArray();
62
        $available = $this->getAvailableCollections();
63
        $result = [];
64

  
65
        foreach ($available as $key => $value) {
66
            $dates = $this->manager->executeQuery('open-data-db.'.$value['key-name'], new Query([], ['projection' => ['date' => true, '_id' => false]]));
67
            $dates->setTypeMap(['root' => 'array']);
68
            $result = array_merge($result, array_map(function ($item) {return $item['date']; }, $dates->toArray()));
69
        }
70

  
71
        return array_values(array_unique($result));
72
    }
73

  
74
    public function getLastAvailableCollections() {
75
        $available = $this->getAvailableCollections();
76
        $result = [];
77

  
78
        foreach ($available as $key => $value) {
79
            $date = $this->manager->executeQuery('open-data-db.'.$value['key-name'], new Query([], ['sort' => ['date' => -1], 'limit' => 1, 'projection' => ['date' => true, '_id' => false]]));
80
            $date->setTypeMap(['root' => 'array']);
66 81

  
67
        $dates = [];
68
        foreach ($result as $value) {
69
            if (preg_match('/\\d{4}-\\d{2}-\\d{2}/', $value->name)) {
70
                array_push($dates, substr($value->name, -10));
82
            $date_array = $date->toArray();
83
            if (!empty($date_array)) {
84
                $result[$value['key-name']] = $date_array[0]['date'];
71 85
            }
72 86
        }
73 87

  
74
        return array_values(array_unique($dates));
88
        return $result;
75 89
    }
76 90

  
77 91
    public function getMaxCollectionNumberAtDay($name, $date) {

Také k dispozici: Unified diff