ssp setting a parameter from a column in array

ssp setting a parameter from a column in array

bbrindzabbrindza Posts: 308Questions: 70Answers: 1

I need to set a variable based on the the value of column in a ssp script , but for some reason it is not returning the value.


$outOfOffice = ''; $columns[] = array( 'db' => 'OUT_OF_OFFICE', 'dt' => 'out_of_office', 'formatter' => function($d, $row) use ($outOfOffice) { $outOfOffice = trim($row['OUT_OF_OFFICE']); return trim($row['OUT_OF_OFFICE']); } ); if($outOfOffice == 'Vacation Day'){ $columns[] = array( 'db' => 'TOTAL_HOURS_SECONDS', 'dt' => 'total_vacation_hours', 'formatter' => function($d, $row){ $totalVacationhours = floor($row['TOTAL_HOURS_SECONDS'] / 3600); return $totalVacationhours; } ); }else if ($outOfOffice == 'Paid Leave Vacation'){ $columns[] = array( 'db' => 'TOTAL_HOURS_SECONDS', 'dt' => 'total_paid_leave_vacation_hours', 'formatter' => function($d, $row){ $totalPaidLeaveVacationHours = floor($row['TOTAL_HOURS_SECONDS'] / 3600); return $totalPaidLeaveVacationHours; } ); }

Replies

  • bbrindzabbrindza Posts: 308Questions: 70Answers: 1

    I figured it out . Unless there is a better way of doing this.

      $columns[] = array( 'db' => 'TOTAL_HOURS_SECONDS', 'dt' => 'total_vacation_hours',
           'formatter' => function($d, $row){
          
                if(trim($row['OUT_OF_OFFICE']) == 'Vacation Day'){
                         $totalVacationhours   = floor($row['TOTAL_HOURS_SECONDS'] / 3600);
                 }else{     
                         $totalVacationhours   = 0;
                 }
                    return   $totalVacationhours;
           }
      );
     
     $columns[] = array( 'db' => 'TOTAL_HOURS_SECONDS', 'dt' => 'total_paid_leave_vacation_hours',
         'formatter' => function($d, $row){
         
             if(trim($row['OUT_OF_OFFICE']) == 'Paid Leave Vacation'){
                 $totalPaidLeaveVacationHours   = floor($row['TOTAL_HOURS_SECONDS'] / 3600);
             }else{
                 $totalPaidLeaveVacationHours   = 0;
             }
                return   $totalPaidLeaveVacationHours;
         }
    );
    
  • allanallan Posts: 62,484Questions: 1Answers: 10,262 Site admin

    That looks good to me. Personally I'd use a ternary to shorten the code a little:

    function($d, $row){
      return trim($row['OUT_OF_OFFICE']) == 'Vacation Day'
        ? floor($row['TOTAL_HOURS_SECONDS'] / 3600)
        : 0;
      );
    

    But that's just a code style thing.

    Allan

Sign In or Register to comment.