TDataGrid com TCheckButton não funciona (Ajuda) Duas TDataGrid com TCheckButton na segunda não retorna nada no getData mesmo fazendo addField, alguém pode me ajudar? código abaixo: ...
IS
TDataGrid com TCheckButton não funciona (Ajuda)  
Duas TDataGrid com TCheckButton na segunda não retorna nada no getData mesmo fazendo addField, alguém pode me ajudar? código abaixo:


 
  1. <?php
  2. class ExameList extends TPage
  3. {
  4. private $form; // search form
  5. private $datagrid; // listing
  6. private $total;
  7. private $cartgrid;
  8. private $pageNavigation;
  9. private $loaded;
  10. public function __construct()
  11. {
  12. parent::__construct();
  13. //new TSession;
  14. // creates the form
  15. $this->form = new TForm('form_exame');
  16. // create the form fields
  17. $description = new TEntry('paciente');
  18. $check = new THidden('check_');
  19. $description->setSize(170);
  20. $description->setValue(TSession::getValue('product_description'));
  21. $table = new TTable;
  22. $row = $table->addRow();
  23. $cell=$row->addCell('');
  24. $cell->width= 100;
  25. $row->addCell($description);
  26. // creates the action button
  27. $button1=new TButton('find');
  28. $button1->setAction(new TAction(array($this, 'onSearch')), 'Busca');
  29. $button1->setImage('fa:search');
  30. $row->addCell($button1);
  31. $this->form->add($table);
  32. $this->form->setFields(array($description, $button1));
  33. // creates a DataGrid
  34. $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  35. $this->cartgrid = new BootstrapDatagridWrapper(new TDataGrid);
  36. $this->datagrid->style = 'width:100%';
  37. $this->cartgrid->style = 'width:100%';
  38. $this->datagrid->disableDefaultClick();
  39. $this->cartgrid->disableDefaultClick();
  40. //$panel = new TPanelGroup(_t('Datagrids with Checkbutton'));
  41. //$panel->add($this->cartgrid)->style = 'overflow-x:auto';
  42. //$this->form->add($panel);
  43. // creates the datagrid columns
  44. $cartao = new TDataGridColumn('CARTAO', 'Cartão SUS', 'left');
  45. $paciente = new TDataGridColumn('NOME_PAC', 'Nome', 'left');
  46. $sexo = new TDataGridColumn('sexo->nome', 'Sexo', 'left');
  47. $this->datagrid->addColumn($cartao);
  48. $this->datagrid->addColumn($paciente);
  49. $this->datagrid->addColumn($sexo);
  50. $DATA_NASC = new TDataGridColumn('DATA_NASC', 'Idade', 'center');
  51. $this->datagrid->addColumn($DATA_NASC);
  52. $DATA_NASC->setTransformer(function($value, $object, $row)
  53. {
  54. $rotulo = calcIdade::calcularIdade($value);
  55. if ($rotulo <= 18)
  56. {
  57. $bar = new TProgressBar;
  58. $bar->setMask('<b>'.$rotulo.'</b>');
  59. $bar->setValue(100);
  60. $bar->setClass('warning');
  61. return $bar;
  62. }
  63. else if (($rotulo >= 19) && ($rotulo <= 59))
  64. {
  65. $bar = new TProgressBar;
  66. $bar->setMask('<b>'.$rotulo.'</b>');
  67. $bar->setValue(100);
  68. $bar->setClass('success');
  69. return $bar;
  70. }
  71. else
  72. {
  73. $bar = new TProgressBar;
  74. $bar->setMask('<b>'.$rotulo.'</b>');
  75. $bar->setValue(100);
  76. $bar->setClass('danger');
  77. return $bar;
  78. }
  79. });
  80. $status = new TDataGridColumn('status', 'Status', 'center');
  81. $status->setTransformer(function($value, $object, $row)
  82. {
  83. if ($value == 1)
  84. {
  85. $bar = new TProgressBar;
  86. $bar->setMask('<b>Coletado</b>');
  87. $bar->setValue(100);
  88. $bar->setClass('warning');
  89. return $bar;
  90. }
  91. else if ($value == 0)
  92. {
  93. $bar = new TProgressBar;
  94. $bar->setMask('<b>Solicitado</b>');
  95. $bar->setValue(100);
  96. $bar->setClass('success');
  97. return $bar;
  98. }
  99. });
  100. $this->datagrid->addColumn($status);
  101. /////////////////////////////////
  102. $check = new TDataGridColumn('check_', 'ID', 'center', '30');
  103. $referencia = new TDataGridColumn('{referencia->procedimento}', 'Procedimento', 'left');
  104. $material = new TDataGridColumn('{material->nome}', 'Material', 'left');
  105. $this->cartgrid->addColumn($check);
  106. $this->cartgrid->addColumn($referencia);
  107. $this->cartgrid->addColumn($material);
  108. // creates datagrid actions
  109. $action1 = new TDataGridAction([$this, 'onSelect'], ['id' => '{id}','CARTAO' => '{CARTAO}'] );
  110. $action2 = new TDataGridAction([$this, 'onSave'], ['id' => '{id}'] );
  111. $this->datagrid->addAction($action1, 'Select', 'far:check-circle green');
  112. $this->datagrid->addAction($action2, 'Save', 'far:trash-alt red');
  113. //$this->cartgrid->addQuickAction('Delete', new TDataGridAction(array($this, 'onDelete')), 'id', 'fa:trash red');
  114. // create the datagrid model
  115. $this->datagrid->createModel();
  116. $this->cartgrid->createModel();
  117. // creates the page navigation
  118. $this->pageNavigation = new TPageNavigation;
  119. $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  120. // creates the page structure using a table
  121. $table1 = new TTable;
  122. $table1->style = 'width: 100%';
  123. $table1->addRow()->addCell($this->form)->height='50';
  124. $table1->addRow()->addCell($this->datagrid);
  125. $table1->addRow()->addCell($this->pageNavigation);
  126. $this->total = new TLabel('');
  127. $this->total->setFontStyle('b');
  128. $table2 = new TTable;
  129. $table2->style = 'width: 100%';
  130. $table2->addRow()->addCell($this->total)->height = '50';
  131. $table2->addRow()->addCell($this->cartgrid);
  132. $hbox = new THBox;
  133. $hbox->add($table1)->style.='vertical-align:top; width: 60%';
  134. $hbox->add($table2)->style.='vertical-align:top; width: 30%';
  135. // wrap the page content using vertical box
  136. $vbox = new TVBox;
  137. $vbox->style = 'width: 100%';
  138. $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  139. $vbox->add($hbox);
  140. //$vbox->add($this->pageNavigation);
  141. parent::add($vbox);
  142. }
  143. /**
  144. * Put a product inside the cart
  145. */
  146. public function onSelect($param)
  147. {
  148. // reload datagrids
  149. // $this->onReload( func_get_arg(0) );
  150. }
  151. public function onSave($param)
  152. {
  153. $data = $this->form->getData();
  154. $this->form->setData($data);
  155. try
  156. {
  157. TTransaction::open('marca');
  158. foreach ($this->form->getFields() as $name => $field)
  159. {
  160. if ($field instanceof TCheckButton)
  161. {
  162. if ($field->getValue() == 'on')
  163. {
  164. $obj = new Exame();
  165. $obj->check_ = 'on';
  166. $obj->store();
  167. }
  168. }
  169. }
  170. TTransaction::close();
  171. }
  172. catch (Exception $e)
  173. {
  174. // show the message
  175. new TMessage('error', $e->getMessage());
  176. }
  177. }
  178. /**
  179. * Remove a product from the cart
  180. */
  181. public function onDelete($param)
  182. {
  183. // get the cart objects from session
  184. $cart_objects = TSession::getValue('cart_objects');
  185. unset($cart_objects[$param['key']]);
  186. TSession::setValue('cart_objects', $cart_objects);
  187. // reload datagrids
  188. $this->onReload( func_get_arg(0) );
  189. }
  190. /**
  191. * method onSearch()
  192. * Register the filter in the session when the user performs a search
  193. */
  194. function onSearch()
  195. {
  196. // get the search form data
  197. $data = $this->form->getData();
  198. var_dump($data);
  199. // check if the user has filled the form
  200. if ($data->paciente)
  201. {
  202. // creates a filter using what the user has typed
  203. $filter = new TFilter('paciente', 'like', "%{$data->paciente}%");
  204. // stores the filter in the session
  205. TSession::setValue('product_filter1', $filter);
  206. TSession::setValue('product_description', $data->paciente);
  207. }
  208. else
  209. {
  210. TSession::setValue('product_filter1', NULL);
  211. TSession::setValue('product_description', '');
  212. }
  213. // fill the form with data again
  214. $this->form->setData($data);
  215. $param=array();
  216. $param['offset'] =0;
  217. $param['first_page']=1;
  218. $this->onReload($param);
  219. }
  220. /**
  221. * method onReload()
  222. * Load the datagrid with the database objects
  223. */
  224. function onReload($param = NULL)
  225. {
  226. try
  227. {
  228. // open a transaction with database 'samples'
  229. TTransaction::open('marca');
  230. // creates a repository for Product
  231. $repository = new TRepository('Exame');
  232. $limit = 10;
  233. // creates a criteria
  234. $criteria = new TCriteria;
  235. $criteria->setProperties($param); // order, offset
  236. $criteria->setProperty('limit', $limit);
  237. $criteria->setProperty('order', 'paciente');
  238. if (TSession::getValue('product_filter1'))
  239. {
  240. // add the filter stored in the session to the criteria
  241. $criteria->add(TSession::getValue('product_filter1'));
  242. }
  243. $conn = TTransaction::get();
  244. $sth = $conn->prepare("SELECT * FROM exame GROUP BY paciente");
  245. $sth->execute();
  246. $resultado = $sth->fetchAll(PDO::FETCH_CLASS);
  247. $this->datagrid->clear();
  248. if ($resultado)
  249. {
  250. foreach ($resultado as $product)
  251. {
  252. $criteria = new TCriteria;
  253. $criteria->add(new TFilter('CARTAO', '=', $product->paciente));
  254. // load using repository
  255. $repository = new TRepository('Paciente');
  256. $customers = $repository->load($criteria);
  257. foreach ($customers as $obj)
  258. {
  259. $obj->status = $product->status;
  260. $this->datagrid->addItem($obj);
  261. }
  262. }
  263. }
  264. if(isset($param['CARTAO']))
  265. {
  266. $criteria = new TCriteria;
  267. $criteria->add(new TFilter('paciente', '=', $param['CARTAO']));
  268. $repository = new TRepository('Exame');
  269. $customers = $repository->load($criteria);
  270. $this->cartgrid->clear();
  271. if ($customers)
  272. {
  273. foreach ($customers as $item)
  274. {
  275. $item->check_ = new TCheckButton('check'.$item->id);
  276. $item->check_->setIndexValue('on');
  277. $this->cartgrid->addItem($item);
  278. $this->form->addField($item->check_);
  279. }
  280. }
  281. }
  282. // reset the criteria for record count
  283. $criteria->resetProperties();
  284. $count= $repository->count($criteria);
  285. $this->pageNavigation->setCount($count); // count of records
  286. $this->pageNavigation->setProperties($param); // order, page
  287. $this->pageNavigation->setLimit($limit); // limit
  288. // close the transaction
  289. TTransaction::close();
  290. $this->loaded = true;
  291. }
  292. catch (Exception $e) // in case of exception
  293. {
  294. // shows the exception error message
  295. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  296. // undo all pending operations
  297. TTransaction::rollback();
  298. }
  299. }
  300. /**
  301. * method show()
  302. * Shows the page
  303. */
  304. function show()
  305. {
  306. // check if the datagrid is already loaded
  307. if (!$this->loaded)
  308. {
  309. $this->onReload( func_get_arg(0) );
  310. }
  311. parent::show();
  312. }
  313. }
  314. ?>


Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (5)


