Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Cadastro Mater/Detail - não grava os detalhes Pessoal se alguém puder dar uma olhada o que está errado em meu fonte, o cadastro máster/detalhe só está gravando o registro pai, os filhos (detalhes) não estão gravando e o sistema não retorna nenhum erro e anda dá mensagem que o registro foi gravado com sucesso. Porém não está gravando no BD os detalhes vou colocar o fonte das classes modelos e o form de controle. Classe Modelo M...
LB
Cadastro Mater/Detail - não grava os detalhes  
Fechado
Pessoal se alguém puder dar uma olhada o que está errado em meu fonte, o cadastro máster/detalhe só está gravando o registro pai, os filhos (detalhes) não estão gravando e o sistema não retorna nenhum erro e anda dá mensagem que o registro foi gravado com sucesso.
Porém não está gravando no BD os detalhes vou colocar o fonte das classes modelos e o form de controle.

Classe Modelo Mater (Prova)
  1. <?php e
  2. /**
  3.  * SaleForm Registration
  4.  * @author  Leandro J N Barbosa
  5.  */
  6. class ProvaForm extends TPage
  7. {
  8.     protected $form// form
  9.     protected $formFields;
  10.     protected $dt_venda;
  11.     
  12.     /**
  13.      * Class constructor
  14.      * Creates the page and the registration form
  15.      */
  16.     function __construct()
  17.     {
  18.         parent::__construct();
  19.         
  20.         // creates the form
  21.         $this->form = new TForm('form_prova');
  22.         $this->form->class 'tform'// CSS class
  23.         parent::include_css('app/resources/custom-frame.css');
  24.         
  25.         $table_master = new TTable;
  26.         $table_master->width '115%';
  27.         
  28.         $table_master->addRowSet( new TLabel('Avaliação'), '''')->class 'tformtitle';
  29.         
  30.         // add a table inside form
  31.         $table_general = new TTable;
  32.         $table_general-> width '105%';
  33.         $tableQuestao = new TTable;
  34.         $tableQuestao-> width '103%';
  35.         
  36.         $frame_general = new TFrame;
  37.         $frame_general->setLegend('Prova');
  38.         $frame_general->style 'background:whiteSmoke';
  39.         $frame_general->add($table_general);
  40.         
  41.         $table_master->addRow()->addCell$frame_general )->colspan=2;
  42.         $row $table_master->addRow();
  43.         $row->addCell$tableQuestao );
  44.         
  45.         $this->form->add($table_master);
  46.         
  47.         // master fields
  48.         $cod_prova           = new TEntry('cod_prova');
  49.         $descricao           = new TEntry('descricao');
  50.         $cod_cab             = new  ">TDBSeekButton('cod_cab''super_prova'$this->form->getName(), 'Cabecalho''descricao''cod_cab''cabecalho_descricao');
  51.         $cabecalho_descricao = new TEntry('cabecalho_descricao');
  52.         $observacao          = new TText('observacao');
  53.         
  54.         // detail fields
  55.         $cod_quest          = new  ">TDBSeekButton('cod_quest''super_prova'$this->form->getName(), 'Questoes''enunciado''cod_quest''questoes_enunciado');
  56.         $questoes_enunciado = new TText('questoes_enunciado');
  57.         $valor              = new TEntry('valor');
  58.         
  59.         $cod_prova->setSize(80);
  60.         $descricao->setSize(650);
  61.         $cabecalho_descricao->setSize(577);
  62.         $observacao->setSize(650,100);
  63.         $cod_quest->setSize(50);
  64.         $cod_cab->setSize(50);
  65.         $questoes_enunciado->setSize(625,100);
  66.         
  67.         $cod_prova->setEditable(false);
  68.         $questoes_enunciado->setEditable(false);
  69.         $cabecalho_descricao->setEditable(false);
  70.         
  71.         $descricao->addValidation('Descricao', new TRequiredValidator);
  72.         $cod_cab->addValidation('Cabecalho', new TRequiredValidator);
  73.         // prova
  74.         $table_general->addRowSet( new TLabel('Cód. Prova'), $cod_prova);
  75.         $table_general->addRowSet$label_descricao   = new TLabel('Descrição (*)'), $descricao );
  76.         $table_general->addRowSet$label_cabecalho   = new TLabel('Cabeçalho (*)'), array( $cod_cab$cabecalho_descricao ) );
  77.         $table_general->addRowSet( new TLabel('Observação'), $observacao );
  78.         $label_descricao->setFontColor('#FF0000');
  79.         $label_cabecalho->setFontColor('#FF0000');
  80.                
  81.         // questoes
  82.         $frame_quest = new TFrame();
  83.         $frame_quest->setLegend('Questões');
  84.         $row $tableQuestao->addRow();
  85.         $row->addCell($frame_quest);
  86.         
  87.         $add_quest = new TButton('add_quest');
  88.         $action_quest = new TAction(array($this'onQuestAdd'));
  89.         $add_quest->setAction($action_quest'Gravar');
  90.         $add_quest->setImage('fa:save');
  91.         
  92.         $subtable_quest = new TTable;
  93.         $frame_quest->add($subtable_quest);
  94.         $subtable_quest->addRowSet$label_quest = new TLabel('Questão (*)'), array($cod_quest,$questoes_enunciado) );
  95.         $subtable_quest->addRowSet$label_valor = new TLabel('Valor (*)'), $valor );
  96.         $subtable_quest->addRowSet$add_quest );
  97.         
  98.         $label_quest->setFontColor('#FF0000');
  99.         $label_valor->setFontColor('#FF0000');
  100.         
  101.         $this->quest_list = new TQuickGrid;
  102.         $this->quest_list->setHeight175 );
  103.         $this->quest_list->makeScrollable();
  104.         $this->quest_list->disableDefaultClick();
  105.         $this->quest_list->addQuickColumn('''edit''left'50);
  106.         $this->quest_list->addQuickColumn('''delete''left'50);
  107.         $this->quest_list->addQuickColumn('Cód. Questão''cod_quest''left'50);
  108.         $this->quest_list->addQuickColumn('Enunciado''questoes_enunciado''left'400);
  109.         $this->quest_list->addQuickColumn('Valor','valor''left'80);
  110.         $this->quest_list->createModel();
  111.         
  112.         $row $tableQuestao->addRow();
  113.         $row->addCell($this->quest_list);
  114.         
  115.         // create an action button (save)
  116.         $save_button=new TButton('save');
  117.         $save_button->setAction(new TAction(array($this'onSave')), _t('Save'));
  118.         $save_button->setImage('ico_save.png');
  119.         // create an new button (edit with no parameters)
  120.         $new_button=new TButton('new');
  121.         $new_button->setAction(new TAction(array($this'onClear')), _t('New'));
  122.         $new_button->setImage('ico_new.png');
  123.         
  124.         // define form fields
  125.         $this->formFields = array($cod_prova,$descricao$cod_cab$cabecalho_descricao$observacao$cod_quest$questoes_enunciado$valor$add_quest$save_button$new_button);
  126.         $this->form->setFields$this->formFields );
  127.         
  128.         $table_master->addRowSet( array($save_button$new_button), '''')->class 'tformaction'// CSS class
  129.         
  130.         // create the page container
  131.         $container = new TVBox;
  132.         $container->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  133.         $container->add($this->form);
  134.         parent::add($container);
  135.     }  
  136.     
  137.     /**
  138.      * Clear form
  139.      * @param $param URL parameters
  140.      */
  141.     function onClear($param)
  142.     {
  143.         $this->form->clear();
  144.         TSession::setValue('quest_prova', array());
  145.         $this->onReload$param );
  146.     }
  147.     
  148.     /**
  149.      * Add a question into item list
  150.      * @param $param URL parameters
  151.      */
  152.     public function onQuestAdd$param )
  153.     {
  154.         try
  155.         {
  156.             TTransaction::open('super_prova');
  157.             $data $this->form->getData();
  158.             
  159.             if( (! $data->cod_quest) || (! $data->valor) )
  160.                 throw new Exception('Os campos Questão e Valor são obrigatórios');
  161.             
  162.             $questao = new Questoes($data->cod_quest);
  163.             
  164.             $quest_prova TSession::getValue('quest_prova');
  165.             $key = (int) $data->cod_quest;
  166.             $quest_prova$key ] = array('cod_quest'          => $data->cod_quest,
  167.                                          'questoes_enunciado' => $data->questoes_enunciado,
  168.                                          'valor'              => $data->valor);
  169.             
  170.             TSession::setValue('quest_prova'$quest_prova);
  171.             
  172.             // clear questao form fields after add
  173.             $data->cod_quest '';
  174.             $data->questoes_enunciado '';
  175.             $data->valor '';
  176.             TTransaction::close();
  177.             $this->form->setData($data);
  178.             
  179.             $this->onReload$param ); // reload the sale items
  180.         }
  181.         catch (Exception $e)
  182.         {
  183.             $this->form->setData$this->form->getData());
  184.             new TMessage('error'$e->getMessage());
  185.         }
  186.     }
  187.     
  188.     /**
  189.      * Edit a question from item list
  190.      * @param $param URL parameters
  191.      */
  192.     public function onEditItemQuest$param )
  193.     {
  194.         $data $this->form->getData();
  195.         
  196.         // read session items
  197.         $quest_prova TSession::getValue('quest_prova');
  198.         
  199.         // get the session item
  200.         $quest_item $quest_prova[ (int) $param['list_cod_quest'] ];
  201.         
  202.         $data->cod_quest $param['list_cod_quest'];
  203.         $data->questoes_enunciado $quest_item['questoes_enunciado'];
  204.         $data->valor $quest_item['valor'];
  205.         
  206.         // fill product fields
  207.         $this->form->setData$data );
  208.     
  209.         $this->onReload$param );
  210.     }
  211.     
  212.     /**
  213.      * Delete a product from item list
  214.      * @param $param URL parameters
  215.      */
  216.     public function onDeleteItem$param )
  217.     {
  218.         $data $this->form->getData();
  219.         
  220.         $data->cod_quest '';
  221.         $data->questoes_enunciado '';
  222.         $data->valor '';
  223.         
  224.         // clear form data
  225.         $this->form->setData$data );
  226.         
  227.         // read session items
  228.         $quest_prova TSession::getValue('quest_prova');
  229.         
  230.         // delete the item from session
  231.         unset($quest_prova[ (int) $param['list_cod_quest'] ] );
  232.         TSession::setValue('quest_prova'$quest_prova);
  233.         
  234.         // reload sale items
  235.         $this->onReload$param );
  236.     }
  237.     
  238.     /**
  239.      * Reload the item list
  240.      * @param $param URL parameters
  241.      */
  242.     public function onReload($param)
  243.     {
  244.         // read session items
  245.         $quest_prova TSession::getValue('quest_prova');
  246.         
  247.         $this->quest_list->clear(); // clear product list
  248.         $data $this->form->getData();
  249.         
  250.         if ($quest_prova)
  251.         {
  252.             $cont 1;
  253.             foreach ($quest_prova as $list_cod_quest => $list_quest)
  254.             {
  255.                 $item_name 'quest_' $cont++;
  256.                 $item = new StdClass;
  257.                 
  258.                 // create action buttons
  259.                 $action_del = new TAction(array($this'onDeleteItem'));
  260.                 $action_del->setParameter('list_cod_quest'$list_cod_quest);
  261.                 
  262.                 $action_edi = new TAction(array($this'onEditItemQuest'));
  263.                 $action_edi->setParameter('list_cod_quest'$list_cod_quest);
  264.                 
  265.                 $button_del = new TButton('delete_quest'.$cont);
  266.                 $button_del->class 'btn btn-default btn-sm';
  267.                 $button_del->setAction$action_del'' );
  268.                 $button_del->setImage('fa:trash-o red fa-lg');
  269.                 
  270.                 $button_edi = new TButton('edit_quest'.$cont);
  271.                 $button_edi->class 'btn btn-default btn-sm';
  272.                 $button_edi->setAction$action_edi'' );
  273.                 $button_edi->setImage('fa:edit blue fa-lg');
  274.                 
  275.                 $item->edit $button_edi;
  276.                 $item->delete $button_del;
  277.                 
  278.                 $this->formFields$item_name.'_edit' ] = $item->edit;
  279.                 $this->formFields$item_name.'_delete' ] = $item->delete;
  280.                 
  281.                 $item->cod_quest $list_quest['cod_quest'];
  282.                 $item->questoes_enunciado $list_quest['questoes_enunciado'];              
  283.                 $item->valor $list_quest['valor'];
  284.                 
  285.                 $row $this->quest_list->addItem$item );
  286.                 $row->onmouseover='';
  287.                 $row->onmouseout='';
  288.             }
  289.             $this->form->setFields$this->formFields );
  290.         }
  291.         
  292.         $this->loaded TRUE;
  293.     }
  294.     
  295.     /**
  296.      * method onEdit()
  297.      * Executed whenever the user clicks at the edit button da datagrid
  298.      */
  299.     function onEdit($param)
  300.     {
  301.         try
  302.         {
  303.             TTransaction::open('super_prova');
  304.             
  305.             if (isset($param['key']))
  306.             {
  307.                 $key $param['key'];
  308.                 
  309.                 $object = new Prova($key);
  310.                 $quest_prova $object->getQuestProva();
  311.                 
  312.                 $session_items = array();
  313.                 foreach( $quest_prova as $item )
  314.                 {
  315.                     $session_items[$item->cod_quest] = $item->toArray();
  316.                     $session_items[$item->cod_quest]['cod_quest'] = $item->cod_quest;
  317.                     $session_items[$item->cod_quest]['questoes_enunciado'] = $item->questoes_enunciado;
  318.                     $session_items[$item->cod_quest]['valor'] = $item->valor;
  319.                 }
  320.                 TSession::setValue('quest_prova'$session_items);
  321.                 
  322.                 $this->form->setData($object); // fill the form with the active record data
  323.                 $this->onReload$param ); // reload sale items list
  324.                 TTransaction::close(); // close transaction
  325.             }
  326.             else
  327.             {
  328.                 $this->form->clear();
  329.                 TSession::setValue('quest_prova'null);
  330.                 $this->onReload$param );
  331.             }
  332.         }
  333.         catch (Exception $e// in case of exception
  334.         {
  335.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  336.             TTransaction::rollback();
  337.         }
  338.     }
  339.     
  340.     /**
  341.      * Save the sale and the sale items
  342.      */
  343.     function onSave()
  344.     {
  345.         try
  346.         {
  347.             // open a transaction with database 'super_prova'
  348.             TTransaction::open('super_prova');
  349.             
  350.             $Prova $this->form->getData('Prova');
  351.             $this->form->validate(); // form validation
  352.             
  353.             // get session questoes
  354.             $quest_prova TSession::getValue('quest_prova');
  355.             
  356.             if( $quest_prova )
  357.             {
  358.                 foreach( $quest_prova as $quest_item )
  359.                 {
  360.                     $item = new QuestProva;
  361.                     $item->cod_quest      $quest_item['cod_quest'];
  362.                     $item->valor          $quest_item['valor'];
  363.                     $Prova->addQuestProva($item);
  364.                 }
  365.             }
  366.             $Prova->store(); // stores the object
  367.             $this->form->setData($Prova); // keep form data
  368.             TTransaction::close(); // close the transaction
  369.             new TMessage('info'TAdiantiCoreTranslator::translate('Record saved'));
  370.         }
  371.         catch (Exception $e// in case of exception
  372.         {
  373.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  374.             $this->form->setData$this->form->getData() ); // keep form data
  375.             TTransaction::rollback();
  376.         }
  377.     }
  378.     
  379.     /**
  380.      * Show the page
  381.      */
  382.     public function show()
  383.     {
  384.         // check if the datagrid is already loaded
  385.         if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
  386.         {
  387.             $this->onReloadfunc_get_arg(0) );
  388.         }
  389.         parent::show();
  390.     }
  391.     
  392. }
  393. ?>


