Merge days into a calendar like Google Calendar

Asked

Viewed 165 times

1

Good afternoon Guys, I have a calendar in php, which looks for information in the database. And I would like the inserted commitments to be merged from the beginning to the end of the same. Like google Calendar. See the image below. This is my current calendar view.

inserir a descrição da imagem aqui

Note the events "Test event 1" and "Test event 3". I would like it to be as in the image below.

inserir a descrição da imagem aqui

My code:

                    $data = date('d/m/y');
                    $data_explode = explode("/", $data);

                    $dia = $data_explode[0];
                    $mes = $data_explode[1];
                    $ano = $data_explode[2];
                    $calendario = "";

                    $v_mes = substr($mes, 0, 2);
                    $novo_mes = (int) $mes - 1;

                    $ultimo_dia_mes = date("t", mktime(0, 0, 0, $mes, 1, $ano));

                    $vetor_dias_semana = array(0, 1, 2, 3, 4, 5, 6);

                    $vetor_mes = array("Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro");

                    $calendario .="<div class='cabecalho_semana'>Domingo</div><div class='cabecalho_semana'>Segunda</div><div class='cabecalho_semana'>Terça</div><div class='cabecalho_semana'>Quarta</div><div div class='cabecalho_semana'>Quinta</div><div class='cabecalho_semana'>Sexta</div><div class='cabecalho_semana'>Sábado</div>";
                    $contador = 1;

                    $dia_semana_primeiro_dia = $dia_semana = date("w", mktime(0, 0, 0, $mes, 1, $ano));

                    $trava = "F";
                    $inicio = 1;

                    for ($i = 0; $i < 7; $i++) {
                        if ($dia_semana_primeiro_dia == $i || $trava == "T") {


                            $dados = connection::select("select * from agenda where (data_agenda <= '$ano-$mes-$inicio' AND termino_agenda >= '$ano-$mes-$inicio')");
                            //$dados = connection::select("select * from agenda as a inner join agendap as p on a.id_agenda = p.agenda_agendap where p.pessoa_agendap = $id_pessoa AND a.data_agenda = '$ano-$mes-$inicio' or a.termino_agenda = '$ano-$mes-$inicio'");
                            $reg = $dados->fetchObject();

                            if (!empty($reg)) {
                                $compromisso = '<small>';

                                $d = connection::select("select * from agenda where (data_agenda <= '$ano-$mes-$inicio' AND termino_agenda >= '$ano-$mes-$inicio')");

                                foreach ($d as $r) {
                                    $compromisso .= '#' . $r['id_agenda'] . ' - ' . $r['compromisso_agenda'] . '<br>';
                                }
                                $compromisso .= '</small>';

                                $calendario .="<div style='background-color:#fff;' class='cabecalho_dia' value='$ano-$mes-$inicio'><a href=" . URL . "agenda/data/$ano-$mes-$inicio>" . $inicio . "<br><font style='color:#fff;background-color:#166C25;'>" . $compromisso . "</font></a></div>";
                            }
                            else {
                                $calendario .="<div style='background-color:#fff;' class='cabecalho_dia' value='$ano-$mes-$inicio'><a href=" . URL . "agenda/data/$ano-$mes-$inicio>" . $inicio . "</a></div>";
                            }
                            $trava = "T";
                            $inicio++;
                        }
                        else {
                            $calendario .="<div style='background-color:#fff;' class='cabecalho_dia'>&nbsp;&nbsp;</div>";
                        }
                    }

                    $fim = "F";
                    $linha_semana = 1;
                    while ($fim == "F" || $linha_semana < 6) {

                        for ($f = 0; $f < 7; $f++) {

                            $linha_semana++;

                            if ($inicio <= $ultimo_dia_mes) {

                                $dados2 = connection::select("select * from agenda where (data_agenda <= '$ano-$mes-$inicio' AND termino_agenda >= '$ano-$mes-$inicio')");
                                //$dados2 = connection::select("select * from agenda as a inner join agendap as p on a.id_agenda = p.agenda_agendap where p.pessoa_agendap = $id_pessoa and data_agenda = '$ano-$mes-$inicio' or a.termino_agenda = '$ano-$mes-$inicio'");
                                $reg2 = $dados2->fetchObject();

                                if (!empty($reg2)) {
                                    $compromisso = '<small>';

                                    $d = connection::select("select * from agenda where (data_agenda <= '$ano-$mes-$inicio' AND termino_agenda >= '$ano-$mes-$inicio')");

                                    foreach ($d as $r) {
                                        $compromisso .= '#' . $r['id_agenda'] . ' - ' . $r['compromisso_agenda'] . '<br>';
                                    }
                                    $compromisso .= '</small>';

                                    $calendario .="<div style='background-color:#fff;' class='cabecalho_dia' value='$inicio/$mes/$ano'><a href=" . URL . "agenda/data/$ano-$mes-$inicio>" . $inicio . "<br><font style='color:#fff;background-color:#166C25;'>" . $compromisso . "</font></div>";
                                }
                                else {
                                    $calendario .="<div style='background-color:#fff;' class='cabecalho_dia' value='$inicio/$mes/$ano'><a href=" . URL . "agenda/data/$ano-$mes-$inicio>" . $inicio . "</a></div>";
                                }

                                if ($inicio == $ultimo_dia_mes) {
                                    $fim = "T";
                                }
                                $inicio++;
                            }
                            else {
                                $calendario .="<div style='background-color:#fff;' class='cabecalho_dia'>&nbsp;&nbsp;</div>";
                            }
                        }
                    }

                    $html = str_replace('#CALENDARIO#', $calendario, $html);
  • Eduardo2222, still needs help?

No answers

Browser other questions tagged

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