Conheça  A Ferramenta LowCode mais moderna e veloz para desenvolvimento PHP: Adianti Creator
Campos created_by and updated_by aparecendo id e não name Boa Tarde, Estou iniciando no Adianti Framework e estou precisando de um help. Tenho um model onde tenho os campos created_by e updated_by, onde gravo o id do usuário logado no momento da inclusão ou alteração. Entretanto, nas grids e forms gostaria de que o campo name do system_user aparecesse e não o id. Segue abaixo o código do model onde tentei fazer o acesso ao system_user e...
PS
Campos created_by and updated_by aparecendo id e não name  
Boa Tarde,

Estou iniciando no Adianti Framework e estou precisando de um help.

Tenho um model onde tenho os campos created_by e updated_by, onde gravo o id do usuário logado no momento da inclusão ou alteração.

Entretanto, nas grids e forms gostaria de que o campo name do system_user aparecesse e não o id.

Segue abaixo o código do model onde tentei fazer o acesso ao system_user e trazer o campo name.

Não entendi exatamente como fazer para aparecer o nome no campo created_by e updated_by ao invés do id. Toda ajuda será bem-vinda.

 
  1. <?php
  2. /**
  3. * TbSanEtaEte
  4. *
  5. * @version 1.0
  6. * @package model
  7. * @subpackage san
  8. * @author Pedro Isaias Soares
  9. * @copyright Copyright (c) 2022 gybwbr Solutions Ltd. (http://www.gybwbr.com)
  10. * @license http://www.adianti.com.br/framework-license
  11. */
  12. class TbSanIndEta extends TRecord
  13. {
  14. const TABLENAME = 'tb_san_indeta';
  15. const PRIMARYKEY= 'id';
  16. const IDPOLICY = 'max'; // {max, serial}
  17. private $tb_san_etaete;
  18. private $system_user;
  19. /**
  20. * Constructor method
  21. */
  22. public function __construct($id = NULL, $callObjectLoad = TRUE)
  23. {
  24. parent::__construct($id, $callObjectLoad);
  25. parent::addAttribute('dtlanc');
  26. parent::addAttribute('hrlanc');
  27. parent::addAttribute('sulal_dens');
  28. parent::addAttribute('sulal_conc');
  29. parent::addAttribute('ab_vazao');
  30. parent::addAttribute('ab_ph');
  31. parent::addAttribute('ab_turb');
  32. parent::addAttribute('pt_m1_precloro');
  33. parent::addAttribute('pt_m1_sulmg');
  34. parent::addAttribute('pt_m1_sulml');
  35. parent::addAttribute('pt_m1_turbdec');
  36. parent::addAttribute('pt_m1_turbf1');
  37. parent::addAttribute('pt_m1_turbf2');
  38. parent::addAttribute('pt_m1_turbf3');
  39. parent::addAttribute('pt_m1_turbf4');
  40. parent::addAttribute('pt_m2_turbdec');
  41. parent::addAttribute('pt_m2_turbf1');
  42. parent::addAttribute('pt_m2_turbf2');
  43. parent::addAttribute('pt_m2_turbf3');
  44. parent::addAttribute('pt_m2_turbf4');
  45. parent::addAttribute('pt_m2_turbf5');
  46. parent::addAttribute('pt_m2_turbf6');
  47. parent::addAttribute('pt_tc_ph');
  48. parent::addAttribute('pt_tc_turb');
  49. parent::addAttribute('pt_tc_cloro');
  50. parent::addAttribute('pt_tc_fluor');
  51. parent::addAttribute('af_res3m_ph');
  52. parent::addAttribute('af_res3m_turb');
  53. parent::addAttribute('af_res3m_cor');
  54. parent::addAttribute('af_res3m_cloro');
  55. parent::addAttribute('af_res3m_fluor');
  56. parent::addAttribute('nafp_ph');
  57. parent::addAttribute('nafp_turb');
  58. parent::addAttribute('nafp_cor');
  59. parent::addAttribute('nafp_cloro');
  60. parent::addAttribute('nafp_fluor');
  61. parent::addAttribute('created_by');
  62. parent::addAttribute('created_at');
  63. parent::addAttribute('updated_by');
  64. parent::addAttribute('updated_at');
  65. parent::addAttribute('tb_san_etaete_id');
  66. }
  67. public function onBeforeStore($object)
  68. {
  69. if (empty($object->id)) {
  70. $object->created_at = date('Y-m-d H:i:s');
  71. $object->created_by = TSession::getValue('userid');
  72. }
  73. $object->updated_at = date('Y-m-d H:i:s');
  74. $object->updated_by = TSession::getValue('userid');
  75. }
  76. /**
  77. * Method set_tb_san_etaete
  78. * Sample of usage: $tb_san_indeta->tb_san_etaete = $object;
  79. * @param $object Instance of TbSanEtaete
  80. */
  81. public function set_tb_san_etaete(TbSanEtaEte $object)
  82. {
  83. $this->tb_san_etaete = $object;
  84. $this->tb_san_etaete_id = $object->id;
  85. }
  86. /**
  87. * Method get_tb_san_etaete
  88. * Sample of usage: $tb_san_indeta->tb_san_etaete->attribute;
  89. * @returns TbSanEtaete instance
  90. */
  91. public function get_tb_san_etaete()
  92. {
  93. // loads the associated object
  94. if (empty($this->tb_san_etaete))
  95. $this->tb_san_etaete = new TbSanEtaEte($this->tb_san_etaete_id);
  96. // returns the associated object
  97. return $this->tb_san_etaete;
  98. }
  99. /**
  100. * Method set_system_user
  101. * Sample of usage: $tb_san_indeta->system_user = $object;
  102. * @param $object Instance of SystemUser
  103. */
  104. public function set_system_user(SystemUser $object)
  105. {
  106. $this->system_user = $object;
  107. $this->system_user_id = $object->id;
  108. }
  109. /**
  110. * Method get_system_user
  111. * Sample of usage: $tb_san_indeta->system_user->attribute;
  112. * @returns SystemUser instance
  113. */
  114. public function get_system_user()
  115. {
  116. // loads the associated object
  117. if (empty($this->system_user))
  118. $this->system_user = new SystemUser($this->system_user_id);
  119. // returns the associated object
  120. return $this->system_user;
  121. }
  122. }

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 (4)


