RA
Mostrar dados na agenda
Pessoal, como faço para mostrar o nome do paciente no resumo da agenda?
- <?php
- class AgendaDeboraForm extends TWindow
- {
- protected $form; // form
- private $formFields = [];
- /**
- * Form constructor
- * @param $param Request
- */
- public function __construct( $param )
- {
- parent::__construct();
- parent::setSize(800, null);
- parent::setTitle('Lembrete');
- parent::setProperty('class', 'window_modal');
- $this->form = new BootstrapFormBuilder('form_AgendaDebora');
- $this->form->setFormTitle('Agenda Débora');
- $view = new THidden('view');
- $id = new TEntry('id');
- $id_cadastro = new TDBUniqueSearch( 'id_cadastro', 'projeto', 'Cadastro', 'id', 'nome', 'nome asc' );
- $horario_inicial = new TDateTime('horario_inicial');
- $horario_final = new TDateTime('horario_final');
- $titulo = new TEntry('titulo');
- $cor = new TColor('cor');
- $observacao = new TText('observacao');
- $id_cadastro->addValidation('Paciente', new TRequiredValidator());
- $horario_inicial->addValidation('Horário inicial', new TRequiredValidator());
- $horario_final->addValidation('Horário final', new TRequiredValidator());
- $id->setEditable(false);
- $id_cadastro->setMinLength(2);
- $horario_final->setMask('dd/mm/yyyy hh:ii');
- $horario_inicial->setMask('dd/mm/yyyy hh:ii');
- $horario_final->setDatabaseMask('yyyy-mm-dd hh:ii');
- $horario_inicial->setDatabaseMask('yyyy-mm-dd hh:ii');
- $id->setSize(100);
- $cor->setSize(100);
- $titulo->setSize('72%');
- $id_cadastro->setSize('76%');
- $horario_final->setSize(150);
- $horario_inicial->setSize(150);
- $observacao->setSize('76%', 68);
- $id->setEditable(FALSE);
- $this->form->addFields([$view]);
- $this->form->addFields([new TLabel('Id:')],[$id]);
- $this->form->addFields([new TLabel('Paciente:', '#ff0000')],[$id_cadastro]);
- $this->form->addFields([new TLabel('Horário inicial:', '#ff0000')],[$horario_inicial],[new TLabel('Horário final:', '#ff0000')],[$horario_final]);
- $this->form->addFields([new TLabel('Título:')],[$titulo],[new TLabel('Cor:')],[$cor]);
- $this->form->addFields([new TLabel('Observação:')],[$observacao]);
- // create the form actions
- $this->form->addAction('Salvar', new TAction([$this, 'onSave']), 'fa:floppy-o')->addStyleClass('btn-primary');
- $this->form->addAction('Limpar formulário', new TAction([$this, 'onClear']), 'fa:eraser #dd5a43');
- $this->form->addAction('Excluir', new TAction([$this, 'onDelete']), 'fa:trash-o #dd5a43');
- parent::add($this->form);
- }
- public function onSave($param = null)
- {
- try
- {
- TTransaction::open('projeto');
- $this->form->validate();
- $data = $this->form->getData();
- $object = new AgendaDebora();
- $object->fromArray( (array) $data);
- $object->store();
- // get the generated {PRIMARY_KEY}
- $data->id = $object->id;
- $this->form->setData($data);
- TTransaction::close();
- $action = new TAction(['AgendaDeboraFormView', 'onReload']);
- $action->setParameter('view', $data->view);
- $action->setParameter('date', explode(' ', $data->horario_inicial)[0]);
- new TMessage('info', AdiantiCoreTranslator::translate('Record saved'), $action);
- }
- catch (Exception $e)
- {
- new TMessage('error', $e->getMessage());
- $this->form->setData( $this->form->getData() );
- TTransaction::rollback();
- }
- }
- public function onDelete($param = null)
- {
- if (isset($param['delete']) && $param['delete'] == 1)
- {
- try
- {
- $key = $param['id'];
- TTransaction::open('projeto');
- $object = new AgendaDebora($key, FALSE);
- $object->delete();
- TTransaction::close();
- $action = new TAction(array('AgendaDeboraFormView', 'onReload'));
- $action->setParameter('view', $param['view']);
- $action->setParameter('date', explode(' ', $param['horario_inicial'])[0]);
- // shows the success message
- new TMessage('info', AdiantiCoreTranslator::translate('Record deleted'), $action);
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage());
- TTransaction::rollback();
- }
- }
- else
- {
- // define the delete action
- $action = new TAction(array($this, 'onDelete'));
- $action->setParameters((array) $this->form->getData()); // pass the key paramsseter ahead
- $action->setParameter('delete', 1);
- // shows a dialog to the user
- new TQuestion(AdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
- }
- }
- /**
- * Clear form data
- * @param $param Request
- */
- public function onClear( $param )
- {
- $this->form->clear();
- }
- public function onEdit( $param )
- {
- try
- {
- if (isset($param['key']))
- {
- $key = $param['key']; // get the parameter $key
- TTransaction::open('projeto'); // open a transaction
- $object = new AgendaDebora($key); // instantiates the Active Record
- $object->view = $param['view'];
- $this->form->setData($object); // fill the form
- TTransaction::close(); // close the transaction
- }
- else
- {
- $this->form->clear();
- }
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- public function onStartEdit($param)
- {
- $this->form->clear();
- $data = new stdClass;
- $data->view = $param['view']; // calendar view
- $data->cor = '#3a87ad';
- if ($param['date'])
- {
- if(strlen($param['date']) == '10')
- {
- $param['date'].= ' 09:00';
- }
- $data->horario_inicial = str_replace('T', ' ', $param['date']);
- $horario_final = new DateTime($data->horario_inicial);
- $horario_final->add(new DateInterval('PT1H'));
- $data->horario_final = $horario_final->format('Y-m-d H:i:s');
- $this->form->setData( $data );
- }
- }
- public static function onUpdateEvent($param)
- {
- try
- {
- if (isset($param['id']))
- {
- // open a transaction with database 'samples'
- TTransaction::open('projeto');
- $object = new AgendaDebora($param['id']);
- $object->horario_inicial = str_replace('T', ' ', $param['start_time']);
- $object->horario_final = str_replace('T', ' ', $param['end_time']);
- $object->store();
- // close the transaction
- TTransaction::close();
- }
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage());
- TTransaction::rollback();
- }
- }
- }?>
- <?php
- class AgendaDeboraFormView extends TPage
- {
- private $fc;
- /**
- * Page constructor
- */
- public function __construct()
- {
- parent::__construct();
- $this->fc = new TFullCalendar(date('Y-m-d'), 'month');
- $this->fc->enableDays([1,2,3,4,5,6]);
- $this->fc->setReloadAction(new TAction(array($this, 'getEvents')));
- $this->fc->setDayClickAction(new TAction(array('AgendaDeboraForm', 'onStartEdit')));
- $this->fc->setEventClickAction(new TAction(array('AgendaDeboraForm', 'onEdit')));
- $this->fc->setEventUpdateAction(new TAction(array('AgendaDeboraForm', 'onUpdateEvent')));
- $this->fc->setTimeRange('07:00', '19:00');
- parent::add( $this->fc );
- }
- /**
- * Output events as an json
- */
- public static function getEvents($param=NULL)
- {
- $return = array();
- try
- {
- TTransaction::open('projeto');
- $events = AgendaDebora::where('horario_inicial', '>=', $param['start'] . ' 00:00:00')
- ->where('horario_final', '<=', $param['end'] . ' 23:59:59')
- ->load();
- if ($events)
- {
- foreach ($events as $event)
- {
- $event_array = $event->toArray();
- $event_array['start'] = str_replace( ' ', 'T', $event_array['horario_inicial']);
- $event_array['end'] = str_replace( ' ', 'T', $event_array['horario_final']);
- $event_array['color'] = $event_array['cor'];
- $event_array['title'] = $event_array['titulo'];
- $return[] = $event_array;
- }
- }
- TTransaction::close();
- echo json_encode($return);
- }
- catch (Exception $e)
- {
- new TMessage('error', $e->getMessage());
- }
- }
- /**
- * Reconfigure the calendar
- */
- public function onReload($param = null)
- {
- if (isset($param['view']))
- {
- $this->fc->setCurrentView($param['view']);
- }
- if (isset($param['date']))
- {
- $this->fc->setCurrentDate($param['date']);
- }
- }
- }?>
Tente adicionar o nome no atributo "title", na função getEvents:
Funcionou, obrigado.
$event_array['title'] = $event_array['titulo'] . ' - ' . $event->cadastro->nome;