Weekly Reservation

Asked

Viewed 70 times

0

I’m developing a scheduling system and it’s almost all right but a question has arisen I need to create an option for weekly scheduling if the user clicked on weekly scheduling he scheduled all week at the time chosen by the client more or less like this:

Cliente Jose Horário 13:00 as 14:00 Agendamento semanal ? sim !

Then the system would schedule it for him:

segunda das 13:00 as 14:00 terça das 13:00 as 14:00 quarta das 13:00 as 14:00 quinta das 13:00 as 14:00 sexta das 13:00 as 14:00

Don’t need to show the code just help me with logic I think that’s enough.

1 answer

0

I worked with an agenda a few days ago, the logic is as follows:

Give the start date and end date option.

Make a query in the bank searching the schedules:

$sql = "SELECT * FROM agendamento WHERE data_inicio >= CURDATE();

Make a structure that mounts these weekly occurrences:

$eventos = Array();
foreach ($res as $row){

    if ($row['semanal'] == 1){

        $data_inicio = $row['data_inicio'];
        $data_fim = $row['data_fim'];

        // Calcule o intervalo das datas em dias
        $intervalo == IntervaloDias($data_inicio, $data_fim);

        // Data do evento (atual)
        $data = $data_inicio;
        for($i = 0; $i < $intervalo; $i++){
            $eventos[] = Array(
                'data_inicio' => $data,
                'data_fim' => $data,
                'hora_inicio' => $row['hora_inicio'],
                'hora_fim' => $row['hora_fim']
            );

            // Adicione um dia para próxima data
            $data = AddDia($data);
        }
    } else {
        // Outros tipos de evento
        $eventos[] = Array(
            'data_inicio' => $row['data_inicio'],
            'data_fim' => $row['data_fim'],
            'hora_inicio' => $row['hora_inicio'],
            'hora_fim' => $row['hora_fim']
        );
    }
}

If the user does not want an end date, put a date limitation in the code, example:

$maxdata = AddDia(Date(), 2*365); // Data máxima 2 anos

foreach ($res as $row){
    $data_inicio = $row['data_inicio'];
    $data_fim = empty($row['data_fim']) ? $maxdata : $row['data_fim'];

    // Calcule o intervalo das datas em dias
    $intervalo == IntervaloDias($data_inicio, $data_fim);

Case did not want the weekend days:

// Adicione um dia para próxima data
$data = AddDia($data);

if (date( "w", $data) == 6){ // Sábado
    $data = AddDia($data, 2); // Vai para segunda feira
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.