<?php
namespace App\Models;

use CodeIgniter\Model;

class userTrips extends Model{
    protected $db;
    public $con_name = 'dbFloat';

    public function __construct()
    {
        parent::__construct();
        $this->db = \Config\Database::connect($this->con_name);
    }

    private function logArray3($in){
        if (!is_array($in)){
            log_message('critical', "NOT ARRAY => $in \n");
            return;
        }
        foreach($in as  $key => $value){
$vl='';
            if (is_array($value)){
                foreach($value as  $kk => $vv){
                    $vl .= "$kk => $vv \n";
                }
            }
            else{
                $vl=$value;
            }

           log_message('critical', "$key=>".$vl);
        }


    }


    public function savvyLoadSavedTrips($in,  &$out) {

        $ret = 0;
        $member_id = $in['member_id'];
        $out["total_record"] = 0;
        $out['session_valid'] = '';
        $out['internal_return'] = PHP_API_OK;
         
            $saveTrips = $this->db->query("SELECT * FROM members_trips WHERE member_id = $member_id AND status  = 1 ORDER BY trip_date DESC");
    
            if ($saveTrips != null) {
                $out["total_record"] = $saveTrips->getNumRows();
                $ic = 0;
                $this->logArray3("card lines total_record =>   ".$saveTrips->getNumRows());

                foreach ($saveTrips->getResultArray() as $f) {
                   // $this->logArray3("Saved Trips total =>   ".$ic);
                    $suffix = str_pad($ic, 5, '0', STR_PAD_LEFT);
                    $out['trip_name_' . $suffix] = $f['trip_name'];
                    $out['trip_id_' . $suffix] = $f['id'];
                    $out['from_' . $suffix] = $f['trip_from'];
                    $out['to_' . $suffix] = $f['trip_to'];
                    $out['date_' . $suffix] = $f['trip_date'];
                    $out['country_' . $suffix] = $f['country'];
                    $out['color_' . $suffix] = $f['color'];
                }

            }
        return $ret;
    }



}