Classe Modelo Detail (QuestProva)
<? php e
/**
* QuestProva Active Record
* @author Leandro J N Barbosa
*/
class QuestProva extends TRecord
{
const TABLENAME = 'quest_prova';
const PRIMARYKEY= 'cod_quest_prov';
const IDPOLICY = 'serial'; // {max, serial}


private $prova;
private $questoes;

/**
* Constructor method
*/
public function __construct(2518 = NULL, $callObjectLoad = TRUE)
{
parent::__construct(2518, $callObjectLoad);
parent::addAttribute('cod_prova');
parent::addAttribute('cod_quest');
parent::addAttribute('valor');
}


/**
* Method set_prova
* Sample of usage: $quest_prova->prova = $object;
* @param $object Instance of Prova
*/
public function set_prova(Prova $object)
{
$this->prova = $object;
$this->cod_prova = $object->id;
}

/**
* Method get_prova
* Sample of usage: $quest_prova->prova->attribute;
* @returns Prova instance
*/
public function get_prova()
{
// loads the associated object
if (empty($this->prova))
$this->prova = new Prova($this->cod_prova);

// returns the associated object
return $this->prova;
}


/**
* Method set_questoes
* Sample of usage: $quest_prova->questoes = $object;
* @param $object Instance of Questoes
*/
public function set_questoes(Questoes $object)
{
$this->questoes = $object;
$this->cod_quest = $object->id;
}

/**
* Method get_questoes
* Sample of usage: $quest_prova->questoes->attribute;
* @returns Questoes instance
*/
public function get_questoes()
{
// loads the associated object
if (empty($this->questoes))
$this->questoes = new Questoes($this->cod_quest);

// returns the associated object
return $this->questoes;
}

/**
* Method get_questoes_eunicado
* Sample of usage: $conteudo->questoes->attribute;
* @returns Questoes->enunciado instance
*/
public function get_questoes_enunciado()
{
// loads the associated object
if (empty($this->Questoes))
$this->Questoes = new Questoes($this->cod_quest);
// returns the associated object
return $this->Questoes->enunciado;
}

}
?>

