Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
12 / 12
AdservingData
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
12 / 12
 getNearPoint
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
11 / 11
 serializeDate
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
1<?php
2
3namespace Qmp\Laravel\Adserving\Models;
4
5class AdservingData extends \Moloquent
6{
7    protected $connection = 'adserving_mongo';
8    protected $collection = 'adserving_data';
9
10
11    public static function getNearPoint($latitude, $longitude, $visualId, $index)
12    {
13        $data = self::raw(function($collection) use ($latitude, $longitude, $visualId, $index) {
14            return $collection->aggregate([
15                [
16                    '$geoNear'    => [
17                        'near'   => [
18                            'type' => 'Point',
19                            'coordinates' => [ (float) $longitude , (float) $latitude ]
20                        ],
21                        'key' => 'location',
22                        'distanceField' => 'distance',
23                        'distanceMultiplier' => 0.001,
24                        'query' => [
25                            'id_visual' => (int) $visualId
26                        ]
27                    ]
28                ],
29                [
30                    '$limit' => (int) $index
31                ]
32            ]);
33        });
34
35        return $data->last();
36    }
37
38    protected $fillable = ['id_visual', 'link_img', 'link_url', 'location'];
39
40    /**
41     * Prepare a date for array / JSON serialization.
42     *
43     * @param  \DateTimeInterface  $date
44     * @return string
45     */
46    protected function serializeDate(\DateTimeInterface $date)
47    {
48        return $date->format('Y-m-d H:i:s');
49    }
50
51}