NR

Se está chamando a função onSave por uma ação da grid, não vai funcionar. As ações da grid fazem um get, não enviando as informações do formulário. Você precisa criar um botão, do mesmo modo que o "Busca".

Além disso, a organização dos containers também precisa ser ajustada. A grid precisa ser filha do formulário e atualmente a estrutura está assim:

1 - table
tr -> td -> form
tr -> td -> grid
tr -> td -> navigation

Somente os campos que estiverem dentro da tag form serão enviados no post.
IS

Nataniel Rabaioli ainda não consegui nada, se você tiver como gerar algum modelo ou exemplo, estou criando software para laboratorio, na primeira grid apresenta nomes e informações do paciente, na segunda grid tem que mostrar os exame por paciente e confirmar coleta através do TCheckButton. Fico grato pela atenção.
IS

Nataniel Rabaioli ainda não consegui nada, se você tiver como gerar algum modelo ou exemplo, estou criando software para laboratorio, na primeira grid apresenta nomes e informações do paciente, na segunda grid tem que mostrar os exame por paciente e confirmar coleta através do TCheckButton. Fico grato pela atenção.
NR

Veja o exemplo abaixo:
https://adianti.com.br/framework_files/tutor/index.php?class=DatagridCheckView

A datagrid é adicionada a um panel que por sua vez é adicionado ao form. É mais ou menos isso que você precisa, pois a grid precisa ser filha de form para que os checks sejam enviados.

