Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Mostrar dados na agenda Pessoal, como faço para mostrar o nome do paciente no resumo da agenda? ...
RA
Mostrar dados na agenda  
Pessoal, como faço para mostrar o nome do paciente no resumo da agenda?

  1. <?php
  2. class AgendaDeboraForm extends TWindow
  3. {
  4.     protected $form// form
  5.     private $formFields = [];
  6.     /**
  7.      * Form constructor
  8.      * @param $param Request
  9.      */
  10.     public function __construct$param )
  11.     {
  12.         parent::__construct();
  13.         parent::setSize(800null);
  14.         parent::setTitle('Lembrete');
  15.         parent::setProperty('class''window_modal');
  16.         
  17.         $this->form = new BootstrapFormBuilder('form_AgendaDebora');
  18.         $this->form->setFormTitle('Agenda Débora');
  19.         $view = new THidden('view');
  20.         $id = new TEntry('id');
  21.         $id_cadastro = new TDBUniqueSearch'id_cadastro''projeto''Cadastro''id''nome''nome asc'  );
  22.         $horario_inicial = new TDateTime('horario_inicial');
  23.         $horario_final = new TDateTime('horario_final');
  24.         $titulo = new TEntry('titulo');
  25.         $cor = new TColor('cor');
  26.         $observacao = new TText('observacao');
  27.         $id_cadastro->addValidation('Paciente', new TRequiredValidator()); 
  28.         $horario_inicial->addValidation('Horário inicial', new TRequiredValidator()); 
  29.         $horario_final->addValidation('Horário final', new TRequiredValidator()); 
  30.         $id->setEditable(false);
  31.         $id_cadastro->setMinLength(2);
  32.         $horario_final->setMask('dd/mm/yyyy hh:ii');
  33.         $horario_inicial->setMask('dd/mm/yyyy hh:ii');
  34.         $horario_final->setDatabaseMask('yyyy-mm-dd hh:ii');
  35.         $horario_inicial->setDatabaseMask('yyyy-mm-dd hh:ii');
  36.         $id->setSize(100);
  37.         $cor->setSize(100);
  38.         $titulo->setSize('72%');
  39.         $id_cadastro->setSize('76%');
  40.         $horario_final->setSize(150);
  41.         $horario_inicial->setSize(150);
  42.         $observacao->setSize('76%'68);
  43.         $id->setEditable(FALSE);
  44.         
  45.         $this->form->addFields([$view]);
  46.         $this->form->addFields([new TLabel('Id:')],[$id]);
  47.         $this->form->addFields([new TLabel('Paciente:''#ff0000')],[$id_cadastro]);
  48.         $this->form->addFields([new TLabel('Horário inicial:''#ff0000')],[$horario_inicial],[new TLabel('Horário final:''#ff0000')],[$horario_final]);
  49.         $this->form->addFields([new TLabel('Título:')],[$titulo],[new TLabel('Cor:')],[$cor]);
  50.         $this->form->addFields([new TLabel('Observação:')],[$observacao]);
  51.         // create the form actions
  52.         $this->form->addAction('Salvar', new TAction([$this'onSave']), 'fa:floppy-o')->addStyleClass('btn-primary');
  53.         $this->form->addAction('Limpar formulário', new TAction([$this'onClear']), 'fa:eraser #dd5a43');
  54.         $this->form->addAction('Excluir', new TAction([$this'onDelete']), 'fa:trash-o #dd5a43');
  55.         parent::add($this->form);
  56.     }
  57.     public function onSave($param null
  58.     {
  59.         try
  60.         {
  61.             TTransaction::open('projeto');
  62.             
  63.             $this->form->validate();
  64.             $data $this->form->getData();
  65.             
  66.             $object = new AgendaDebora(); 
  67.             $object->fromArray( (array) $data);
  68.             $object->store(); 
  69.             // get the generated {PRIMARY_KEY}
  70.             $data->id $object->id
  71.             $this->form->setData($data);
  72.             TTransaction::close();
  73.             
  74.             $action = new TAction(['AgendaDeboraFormView''onReload']);
  75.             $action->setParameter('view'$data->view);
  76.             $action->setParameter('date'explode(' '$data->horario_inicial)[0]); 
  77.             new TMessage('info'AdiantiCoreTranslator::translate('Record saved'), $action);
  78.         }
  79.         catch (Exception $e)
  80.         {
  81.             new TMessage('error'$e->getMessage());
  82.             $this->form->setData$this->form->getData() );
  83.             TTransaction::rollback();
  84.         }
  85.     }
  86.     
  87.     public function onDelete($param null
  88.     {
  89.         if (isset($param['delete']) && $param['delete'] == 1)
  90.         {
  91.             try
  92.             {
  93.                 $key $param['id'];
  94.                 TTransaction::open('projeto');
  95.                 $object = new AgendaDebora($keyFALSE);
  96.                 $object->delete();
  97.                 TTransaction::close();
  98.                 
  99.                 $action = new TAction(array('AgendaDeboraFormView''onReload'));
  100.                 $action->setParameter('view'$param['view']);
  101.                 $action->setParameter('date'explode(' '$param['horario_inicial'])[0]);
  102.                 // shows the success message
  103.                 new TMessage('info'AdiantiCoreTranslator::translate('Record deleted'), $action);
  104.             }
  105.             catch (Exception $e// in case of exception
  106.             {
  107.                 new TMessage('error'$e->getMessage());
  108.                 TTransaction::rollback();
  109.             }
  110.         }
  111.         else
  112.         {
  113.             // define the delete action
  114.             $action = new TAction(array($this'onDelete'));
  115.             $action->setParameters((array) $this->form->getData()); // pass the key paramsseter ahead
  116.             $action->setParameter('delete'1);
  117.             
  118.             // shows a dialog to the user
  119.             new TQuestion(AdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);   
  120.         }
  121.     }
  122.     /**
  123.      * Clear form data
  124.      * @param $param Request
  125.      */
  126.     public function onClear$param )
  127.     {
  128.         $this->form->clear();
  129.     }  
  130.     public function onEdit$param )
  131.     {
  132.         try
  133.         {
  134.             if (isset($param['key']))
  135.             {
  136.                 $key $param['key'];  // get the parameter $key
  137.                 TTransaction::open('projeto'); // open a transaction
  138.                 $object = new AgendaDebora($key); // instantiates the Active Record 
  139.                 $object->view $param['view']; 
  140.                 $this->form->setData($object); // fill the form 
  141.                 TTransaction::close(); // close the transaction 
  142.             }
  143.             else
  144.             {
  145.                 $this->form->clear();
  146.             }
  147.         }
  148.         catch (Exception $e// in case of exception
  149.         {
  150.             new TMessage('error'$e->getMessage()); // shows the exception error message
  151.             TTransaction::rollback(); // undo all pending operations
  152.         }
  153.     }
  154.     
  155.     public function onStartEdit($param)
  156.     {
  157.         $this->form->clear();
  158.         
  159.         $data = new stdClass;
  160.         $data->view $param['view']; // calendar view
  161.         $data->cor '#3a87ad';
  162.         if ($param['date'])
  163.         {
  164.             if(strlen($param['date']) == '10')
  165.             {
  166.                 $param['date'].= ' 09:00';
  167.             }
  168.             
  169.             $data->horario_inicial str_replace('T'' '$param['date']);
  170.             $horario_final = new DateTime($data->horario_inicial);
  171.             $horario_final->add(new DateInterval('PT1H'));
  172.             $data->horario_final $horario_final->format('Y-m-d H:i:s');
  173.             $this->form->setData$data );
  174.         }
  175.     }
  176.     public static function onUpdateEvent($param)
  177.     {
  178.         try
  179.         {
  180.             if (isset($param['id']))
  181.             {
  182.                 // open a transaction with database 'samples'
  183.                 TTransaction::open('projeto');
  184.                 $object = new AgendaDebora($param['id']);
  185.                 $object->horario_inicial str_replace('T'' '$param['start_time']);
  186.                 $object->horario_final   str_replace('T'' '$param['end_time']);
  187.                 $object->store();
  188.                 // close the transaction
  189.                 TTransaction::close();
  190.             }
  191.         }
  192.         catch (Exception $e// in case of exception
  193.         {
  194.             new TMessage('error'$e->getMessage());
  195.             TTransaction::rollback();
  196.         }
  197.     }
  198. }?>


  1. <?php
  2. class AgendaDeboraFormView extends TPage
  3. {
  4.     private $fc;
  5.     /**
  6.      * Page constructor
  7.      */
  8.     public function __construct()
  9.     {
  10.         parent::__construct();
  11.         $this->fc = new TFullCalendar(date('Y-m-d'), 'month');
  12.         $this->fc->enableDays([1,2,3,4,5,6]);
  13.         $this->fc->setReloadAction(new TAction(array($this'getEvents')));
  14.         $this->fc->setDayClickAction(new TAction(array('AgendaDeboraForm''onStartEdit')));
  15.         $this->fc->setEventClickAction(new TAction(array('AgendaDeboraForm''onEdit')));
  16.         $this->fc->setEventUpdateAction(new TAction(array('AgendaDeboraForm''onUpdateEvent')));
  17.         $this->fc->setTimeRange('07:00''19:00');
  18.         parent::add$this->fc );
  19.     }
  20.     /**
  21.      * Output events as an json
  22.      */
  23.     public static function getEvents($param=NULL)
  24.     {
  25.         $return = array();
  26.         try
  27.         {
  28.             TTransaction::open('projeto');
  29.             $events AgendaDebora::where('horario_inicial''>='$param['start'] . ' 00:00:00')
  30.                                 ->where('horario_final',   '<='$param['end']   . ' 23:59:59')
  31.                                 ->load();
  32.             if ($events)
  33.             {
  34.                 foreach ($events as $event)
  35.                 {
  36.                     $event_array $event->toArray();
  37.                     $event_array['start'] = str_replace' ''T'$event_array['horario_inicial']);
  38.                     $event_array['end']   = str_replace' ''T'$event_array['horario_final']);
  39.                     $event_array['color'] = $event_array['cor'];
  40.                     $event_array['title'] = $event_array['titulo'];
  41.                     $return[] = $event_array;
  42.                 }
  43.             }
  44.             TTransaction::close();
  45.             echo json_encode($return);
  46.         }
  47.         catch (Exception $e)
  48.         {
  49.             new TMessage('error'$e->getMessage());
  50.         }
  51.     }
  52.     /**
  53.      * Reconfigure the calendar
  54.      */
  55.     public function onReload($param null)
  56.     {
  57.         if (isset($param['view']))
  58.         {
  59.             $this->fc->setCurrentView($param['view']);
  60.         }
  61.         if (isset($param['date']))
  62.         {
  63.             $this->fc->setCurrentDate($param['date']);
  64.         }
  65.     }
  66. }?>

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (2)


NR

Tente adicionar o nome no atributo "title", na função getEvents:
  1. <?php
  2. $event_array['title'] = $event_array['titulo'] . ' - ' $event->atributo_com_nome_do_paciente;
  3. ?>
RA

Funcionou, obrigado.

$event_array['title'] = $event_array['titulo'] . ' - ' . $event->cadastro->nome;