<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class ReportAssignmentCtrl extends MY_Controller {

  public function __construct($config = 'rest')
  {
    header('Access-Control-Allow-Origin: *');
    header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Authorization, Access-Control-Request-Method");
    header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
    header("Allow: GET, POST, OPTIONS, PUT, DELETE");
    header('content-type: application/json; charset=utf-8');
    $method = $_SERVER['REQUEST_METHOD'];
    if($method == "OPTIONS") {
        die();
    }
      parent::__construct();
  }
  public function _remap($met,$parametros = array()){

  $method = $_SERVER['REQUEST_METHOD'];

 switch ($met)  
 { case 'Buscar1':
     $this->Buscar1($parametros); 
     break;
   case 'Buscar2': 
     $this->Buscar2($parametros);   
   break;
   case 'Buscar3': 
     $this->Buscar3($parametros); 
   break; 
   case 'Buscar4': 
    $this->Buscar4($parametros);
   break; 
   case 'Buscar5': 
    $this->Buscar5($parametros);
   break; 
   case "MetaData":
    $this->MetaData($parametros);
   break;

 }
 if($met ==="index"){

  switch ($method)  
  { case 'GET': 
      $this->Search($parametros);
    break;
   default: 
   echo json_encode( "Error" );
   break; 
  }
}


 }
    



// aqui viene los metodos de buscar



private function Search($Arr =array() ){
  $Asignacion =array();
  switch (count($Arr)) 
  { case 0:
    $Asignacion= $this->ReportAssignmentModels->getReportAssignment();
    break;
    case 1: 
      $Asignacion = $this->ReportAssignmentModels->getReportAssignment($Arr[0]);
    break;
    case 2: 
      $Asignacion = $this->ReportAssignmentModels->getReportAssignmentLimite($Arr[0],$Arr[1]);
    break; 
    case 4: 
      $Asignacion = $this->ReportAssignmentModels->getReportAssignmentLimiteOrden($Arr[0],$Arr[1],$Arr[2],$Arr[3]);
    break; 
    case 5: 
      $Asignacion = $this->ReportAssignmentModels->getReportAssignmentLimiteOrdenColumnas($Arr[0],$Arr[1],$Arr[2],$Arr[3],urldecode($Arr[4]));
   break; 
   default: 
   echo json_encode( "Error" );
   break; 
  }
  header('Content-type: application/json; charset=utf-8');
  echo json_encode($Asignacion); 
}

private function Buscar1 ($Arr = array()){
  $Asignacion =array();
  switch (count($Arr)) 
  {
    case 1: 
      $Asignacion = $this->ReportAssignmentModels->getReportAssignmentFiltro(urldecode($Arr[0]));
    break;
    case 3: 
      $Asignacion = $this->ReportAssignmentModels->getReportAssignmentFiltroLimite(urldecode($Arr[0]),$Arr[1],$Arr[2]);
    break; 
    case 5: 
      $Asignacion = $this->ReportAssignmentModels->getReportAssignmentFiltroLimiteOrden(urldecode($Arr[0]),$Arr[1],$Arr[2],$Arr[3],$Arr[4]);
   break; 
   case 6: 
    $Asignacion = $this->ReportAssignmentModels->getReportAssignmentFiltroLimiteOrdenColumnas(urldecode($Arr[0]),$Arr[1],$Arr[2],$Arr[3],$Arr[4],urldecode($Arr[5]));
    break; 
   default: 
   echo json_encode( $Arr );
   break; 
  }
  header('Content-type: application/json; charset=utf-8');
  echo json_encode($Asignacion); 
  
}
private function Buscar2 ($Arr =array()){
  $Asignacion =array();
  $Asignacion = $this->ReportAssignmentModels->getReportAssignmentFiltroColumnas(urldecode($Arr[0]),urldecode($Arr[1]));
  header('Content-type: application/json; charset=utf-8');
  echo json_encode($Asignacion); 
}

private function Buscar3 ($Arr =array()){
  $Asignacion =array();
    $Asignacion= $this->ReportAssignmentModels->  getReportAssignmentIdColum($Arr[0],urldecode($Arr[1]));
  header('Content-type: application/json; charset=utf-8');
  echo json_encode($Asignacion); 
}
private function Buscar4 ($Arr = array()){
  $Asignacion =array();
    $Asignacion= $this->ReportAssignmentModels->getReportAssignmentLimiteColum($Arr[0],$Arr[1],urldecode($Arr[2]));
  header('Content-type: application/json; charset=utf-8');
  echo json_encode($Asignacion); 
}
private function Buscar5 ($Arr =  array()){
  $Asignacion =array();
  $Asignacion = $this->ReportAssignmentModels->getReportAssignmentFiltroLimitesColumnas(urldecode($Arr[0]),$Arr[1],$Arr[2],urldecode($Arr[3]));
  header('Content-type: application/json; charset=utf-8');
  echo json_encode($Asignacion); 

}
private function MetaData(){
  $Asignacion =array();
  $Asignacion = $this->ReportAssignmentModels->MetaData();
  header('Content-type: application/json; charset=utf-8');
  echo json_encode($Asignacion); 
}



    protected function middleware()
    {
      return ['Sesion','Permisos'];
    }

	
}