AF
fullcalendar carregando o mês de janeiro sempre no ano posterior
Boa tarde.
Estou utilizando o fullcalendar e o mesmo está me acarretando um problema em relação ao mês de janeiro.
Lanço uma data em 10 01 2018, grava corretamente no banco, mas o mesmo só está carregando em 2019. Fiz também um lançamento em janeiro de 2019 e o mesmo só me aparece em janeiro de 2020. Os meses subsequentes e anteriores estão carregando corretamente. Não sei se o problema é em relação ao mês corrente, pois só percebi esse problema agora.
Estou desconfiando da função $script->add, fiz alguns testes e é ali que acarreta o problema, mas não consegui identificar uma possível solução.
$script->add("
{
id: ".$event->id.",
title: '".$event->title."',
start: new Date(".date('Y', strtotime($event->event_date)).", ".date('m', strtotime('-1 months',strtotime($event->event_date)) ).", ".date('d', strtotime($event->event_date)).", ".str_replace(':',',',$event->start_hour)."),
end: new Date(".date('Y', strtotime($event->event_date)).", ".date('m', strtotime('-1 months',strtotime($event->event_date)) ).", ".date('d', strtotime($event->event_date)).", ".($event->start_hour + $event->duration)."),
backgroundColor: '".$event->color."',
borderColor: '".$event->color."',
url: "index.php?class=EventForm&method=onEdit&key=".$event->id."&event_date=".date('d', strtotime($event->event_date))."&start_hour=".$event->start_hour."",
status: false
},
");
Vou postar o código do AgendaView.class.php.
Agradeço qualquer ajuda.
Atenciosamente,
Ailton Furtado
Estou utilizando o fullcalendar e o mesmo está me acarretando um problema em relação ao mês de janeiro.
Lanço uma data em 10 01 2018, grava corretamente no banco, mas o mesmo só está carregando em 2019. Fiz também um lançamento em janeiro de 2019 e o mesmo só me aparece em janeiro de 2020. Os meses subsequentes e anteriores estão carregando corretamente. Não sei se o problema é em relação ao mês corrente, pois só percebi esse problema agora.
Estou desconfiando da função $script->add, fiz alguns testes e é ali que acarreta o problema, mas não consegui identificar uma possível solução.
$script->add("
{
id: ".$event->id.",
title: '".$event->title."',
start: new Date(".date('Y', strtotime($event->event_date)).", ".date('m', strtotime('-1 months',strtotime($event->event_date)) ).", ".date('d', strtotime($event->event_date)).", ".str_replace(':',',',$event->start_hour)."),
end: new Date(".date('Y', strtotime($event->event_date)).", ".date('m', strtotime('-1 months',strtotime($event->event_date)) ).", ".date('d', strtotime($event->event_date)).", ".($event->start_hour + $event->duration)."),
backgroundColor: '".$event->color."',
borderColor: '".$event->color."',
url: "index.php?class=EventForm&method=onEdit&key=".$event->id."&event_date=".date('d', strtotime($event->event_date))."&start_hour=".$event->start_hour."",
status: false
},
");
Vou postar o código do AgendaView.class.php.
Agradeço qualquer ajuda.
Atenciosamente,
Ailton Furtado
- <?php
- class AgendaView extends TPage
- {
- function __construct()
- {
- parent::__construct();
-
- $this->form = new TQuickForm('form_agenda');
- $this->form->setFormTitle('Agenda - Sistema Financeiro - Casa de Jorge');
- $this->form->class = 'tform';
- $this->form->style = 'width: 800px';
- $table = new TTable;
- $calendar = new TElement('div');
- $calendar->id = 'calendar';
-
- $table->addRow()->addCell($calendar);
- try
- {
- TTransaction::open('jorge');
-
- $repository = new TRepository('Event');
- $events = $repository->load();
-
- $script =new TElement('script');
- $script->type = 'text/javascript';
- $script->add("
- $(document).ready(function() {
- $('#calendar').fullCalendar({
- timezone: 'America/Sao_Paulo',
- header: {
- left: 'prev,next today',
- center: 'title',
- right: 'month,agendaWeek,agendaDay'
- },
- events: [
- ");
- foreach($events as $event)
- {
-
- $script->add("
- {
- id: ".$event->id.",
- title: '".$event->title."',
- start: new Date(".date('Y', strtotime($event->event_date)).", ".date('m', strtotime('-1 months',strtotime($event->event_date)) ).", ".date('d', strtotime($event->event_date)).", ".str_replace(':',',',$event->start_hour)."),
- end: new Date(".date('Y', strtotime($event->event_date)).", ".date('m', strtotime('-1 months',strtotime($event->event_date)) ).", ".date('d', strtotime($event->event_date)).", ".($event->start_hour + $event->duration)."),
- backgroundColor: '".$event->color."',
- borderColor: '".$event->color."',
- url: \"index.php?class=EventForm&method=onEdit&key=".$event->id."&event_date=".date('d', strtotime($event->event_date))."&start_hour=".$event->start_hour."\",
- status: false
- },
- ");
- }
- $script->add("
- ],
- eventRender: function(event, eventElement)
- {
- if(event.status == true)
- {
- eventElement.find('div.fc-content').prepend(\"<i class='fa fa-check'></i> \");
- }
- else
- {
- eventElement.find('div.fc-content').prepend(\"<i class='fa fa-clock-o'></i> \");
- }
-
- },
- dayClick: function(date, jsEvent, view) {
-
- if (view.name === 'month') {
- $('#calendar').fullCalendar('gotoDate', date);
- $('#calendar').fullCalendar('changeView', 'agendaDay');
- $('.fc-event-container').children('a').attr('generator', 'adianti');
- $('.fc-widget-content').mouseover(function(){
- $(this).css('cursor','pointer');
- });
- }
- else if(view.name === 'agendaDay' || view.name === 'agendaWeek')
- {
- $(this).append('<a></a>');
- $(this).children('a').attr('generator', 'adianti');
- var href = $(this).children('a').attr('href', 'index.php?class=EventForm&method=onStartEdit&event_date='+date.format('DD/MM/YYYY')+'&start_hour='+date.format('hh:mm'));
- $(this).children('a').click();
- }
- },
- });
- $('.fc-content').click(function(){
- $(this).parent('a').attr('generator', 'adianti');
- });
- $('.fc-widget-content').mouseover(function(){
- $(this).css('cursor','pointer');
- });
- $('body').on('click', ':button.fc-button', function(event){
- event.preventDefault();
- $('.fc-content').parent('a').attr('generator', 'adianti');
- $('.fc-widget-content').mouseover(function(){
- $(this).css('cursor','pointer');
- });
- });
- $(':button.fc-today-button').click(function(){
- $('.fc-content').parent('a').attr('generator', 'adianti');
- $('.fc-widget-content').mouseover(function(){
- $(this).css('cursor','pointer');
- });
- });
-
- });
- ");
-
- print_r($script);
- $table->addRow()->addCell($script);
-
- TTransaction::close();
- }
- catch (Exception $e)
- {
- new TMessage('error', $e->getMessage());
- }
-
- $vbox = new TVBox;
- //$vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $vbox->add($this->form);
- $vbox->add($table);
-
- parent::add($vbox);
- }
-
- public function onDelete( $param )
- {
- $action = new TAction(array($this, 'Delete'));
- $action->setParameters($param);
- new TQuestion('Dejesa relamente deletar o registro?', $action);
- }
- public function Delete( $param )
- {
- try
- {
- if (isset($param['id']))
- {
- $key=$param['id'];
-
- TTransaction::open('jorge');
-
- $object = new Event($key);
- $object->delete();
- TTransaction::close();
-
- $posAction = new TAction(array('AgendaView', 'reload'));
- new TMessage('info', 'Registro deletado', $posAction);
- }
- }
- catch (Exception $e)
- {
- new TMessage('error', '<b>Error</b> ' . $e->getMessage());
- TTransaction::rollback();
- }
- }
-
- public function reload()
- {
-
- }
- }
- ?>
Olá Ailton, boa noite.
Algumas questões para ver se consigo ajudar:
Por que razão está a usar "-1 months" ? Sabe que há alguns problemas com essa função (-1 e +1), quando os meses antes ou depois não têm o mesmo número de dias ( php.net/manual/en/function.strtotime.php#111989 )
Pode mostrar o var_dump dos valores de "start" e "end" na função $script->add ?
Já agora o var_dump dos valores de $event->event_date e $event->start_hour ?
Sem esses valores não posso testar aqui.
Obrigado
Abel Gomes
Boa tarde Abel.
Em primeiro lugar agradeço sua atenção.
O caso é aqui ".date('m', strtotime('-1 months',strtotime($event->event_date)) ).", o php está transformando 01 (janeiro) em 12 (dezembro) ao invés de 00 (janeiro em javascript) e o javascript aceita de 0 a 11 para meses.
Estou vendo aqui como acertar isso.
Se tiver alguma dica, agradeço.
Atenciosamente,
Ailton Furtado
Boa tarde Abel.
Consegui resolver o problema.
Mais uma vez agradeço sua atenção.
Ailton Furtado
Boa tarde Ailton.
Ainda bem que conseguiu encontrar a solução. Peço desculpa por não ter respondido, mas também eu andava à procura de uma solução para um problema meu que só esta madrugada encontrei... :-)
Já agora, se puder, coloque aqui a sua solução para ajudar outros que possam vir a debater-se com o mesmo problema.
Um abraço!
Abel
Bom dia Abel.
Compartilho a solução que pensei. Caso alguém tenha uma melhor é sempre bem vinda.
Como lhe disse anteriormente, o problema era esse:
O caso é aqui ".date('m', strtotime('-1 months',strtotime($event->event_date)) ).", o php está transformando 01 (janeiro) em 12 (dezembro) ao invés de 00 (janeiro em javascript) e o javascript aceita de 0 a 11 para meses.
Então peguei essa parte e atribuí a uma variável php $mes e fiz uma lógica quando o $mes fosse igual a 12, queria dizer que ele valeria 00. Para o javascript, o mês de janeiro, e o substituí na fórmula do javascript descrita abaixo.
Assim não precisei fazer grande alterações no código original do javascript.
----------------------------------------------------------------------------------------------------------
$mes = date('m', strtotime('-1 months',strtotime($event->event_date)) );
if ($mes == '12')
$mes = '00';
$script->add("
{
id: ".$event->id.",
title: '".$event->title."',
start: new Date(".date('Y', strtotime($event->event_date)).", ".$mes.", ".date('d', strtotime($event->event_date)).", ".str_replace(':',',',$event->start_hour)."),
end: new Date(".date('Y', strtotime($event->event_date)).", ".$mes.", ".date('d', strtotime($event->event_date)).", ".($event->start_hour + $event->duration)."),
backgroundColor: '".$event->color."',
borderColor: '".$event->color."',
url: "index.php?class=EventForm&method=onEdit&key=".$event->id."&event_date=".date('d', strtotime($event->event_date))."&start_hour=".$event->start_hour."",
status: false
},
");