Shows days with pouch ignoring today's day with return JSON

-1

I'm trying to make a logic to display the next day that a certain warehouse will have pouch shipping, I'm trying to create a array with the search I'm doing on my banco de dados and trying to skip today and always see the next day, but without success. In my bank the days are 0 and 1, with 0 being no pouch and 1, yes.

My bank looks like this:

WhatIhaveincodelookslikethis:

if(GetApplication()->isGetValueSet('IdUnicoop')){$IdUnicoop=GetApplication()->GetGETValue('IdUnicoop');$sql="SELECT * FROM dvsMaloteDias WHERE dvsMaloteDias.IdUnicoop = $IdUnicoop";
    $queryResult = $this->GetConnection()->fetchAll($sql);

    $Notificacao = array();

              foreach($queryResult as $RegResult) {           

            if ($RegResult['Segunda'] != 0) {       
                array_push($Notificacao, "Segunda");
            }
            if ($RegResult['Terça'] != 0) {     
                array_push($Notificacao, "Terça");
            }
            if ($RegResult['Quarta'] != 0) {        
                array_push($Notificacao, "Quarta");
            }       
            if ($RegResult['Quinta'] != 0) {        
                array_push($Notificacao, "Quinta");
            }
            if ($RegResult['Sexta'] != 0) {     
                array_push($Notificacao, "Sexta");
            }
            if ($RegResult['Sabado'] != 0) {        
                array_push($Notificacao, "Sábado");
            }
            if ($RegResult['Domimgo']!= 0) {        
                array_push($Notificacao, "Domingo");
            }
            if ($RegResult['Todos'] != 0) {     
                array_push($Notificacao, "Todos");
            }          

        }


    $result = array(
        'Notificacao' => 'O próximo dia do malote é: ' . $Notificacao
    );

    echo json_encode($result);
    exit;                              
}

According to the image, for example, warehouse 9 has a pouch in the second, but I should check what day it is today and if it is second, I have to show that there will be a pouch on the fourth and fourth, check the day and if it is fourth, show sixth.

I even discovered the day of the week, but the comparison did not, see:

    $now = new DateTime('now', new DateTimeZone('America/Sao_Paulo'));
    $minhadataYmdHis = $now->format('Y-m-d');

    $diaSemanaN= date("w", strtotime($minhadataYmdHis));

    switch($diaSemanaN) {
        case 0:
        $diaSemana="Domingo";
        break;
        case 1:
        $diaSemana="Segunda";
        break;  
        case 2:
        $diaSemana="Terça";
        break;  
        case 3:
        $diaSemana="Quarta";
        break;
        case 4:
        $diaSemana="Quinta";
        break;  
        case 5:
        $diaSemana="Sexta";
        break;          
        case 6:
        $diaSemana="Sábado";
        break;              
    }

    echo $diaSemana;
    
asked by anonymous 19.11.2018 / 17:48

1 answer

1

Hello.

This is a logic problem. It's usually not something that should be resolved here.

But I'll give you a code that works, but it's not 100% stoned. This code does not check for example when every day has a pouch. And there is one more problem in it that you must solve. If today is Thursday and you have a pouch on Monday, he will not be able to warn you.

setlocale(LC_TIME, 'pt_BR', 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese');

$simulacaoBanco = [
    [
        "idUnicoop" => 1,
        "Segunda" => 1,
        "Terca" => 0,
        "Quarta" => 1,
        "Quinta" => 0,
        "Sexta" => 1,
        "Sabado" => 0,
        "Domingo" => 0,
        "Todos" => 0
    ]    
];
//percorre todos linha a linha vinda do banco, no exemplo há somente uma linha
foreach($simulacaoBanco as $simulacao){
    $idUnicoop = $simulacao['idUnicoop'];
    unset($simulacao['idUnicoop']);
    $todos = $simulacao['Todos'];
    unset($simulacao['Todos']);
    $simulacao = array_values($simulacao); //reseta o array para indices numericos 
começando de segunda = 0
    $diaSemana = date('w', time()); //pega o dia da semana começando de domingo = 0;
    if($diaSemana === 0){
        $diaSemana = 6; //é o domingo vindo do banco
    }else{
        $diaSemana = $diaSemana - 1; //hoje segunda é = 1 mas no banco é 0 então por 
isso a subtração para igualar os dias
    }
    foreach($simulacao as $diaBanco => $temMalote){
        if($diaBanco > $diaSemana){
            if($temMalote === 1){
                //dia atual + dia vindo do banco = proximo dia com malote
                echo 'Na ' . date('l', strtotime('+' . ($diaBanco) . ' days'  , 
time())) . ' tem malote.' . PHP_EOL; 
            }
        }
    }
}
    
19.11.2018 / 18:26