Lançado Adianti Framework 7.6!
Clique aqui para saber mais
TFullCalendar não carrega os eventos do banco de dados Pessoal, alguém já está utilizando o novo componete TFullCalendar? Estou tentando utiliza-lo, porém, quando tento carregar os eventos do banco, seguindo o exemplo do tutor, utilizando a função setReloadAction, não consigo ter os eventos carregados. Fuçando o exemplo do tutor, percebi que se faço uma chamada à função var_dump, por exemplo, dentro da função setReloadAction, o TFullC...
RR
TFullCalendar não carrega os eventos do banco de dados  
Pessoal, alguém já está utilizando o novo componete TFullCalendar?
Estou tentando utiliza-lo, porém, quando tento carregar os eventos do banco, seguindo o exemplo do tutor, utilizando a função setReloadAction, não consigo ter os eventos carregados.
Fuçando o exemplo do tutor, percebi que se faço uma chamada à função var_dump, por exemplo, dentro da função setReloadAction, o TFullCalendar deixa de carregar os eventos.
No meu caso, estou criando uma tela de marcação de consultas onde o usuário seleciona um médico e paciente de um TSeek e abaixo o TFullCalendar deverá carregar os eventos(consultas) para o dia em questão.
Alguém poderia me dar uma força ?
Desde já, grato.

Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto Quero me inscrever agora!

Comentários (5)


NR

Romero, se conseguir postar o código fica mais fácil para analisarmos.
RR

Ok Nataniel!