Se tiver dúvidas inspecione o código fonte, os checks devem estar dentro da tag form.

E na onSave use $param para recuperar os dados ao invés de $this->form->getData().
IS

Nataniel Rabaioli seguindo o modelo do tutor "https://adianti.com.br/framework_files/tutor/index.php?class=MultiCheckView" mas ainda não consegui. Se puder ajudar desta vez eu não consigo fazer a carga das grids.
https://drive.google.com/file/d/1LH9pCLgL6B4eHqm5qhSWXy0uQ17I0I32/view?usp=sharing
Resumo: seleção da primeira grid por paciente gera uma segunda grid alimentada por TCheckButton coleta e resultado de lista de exames por pessoa.
Se alguém quiser ajudar e cobrar eu gostaria de entrar em contato.


 
  1. <?php
  2. class ExameList extends TStandardList
  3. {
  4. protected $form; // registration form
  5. protected $datagrid;
  6. protected $cartgrid; // listing
  7. protected $pageNavigation;
  8. protected $formDatagrid;
  9. protected $postAction;
  10. public function __construct($param)
  11. {
  12. parent::__construct();
  13. parent::setDatabase('marca'); // defines the database
  14. parent::setActiveRecord('Exame'); // defines the active record
  15. parent::setDefaultOrder('id', 'asc'); // defines the default order
  16. parent::addFilterField('description', 'like'); // add a filter field
  17. parent::setTransformer( array($this, 'onBeforeLoad') );
  18. // creates the form, with a table inside
  19. $this->form = new BootstrapFormBuilder('form_search_Product');
  20. //$this->form->setFormTitle(_t('Multi check form'));
  21. // create the form fields
  22. $description = new TEntry('NOME_PAC');
  23. // add a row for the filter field
  24. $this->form->addFields( [new TLabel('Description')], [$description] );
  25. $this->form->setData( TSession::getValue('Product_filter_data') );
  26. $this->form->addAction( _t('Find'), new TAction(array($this, 'onSearch')), 'fa:search');
  27. // create the datagrid form wrapper
  28. $this->formDatagrid = new TForm('datagrid_form');
  29. // creates a DataGrid
  30. $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  31. $this->datagrid->style='width:65%;float:left;margin:2px';
  32. $this->formDatagrid->add($this->datagrid);
  33. $this->datagrid->disableDefaultClick();
  34. $this->cartgrid = new BootstrapDatagridWrapper(new TDataGrid);
  35. $this->cartgrid->style = 'width:30%;float:left;margin:2px';'30%';
  36. $this->formDatagrid->add($this->cartgrid);
  37. $this->cartgrid->disableDefaultClick();
  38. // creates the datagrid columns
  39. $cartao = $this->datagrid->addColumn( new TDataGridColumn('CARTAO', 'Cartão SUS', 'left') );
  40. $paciente = $this->datagrid->addColumn( new TDataGridColumn('NOME_PAC', 'Nome', 'left') );
  41. $sexo = $this->datagrid->addColumn( new TDataGridColumn('sexo->nome', 'Sexo', 'left') );
  42. $DATA_NASC = $this->datagrid->addColumn( new TDataGridColumn('DATA_NASC', 'Idade', 'center') );
  43. $status = $this->datagrid->addColumn( new TDataGridColumn('status', 'Status', 'center') );
  44. $DATA_NASC->setTransformer(function($value, $object, $row)
  45. {
  46. $rotulo = calcIdade::calcularIdade($value);
  47. if ($rotulo <= 18)
  48. {
  49. $bar = new TProgressBar;
  50. $bar->setMask('<b>'.$rotulo.'</b>');
  51. $bar->setValue(100);
  52. $bar->setClass('warning');
  53. return $bar;
  54. }
  55. else if (($rotulo >= 19) && ($rotulo <= 59))
  56. {
  57. $bar = new TProgressBar;
  58. $bar->setMask('<b>'.$rotulo.'</b>');
  59. $bar->setValue(100);
  60. $bar->setClass('success');
  61. return $bar;
  62. }
  63. else
  64. {
  65. $bar = new TProgressBar;
  66. $bar->setMask('<b>'.$rotulo.'</b>');
  67. $bar->setValue(100);
  68. $bar->setClass('danger');
  69. return $bar;
  70. }
  71. });
  72. $status->setTransformer(function($value, $object, $row)
  73. {
  74. if ($value == 1)
  75. {
  76. $bar = new TProgressBar;
  77. $bar->setMask('<b>Coletado</b>');
  78. $bar->setValue(100);
  79. $bar->setClass('warning');
  80. return $bar;
  81. }
  82. else if ($value == 0)
  83. {
  84. $bar = new TProgressBar;
  85. $bar->setMask('<b>Solicitado</b>');
  86. $bar->setValue(100);
  87. $bar->setClass('success');
  88. return $bar;
  89. }
  90. });
  91. $check = $this->cartgrid->addColumn( new TDataGridColumn('check', 'ID', 'center') );
  92. $referencia = $this->cartgrid->addColumn( new TDataGridColumn('{referencia->procedimento}', 'Procedimento', 'left') );
  93. $material = $this->cartgrid->addColumn( new TDataGridColumn('{material->nome}', 'Material', 'left') );
  94. // creates datagrid actions
  95. $action1 = new TDataGridAction([$this, 'onSelect'], ['id' => '{id}','CARTAO' => '{CARTAO}'] );
  96. //$action2 = new TDataGridAction([$this, 'onSave'], ['id' => '{id}'] );
  97. $this->datagrid->addAction($action1, 'Select', 'far:check-circle green');
  98. // create the datagrid model
  99. $this->datagrid->createModel();
  100. $this->cartgrid->createModel();
  101. // create the page navigation
  102. $this->pageNavigation = new TPageNavigation;
  103. $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  104. $this->postAction = new TAction(array($this, 'onPost'));
  105. $post = new TButton('post');
  106. $post->setAction($this->postAction);
  107. $post->setImage('far:check-circle green');
  108. $post->setLabel('Send');
  109. $this->formDatagrid->addField($post);
  110. // create the page container
  111. $container = new TVBox;
  112. $container->style = 'width: 100%';
  113. $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  114. $container->add($this->form);
  115. $container->add($panel = TPanelGroup::pack('', $this->formDatagrid, $this->pageNavigation));
  116. $panel->getBody()->style = 'overflow-x: auto';
  117. $container->add($post);
  118. parent::add($container);
  119. }
  120. public function onSelect($param)
  121. {
  122. }
  123. public function onReload( $param = NULL )
  124. {
  125. try
  126. {
  127. // open a transaction with database 'samples'
  128. TTransaction::open('marca');
  129. // creates a repository for Product
  130. $repository = new TRepository('Exame');
  131. $limit = 10;
  132. // creates a criteria
  133. $criteria = new TCriteria;
  134. $criteria->setProperties($param); // order, offset
  135. $criteria->setProperty('limit', $limit);
  136. $criteria->setProperty('order', 'paciente');
  137. if (TSession::getValue('product_filter1'))
  138. {
  139. // add the filter stored in the session to the criteria
  140. $criteria->add(TSession::getValue('product_filter1'));
  141. }
  142. $conn = TTransaction::get();
  143. $sth = $conn->prepare("SELECT * FROM exame GROUP BY paciente");
  144. $sth->execute();
  145. $resultado = $sth->fetchAll(PDO::FETCH_CLASS);
  146. $this->datagrid->clear();
  147. if ($resultado)
  148. {
  149. foreach ($resultado as $product)
  150. {
  151. $criteria = new TCriteria;
  152. $criteria->add(new TFilter('CARTAO', '=', $product->paciente));
  153. // load using repository
  154. $repository = new TRepository('Paciente');
  155. $customers = $repository->load($criteria);
  156. foreach ($customers as $obj)
  157. {
  158. $obj->status = $product->status;
  159. $this->datagrid->addItem($obj);
  160. }
  161. }
  162. }
  163. ///////////////////////////////
  164. if(isset($param['CARTAO']))
  165. {
  166. $criteriab = new TCriteria;
  167. $criteriab->add(new TFilter('paciente', '=', $param['CARTAO']));
  168. $repositoryb = new TRepository('Exame');
  169. $customerss = $repositoryb->load($criteriab);
  170. $this->cartgrid->clear();
  171. if ($customerss)
  172. {
  173. foreach ($customerss as $item)
  174. {
  175. $this->cartgrid->addItem($item);
  176. }
  177. }
  178. }
  179. // reset the criteria for record count
  180. $criteria->resetProperties();
  181. $count= $repository->count($criteria);
  182. $this->pageNavigation->setCount($count); // count of records
  183. $this->pageNavigation->setProperties($param); // order, page
  184. $this->pageNavigation->setLimit($limit); // limit
  185. // close the transaction
  186. TTransaction::close();
  187. $this->loaded = true;
  188. $this->postAction->setParameters($param); // important!
  189. return parent::onReload( $param );
  190. }
  191. catch (Exception $e) // in case of exception
  192. {
  193. // shows the exception error message
  194. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  195. // undo all pending operations
  196. TTransaction::rollback();
  197. }
  198. }
  199. /**
  200. * Transform the objects before load them into the datagrid
  201. */
  202. public function onBeforeLoad( $objects )
  203. {
  204. foreach ($objects as $object)
  205. {
  206. $object->check = new TCheckButton('check_'.$object->id);
  207. $object->check->setIndexValue('on');
  208. $this->form->addField($object->check); // important!
  209. }
  210. }
  211. /**
  212. * Get post data and redirects to the next screen
  213. */
  214. public function onPost( $param )
  215. {
  216. $data = $this->form->getData();
  217. $this->form->setData($data);
  218. $selected_products = array();
  219. foreach ($this->form->getFields() as $name => $field)
  220. {
  221. if ($field instanceof TCheckButton)
  222. {
  223. $parts = explode('_', $name);
  224. $id = $parts[1];
  225. if ($field->getValue() == 'on')
  226. {
  227. $selected_products[] = $id;
  228. }
  229. }
  230. }
  231. TSession::setValue('selected_products', $selected_products );
  232. TApplication::loadPage('MultiCheck2View');
  233. }
  234. }
 
  1. <?php
  2. class ExameList extends TStandardList
  3. {
  4. protected $form; // registration form
  5. protected $datagrid;
  6. protected $cartgrid; // listing
  7. protected $pageNavigation;
  8. protected $formDatagrid;
  9. protected $postAction;
  10. public function __construct($param)
  11. {
  12. parent::__construct();
  13. parent::setDatabase('marca'); // defines the database
  14. parent::setActiveRecord('Exame'); // defines the active record
  15. parent::setDefaultOrder('id', 'asc'); // defines the default order
  16. parent::addFilterField('description', 'like'); // add a filter field
  17. parent::setTransformer( array($this, 'onBeforeLoad') );
  18. // creates the form, with a table inside
  19. $this->form = new BootstrapFormBuilder('form_search_Product');
  20. //$this->form->setFormTitle(_t('Multi check form'));
  21. // create the form fields
  22. $description = new TEntry('NOME_PAC');
  23. // add a row for the filter field
  24. $this->form->addFields( [new TLabel('Description')], [$description] );
  25. $this->form->setData( TSession::getValue('Product_filter_data') );
  26. $this->form->addAction( _t('Find'), new TAction(array($this, 'onSearch')), 'fa:search');
  27. // create the datagrid form wrapper
  28. $this->formDatagrid = new TForm('datagrid_form');
  29. // creates a DataGrid
  30. $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  31. $this->datagrid->style='width:65%;float:left;margin:2px';
  32. $this->formDatagrid->add($this->datagrid);
  33. $this->datagrid->disableDefaultClick();
  34. $this->cartgrid = new BootstrapDatagridWrapper(new TDataGrid);
  35. $this->cartgrid->style = 'width:30%;float:left;margin:2px';'30%';
  36. $this->formDatagrid->add($this->cartgrid);
  37. $this->cartgrid->disableDefaultClick();
  38. // creates the datagrid columns
  39. $cartao = $this->datagrid->addColumn( new TDataGridColumn('CARTAO', 'Cartão SUS', 'left') );
  40. $paciente = $this->datagrid->addColumn( new TDataGridColumn('NOME_PAC', 'Nome', 'left') );
  41. $sexo = $this->datagrid->addColumn( new TDataGridColumn('sexo->nome', 'Sexo', 'left') );
  42. $DATA_NASC = $this->datagrid->addColumn( new TDataGridColumn('DATA_NASC', 'Idade', 'center') );
  43. $status = $this->datagrid->addColumn( new TDataGridColumn('status', 'Status', 'center') );
  44. $DATA_NASC->setTransformer(function($value, $object, $row)
  45. {
  46. $rotulo = calcIdade::calcularIdade($value);
  47. if ($rotulo <= 18)
  48. {
  49. $bar = new TProgressBar;
  50. $bar->setMask('<b>'.$rotulo.'</b>');
  51. $bar->setValue(100);
  52. $bar->setClass('warning');
  53. return $bar;
  54. }
  55. else if (($rotulo >= 19) && ($rotulo <= 59))
  56. {
  57. $bar = new TProgressBar;
  58. $bar->setMask('<b>'.$rotulo.'</b>');
  59. $bar->setValue(100);
  60. $bar->setClass('success');
  61. return $bar;
  62. }
  63. else
  64. {
  65. $bar = new TProgressBar;
  66. $bar->setMask('<b>'.$rotulo.'</b>');
  67. $bar->setValue(100);
  68. $bar->setClass('danger');
  69. return $bar;
  70. }
  71. });
  72. $status->setTransformer(function($value, $object, $row)
  73. {
  74. if ($value == 1)
  75. {
  76. $bar = new TProgressBar;
  77. $bar->setMask('<b>Coletado</b>');
  78. $bar->setValue(100);
  79. $bar->setClass('warning');
  80. return $bar;
  81. }
  82. else if ($value == 0)
  83. {
  84. $bar = new TProgressBar;
  85. $bar->setMask('<b>Solicitado</b>');
  86. $bar->setValue(100);
  87. $bar->setClass('success');
  88. return $bar;
  89. }
  90. });
  91. $check = $this->cartgrid->addColumn( new TDataGridColumn('check', 'ID', 'center') );
  92. $referencia = $this->cartgrid->addColumn( new TDataGridColumn('{referencia->procedimento}', 'Procedimento', 'left') );
  93. $material = $this->cartgrid->addColumn( new TDataGridColumn('{material->nome}', 'Material', 'left') );
  94. // creates datagrid actions
  95. $action1 = new TDataGridAction([$this, 'onSelect'], ['id' => '{id}','CARTAO' => '{CARTAO}'] );
  96. //$action2 = new TDataGridAction([$this, 'onSave'], ['id' => '{id}'] );
  97. $this->datagrid->addAction($action1, 'Select', 'far:check-circle green');
  98. // create the datagrid model
  99. $this->datagrid->createModel();
  100. $this->cartgrid->createModel();
  101. // create the page navigation
  102. $this->pageNavigation = new TPageNavigation;
  103. $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  104. $this->postAction = new TAction(array($this, 'onPost'));
  105. $post = new TButton('post');
  106. $post->setAction($this->postAction);
  107. $post->setImage('far:check-circle green');
  108. $post->setLabel('Send');
  109. $this->formDatagrid->addField($post);
  110. // create the page container
  111. $container = new TVBox;
  112. $container->style = 'width: 100%';
  113. $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  114. $container->add($this->form);
  115. $container->add($panel = TPanelGroup::pack('', $this->formDatagrid, $this->pageNavigation));
  116. $panel->getBody()->style = 'overflow-x: auto';
  117. $container->add($post);
  118. parent::add($container);
  119. }
  120. public function onSelect($param)
  121. {
  122. }
  123. public function onReload( $param = NULL )
  124. {
  125. try
  126. {
  127. // open a transaction with database 'samples'
  128. TTransaction::open('marca');
  129. // creates a repository for Product
  130. $repository = new TRepository('Exame');
  131. $limit = 10;
  132. // creates a criteria
  133. $criteria = new TCriteria;
  134. $criteria->setProperties($param); // order, offset
  135. $criteria->setProperty('limit', $limit);
  136. $criteria->setProperty('order', 'paciente');
  137. if (TSession::getValue('product_filter1'))
  138. {
  139. // add the filter stored in the session to the criteria
  140. $criteria->add(TSession::getValue('product_filter1'));
  141. }
  142. $conn = TTransaction::get();
  143. $sth = $conn->prepare("SELECT * FROM exame GROUP BY paciente");
  144. $sth->execute();
  145. $resultado = $sth->fetchAll(PDO::FETCH_CLASS);
  146. $this->datagrid->clear();
  147. if ($resultado)
  148. {
  149. foreach ($resultado as $product)
  150. {
  151. $criteria = new TCriteria;
  152. $criteria->add(new TFilter('CARTAO', '=', $product->paciente));
  153. // load using repository
  154. $repository = new TRepository('Paciente');
  155. $customers = $repository->load($criteria);
  156. foreach ($customers as $obj)
  157. {
  158. $obj->status = $product->status;
  159. $this->datagrid->addItem($obj);
  160. }
  161. }
  162. }
  163. ///////////////////////////////
  164. if(isset($param['CARTAO']))
  165. {
  166. $criteriab = new TCriteria;
  167. $criteriab->add(new TFilter('paciente', '=', $param['CARTAO']));
  168. $repositoryb = new TRepository('Exame');
  169. $customerss = $repositoryb->load($criteriab);
  170. $this->cartgrid->clear();
  171. if ($customerss)
  172. {
  173. foreach ($customerss as $item)
  174. {
  175. $this->cartgrid->addItem($item);
  176. }
  177. }
  178. }
  179. // reset the criteria for record count
  180. $criteria->resetProperties();
  181. $count= $repository->count($criteria);
  182. $this->pageNavigation->setCount($count); // count of records
  183. $this->pageNavigation->setProperties($param); // order, page
  184. $this->pageNavigation->setLimit($limit); // limit
  185. // close the transaction
  186. TTransaction::close();
  187. $this->loaded = true;
  188. $this->postAction->setParameters($param); // important!
  189. return parent::onReload( $param );
  190. }
  191. catch (Exception $e) // in case of exception
  192. {
  193. // shows the exception error message
  194. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  195. // undo all pending operations
  196. TTransaction::rollback();
  197. }
  198. }
  199. /**
  200. * Transform the objects before load them into the datagrid
  201. */
  202. public function onBeforeLoad( $objects )
  203. {
  204. foreach ($objects as $object)
  205. {
  206. $object->check = new TCheckButton('check_'.$object->id);
  207. $object->check->setIndexValue('on');
  208. $this->form->addField($object->check); // important!
  209. }
  210. }
  211. /**
  212. * Get post data and redirects to the next screen
  213. */
  214. public function onPost( $param )
  215. {
  216. $data = $this->form->getData();
  217. $this->form->setData($data);
  218. $selected_products = array();
  219. foreach ($this->form->getFields() as $name => $field)
  220. {
  221. if ($field instanceof TCheckButton)
  222. {
  223. $parts = explode('_', $name);
  224. $id = $parts[1];
  225. if ($field->getValue() == 'on')
  226. {
  227. $selected_products[] = $id;
  228. }
  229. }
  230. }
  231. TSession::setValue('selected_products', $selected_products );
  232. TApplication::loadPage('MultiCheck2View');
  233. }
  234. }