KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Undefined offset: 0 When the cursor is empty #774

Open salah karouia opened this topic on on Apr 2, 2019 - 2 comments

salah karouia commented on Apr 2, 2019

Hi,

How we can avoid "Undefined offset: 0" error When the cursor is empty in koolreport/packages/mongodb/MongoDataSource.php in Line 106

Please find below our piece of code `

    $start = strtotime(date($this->params['dateRange'][0]));
    $end = strtotime(date($this->params['dateRange'][1]));

    $stops_source = $this->src("mongodb")
    ->query([
      "collection" => "stops",
      "find" => [
        'organization_id' => '3',
        'place_id' => [
          '$exists' => true,
          '$not' => ['$type' => 10]
        ],
        'duration' => [
          '$exists' => true,
          '$not' => ['$type' => 10]
        ],
        'started_at' => [
            '$exists' => true,
          '$gte' => new \MongoDB\BSON\UTCDateTime($start * 1000),
          '$lte' => new \MongoDB\BSON\UTCDateTime($end * 1000)
        ]
      ],
    ])
    ->pipe(new ColumnRename(array(
        "_id"=>"stopid",
    )))
    ->pipe(new Group(array(
        "by"=>array("place_id"),
        "count"=>array("stopid"),
        "avg"=>array("duration"),
    )))
    ->saveTo($s1)
    ->pipe($this->dataStore("stops"));

David Winterburn commented on Apr 3, 2019

Hi Salah,

Please open the file koolreport/packages/mongodb/MongoDataSource.php and replace this line:

$firstRow = $data[0];

with this:

$firstRow = Utility::get($data, 0, []);

Please try it and let us know if there's any problem remained. Thanks!

salah karouia commented on Apr 3, 2019

Thanks a lot it's resolve the problem

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None