Formulário de Controle (ProvaForm)
<? php e
/**
* SaleForm Registration
* @author Leandro J N Barbosa
*/
class ProvaForm extends TPage
{
protected $form; // form
protected $formFields;
protected $dt_venda;

/**
* Class constructor
* Creates the page and the registration form
*/
function __construct()
{
parent::__construct();

// creates the form
$this->form = new TForm('form_prova');
$this->form->class = 'tform'; // CSS class
parent::include_css('app/resources/custom-frame.css');

$table_master = new TTable;
$table_master->width = '115%';

$table_master->addRowSet( new TLabel('Avaliação'), '', '')->class = 'tformtitle';

// add a table inside form
$table_general = new TTable;
$table_general-> width = '105%';
$tableQuestao = new TTable;
$tableQuestao-> width = '103%';

$frame_general = new TFrame;
$frame_general->setLegend('Prova');
$frame_general->style = 'background:whiteSmoke';
$frame_general->add($table_general);

$table_master->addRow()->addCell( $frame_general )->colspan=2;
$row = $table_master->addRow();
$row->addCell( $tableQuestao );

$this->form->add($table_master);

// master fields
$cod_prova = new TEntry('cod_prova');
$descricao = new TEntry('descricao');
$cod_cab = new TDBSeekButton('cod_cab', 'super_prova', $this->form->getName(), 'Cabecalho', 'descricao', 'cod_cab', 'cabecalho_descricao');
$cabecalho_descricao = new TEntry('cabecalho_descricao');
$observacao = new TText('observacao');

// detail fields
$cod_quest = new TDBSeekButton('cod_quest', 'super_prova', $this->form->getName(), 'Questoes', 'enunciado', 'cod_quest', 'questoes_enunciado');
$questoes_enunciado = new TText('questoes_enunciado');
$valor = new TEntry('valor');

$cod_prova->setSize(80);
$descricao->setSize(650);
$cabecalho_descricao->setSize(577);
$observacao->setSize(650,100);
$cod_quest->setSize(50);
$cod_cab->setSize(50);
$questoes_enunciado->setSize(625,100);

$cod_prova->setEditable(false);
$questoes_enunciado->setEditable(false);
$cabecalho_descricao->setEditable(false);

$descricao->addValidation('Descricao', new TRequiredValidator);
$cod_cab->addValidation('Cabecalho', new TRequiredValidator);

// prova
$table_general->addRowSet( new TLabel('Cód. Prova'), $cod_prova);
$table_general->addRowSet( $label_descricao = new TLabel('Descrição (*)'), $descricao );
$table_general->addRowSet( $label_cabecalho = new TLabel('Cabeçalho (*)'), array( $cod_cab, $cabecalho_descricao ) );
$table_general->addRowSet( new TLabel('Observação'), $observacao );
$label_descricao->setFontColor('#FF0000');
$label_cabecalho->setFontColor('#FF0000');

// questoes
$frame_quest = new TFrame();
$frame_quest->setLegend('Questões');
$row = $tableQuestao->addRow();
$row->addCell($frame_quest);

$add_quest = new TButton('add_quest');
$action_quest = new TAction(array($this, 'onQuestAdd'));
$add_quest->setAction($action_quest, 'Gravar');
$add_quest->setImage('fa:save');

$subtable_quest = new TTable;
$frame_quest->add($subtable_quest);
$subtable_quest->addRowSet( $label_quest = new TLabel('Questão (*)'), array($cod_quest,$questoes_enunciado) );
$subtable_quest->addRowSet( $label_valor = new TLabel('Valor (*)'), $valor );
$subtable_quest->addRowSet( $add_quest );

$label_quest->setFontColor('#FF0000');
$label_valor->setFontColor('#FF0000');

$this->quest_list = new TQuickGrid;
$this->quest_list->setHeight( 175 );
$this->quest_list->makeScrollable();
$this->quest_list->disableDefaultClick();
$this->quest_list->addQuickColumn('', 'edit', 'left', 50);
$this->quest_list->addQuickColumn('', 'delete', 'left', 50);
$this->quest_list->addQuickColumn('Cód. Questão', 'cod_quest', 'left', 50);
$this->quest_list->addQuickColumn('Enunciado', 'questoes_enunciado', 'left', 400);
$this->quest_list->addQuickColumn('Valor','valor', 'left', 80);
$this->quest_list->createModel();

$row = $tableQuestao->addRow();
$row->addCell($this->quest_list);

// create an action button (save)
$save_button=new TButton('save');
$save_button->setAction(new TAction(array($this, 'onSave')), _t('Save'));
$save_button->setImage('ico_save.png');

// create an new button (edit with no parameters)
$new_button=new TButton('new');
$new_button->setAction(new TAction(array($this, 'onClear')), _t('New'));
$new_button->setImage('ico_new.png');

// define form fields
$this->formFields = array($cod_prova,$descricao, $cod_cab, $cabecalho_descricao, $observacao, $cod_quest, $questoes_enunciado, $valor, $add_quest, $save_button, $new_button);
$this->form->setFields( $this->formFields );

$table_master->addRowSet( array($save_button, $new_button), '', '')->class = 'tformaction'; // CSS class

// create the page container
$container = new TVBox;
$container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
$container->add($this->form);
parent::add($container);
}

/**
* Clear form
* @param $param URL parameters
*/
function onClear($param)
{
$this->form->clear();
TSession::setValue('quest_prova', array());
$this->onReload( $param );
}

/**
* Add a question into item list
* @param $param URL parameters
*/
public function onQuestAdd( $param )
{
try
{
TTransaction::open('super_prova');
$data = $this->form->getData();

if( (! $data->cod_quest) || (! $data->valor) )
throw new Exception('Os campos Questão e Valor são obrigatórios');

$questao = new Questoes($data->cod_quest);

$quest_prova = TSession::getValue('quest_prova');
$key = (int) $data->cod_quest;
$quest_prova[ $key ] = array('cod_quest' => $data->cod_quest,
'questoes_enunciado' => $data->questoes_enunciado,
'valor' => $data->valor);

TSession::setValue('quest_prova', $quest_prova);

// clear questao form fields after add
$data->cod_quest = '';
$data->questoes_enunciado = '';
$data->valor = '';
TTransaction::close();
$this->form->setData($data);

$this->onReload( $param ); // reload the sale items
}
catch (Exception $e)
{
$this->form->setData( $this->form->getData());
new TMessage('error', $e->getMessage());
}
}

/**
* Edit a question from item list
* @param $param URL parameters
*/
public function onEditItemQuest( $param )
{
$data = $this->form->getData();

// read session items
$quest_prova = TSession::getValue('quest_prova');

// get the session item
$quest_item = $quest_prova[ (int) $param['list_cod_quest'] ];

$data->cod_quest = $param['list_cod_quest'];
$data->questoes_enunciado = $quest_item['questoes_enunciado'];
$data->valor = $quest_item['valor'];

// fill product fields
$this->form->setData( $data );

$this->onReload( $param );
}

/**
* Delete a product from item list
* @param $param URL parameters
*/
public function onDeleteItem( $param )
{
$data = $this->form->getData();

$data->cod_quest = '';
$data->questoes_enunciado = '';
$data->valor = '';

// clear form data
$this->form->setData( $data );

// read session items
$quest_prova = TSession::getValue('quest_prova');

// delete the item from session
unset($quest_prova[ (int) $param['list_cod_quest'] ] );
TSession::setValue('quest_prova', $quest_prova);

// reload sale items
$this->onReload( $param );
}

/**
* Reload the item list
* @param $param URL parameters
*/
public function onReload($param)
{
// read session items
$quest_prova = TSession::getValue('quest_prova');

$this->quest_list->clear(); // clear product list
$data = $this->form->getData();

if ($quest_prova)
{
$cont = 1;
foreach ($quest_prova as $list_cod_quest => $list_quest)
{
$item_name = 'quest_' . $cont++;
$item = new StdClass;

// create action buttons
$action_del = new TAction(array($this, 'onDeleteItem'));
$action_del->setParameter('list_cod_quest', $list_cod_quest);

$action_edi = new TAction(array($this, 'onEditItemQuest'));
$action_edi->setParameter('list_cod_quest', $list_cod_quest);

$button_del = new TButton('delete_quest'.$cont);
$button_del->class = 'btn btn-default btn-sm';
$button_del->setAction( $action_del, '' );
$button_del->setImage('fa:trash-o red fa-lg');

$button_edi = new TButton('edit_quest'.$cont);
$button_edi->class = 'btn btn-default btn-sm';
$button_edi->setAction( $action_edi, '' );
$button_edi->setImage('fa:edit blue fa-lg');

$item->edit = $button_edi;
$item->delete = $button_del;

$this->formFields[ $item_name.'_edit' ] = $item->edit;
$this->formFields[ $item_name.'_delete' ] = $item->delete;

$item->cod_quest = $list_quest['cod_quest'];
$item->questoes_enunciado = $list_quest['questoes_enunciado'];
$item->valor = $list_quest['valor'];

$row = $this->quest_list->addItem( $item );
$row->onmouseover='';
$row->onmouseout='';
}

$this->form->setFields( $this->formFields );
}

$this->loaded = TRUE;
}

/**
* method onEdit()
* Executed whenever the user clicks at the edit button da datagrid
*/
function onEdit($param)
{
try
{
TTransaction::open('super_prova');

if (isset($param['key']))
{
$key = $param['key'];

$object = new Prova($key);
$quest_prova = $object->getQuestProva();

$session_items = array();
foreach( $quest_prova as $item )
{
$session_items[$item->cod_quest] = $item->toArray();
$session_items[$item->cod_quest]['cod_quest'] = $item->cod_quest;
$session_items[$item->cod_quest]['questoes_enunciado'] = $item->questoes_enunciado;
$session_items[$item->cod_quest]['valor'] = $item->valor;
}
TSession::setValue('quest_prova', $session_items);

$this->form->setData($object); // fill the form with the active record data
$this->onReload( $param ); // reload sale items list
TTransaction::close(); // close transaction
}
else
{
$this->form->clear();
TSession::setValue('quest_prova', null);
$this->onReload( $param );
}
}
catch (Exception $e) // in case of exception
{
new TMessage('error', 'Error ' . $e->getMessage());
TTransaction::rollback();
}
}

/**
* Save the sale and the sale items
*/
function onSave()
{
try
{
// open a transaction with database 'super_prova'
TTransaction::open('super_prova');

$Prova = $this->form->getData('Prova');
$this->form->validate(); // form validation

// get session questoes
$quest_prova = TSession::getValue('quest_prova');

if( $quest_prova )
{
foreach( $quest_prova as $quest_item )
{
$item = new QuestProva;
$item->cod_quest = $quest_item['cod_quest'];
$item->valor = $quest_item['valor'];
$Prova->addQuestProva($item);
}
}
$Prova->store(); // stores the object
$this->form->setData($Prova); // keep form data
TTransaction::close(); // close the transaction
new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
}
catch (Exception $e) // in case of exception
{
new TMessage('error', 'Error ' . $e->getMessage());
$this->form->setData( $this->form->getData() ); // keep form data
TTransaction::rollback();
}
}

/**
* Show the page
*/
public function show()
{
// check if the datagrid is already loaded
if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )

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


NR

Poste o modelo do master também...
LB

Classe Master - é a Prova segue abaixo, já tinha ido mas no post acima ficou zuado
<? php e
/**
* Prova Active Record
* @author Leandro J N Barbosa
*/
class Prova extends TRecord
{
const TABLENAME = 'prova';
const PRIMARYKEY= 'cod_prova';
const IDPOLICY = 'serial'; // {max, serial}


private $cabecalho;
private $questprova;

/**
* Constructor method
*/
public function __construct($id = NULL, $callObjectLoad = TRUE)
{
parent::__construct($id, $callObjectLoad);
parent::addAttribute('descricao');
parent::addAttribute('cod_cab');
parent::addAttribute('observacao');
}


/**
* Method set_cabecalho
* Sample of usage: $prova->cabecalho = $object;
* @param $object Instance of Cabecalho
*/
public function set_cabecalho(Cabecalho $object)
{
$this->cabecalho = $object;
$this->cod_cab = $object->id;
}

/**
* Method get_cabecalho
* Sample of usage: $prova->cabecalho->attribute;
* @returns Cabecalho instance
*/
public function get_cabecalho()
{
// loads the associated object
if (empty($this->cabecalho))
$this->cabecalho = new Cabecalho($this->cod_cab);

// returns the associated object
return $this->cabecalho;
}

/**
* Method get_cabecalho_descricao
* Sample of usage: $prova->cabecalho->descricao;
* @returns Cabecalho Descricao instance
*/
public function get_cabecalho_descricao()
{
// loads the associated object
if (empty($this->Cabecalho))
$this->Cabecalho = new Cabecalho($this->cod_cab);
// returns the associated object
return $this->Cabecalho->descricao;
}

/**
* Method addQuestProva
* Add a QuestItem to the Prova
* @param $object Instance of QuestItem
*/
public function addQuestProva(QuestProva $object)
{
$this->Quest_Provas[] = $object;
}

/**
* Method getQuestProva
* Return the Prova QuestProva
* @return Collection of QuestProva
*/
public function getQuestProva()
{
return $this->Quest_Provas;
}

/**
* Reset aggregates
*/
public function clearParts()
{
$this->Quest_Provas = array();
}

/**
* Load the object and its aggregates
* @param $id object ID
*/
public function load($id)
{

// load the related QuestProva objects
$repository = new TRepository('QuestProva');
$criteria = new TCriteria;
$criteria->add(new TFilter('cod_prova', '=', $id));
$this->Quest_Provas = $repository->load($criteria);

// load the object itself
return parent::load($id);
}

/**
* Store the object and its aggregates
*/
public function store()
{
// store the object itself
parent::store();

// delete the related QuestProva objects
$criteria = new TCriteria;
$criteria->add(new TFilter('cod_prova', '=', $this->cod_prova));
$repository = new TRepository('QuestProva');
$repository->delete($criteria);
// store the related QuestProva objects
if ($this->Quest_Provas)
{
foreach ($this->Quest_Provas as $quest_prova)
{
unset($quest_prova->cod_prova);
$quest_prova->cod_prova = $this->cod_prova;
$quest_prova->store();
}
}
}

/**
* Delete the object and its aggregates
* @param $id object ID
*/
public function delete($id = NULL)
{
// delete the related QuestProva objects
$id = isset($id) ? $id : $this->cod_prova;
$repository = new TRepository('QuestProva');
$criteria = new TCriteria;
$criteria->add(new TFilter('cod_prova', '=', $id));
$repository->delete($criteria);

// delete the object itself
parent::delete($id);
}

}
?>
LB

Classe Detail - QuestProva
  1. <?php e
  1. <?php
  2. /**
  3.  * QuestProva Active Record
  4.  * @author  Leandro J N Barbosa
  5.  */
  6. class QuestProva extends TRecord
  7. {
  8.     const TABLENAME 'quest_prova';
  9.     const PRIMARYKEY'cod_quest_prov';
  10.     const IDPOLICY =  'serial'// {max, serial}
  11.     
  12.     
  13.     private $prova;
  14.     private $questoes;
  15.     /**
  16.      * Constructor method
  17.      */
  18.     public function __construct($id NULL$callObjectLoad TRUE)
  19.     {
  20.         parent::__construct($id$callObjectLoad);
  21.         parent::addAttribute('cod_prova');
  22.         parent::addAttribute('cod_quest');
  23.         parent::addAttribute('valor');
  24.     }
  25.     
  26.     /**
  27.      * Method set_prova
  28.      * Sample of usage: $quest_prova->prova = $object;
  29.      * @param $object Instance of Prova
  30.      */
  31.     public function set_prova(Prova $object)
  32.     {
  33.         $this->prova $object;
  34.         $this->cod_prova $object->id;
  35.     }
  36.     
  37.     /**
  38.      * Method get_prova
  39.      * Sample of usage: $quest_prova->prova->attribute;
  40.      * @returns Prova instance
  41.      */
  42.     public function get_prova()
  43.     {
  44.         // loads the associated object
  45.         if (empty($this->prova))
  46.             $this->prova = new Prova($this->cod_prova);
  47.     
  48.         // returns the associated object
  49.         return $this->prova;
  50.     }
  51.     
  52.     
  53.     /**
  54.      * Method set_questoes
  55.      * Sample of usage: $quest_prova->questoes = $object;
  56.      * @param $object Instance of Questoes
  57.      */
  58.     public function set_questoes(Questoes $object)
  59.     {
  60.         $this->questoes $object;
  61.         $this->cod_quest $object->id;
  62.     }
  63.     
  64.     /**
  65.      * Method get_questoes
  66.      * Sample of usage: $quest_prova->questoes->attribute;
  67.      * @returns Questoes instance
  68.      */
  69.     public function get_questoes()
  70.     {
  71.         // loads the associated object
  72.         if (empty($this->questoes))
  73.             $this->questoes = new Questoes($this->cod_quest);
  74.     
  75.         // returns the associated object
  76.         return $this->questoes;
  77.     }
  78.     
  79.     /**
  80.      * Method get_questoes_eunicado
  81.      * Sample of usage: $conteudo->questoes->attribute;
  82.      * @returns Questoes->enunciado instance
  83.      */
  84.     public function get_questoes_enunciado()
  85.     {
  86.         // loads the associated object
  87.         if (empty($this->Questoes))
  88.             $this->Questoes = new Questoes($this->cod_quest);
  89.             // returns the associated object
  90.         return $this->Questoes->enunciado;
  91.     }
  92. }
  93. ?>
LB

Por fim a classe de controle - ProvaForm

<? php e
  1. <?php
  2. /**
  3.  * SaleForm Registration
  4.  * @author  Leandro J N Barbosa
  5.  */
  6. class ProvaForm extends TPage
  7. {
  8.     protected $form// form
  9.     protected $formFields;
  10.     protected $dt_venda;
  11.     
  12.     /**
  13.      * Class constructor
  14.      * Creates the page and the registration form
  15.      */
  16.     function __construct()
  17.     {
  18.         parent::__construct();
  19.         
  20.         // creates the form
  21.         $this->form = new TForm('form_prova');
  22.         $this->form->class 'tform'// CSS class
  23.         parent::include_css('app/resources/custom-frame.css');
  24.         
  25.         $table_master = new TTable;
  26.         $table_master->width '115%';
  27.         
  28.         $table_master->addRowSet( new TLabel('Avaliação'), '''')->class 'tformtitle';
  29.         
  30.         // add a table inside form
  31.         $table_general = new TTable;
  32.         $table_general-> width '105%';
  33.         $tableQuestao = new TTable;
  34.         $tableQuestao-> width '103%';
  35.         
  36.         $frame_general = new TFrame;
  37.         $frame_general->setLegend('Prova');
  38.         $frame_general->style 'background:whiteSmoke';
  39.         $frame_general->add($table_general);
  40.         
  41.         $table_master->addRow()->addCell$frame_general )->colspan=2;
  42.         $row $table_master->addRow();
  43.         $row->addCell$tableQuestao );
  44.         
  45.         $this->form->add($table_master);
  46.         
  47.         // master fields
  48.         $cod_prova           = new TEntry('cod_prova');
  49.         $descricao           = new TEntry('descricao');
  50.         $cod_cab             = new  ">TDBSeekButton('cod_cab''super_prova'$this->form->getName(), 'Cabecalho''descricao''cod_cab''cabecalho_descricao');
  51.         $cabecalho_descricao = new TEntry('cabecalho_descricao');
  52.         $observacao          = new TText('observacao');
  53.         
  54.         // detail fields
  55.         $cod_quest          = new  ">TDBSeekButton('cod_quest''super_prova'$this->form->getName(), 'Questoes''enunciado''cod_quest''questoes_enunciado');
  56.         $questoes_enunciado = new TText('questoes_enunciado');
  57.         $valor              = new TEntry('valor');
  58.         
  59.         $cod_prova->setSize(80);
  60.         $descricao->setSize(650);
  61.         $cabecalho_descricao->setSize(577);
  62.         $observacao->setSize(650,100);
  63.         $cod_quest->setSize(50);
  64.         $cod_cab->setSize(50);
  65.         $questoes_enunciado->setSize(625,100);
  66.         
  67.         $cod_prova->setEditable(false);
  68.         $questoes_enunciado->setEditable(false);
  69.         $cabecalho_descricao->setEditable(false);
  70.         
  71.         $descricao->addValidation('Descricao', new TRequiredValidator);
  72.         $cod_cab->addValidation('Cabecalho', new TRequiredValidator);
  73.         // prova
  74.         $table_general->addRowSet( new TLabel('Cód. Prova'), $cod_prova);
  75.         $table_general->addRowSet$label_descricao   = new TLabel('Descrição (*)'), $descricao );
  76.         $table_general->addRowSet$label_cabecalho   = new TLabel('Cabeçalho (*)'), array( $cod_cab$cabecalho_descricao ) );
  77.         $table_general->addRowSet( new TLabel('Observação'), $observacao );
  78.         $label_descricao->setFontColor('#FF0000');
  79.         $label_cabecalho->setFontColor('#FF0000');
  80.                
  81.         // questoes
  82.         $frame_quest = new TFrame();
  83.         $frame_quest->setLegend('Questões');
  84.         $row $tableQuestao->addRow();
  85.         $row->addCell($frame_quest);
  86.         
  87.         $add_quest = new TButton('add_quest');
  88.         $action_quest = new TAction(array($this'onQuestAdd'));
  89.         $add_quest->setAction($action_quest'Gravar');
  90.         $add_quest->setImage('fa:save');
  91.         
  92.         $subtable_quest = new TTable;
  93.         $frame_quest->add($subtable_quest);
  94.         $subtable_quest->addRowSet$label_quest = new TLabel('Questão (*)'), array($cod_quest,$questoes_enunciado) );
  95.         $subtable_quest->addRowSet$label_valor = new TLabel('Valor (*)'), $valor );
  96.         $subtable_quest->addRowSet$add_quest );
  97.         
  98.         $label_quest->setFontColor('#FF0000');
  99.         $label_valor->setFontColor('#FF0000');
  100.         
  101.         $this->quest_list = new TQuickGrid;
  102.         $this->quest_list->setHeight175 );
  103.         $this->quest_list->makeScrollable();
  104.         $this->quest_list->disableDefaultClick();
  105.         $this->quest_list->addQuickColumn('''edit''left'50);
  106.         $this->quest_list->addQuickColumn('''delete''left'50);
  107.         $this->quest_list->addQuickColumn('Cód. Questão''cod_quest''left'50);
  108.         $this->quest_list->addQuickColumn('Enunciado''questoes_enunciado''left'400);
  109.         $this->quest_list->addQuickColumn('Valor','valor''left'80);
  110.         $this->quest_list->createModel();
  111.         
  112.         $row $tableQuestao->addRow();
  113.         $row->addCell($this->quest_list);
  114.         
  115.         // create an action button (save)
  116.         $save_button=new TButton('save');
  117.         $save_button->setAction(new TAction(array($this'onSave')), _t('Save'));
  118.         $save_button->setImage('ico_save.png');
  119.         // create an new button (edit with no parameters)
  120.         $new_button=new TButton('new');
  121.         $new_button->setAction(new TAction(array($this'onClear')), _t('New'));
  122.         $new_button->setImage('ico_new.png');
  123.         
  124.         // define form fields
  125.         $this->formFields = array($cod_prova,$descricao$cod_cab$cabecalho_descricao$observacao$cod_quest$questoes_enunciado$valor$add_quest$save_button$new_button);
  126.         $this->form->setFields$this->formFields );
  127.         
  128.         $table_master->addRowSet( array($save_button$new_button), '''')->class 'tformaction'// CSS class
  129.         
  130.         // create the page container
  131.         $container = new TVBox;
  132.         $container->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  133.         $container->add($this->form);
  134.         parent::add($container);
  135.     }  
  136.     
  137.     /**
  138.      * Clear form
  139.      * @param $param URL parameters
  140.      */
  141.     function onClear($param)
  142.     {
  143.         $this->form->clear();
  144.         TSession::setValue('quest_prova', array());
  145.         $this->onReload$param );
  146.     }
  147.     
  148.     /**
  149.      * Add a question into item list
  150.      * @param $param URL parameters
  151.      */
  152.     public function onQuestAdd$param )
  153.     {
  154.         try
  155.         {
  156.             TTransaction::open('super_prova');
  157.             $data $this->form->getData();
  158.             
  159.             if( (! $data->cod_quest) || (! $data->valor) )
  160.                 throw new Exception('Os campos Questão e Valor são obrigatórios');
  161.             
  162.             $questao = new Questoes($data->cod_quest);
  163.             
  164.             $quest_prova TSession::getValue('quest_prova');
  165.             $key = (int) $data->cod_quest;
  166.             $quest_prova$key ] = array('cod_quest'          => $data->cod_quest,
  167.                                          'questoes_enunciado' => $data->questoes_enunciado,
  168.                                          'valor'              => $data->valor);
  169.             
  170.             TSession::setValue('quest_prova'$quest_prova);
  171.             
  172.             // clear questao form fields after add
  173.             $data->cod_quest '';
  174.             $data->questoes_enunciado '';
  175.             $data->valor '';
  176.             TTransaction::close();
  177.             $this->form->setData($data);
  178.             
  179.             $this->onReload$param ); // reload the sale items
  180.         }
  181.         catch (Exception $e)
  182.         {
  183.             $this->form->setData$this->form->getData());
  184.             new TMessage('error'$e->getMessage());
  185.         }
  186.     }
  187.     
  188.     /**
  189.      * Edit a question from item list
  190.      * @param $param URL parameters
  191.      */
  192.     public function onEditItemQuest$param )
  193.     {
  194.         $data $this->form->getData();
  195.         
  196.         // read session items
  197.         $quest_prova TSession::getValue('quest_prova');
  198.         
  199.         // get the session item
  200.         $quest_item $quest_prova[ (int) $param['list_cod_quest'] ];
  201.         
  202.         $data->cod_quest $param['list_cod_quest'];
  203.         $data->questoes_enunciado $quest_item['questoes_enunciado'];
  204.         $data->valor $quest_item['valor'];
  205.         
  206.         // fill product fields
  207.         $this->form->setData$data );
  208.     
  209.         $this->onReload$param );
  210.     }
  211.     
  212.     /**
  213.      * Delete a product from item list
  214.      * @param $param URL parameters
  215.      */
  216.     public function onDeleteItem$param )
  217.     {
  218.         $data $this->form->getData();
  219.         
  220.         $data->cod_quest '';
  221.         $data->questoes_enunciado '';
  222.         $data->valor '';
  223.         
  224.         // clear form data
  225.         $this->form->setData$data );
  226.         
  227.         // read session items
  228.         $quest_prova TSession::getValue('quest_prova');
  229.         
  230.         // delete the item from session
  231.         unset($quest_prova[ (int) $param['list_cod_quest'] ] );
  232.         TSession::setValue('quest_prova'$quest_prova);
  233.         
  234.         // reload sale items
  235.         $this->onReload$param );
  236.     }
  237.     
  238.     /**
  239.      * Reload the item list
  240.      * @param $param URL parameters
  241.      */
  242.     public function onReload($param)
  243.     {
  244.         // read session items
  245.         $quest_prova TSession::getValue('quest_prova');
  246.         
  247.         $this->quest_list->clear(); // clear product list
  248.         $data $this->form->getData();
  249.         
  250.         if ($quest_prova)
  251.         {
  252.             $cont 1;
  253.             foreach ($quest_prova as $list_cod_quest => $list_quest)
  254.             {
  255.                 $item_name 'quest_' $cont++;
  256.                 $item = new StdClass;
  257.                 
  258.                 // create action buttons
  259.                 $action_del = new TAction(array($this'onDeleteItem'));
  260.                 $action_del->setParameter('list_cod_quest'$list_cod_quest);
  261.                 
  262.                 $action_edi = new TAction(array($this'onEditItemQuest'));
  263.                 $action_edi->setParameter('list_cod_quest'$list_cod_quest);
  264.                 
  265.                 $button_del = new TButton('delete_quest'.$cont);
  266.                 $button_del->class 'btn btn-default btn-sm';
  267.                 $button_del->setAction$action_del'' );
  268.                 $button_del->setImage('fa:trash-o red fa-lg');
  269.                 
  270.                 $button_edi = new TButton('edit_quest'.$cont);
  271.                 $button_edi->class 'btn btn-default btn-sm';
  272.                 $button_edi->setAction$action_edi'' );
  273.                 $button_edi->setImage('fa:edit blue fa-lg');
  274.                 
  275.                 $item->edit $button_edi;
  276.                 $item->delete $button_del;
  277.                 
  278.                 $this->formFields$item_name.'_edit' ] = $item->edit;
  279.                 $this->formFields$item_name.'_delete' ] = $item->delete;
  280.                 
  281.                 $item->cod_quest $list_quest['cod_quest'];
  282.                 $item->questoes_enunciado $list_quest['questoes_enunciado'];              
  283.                 $item->valor $list_quest['valor'];
  284.                 
  285.                 $row $this->quest_list->addItem$item );
  286.                 $row->onmouseover='';
  287.                 $row->onmouseout='';
  288.             }
  289.             $this->form->setFields$this->formFields );
  290.         }
  291.         
  292.         $this->loaded TRUE;
  293.     }
  294.     
  295.     /**
  296.      * method onEdit()
  297.      * Executed whenever the user clicks at the edit button da datagrid
  298.      */
  299.     function onEdit($param)
  300.     {
  301.         try
  302.         {
  303.             TTransaction::open('super_prova');
  304.             
  305.             if (isset($param['key']))
  306.             {
  307.                 $key $param['key'];
  308.                 
  309.                 $object = new Prova($key);
  310.                 $quest_prova $object->getQuestProva();
  311.                 
  312.                 $session_items = array();
  313.                 foreach( $quest_prova as $item )
  314.                 {
  315.                     $session_items[$item->cod_quest] = $item->toArray();
  316.                     $session_items[$item->cod_quest]['cod_quest'] = $item->cod_quest;
  317.                     $session_items[$item->cod_quest]['questoes_enunciado'] = $item->questoes_enunciado;
  318.                     $session_items[$item->cod_quest]['valor'] = $item->valor;
  319.                 }
  320.                 TSession::setValue('quest_prova'$session_items);
  321.                 
  322.                 $this->form->setData($object); // fill the form with the active record data
  323.                 $this->onReload$param ); // reload sale items list
  324.                 TTransaction::close(); // close transaction
  325.             }
  326.             else
  327.             {
  328.                 $this->form->clear();
  329.                 TSession::setValue('quest_prova'null);
  330.                 $this->onReload$param );
  331.             }
  332.         }
  333.         catch (Exception $e// in case of exception
  334.         {
  335.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  336.             TTransaction::rollback();
  337.         }
  338.     }
  339.     
  340.     /**
  341.      * Save the sale and the sale items
  342.      */
  343.     function onSave()
  344.     {
  345.         try
  346.         {
  347.             // open a transaction with database 'super_prova'
  348.             TTransaction::open('super_prova');
  349.             
  350.             $Prova $this->form->getData('Prova');
  351.             $this->form->validate(); // form validation
  352.             
  353.             // get session questoes
  354.             $quest_prova TSession::getValue('quest_prova');
  355.             
  356.             if( $quest_prova )
  357.             {
  358.                 foreach( $quest_prova as $quest_item )
  359.                 {
  360.                     $item = new QuestProva;
  361.                     $item->cod_quest      $quest_item['cod_quest'];
  362.                     $item->valor          $quest_item['valor'];
  363.                     $Prova->addQuestProva($item);
  364.                 }
  365.             }
  366.             $Prova->store(); // stores the object
  367.             $this->form->setData($Prova); // keep form data
  368.             TTransaction::close(); // close the transaction
  369.             new TMessage('info'TAdiantiCoreTranslator::translate('Record saved'));
  370.         }
  371.         catch (Exception $e// in case of exception
  372.         {
  373.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  374.             $this->form->setData$this->form->getData() ); // keep form data
  375.             TTransaction::rollback();
  376.         }
  377.     }
  378.     
  379.     /**
  380.      * Show the page
  381.      */
  382.     public function show()
  383.     {
  384.         // check if the datagrid is already loaded
  385.         if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
  386.         {
  387.             $this->onReloadfunc_get_arg(0) );
  388.         }
  389.         parent::show();
  390.     }
  391.     
  392. }
  393. ?>