PS

Boa Tarde, pessoal.

Consegui resolver o problema levantado anteriormente usando o Adianti Builder. Nele criei o model das tabelas e pedi para gerar as classes. Na sequencia copiei os dados gerados para o meu programa e funcionou para a Grid.

No TEntry do controle Form ainda não aparece, mas provavelmente deve ser o componente TEntry que não esta aceitando. Ele não deve funcionar como o componente TDBGrid no controle List.

Mas se puderem me informar como fazer com que quando eu seleciono um registro na grid para edição eu possa mostar o nome do usuário que fez inclusão e o nome do que fez alteração no Form que se abre agradeço. Na grid tá funcionando perfeitamente bem. No Form não aparece nada, nem o id nem o name.
LA

 
  1. <?php
  2. $updated_by = new THidden('usuario_nome');
  3. $created_by = new THidden('usuario_nome');
  4. $this->form->addFields([$updated_by],[$created_by]);
  5. public function onNew() {
  6. //ExemploList: $this->form->addAction(_t('New'), new TAction(array('ExemploForm', 'onNew')), 'ico_new2.png');
  7. $this->form->clear();
  8. $object = new StdClass;
  9. $object->created_by = TSession::getValue('username');
  10. $this->form->setData($object);
  11. }
  12. public function onEdit($param) {
  13. if (isset($param['key'])) {
  14. TTransaction::open($this->database);
  15. $object = new TbSanIndEta($param['key']);
  16. $object->updated_by = TSession::getValue('username');
  17. TTransaction::close();
  18. $this->form->setData($object);
  19. } else {
  20. $this->form->clear();
  21. }
  22. }
  23. ?>
LA

Corrigindo!
 
  1. <?php
  2. $updated_by = new THidden('updated_by');
  3. $created_by = new THidden('created_by');
  4. ?>
PS

Obrigado, Luis.

Adaptei o exemplo que você postou aqui e funcionou.

Valeu pela ajuda!!!