KoolReport's Forum

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

Array mapping #2701

Closed 50Grosh opened this topic on on May 30, 2022 - 1 comments

50Grosh commented on May 30, 2022

Hello Team :)

I want to use mapping (for the first time)

and I try to go from this

$dateBefore = ...
$dateAfter = ...
$selected_group = ...
 $reportData = EventItems::getInstance()->myReport($dateBefore, $dateAfter, $selected_group);

// $reportData 
array(12) {
  [0] => array(10) {
    ["id"] => string(1)"1"
    ["point"] => string(2)"1a" 
    ["text"] =>  string(2)"1a" 
    ["price"] =>  string(2)"1a" 
    ["ile"] =>  string(2)"1a" 
    ["koszt"] =>  string(2)"1a" 
    ["umowa"] =>  string(2)"1a" 
    ["iler"] =>  string(2)"1a" 
    ["kosztr"] =>  string(2)"1a" 
    ["umowar"] =>  string(2)"1a" 
  }     
[1] => array(10) {
    ["id"] => string(1)"2" 
    ["point"] => string(2)"1b" 
    ["text"] => string(2)"1b" 
    ["price"] => string(2)"1b" 
    ["ile"] => string(2)"1b" 
    ["koszt"] => string(2)"1b" 
    ["umowa"] => string(2)"1b" 
    ["iler"] => string(2)"1b" 
    ["kosztr"] => string(2)"1b" 
    ["umowar"] => string(2)"1b" 
  } 
[2] => array(10) {
    ["id"] => string(1)"2" 
    ["point"] => string(2)"1b" 
    ["text"] => string(2)"1b" 
    ["price"] => NULL
    ["ile"] => string(2)"1b" 
    ["koszt"] => NULL
    ["umowa"] => NULL
    ["iler"] => NULL
    ["kosztr"] => string(2)"1b" 
    ["umowar"] => NULL
  }
}

to this

and I try to make it using Maping like this


$reportData ->pipe(new Map(array(
         '{value}' => function($row, $metaData) {
            return array($row);
        },
        '{meta}' => function($metaData) {
            $metaData['columns']['text'] = array(
                'label' => 'test',
            );
            $metaData['columns']['price'] = array(
                'label' => 'price',
                'type' => 'number',
            );
            $metaData['columns']['ile'] = array(
                'label' => 'ile',
                'type' => 'number',
            );
            $metaData['columns']['koszt'] = array(
                'label' => 'koszt',
                'type' => 'number',
            );
            $metaData['columns']['umowa'] = array(
                'label' => 'koszt',
                'type' => 'number',
            );
            $metaData['columns']['iler'] = array(
                'label' => 'iler',
                'type' => 'number',
            );
            $metaData['columns']['kosztr'] = array(
                'label' => 'kosztr',
                'type' => 'number',
            );
            $metaData['columns']['umowar'] = array(
                'label' => 'umowar',
                'type' => 'number',
            );
            return $metaData;
        },
    )));

and i get error "Call to a member function pipe() on array".

I guess i understand it in wrong way.

( Meaby there is better way to make it ? )

Best Regards

50Grosh commented on May 30, 2022

My mistake :) its working :)

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
help needed

None