KoolReport's Forum

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

Error when query (mongodb) return no data #779

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

salah karouia commented on Apr 4, 2019

Hi,

We have two problems to resolve:

1 - How to handle condition with nested in find action 'organization.id' => $id 2 - In the example below when query return no result, the CopyColumn process and Custom process generate an error (Not find index)

$positions_source = $this->src("mongodb")
        ->query([
          "collection" => "positions",
          "find" => [
            'vrn' => $this->params['vrn'],
            'organization.id' => $id,
            'acquired_at' => [
                '$exists' => true,
                '$gte' => new \MongoDB\BSON\UTCDateTime($start * 1000),
                '$lte' => new \MongoDB\BSON\UTCDateTime($end * 1000)
            ]
          ]
        ])->pipe(new CopyColumn(array(
            "date"=>"acquired_at"
        )))->pipe(new Custom(function($row){
           $row["date"] = $row["acquired_at"]->toDateTime()->format('H:m:s');
            return $row;
        }));
KoolReport commented on Apr 6, 2019

Sorry for my late reply. I have forwarded your issue to dev.team to see if they have solution for this.

salah karouia commented on Apr 6, 2019

Thank you for your replay, We are waiting for your

David Winterburn commented on Apr 9, 2019

Hi Salah,

  1. I think you need to put id to an input in a form and submit it. Then in the report you could retrieve by $_POST["id"] or $_GET["id"]. Finally put the retrieved id to the query.

  2. Please open the file processes/CopyColumn.php and replace the following lines:

$metaData["columns"][$copy] = $metaData["columns"][$original];
...
$data[$copy] = $data[$original];

with:

    if (isset($metaData["columns"][$original]))
                $metaData["columns"][$copy] = $metaData["columns"][$original];
...
    if (isset($data[$original]))
                $data[$copy] = $data[$original];

In your code for the Custom process, please replace:

$row["date"] = $row["acquired_at"]->toDateTime()->format('H:m:s');

with:

if (isset($row["acquired_at"]))
    $row["date"] = $row["acquired_at"]->toDateTime()->format('H:m:s');

Thanks!

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