Segue o código da página que utiliza o TFullCalendar:

  1. <?php
  2. class Marcacao extends TPage
  3. {
  4.     private $fc;
  5.     private $form;
  6.     
  7.     public function __construct()
  8.     {
  9.         parent::__construct();
  10.         $this->form = new TQuickForm('marcacao');
  11.         $this->form->class 'tform';
  12.         
  13.         $medico_id = new  ">TDBSeekButton('medico_id''cmr''marcacao''Medico''nome''medico_id''medico_nome');
  14.         $medicoExitAction = new TAction(array($this'onMedicoExitAction'));
  15.         $medico_id->setExitAction($medicoExitAction);
  16.         $medico_nome = new TEntry('medico_nome');
  17.         
  18.         $paciente_id = new  ">TDBSeekButton('paciente_id''cmr''marcacao''Paciente''nome''paciente_id''paciente_nome');
  19.         $pacienteExitAction = new TAction(array($this'onPacienteExitAction'));
  20.         $paciente_id->setExitAction($pacienteExitAction);
  21.         $paciente_nome = new TEntry('paciente_nome');
  22.         
  23.         $medico_id->setSize(50);
  24.         $medico_nome->setEditable(FALSE);
  25.         
  26.         $paciente_id->setSize(50);
  27.         $paciente_nome->setEditable(FALSE);
  28.         
  29.         $this->form->addQuickFields('Médico', array($medico_id$medico_nome));
  30.         $this->form->addQuickFields('Paciente', array($paciente_id$paciente_nome));
  31.       
  32.         $this->fc = new TFullCalendar(date('Y-m-d'), 'month');
  33.         //$this->fc->setTimeRange( '08:00:00', '17:00:00' );
  34.         $return = array();
  35.         try
  36.         {
  37.             TTransaction::open('cmr');
  38.             
  39.             $events Agenda::where('medico_id''='1)->load();  //$param['medico_id'])->load();
  40.             if ($events)
  41.             {
  42.                 //print_r($events);
  43.                 foreach ($events as $event)
  44.                 {
  45.                     $event_array $event->toArray();
  46.                     $event_array['start'] = str_replace' ''T'$event_array['start_time']);
  47.                     $event_array['end'] = str_replace' ''T'$event_array['end_time']);
  48.                     $this->fc->addEvent($event_array['medico_id'], $event_array['title'], $event_array['start'], $event_array['end'], null$event_array['color']);
  49.                     $return[] = $event_array;
  50.                 }
  51.             }
  52.             TTransaction::close();
  53.             //echo json_encode($return);
  54.         }
  55.         catch (Exception $e)
  56.         {
  57.             new TMessage('error'$e->getMessage());
  58.         }
  59.         $before_yesterday = (new DateTime(date('Y-m-d')))->sub(new DateInterval("P2D"))->format('Y-m-d');
  60.         $this->fc->addEvent(10'Event 1'$before_yesterday.'T08:30:00'$before_yesterday.'T12:30:00'null'#C04747');
  61.         //$this->fc->setReloadAction(new TAction(array($this, 'getEvents')));
  62.         $this->fc->setDayClickAction(new TAction(array('AgendaForm''onStartEdit')));
  63.         $this->fc->setEventClickAction(new TAction(array('AgendaForm''onEdit')));
  64.         $this->fc->setEventUpdateAction(new TAction(array('AgendaForm''onUpdateEvent')));
  65.        
  66.         $vbox = new TVBox;
  67.         $vbox->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  68.         $vbox->add($this->form);
  69.         $vbox->add($this->fc); 
  70.         
  71.         parent::add$vbox );
  72.     }
  73.     
  74.     public static function onMedicoExitAction$param )
  75.     {
  76.         Marcacao::getEvents($param);
  77.         //$param['view'] = 'month';
  78.         //TApplication::executeMethod('Marcacao', 'onReload', $param);
  79.     }
  80.     public static function onPacienteExitAction$param )
  81.     {
  82.         TSession::setValue('medicoId'$param['medico_id']);
  83.         TSession::setValue('medicoNome'$param['medico_nome']);
  84.         TSession::setValue('pacienteId'$param['paciente_id']);
  85.         TSession::setValue('pacienteNome'$param['paciente_nome']);
  86.     }
  87.     /**
  88.      * Output events as an json
  89.      */
  90.     public static function getEvents($param=NULL)
  91.     {
  92.         $return = array();
  93.         try
  94.         {
  95.             TTransaction::open('cmr');
  96.             
  97.             $events Agenda::where('medico_id''='$param['medico_id'])->load();
  98.             if ($events)
  99.             {
  100.                 foreach ($events as $event)
  101.                 {
  102.                     $event_array $event->toArray();
  103.                     $event_array['start'] = str_replace' ''T'$event_array['start_time']);
  104.                     $event_array['end'] = str_replace' ''T'$event_array['end_time']);
  105.                     $return[] = $event_array;
  106.                 }
  107.             }
  108.             TTransaction::close();
  109.             echo json_encode($return);
  110.         }
  111.         catch (Exception $e)
  112.         {
  113.             new TMessage('error'$e->getMessage());
  114.         }
  115.     }
  116.     
  117.     /**
  118.      * Reconfigure the callendar
  119.      */
  120.     public function onReload($param null)
  121.     {
  122.         if (isset($param['view']))
  123.         {
  124.             $this->fc->setCurrentView($param['view']);
  125.         }
  126.         
  127.         if (isset($param['date']))
  128.         {
  129.             $this->fc->setCurrentDate($param['date']);
  130.         }
  131.     }
  132.     
  133. }
  134. ?>
RR

