RC
TDatagrid não mostra os dados
Estou com um formulario com um TSeekButton para selecionar os alunos.
Quando seleciono um aluno a TDataGrid não mostra os dados do aluno.
Segue o codigo do form:
Alguém pode verificar onde está o erro.
Quando seleciono um aluno a TDataGrid não mostra os dados do aluno.
Segue o codigo do form:
- <?php
- /**
- * AcompanhamentoFormList Registration
- * @author <your name here>
- */
- class AcompanhamentoFormList extends TPage
- {
- protected $form; // form
- protected $datagrid; // datagrid
- protected $pageNavigation;
- protected $loaded;
- /**
- * Class constructor
- * Creates the page and the registration form
- */
- function __construct()
- {
- parent::__construct();
- // creates the form
- $this->form = new TQuickForm('form_Acompanhamento');
- $this->form->class = 'tform'; // CSS class
- $this->form->setFormTitle('Acompanhamento'); // define the form title
- // create the form fields
- $id = new TEntry('id');
- $id->setEditable(FALSE);
- $data_cadastro = new TDate('data_cadastro');
- $data_cadastro->setMask('dd-mm-yyyy');
- $data_cadastro->setValue(date('d/m/Y'));
- $criteria = new TCriteria(new TFilter('ativo', '=', TRUE));
- $aluno_id = new ">TDBSeekButton('aluno_id', 'elainelins', 'form_Acompanhamento', 'Aluno', 'nome', 'aluno_id', 'aluno_nome', $criteria);
- $aluno_id->setSize(90);
- $changeAction = new TAction( array($this, 'onChangeAction') );
- $changeAction->setParameter('key', $aluno_id->getValue);
- $aluno_id->setExitAction($changeAction);
- /*
- $aluno_id = new TEntry('aluno_id');
- $aluno_id->setEditable(FALSE);
- $aluno_id->setSize(100);
- */
- $aluno_nome = new TEntry('aluno_nome');
- $aluno_nome->setEditable(FALSE);
- $aluno_nome->setSize(250);
- $peso = new TSpinner('peso');
- $peso->setRange(40.0, 140.0, 0.1);
- $pa = new TEntry('pa');
- $abdomen = new TEntry('abdomen');
- $quadril = new TEntry('quadril');
- $flex = new TEntry('flex');
- $observacao = new TEntry('observacao');
- // add the fields
- $this->form->addQuickField('id', $id, 110);
- $this->form->addQuickField('data cadastro', $data_cadastro, 90, new TRequiredValidator );
- $this->form->addQuickFields('Aluno', array($aluno_id, $aluno_nome));
- $this->form->addQuickField('peso', $peso, 105);
- $this->form->addQuickField('pa', $pa, 110);
- $this->form->addQuickField('abdomen', $abdomen, 110);
- $this->form->addQuickField('quadril', $quadril, 110);
- $this->form->addQuickField('flex', $flex, 110);
- $this->form->addQuickField('observacao', $observacao, 360);
- // create the form actions
- $this->form->addQuickAction(_t('Save'), new TAction(array($this, 'onSave')), 'ico_save.png');
- $this->form->addQuickAction(_t('New'), new TAction(array($this, 'onEdit')), 'ico_new.png');
- // creates a DataGrid
- $this->datagrid = new TQuickGrid;
- $this->datagrid->setHeight(320);
- // creates the datagrid columns
- $id = $this->datagrid->addQuickColumn('id', 'id', 'left', 100);
- $data_cadastro = $this->datagrid->addQuickColumn('Data Cadastro', 'data_cadastro', 'left', 100);
- //$aluno_id = $this->datagrid->addQuickColumn('Aluno', 'aluno_id', 'left', 100);
- //$aluno_nome = $this->datagrid->addQuickColumn('Aluno', 'aluno_nome', 'left', 200);
- $peso = $this->datagrid->addQuickColumn('peso', 'peso', 'left', 100);
- $pa = $this->datagrid->addQuickColumn('pa', 'pa', 'left', 100);
- $abdomen = $this->datagrid->addQuickColumn('abdomen', 'abdomen', 'left', 100);
- $quadril = $this->datagrid->addQuickColumn('quadril', 'quadril', 'left', 100);
- $flex = $this->datagrid->addQuickColumn('flex', 'flex', 'left', 100);
- $observacao = $this->datagrid->addQuickColumn('observacao', 'observacao', 'left', 200);
- // create the datagrid actions
- $edit_action = new TDataGridAction(array($this, 'onEdit'));
- $delete_action = new TDataGridAction(array($this, 'onDelete'));
- // add the actions to the datagrid
- $this->datagrid->addQuickAction(_t('Edit'), $edit_action, 'id', 'ico_edit.png');
- $this->datagrid->addQuickAction(_t('Delete'), $delete_action, 'id', 'ico_delete.png');
- // create the datagrid model
- $this->datagrid->createModel();
- // creates the page navigation
- $this->pageNavigation = new TPageNavigation;
- $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
- $this->pageNavigation->setWidth($this->datagrid->getWidth());
- /*
- // create the datagrid model
- $this->datagrid->createModel();
- // creates the page navigation
- $this->pageNavigation = new TPageNavigation;
- $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
- $this->pageNavigation->setWidth($this->datagrid->getWidth());
- */
- // create the page container
- $container = TVBox::pack( $this->form, $this->datagrid, $this->pageNavigation);
- parent::add($container);
- }
- /**
- * method onReload()
- * Load the datagrid with the database objects
- */
- function onReload($param = NULL)
- {
- try
- {
- $this->datagrid->clear();
- if(isset($param['key']))
- {
- // open a transaction with database 'elainelins'
- TTransaction::open('elainelins');
- // creates a repository for Acompanhamento
- $repository = new TRepository('Acompanhamento');
- $limit = 10;
- // creates a criteria
- $criteria = new TCriteria;
- $id = $param['key'];
- $criteria->add(new TFilter('aluno_id', '=', $id));
- // default order
- if (empty($param['order']))
- {
- $param['order'] = 'id';
- $param['direction'] = 'asc';
- }
- $criteria->setProperties($param); // order, offset
- $criteria->setProperty('limit', $limit);
- if (TSession::getValue('Acompanhamento_filter'))
- {
- // add the filter stored in the session to the criteria
- $criteria->add(TSession::getValue('Acompanhamento_filter'));
- }
- // load the objects according to criteria
- $objects = $repository->load($criteria);
- //print_r($objects);die;
- if ($objects)
- {
- // iterate the collection of active records
- foreach ($objects as $object)
- {
- // add the object inside the datagrid
- $this->datagrid->addItem($object);
- }
- }
- // reset the criteria for record count
- $criteria->resetProperties();
- $count= $repository->count($criteria);
- $this->pageNavigation->setCount($count); // count of records
- $this->pageNavigation->setProperties($param); // order, page
- $this->pageNavigation->setLimit($limit); // limit
- // close the transaction
- TTransaction::close();
- }
- $this->loaded = true;
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * method onEdit()
- * Executed whenever the user clicks at the edit button da datagrid
- */
- function onEdit($param)
- {
- try
- {
- if (isset($param['key']))
- {
- // get the parameter $key
- $key=$param['key'];
- // open a transaction with database 'elainelins'
- TTransaction::open('elainelins');
- // instantiates object Aluno
- $object = new Acompanhamento($key);
- //transforma os dados necessarios
- $object->data_cadastro = TDate::date2br($object->data_cadastro);
- // fill the form with the active record data
- $this->form->setData($object);
- // close the transaction
- TTransaction::close();
- }
- else
- {
- $this->form->clear();
- }
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', '<b>Error</b> ' . $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- /**
- * method onDelete()
- * executed whenever the user clicks at the delete button
- * Ask if the user really wants to delete the record
- */
- function onDelete($param)
- {
- // define the delete action
- $action = new TAction(array($this, 'Delete'));
- $action->setParameters($param); // pass the key parameter ahead
- // shows a dialog to the user
- new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
- }
- /**
- * method Delete()
- * Delete a record
- */
- function Delete($param)
- {
- try
- {
- // get the parameter $key
- $key=$param['key'];
- TTransaction::open('elainelins'); // open the transaction
- $object = new Acompanhamento($key, FALSE); // instantiates the Active Record
- $object->delete(); // deletes the object
- TTransaction::close(); // close the transaction
- $this->onReload( $param ); // reload the listing
- new TMessage('info', TAdiantiCoreTranslator::translate('Record deleted')); // success message
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * method onSave()
- * Executed whenever the user clicks at the save button
- */
- function onSave()
- {
- try
- {
- TTransaction::open('elainelins'); // open a transaction with database
- // get the form data into an active record Acompanhamento
- $object = $this->form->getData('Acompanhamento');
- $this->form->validate(); // form validation
- $object->data_cadastro = TDate::date2us($object->data_cadastro);
- $object->store(); // stores the object
- $object->data_cadastro = TDate::date2br($object->data_cadastro);
- $this->form->setData($object); // fill the form with the active record data
- TTransaction::close(); // close the transaction
- new TMessage('info', TAdiantiCoreTranslator::translate('Record saved')); // success message
- $param['key'] = $object->aluno_id;
- $this->onReload($param); // reload the listing
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * method onLoad()
- *
- */
- public function onLoad($param = NULL)
- {
- $this->loaded = FALSE;
- try
- {
- if (isset($param['key']))
- {
- $key=$param['key']; // get the parameter $key
- TTransaction::open('elainelins'); // open a transaction with the database
- $aluno = new Aluno($key); // instantiates the Active Record
- //print_r($aluno);die;
- $object = new stdClass;
- $object->aluno_id = $aluno->id;
- $object->aluno_nome = $aluno->nome;
- $this->form->setData($object);
- $this->onReload($param);
- TTransaction::close(); // close the transaction
- }
- else
- {
- $this->form->clear();
- $this->datagrid->clear();
- }
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- public static function onChangeAction($param)
- {
- $param['key'] = $param['aluno_id'];
- //print_r($param);die;
- TApplication::loadPage( 'AcompanhamentoFormList', 'onLoad', (array)$param );
- }
- /**
- * method show()
- * Shows the page e seu conteúdo
- */
- function show()
- {
- // check if the datagrid is already loaded
- if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
- {
- $this->onReload( func_get_arg(0) );
- }
- parent::show();
- }
- }
- ?>
Alguém pode verificar onde está o erro.
cade o chamamento da class TRecord???
tente usar