KoolReport's Forum

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

Use $_SESSION as function arg #289

Open arthur opened this topic on on May 18, 2018 - 4 comments

arthur commented on May 18, 2018

Hi,

I want to do this custom process, based on $data and also on $_SESSION :

->pipe(new CalculatedColumn(array(
            "Challenge"=>function($data){	

              if ($_SESSION['Username'] !='VALIFAX' && $data["ACC"] != 'VALIFAX'){

                    if ($data["Prospect_Client"]=='client' ){
                        return  ( ($data["Marge_FAS_Déclarée"] + 12 * $data["MARGE_DELTA_REC"])*1.1 ); 
                    }
                    else { 
                        return ( ($data["Marge_FAS_Déclarée"] + 12 * $data["MARGE_DELTA_REC"]) ) ; 

                    }

               } 
               else {
                
                    if ($data["Prospect_Client"]=='client' ){
                        return  ( 2.5 * ($data["Marge_FAS_Déclarée"] + 12 * $data["MARGE_DELTA_REC"])*1.1 ); 
                    }
                    else { 
                        return ( 2.5 * ($data["Marge_FAS_Déclarée"] + 12 * $data["MARGE_DELTA_REC"]) ) ; 
                    }
               }
            }   
        )))

Tthe $_SESSION doesnt work inside the function (but it works outside). And when I try to insert in the function arg, it doesn't work either. How could I do ?

Thanks a lot

KoolReport commented on May 18, 2018

$_SESSION can be used anywhere, it is global variables. However, make sure that the parameters inside session is available like the "username". You can use isset() function to check first before use.

arthur commented on May 19, 2018

The $_SESSION is set because I use it before in my code which is. It works with filter, but strangely nothing happened. What's wrong ?

$this->src('sales')


        ->pipe(new Filter(array(
            array("Ccial","=",$_SESSION['Username']),
            'or',
            array("ACC","=",$_SESSION['Username']),
        )))

->pipe(new Map(array(
      '{value}' => function($row, $metaData) {
        if ($row['Société'] != null && trim($row['Société']) != '' && trim($row['Société']) != '-')
          return array($row);
      },
    )))


->pipe(new Filter(array(
         array("Ccial","!=",null),
            array("Société","!=",null),
 )))


->pipe(new CalculatedColumn(array(
            "PO"=>function($data){

                        return  ($data["Marge_FAS_Déclarée"] + 12 * $data["MARGE_DELTA_REC"]); 
                   
            }
        )))

->pipe(new CalculatedColumn(array(
            "Challenge"=>function($data){	

              if ($_SESSION['Username'] !='VALIFAX' && $data["ACC"]!='VALIFAX' ){

                    if ($data["Prospect_Client"]=='client' ){
                        return  ( ($data["Marge_FAS_Déclarée"] + 12 * $data["MARGE_DELTA_REC"])*1.1 ); 
                    }
                    else { 
                        return ( ($data["Marge_FAS_Déclarée"] + 12 * $data["MARGE_DELTA_REC"]) ) ; 

                    }

               } 
               else {
                
                    if ($data["Prospect_Client"]=='client' ){
                        return  ( 2.5 * ($data["Marge_FAS_Déclarée"] + 12 * $data["MARGE_DELTA_REC"])*1.1 ); 
                    }
                    else { 
                        return ( 2.5 * ($data["Marge_FAS_Déclarée"] + 12 * $data["MARGE_DELTA_REC"]) ) ; 
                    }
               }
            }   
        )))

        ->pipe(new Filter($filter_args))

        
        ->pipe($this->dataStore('commandes'));
arthur commented on May 22, 2018

Hi, I did some tests and the $_SESSION variable seems to doesn't work inside

->pipe(new CalculatedColumn(array(
            "Challenge"=>function($data){	
...

}
KoolReport commented on May 23, 2018

Problem is solved in topic 292

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
solved

None