?>
NR

Habilita os logs do sql logo após o TTransaction::open na onSave:
  1. <?php
  2. TTransaction::setLogger(new TLoggerSTD());
  3. ?>
LB

Já habilitei onde o arquivo de log é gerado?

LB

Nataniel, consegui ver o log na tela mesmo mas tava tudo certo no sql, dai alterei função onSave para o código conforme abaixo e agora está gravando.
  1. <?php e
  1. <?php
  2. function onSave()
  3.     {
  4.         try
  5.         {
  6.             // open a transaction with database 'super_prova'
  7.             TTransaction::open('super_prova');
  8.             TTransaction::setLogger(new TLoggerSTD()); 
  9.             
  10.             $Prova $this->form->getData('Prova');
  11.             $this->form->validate(); // form validation
  12.             
  13.             // get session questoes
  14.             $Prova->store(); // stores the object
  15.             
  16.             $quest_prova TSession::getValue('quest_prova');
  17.             
  18.             if( $quest_prova )
  19.             {
  20.                 foreach( $quest_prova as $quest_item )
  21.                 {                    
  22.                     $item = new QuestProva;
  23.                     $item->cod_quest      $quest_item['cod_quest'];
  24.                     $item->valor          $quest_item['valor'];
  25.                     $item->cod_prova      $Prova->cod_prova;
  26.                     $Prova->addQuestProva($item);
  27.                     $item->store();
  28.                     
  29.                 }
  30.             }
  31. ?>

?>