JA
Como filtrar data da Busca para o datagrid
Olá, Galera!
Peço ajuda dos colegas, preciso parar a data da busca para o datagrid.
Att,
Jonathas Alves
Peço ajuda dos colegas, preciso parar a data da busca para o datagrid.
- <?php
- /**
- * ExemploCheckList Listing
- * @author <your name here>
- */
- class SystemAlunoFrequenciaUpdate extends TPage
- {
- private $form; // form
- private $datagrid; // listing
- private $pageNavigation;
- private $formgrid;
- private $loaded;
- private $deleteButton;
- private static $database = 'db_guiansoft';
- private static $activeRecord = 'SystemAlunoTurma';
- private static $primaryKey = 'id';
- private static $formName = 'form_system_aluno_frequencia';
- /**
- * Class constructor
- * Creates the page, the form and the listing
- */
- public function __construct()
- {
- parent::__construct();
- // creates the form
- $this->form = new BootstrapFormBuilder(self::$formName);
- // define the form title
- $this->form->setFormTitle('Frequência');
- $id = new TEntry('id');
- $periodo_id = new TDBCombo('periodo_id', 'db_guiansoft', 'SystemPeriodo', 'id', 'nome');
- $curso_id = new TDBCombo('curso_id', 'db_guiansoft', 'SystemCurso', 'id', 'nome');
- $modulo_id = new TDBCombo('modulo_id', 'db_guiansoft', 'SystemModulo', 'id', 'nome');
- $turma_id = new TDBCombo('turma_id', 'db_guiansoft', 'SystemTurma', 'id', 'nome');
- $situacao_id = new TDBCombo('situacao_id', 'db_guiansoft', 'SystemSituacaoAlunoTurma', 'id', 'nome');
- $data_frequencia = new TDate('data_frequencia');
- $id->setSize(100);
- $curso_id->setSize('100%');
- $modulo_id->setSize('100%');
- $turma_id->setSize('100%');
- $situacao_id->setSize('100%');
- $data_frequencia->setSize('100%');
- $this->form->addFields( [new TLabel(('Período'))], [$periodo_id], [new TLabel(('Curso'))], [$curso_id] );
- $this->form->addFields( [new TLabel(('Módulo'))], [$modulo_id], [new TLabel(('Turma'))], [$turma_id] );
- $this->form->addFields( [new TLabel(('Situação'))], [$situacao_id], [new TLabel(('Data'))], [$data_frequencia] );
- // keep the form filled during navigation with session data
- $this->form->setData( TSession::getValue(__CLASS__.'_filter_data') );
- $btn_onsearch = $this->form->addAction('Buscar', new TAction([$this, 'onSearch']), 'fa:search');
- $btn_onsearch->addStyleClass('btn');
- $bt_marcar = $this->form->addAction('Presente', new TAction([$this, 'onSelectedAll']), 'fa:check #ffffff');
- $bt_marcar->addFunction("$('input:checkbox').prop('frequencia_check',true);");
- $bt_marcar->addStyleClass('btn-success');
- $bt_desmarcar = $this->form->addAction('Faltou', new TAction([$this, 'offSelectedAll']), 'fa:check #ffffff');
- $bt_desmarcar->addFunction("$('input:checkbox').prop('frequencia_check',false);");
- $bt_desmarcar->addStyleClass('btn-danger');
- $btn_onsave = $this->form->addAction('Salvar', new TAction([$this, 'onSearch']), 'fa:floppy-o #ffffff');
- $btn_onsave->addStyleClass('btn-primary');
- // creates a Datagrid
- $this->datagrid = new TDataGrid;
- $this->datagrid = new BootstrapDatagridWrapper($this->datagrid);
- $this->datagrid->style = 'width: 100%';
- $this->datagrid->setHeight(320);
- $column_id = new TDataGridColumn('id', 'Id', 'center' , '70px');
- $column_aluno_id = new TDataGridColumn('SystemAluno->name', 'Aluno', 'left');
- $column_data_frequencia = new TDataGridColumn('data_frequencia', 'Data', 'left');
- $column_frequencia_check = new TDataGridColumn('frequencia_check', 'Frequência', 'left');
- $column_frequencia_check->setTransformer( function($value, $object, $row) {
- $frequencia_check = new TCheckButton('check_'.$object->id);
- $frequencia_check->setSize('70%');
- $frequencia_check->setFormName(self::$formName);
- $frequencia_check->setValue($value);
- $frequencia_check->setIndexValue('on');
- $frequencia_check->onchange = 'mudarCor(this)';
- $this->formgrid->addField($frequencia_check); // important
- return $frequencia_check;
- });
- $order_id = new TAction(array($this, 'onReload'));
- $order_id->setParameter('order', 'id');
- $column_id->setAction($order_id);
- $this->datagrid->addColumn($column_id);
- $this->datagrid->addColumn($column_aluno_id);
- $this->datagrid->addColumn($column_data_frequencia);
- $this->datagrid->addColumn($column_frequencia_check);
- // 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());
- $this->datagrid->disableDefaultClick();
- // put datagrid inside a form
- $this->formgrid = new TForm;
- $this->formgrid->add($this->datagrid);
- $panel = new TPanelGroup;
- $panel->add($this->formgrid);
- $panel->addFooter($this->pageNavigation);
- // vertical box container
- $container = new TVBox;
- $container->style = 'width: 100%';
- $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add($this->form);
- $container->add($panel);
- parent::add($container);
- }
- /**
- * method onSelectedAll()
- * Executed when the user clicks at the marcar todos button
- */
- function onSelectedAll()
- {
- $data = $this->form->getData();
- if($data->aluno_id != '')
- {
- $data->frequencia_check = 'true';
- TButton::enableField('form_system_aluno_frequencia','bt_desmarcar');
- //$this->onReload($data);
- }
- }
- /**
- * method offSelectedAll()
- * Executed when the user clicks at the desmarcar todos button
- */
- function offSelectedAll()
- {
- $data = $this->form->getData();
- if($data->aluno_id != '')
- {
- $data->frequencia_check = 'false';
- TButton::disableField('form_system_aluno_frequencia','bt_desmarcar');
- //$this->onReload($data);
- }
- }
- public static function onSave($param)
- {
- $frequencia_check = $param['_field_frequencia_check'];
- $value = $param['_field_value'];
- $column = $param['column'];
- $parts = explode('_', $frequencia_check);
- $id = end($parts);
- try
- {
- // open transaction
- TTransaction::open('db_guiansoft');
- $class = self::$activeRecord;
- $object = $class::find($id);
- if ($object)
- {
- $object->$column = $value;
- $object->store();
- }
- // close transaction
- TTransaction::close();
- }
- catch (Exception $e)
- {
- // show the exception message
- new TMessage('error', $e->getMessage());
- }
- }
- /**
- * Register the filter in the session
- */
- public function onSearch()
- {
- // get the search form data
- $data = $this->form->getData();
- $filters = [];
- TSession::setValue(__CLASS__.'_filter_data', NULL);
- TSession::setValue(__CLASS__.'_filters', NULL);
- if (isset($data->id) AND ($data->id))
- {
- $filters[] = new TFilter('id', '=', $data->id);// create the filter
- }
- if (isset($data->periodo_id) AND ($data->periodo_id))
- {
- $filters[] = new TFilter('periodo_id', 'like', "%{$data->periodo_id}%");// create the filter
- }
- if (isset($data->curso_id) AND ($data->curso_id))
- {
- $filters[] = new TFilter('curso_id', 'like', "%{$data->curso_id}%");// create the filter
- }
- if (isset($data->modulo_id) AND ($data->modulo_id))
- {
- $filters[] = new TFilter('modulo_id', 'like', "%{$data->modulo_id}%");// create the filter
- }
- if (isset($data->turma_id) AND ($data->turma_id))
- {
- $filters[] = new TFilter('turma_id', 'like', "%{$data->turma_id}%");// create the filter
- }
- if (isset($data->situacao_id) AND ($data->situacao_id))
- {
- $filters[] = new TFilter('situacao_id', 'like', "%{$data->situacao_id}%");// create the filter
- }
- // fill the form with data again
- $this->form->setData($data);
- // keep the search data in the session
- TSession::setValue(__CLASS__.'_filter_data', $data);
- TSession::setValue(__CLASS__.'_filters', $filters);
- $param=array();
- $param['offset'] =0;
- $param['first_page']=1;
- $this->onReload($param);
- }
- /**
- * Load the datagrid with data
- */
- public function onReload($param = NULL)
- {
- try
- {
- // open a transaction with database 'exemplo1'
- TTransaction::open(self::$database);
- // creates a repository for CheckList
- $repository = new TRepository(self::$activeRecord);
- $limit = 20;
- // creates a criteria
- $criteria = new TCriteria;
- if (empty($param['order']))
- {
- $param['order'] = 'id';
- }
- if (empty($param['direction']))
- {
- $param['direction'] = 'desc';
- }
- $criteria->setProperties($param); // order, offset
- $criteria->setProperty('limit', $limit);
- if($filters = TSession::getValue(__CLASS__.'_filters'))
- {
- foreach ($filters as $filter)
- {
- $criteria->add($filter);
- }
- }
- // load the objects according to criteria
- $objects = $repository->load($criteria, FALSE);
- $this->datagrid->clear();
- 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
- {
- // shows the exception error message
- new TMessage('error', $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- public function onShow()
- {
- }
- /**
- * method show()
- * Shows the page
- */
- public function show()
- {
- // frequencia_check if the datagrid is already loaded
- if (!$this->loaded AND (!isset($_GET['method']) OR !(in_array($_GET['method'], array('onReload', 'onSearch')))) )
- {
- if (func_num_args() > 0)
- {
- $this->onReload( func_get_arg(0) );
- }
- else
- {
- $this->onReload();
- }
- }
- parent::show();
- }
- }
- ?>
Att,
Jonathas Alves
Consegue detalhar um pouco mais? Não entendi exatamente o que você quer fazer
Olá, Nataniel!
SystemAlunoFrequenciaUpdate faz uma consulta:
Período, Curso, Módulo, Turma, Situação e Data;
OBS: Situação = situação do aluno na turma que pode ser cursando, cancelado, transferido, reprovado ou aprovado.
Data: data do registro da frequencia.
Essas informações para consulta estão na SystemAlunoTurma que retorna no list da SystemAlunoFrequenciaUpdate.
então queria armazenar para cada aluno que esta no list essas informações e se ele esta presente ou faltou.
tem dois botoes um presente em verde e faltou em vermelho ao clicar posso marcar todos como presente ou como faltou.
e em seguida gravo essas informações em SystemAlunoFrequencia.
essa é a ideia
Att,
Jonathas Alves
Quando você clica em Buscar, a função onSearch guarda os dados dos formulário na sessão:
Com isso você consegue recuperar a data em outras funções da classe, como a onReload, onSelectedAll, etc
Olá, Nataniel!
Obrigado pela atenção
Retorna o campo data_frequencia null
Fiz essa alteração no código, mais ainda não estou conseguindo pegar o valor da data da frequência.
Jonathas, você está fazendo um var_dump da variável $object, que é uma instância da classe SystemAlunoTurma. Nessa variável você tem os valores de cada registro gravados no banco de dados. Se quiser adicionar outras informaçõe que não estejam no banco de dados, como uma data do formulário, você vai precisar especificar isso: