aboutsummaryrefslogtreecommitdiff
path: root/lib/models/OERDownloadcounter.php
blob: fa603a380a5c170a8dd2b0fe3df79fade5bc9226 (plain)
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
<?php
class OERDownloadcounter extends SimpleORMap
{
    protected static function configure($config = [])
    {
        $config['db_table'] = 'oer_downloadcounter';
        parent::configure($config);
    }

    public static function addCounter($material_id)
    {
        $counter = new self();
        $counter['material_id'] = $material_id;
        if (Config::get()->oer_GEOLOCATOR_API) {
            list($url, $lon, $lat) = explode(" ", Config::get()->oer_GEOLOCATOR_API);
            $output = json_decode(file_get_contents(sprintf($url, $_SERVER['REMOTE_ADDR'])), true);
            if (isset($output[$lon])) {
                $counter['longitude'] = $output[$lon];
            }
            if (isset($output[$lat])) {
                $counter['latitude'] = $output[$lat];
            }
        }
        $counter->store();
        return $counter;
    }
}