Este é o código do AgendaForm(tentando seguir o exemplo do Tutor):

  1. <?php
  2. class AgendaForm extends TWindow
  3. {
  4.     protected $form// form
  5.     
  6.     /**
  7.      * Class constructor
  8.      * Creates the page and the registration form
  9.      */
  10.     public function __construct()
  11.     {
  12.         parent::__construct();
  13.         parent::setSize(640null);
  14.         parent::setTitle('Agenda');
  15.         
  16.         // creates the form
  17.         $this->form = new TForm('form_event');
  18.         $this->form->class 'tform'// CSS class
  19.         $this->form->style 'width: 600px';
  20.         
  21.         // add a table inside form
  22.         $table = new TTable;
  23.         $table-> width '100%';
  24.         $this->form->add($table);
  25.         
  26.         // add a row for the form title
  27.         $row $table->addRow();
  28.         $row->class 'tformtitle'// CSS class
  29.         $row->addCell( new TLabel('Nova Consulta') )->colspan 2;
  30.         
  31.         $hours = array();
  32.         $minutes = array();
  33.         for ($n=0$n<24$n++)
  34.         {
  35.             $hours[$n] = str_pad($n2'0'STR_PAD_LEFT);
  36.         }
  37.         
  38.         for ($n=0$n<=55$n+=5)
  39.         {
  40.             $minutes[$n] = str_pad($n2'0'STR_PAD_LEFT);
  41.         }
  42.         
  43.         // create the form fields
  44.         $view           = new THidden('view');
  45.         $id             = new TEntry('id');
  46.         $medico_id      = new THidden('medico_id');
  47.         $medico_nome    = new TEntry('medico_nome');
  48.         $paciente_id    = new THidden('paciente_id');
  49.         $color          = new TColor('color');
  50.         $start_date     = new TDate('start_date');
  51.         $start_hour     = new TCombo('start_hour');
  52.         $start_minute   = new TCombo('start_minute');
  53.         $end_date       = new TDate('end_date');
  54.         $end_hour       = new TCombo('end_hour');
  55.         $end_minute     = new TCombo('end_minute');
  56.         $title          = new TEntry('title');
  57.         $description    = new TText('description');
  58.         $color->setValue('#3a87ad');
  59.         
  60.         $start_hour->addItems($hours);
  61.         $start_minute->addItems($minutes);
  62.         $end_hour->addItems($hours);
  63.         $end_minute->addItems($minutes);
  64.         
  65.         $id->setEditable(FALSE);
  66.         // define the sizes
  67.         $id->setSize(40);
  68.         $medico_nome->setSize(400);
  69.         $medico_nome->setEditable(FALSE);
  70.         $title->setSize(400);
  71.         $title->setEditable(FALSE);
  72.         $color->setSize(100);
  73.         $start_date->setSize(100);
  74.         $end_date->setSize(100);
  75.         $start_hour->setSize(50);
  76.         $end_hour->setSize(50);
  77.         $start_minute->setSize(50);
  78.         $end_minute->setSize(50);
  79.         $description->setSize(40050);
  80.         $start_hour->setChangeAction(new TAction(array($this'onChangeStartHour')));
  81.         $end_hour->setChangeAction(new TAction(array($this'onChangeEndHour')));
  82.         $start_date->setExitAction(new TAction(array($this'onChangeStartDate')));
  83.         $end_date->setExitAction(new TAction(array($this'onChangeEndDate')));
  84.         // add one row for each form field
  85.         $table->addRowSet$view );
  86.         $table->addRowSet( new TLabel('ID:'), $id );
  87.         $table->addRowSet( new TLabel('Médico'), $medico_nome);
  88.         $table->addRowSet( new TLabel('Paciente:'), $title );
  89.         $table->addRowSet( new TLabel('Color:'), $color );
  90.         $table->addRowSet( new TLabel('Start time:'), array($start_date$start_hour':'$start_minute) );
  91.         $table->addRowSet( new TLabel('End time:'), array($end_date$end_hour':'$end_minute));
  92.         $table->addRowSet( new TLabel('Observação:'), $description );
  93.         // create an action button (save)
  94.         $save_button=new TButton('save');
  95.         $save_button->setAction(new TAction(array($this'onSave')), _t('Save'));
  96.         $save_button->setImage('fa:save green');
  97.  
  98.         // create an new button (edit with no parameters)
  99.         $new_button=new TButton('new');
  100.         $new_button->setAction(new TAction(array($this'onEdit')), _t('Clear'));
  101.         $new_button->setImage('fa:eraser orange');
  102.         // create an del button (edit with no parameters)
  103.         $del_button=new TButton('del');
  104.         $del_button->setAction(new TAction(array($this'onDelete')), _t('Delete'));
  105.         $del_button->setImage('fa:trash-o red');
  106.         
  107.         $this->form->setFields(array($id$medico_id$medico_nome$paciente_id$view$color$title$description$start_date$start_hour$start_minute$end_date$end_hour$end_minute$save_button,$new_button,$del_button));
  108.         
  109.         $buttons_box = new THBox;
  110.         $buttons_box->add($save_button);
  111.         $buttons_box->add($new_button);
  112.         $buttons_box->add($del_button);
  113.         
  114.         // add a row for the form action
  115.         $row $table->addRow();
  116.         $row->class 'tformaction'// CSS class
  117.         $row->addCell($buttons_box)->colspan 2;
  118.         
  119.         parent::add($this->form);
  120.     }
  121.     /**
  122.      * Executed when user leaves start hour field
  123.      */
  124.     public static function onChangeStartHour($param=NULL)
  125.     {
  126.         $obj = new stdClass;
  127.         if (empty($param['start_minute']))
  128.         {
  129.             $obj->start_minute '0';
  130.             TForm::sendData('form_event'$obj);
  131.         }
  132.         
  133.         if (empty($param['end_hour']) AND empty($param['end_minute']))
  134.         {
  135.             $obj->end_hour $param['start_hour'] +1;
  136.             $obj->end_minute '0';
  137.             TForm::sendData('form_event'$obj);
  138.         }
  139.     }
  140.     
  141.     /**
  142.      * Executed when user leaves end hour field
  143.      */
  144.     public static function onChangeEndHour($param=NULL)
  145.     {
  146.         if (empty($param['end_minute']))
  147.         {
  148.             $obj = new stdClass;
  149.             $obj->end_minute '0';
  150.             TForm::sendData('form_event'$obj);
  151.         }
  152.     }
  153.     
  154.     /**
  155.      * Executed when user leaves start date field
  156.      */
  157.     public static function onChangeStartDate($param=NULL)
  158.     {
  159.         if (empty($param['end_date']) AND !empty($param['start_date']))
  160.         {
  161.             $obj = new stdClass;
  162.             $obj->end_date $param['start_date'];
  163.             TForm::sendData('form_event'$obj);
  164.         }
  165.     }
  166.     
  167.     /**
  168.      * Executed when user leaves end date field
  169.      */
  170.     public static function onChangeEndDate($param=NULL)
  171.     {
  172.         if (empty($param['end_hour']) AND empty($param['end_minute']) AND !empty($param['start_hour']))
  173.         {
  174.             $obj = new stdClass;
  175.             $obj->end_hour min($param['start_hour'],22) +1;
  176.             $obj->end_minute '0';
  177.             TForm::sendData('form_event'$obj);
  178.         }
  179.     }
  180.     
  181.     /**
  182.      * method onSave()
  183.      * Executed whenever the user clicks at the save button
  184.      */
  185.     public function onSave()
  186.     {
  187.         $medicoId     TSession::getValue('medicoId');
  188.         $medicoNome   TSession::getValue('medicoNome');
  189.         $pacienteId   TSession::getValue('pacienteId');
  190.         $pacienteNome TSession::getValue('pacienteNome');
  191.         try
  192.         {
  193.             // open a transaction with database 'samples'
  194.             TTransaction::open('cmr');
  195.             
  196.             $this->form->validate(); // form validation
  197.             
  198.             // get the form data into an active record Entry
  199.             $data $this->form->getData();
  200.             $data->medico_id $medicoId;
  201.             $data->medico_nome $medicoNome;
  202.             $data->paciente_id $pacienteId;
  203.             $data->title $pacienteNome;            
  204.             $object        = new Agenda;
  205.             $object->id    $data->id;
  206.             $object->medico_id $data->medico_id;
  207.             $object->paciente_id $data->paciente_id;
  208.             $object->title $data->title;
  209.             $object->color $data->color;
  210.             $object->nota $data->description;
  211.             $object->start_time $data->start_date ' ' str_pad($data->start_hour2'0'STR_PAD_LEFT) . ':' str_pad($data->start_minute2'0'STR_PAD_LEFT) . ':00';
  212.             $object->end_time $data->end_date ' ' str_pad($data->end_hour2'0'STR_PAD_LEFT) . ':' str_pad($data->end_minute2'0'STR_PAD_LEFT) . ':00';
  213.             
  214.             $object->store(); // stores the object
  215.             
  216.             $data->id $object->id;
  217.             $this->form->setData($data); // keep form data
  218.             
  219.             TTransaction::close(); // close the transaction
  220.             $posAction = new TAction(array('Marcacao''onReload'));
  221.             $posAction->setParameter('view'$data->view);
  222.             $posAction->setParameter('date'$data->start_date);
  223.             
  224.             // shows the success message
  225.             new TMessage('info'TAdiantiCoreTranslator::translate('Record saved'), $posAction);
  226.         }
  227.         catch (Exception $e// in case of exception
  228.         {
  229.             // shows the exception error message
  230.             new TMessage('error'$e->getMessage());
  231.             
  232.             $this->form->setData$this->form->getData() ); // keep form data
  233.             
  234.             // undo all pending operations
  235.             TTransaction::rollback();
  236.         }
  237.     }
  238.     
  239.     /**
  240.      * method onEdit()
  241.      * Executed whenever the user clicks at the edit button da datagrid
  242.      */
  243.     public function onEdit($param)
  244.     {
  245.         try
  246.         {
  247.             if (isset($param['key']))
  248.             {
  249.                 // get the parameter $key
  250.                 $key=$param['key'];
  251.                 
  252.                 // open a transaction with database 'samples'
  253.                 TTransaction::open('cmr');
  254.                 
  255.                 // instantiates object CalendarEvent
  256.                 $object = new Agenda($key);
  257.                 
  258.                 $data = new stdClass;
  259.                 $data->id $object->id;
  260.                 $data->medico_id $object->medico_id;
  261.                 $data->paciente_id $object->paciente_id;
  262.                 $data->title $object->title;
  263.                 $data->color $object->color;
  264.                 $data->description $object->nota;
  265.                 $data->start_date substr($object->start_time,0,10);
  266.                 $data->start_hour substr($object->start_time,11,2);
  267.                 $data->start_minute substr($object->start_time,14,2);
  268.                 $data->end_date substr($object->end_time,0,10);
  269.                 $data->end_hour substr($object->end_time,11,2);
  270.                 $data->end_minute substr($object->end_time,14,2);
  271.                 $data->view $param['view'];
  272.                 
  273.                 // fill the form with the active record data
  274.                 $this->form->setData($data);
  275.                 
  276.                 // close the transaction
  277.                 TTransaction::close();
  278.             }
  279.             else
  280.             {
  281.                 $this->form->clear();
  282.             }
  283.         }
  284.         catch (Exception $e// in case of exception
  285.         {
  286.             // shows the exception error message
  287.             new TMessage('error'$e->getMessage());
  288.             
  289.             // undo all pending operations
  290.             TTransaction::rollback();
  291.         }
  292.     }
  293.     
  294.     /**
  295.      * Delete event
  296.      */
  297.     public static function onDelete($param)
  298.     {
  299.         // define the delete action
  300.         $action = new TAction(array('AgendaForm''Delete'));
  301.         $action->setParameters($param); // pass the key parameter ahead
  302.         
  303.         // shows a dialog to the user
  304.         new TQuestion(AdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  305.     }
  306.     
  307.     /**
  308.      * Delete a record
  309.      */
  310.     public static function Delete($param)
  311.     {
  312.         try
  313.         {
  314.             // get the parameter $key
  315.             $key $param['id'];
  316.             // open a transaction with database
  317.             TTransaction::open('cmr');
  318.             
  319.             // instantiates object
  320.             $object = new CalendarEvent($keyFALSE);
  321.             
  322.             // deletes the object from the database
  323.             $object->delete();
  324.             
  325.             // close the transaction
  326.             TTransaction::close();
  327.             
  328.             $posAction = new TAction(array('Marcacao''onReload'));
  329.             $posAction->setParameter('view'$param['view']);
  330.             $posAction->setParameter('date'$param['start_date']);
  331.             
  332.             // shows the success message
  333.             new TMessage('info'AdiantiCoreTranslator::translate('Record deleted'), $posAction);
  334.         }
  335.         catch (Exception $e// in case of exception
  336.         {
  337.             // shows the exception error message
  338.             new TMessage('error'$e->getMessage());
  339.             // undo all pending operations
  340.             TTransaction::rollback();
  341.         }
  342.     }
  343.     
  344.     /**
  345.      * Fill form from the user selected time
  346.      */
  347.     public function onStartEdit($param)
  348.     {
  349.         $medicoId     TSession::getValue('medicoId');
  350.         $medicoNome   TSession::getValue('medicoNome');
  351.         $pacienteId   TSession::getValue('pacienteId');
  352.         $pacienteNome TSession::getValue('pacienteNome');
  353.         if (!empty($medicoId) && !empty($pacienteId))
  354.         {
  355.             $this->form->clear();
  356.             $data = new stdClass;
  357.             $data->view        $param['view']; // calendar view
  358.             $data->color       '#3a87ad';
  359.             $data->medico_id   $medicoId;
  360.             $data->medico_nome $medicoNome;
  361.             $data->paciente_id $pacienteId;
  362.             $data->title       $pacienteNome;
  363.             
  364.             if ($param['date'])
  365.             {
  366.                 if (strlen($param['date']) == 10)
  367.                 {
  368.                     $data->start_date $param['date'];
  369.                     $data->end_date $param['date'];
  370.                 }
  371.                 if (strlen($param['date']) == 19)
  372.                 {
  373.                     $data->start_date   substr($param['date'],0,10);
  374.                     $data->start_hour   substr($param['date'],11,2);
  375.                     $data->start_minute substr($param['date'],14,2);
  376.                     
  377.                     $data->end_date   substr($param['date'],0,10);
  378.                     $data->end_hour   substr($param['date'],11,2) +1;
  379.                     $data->end_minute substr($param['date'],14,2);
  380.                 }
  381.             }            
  382.             
  383.             $this->form->setData$data );
  384.         }
  385.     }
  386.     
  387.     /**
  388.      * Update event. Result of the drag and drop or resize.
  389.      */
  390.     public static function onUpdateEvent($param)
  391.     {
  392.         $medicoId     TSession::getValue('medicoId');
  393.         $medicoNome   TSession::getValue('medicoNome');
  394.         $pacienteId   TSession::getValue('pacienteId');
  395.         $pacienteNome TSession::getValue('pacienteNome');
  396.         try
  397.         {
  398.             if (isset($param['id']))
  399.             {
  400.                 // get the parameter $key
  401.                 $key=$param['id'];
  402.                 
  403.                 // open a transaction with database 'samples'
  404.                 TTransaction::open('cmr');
  405.                 
  406.                 // instantiates object CalendarEvent
  407.                 $object = new Agenda($key);
  408.                 $object->start_time str_replace('T'' '$param['start_time']);
  409.                 $object->end_time   str_replace('T'' '$param['end_time']);
  410.                 $object->store();
  411.                                 
  412.                 // close the transaction
  413.                 TTransaction::close();
  414.             }
  415.         }
  416.         catch (Exception $e// in case of exception
  417.         {
  418.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  419.             TTransaction::rollback();
  420.         }
  421.     }
  422. }
  423. ?>
RR

E, finalmente, o código do Modelo Agenda:
  1. <?php
  2. /**
  3.  * Agenda Active Record
  4.  * @author  <your-name-here>
  5.  */
  6. class Agenda extends TRecord
  7. {
  8.     const TABLENAME 'public.agenda';
  9.     const PRIMARYKEY'id';
  10.     const IDPOLICY =  'serial'// {max, serial}
  11.     
  12.     
  13.     /**
  14.      * Constructor method
  15.      */
  16.     public function __construct($id NULL$callObjectLoad TRUE)
  17.     {
  18.         parent::__construct($id$callObjectLoad);
  19.         parent::addAttribute('medico_id');
  20.         parent::addAttribute('paciente_id');
  21.         parent::addAttribute('start_time');
  22.         parent::addAttribute('end_time');
  23.         parent::addAttribute('title');
  24.         parent::addAttribute('nota');
  25.         parent::addAttribute('color');
  26.     }
  27. }
  28. ?>
NR

Por exemplo, se quiser atualizar o calendário após a escolha do médico:
  1. <?php
  2. public static function onMedicoExitAction$param )
  3. {
  4.         TApplication::postData('marcacao',__CLASS__,'onReload');
  5. }
  6. // necessario preencher o form na funcao onReload
  7. public function onReload($param null)
  8. {
  9.       $this->form->setData($this->form->getData());
  10.       ...  
  11. }
  12. ?>