<?php
namespace App\Controllers;
use Config\Services;

class Getyearsbydetails extends BaseController{
    private $dbHandle;

    public function index(){
        $this->dbHandle   = \Config\Database::connect();
        $dataToReturn = [];

        $makecode = $this->request->getVar('make');
        $modelcode = $this->request->getVar('model');
        $engdesc = $this->request->getVar('engdesc');
        
        $R = $this->dbHandle->query("select min(`genfr`) as 'yearA', max(`gento`) as 'yearB' from `3V_supplementary` where `makecode` = '{$makecode}' and `modelcode` = '{$modelcode}' and `engdesc` = '{$engdesc}'");
        $A = $R->getResultArray();
        if(sizeof($A)>0){
            $dataToReturn['status'] = 0;
            for($i = $A[0]['yearA']; $i <= $A[0]['yearB']; $i++){
                $dataToReturn['load'][] = ["year" => $i];
            }
        }else{
            $dataToReturn['status'] = 1;
        }

        return json_encode($dataToReturn, JSON_HEX_APOS | JSON_HEX_QUOT);
    }
}