Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 16.53 KB | None | 0 0
  1. <?php
  2. /**
  3.  * VwProfessordisciplinassemestreList Listing
  4.  * @author  <your name here>
  5.  */
  6. class VwProfessordisciplinassemestreList extends TPage
  7. {
  8.     private $form; // form
  9.     private $datagrid; // listing
  10.     private $pageNavigation;
  11.     private $formgrid;
  12.     private $loaded;
  13.     private $deleteButton;
  14.    
  15.     /**
  16.      * Class constructor
  17.      * Creates the page, the form and the listing
  18.      */
  19.     public function __construct()
  20.     {
  21.         parent::__construct();
  22.        
  23.         // creates the form
  24.         $this->form = new TQuickForm('form_search_VwProfessordisciplinassemestre');
  25.         $this->form->class = 'tform'; // change CSS class
  26.         $this->form = new BootstrapFormWrapper($this->form);
  27.         $this->form->style = 'display: table;width:100%'; // change style
  28.         $this->form->setFormTitle('VwProfessordisciplinassemestre');
  29.        
  30.  
  31.         // create the form fields
  32.         $NomeProfessor = new TEntry('NomeProfessor');
  33.         $NomeCurso = new TEntry('NomeCurso');
  34.         $Etapa = new TEntry('Etapa');
  35.         $NomeDisciplina = new TEntry('NomeDisciplina');
  36.         $Identificacao = new TEntry('Identificacao');
  37.         $Ano = new TEntry('Ano');
  38.         $Semestre = new TEntry('Semestre');
  39.         $NomeEntidade = new TEntry('NomeEntidade');
  40.  
  41.  
  42.         // add the fields
  43.         $this->form->addQuickField('Professor', $NomeProfessor,  '100%' );
  44.         $this->form->addQuickField('Curso', $NomeCurso,  '100%' );
  45.  //       $this->form->addQuickField('Etapa', $Etapa,  '100%' );
  46.         $this->form->addQuickField('Disciplina', $NomeDisciplina,  '100%' );
  47.         /*$this->form->addQuickField('Identificacao', $Identificacao,  '100%' );
  48.         $this->form->addQuickField('Ano', $Ano,  '100%' );
  49.         $this->form->addQuickField('Semestre', $Semestre,  '100%' );
  50.         $this->form->addQuickField('Mantida', $NomeEntidade,  '100%' );*/
  51.  
  52.        
  53.         // keep the form filled during navigation with session data
  54.         $this->form->setData( TSession::getValue('VwProfessordisciplinassemestre_filter_data') );
  55.        
  56.         // add the search form actions
  57.         $btn = $this->form->addQuickAction(_t('Find'), new TAction(array($this, 'onSearch')), 'fa:search');
  58.         $btn->class = 'btn btn-sm btn-primary';
  59.       //  $this->form->addQuickAction(_t('New'),  new TAction(array('', 'onEdit')), 'bs:plus-sign green');
  60.        
  61.         // creates a Datagrid
  62.         $this->datagrid = new TDataGrid;
  63.         $this->datagrid = new BootstrapDatagridWrapper($this->datagrid);
  64.         $this->datagrid->style = 'width: 100%';
  65.         $this->datagrid->datatable = 'true';
  66.         // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
  67.        
  68.  
  69.         // creates the datagrid columns
  70.         $column_NomeProfessor = new TDataGridColumn('NomeProfessor', 'Professor', 'left');
  71.         $column_NomeCurso = new TDataGridColumn('NomeCurso', 'Curso', 'left');
  72.         $column_NomeDisciplina = new TDataGridColumn('NomeDisciplina', 'Disciplina', 'left');
  73.         $column_Etapa = new TDataGridColumn('Etapa', 'Etapa', 'left');
  74.         $column_Identificacao = new TDataGridColumn('Identificacao', 'Identificacao', 'left');
  75.         //$column_Ano = new TDataGridColumn('Ano', 'Ano', 'left');
  76.         //$column_Semestre = new TDataGridColumn('Semestre', 'Semestre', 'left');
  77.         //$column_NomeEntidade = new TDataGridColumn('NomeEntidade', 'Nomeentidade', 'left');
  78.  
  79.  
  80.         // add the columns to the DataGrid
  81.         $this->datagrid->addColumn($column_NomeProfessor);
  82.         $this->datagrid->addColumn($column_NomeCurso);
  83.         $this->datagrid->addColumn($column_NomeDisciplina);
  84.         $this->datagrid->addColumn($column_Etapa);
  85.         $this->datagrid->addColumn($column_Identificacao);
  86.         //$this->datagrid->addColumn($column_Ano);
  87.         //$this->datagrid->addColumn($column_Semestre);
  88. //        $this->datagrid->addColumn($column_NomeEntidade);
  89.  
  90.        
  91.         // create EDIT action
  92.  /*       $action_edit = new TDataGridAction(array('', 'onEdit'));
  93.         //$action_edit->setUseButton(TRUE);
  94.         //$action_edit->setButtonClass('btn btn-default');
  95.         $action_edit->setLabel(_t('Edit'));
  96.         $action_edit->setImage('fa:pencil-square-o blue fa-lg');
  97.         $action_edit->setField('CodProfessor');
  98.         $this->datagrid->addAction($action_edit);*/
  99.        
  100.         // create DELETE action
  101.         $action_del = new TDataGridAction(array($this, 'onDelete'));
  102.         //$action_del->setUseButton(TRUE);
  103.         //$action_del->setButtonClass('btn btn-default');
  104.         $action_del->setLabel(_t('Delete'));
  105.         $action_del->setImage('fa:trash-o red fa-lg');
  106.         $action_del->setField('CodProfessor');
  107.         $this->datagrid->addAction($action_del);
  108.        
  109.         // create the datagrid model
  110.         $this->datagrid->createModel();
  111.        
  112.         // creates the page navigation
  113.         $this->pageNavigation = new TPageNavigation;
  114.         $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  115.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  116.        
  117.  
  118.  
  119.         // vertical box container
  120.         $container = new TVBox;
  121.         $container->style = 'width: 90%';
  122.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  123.         $container->add(TPanelGroup::pack('Atribuição de Disciplinas', $this->form));
  124.         $container->add(TPanelGroup::pack('', $this->datagrid, $this->pageNavigation));
  125.        
  126.         parent::add($container);
  127.     }
  128.    
  129.     /**
  130.      * Inline record editing
  131.      * @param $param Array containing:
  132.      *              key: object ID value
  133.      *              field name: object attribute to be updated
  134.      *              value: new attribute content
  135.      */
  136. /*    public function onInlineEdit($param)
  137.     {
  138.         try
  139.         {
  140.             // get the parameter $key
  141.             $field = $param['field'];
  142.             $key   = $param['key'];
  143.             $value = $param['value'];
  144.            
  145.             TTransaction::open('Dados_Fei_T'); // open a transaction with database
  146.             $object = new VwProfessordisciplinassemestre($key); // instantiates the Active Record
  147.             $object->{$field} = $value;
  148.             $object->store(); // update the object in the database
  149.             TTransaction::close(); // close the transaction
  150.            
  151.             $this->onReload($param); // reload the listing
  152.             new TMessage('info', "Record Updated");
  153.         }
  154.         catch (Exception $e) // in case of exception
  155.         {
  156.             new TMessage('error', $e->getMessage()); // shows the exception error message
  157.             TTransaction::rollback(); // undo all pending operations
  158.         }
  159.     }*/
  160.    
  161.     /**
  162.      * Register the filter in the session
  163.      */
  164.     public function onSearch()
  165.     {
  166.         // get the search form data
  167.         $data = $this->form->getData();
  168.        
  169.         // clear session filters
  170.         TSession::setValue('VwProfessordisciplinassemestreList_filter_NomeProfessor',   NULL);
  171.         TSession::setValue('VwProfessordisciplinassemestreList_filter_NomeCurso',   NULL);
  172.         TSession::setValue('VwProfessordisciplinassemestreList_filter_Etapa',   NULL);
  173.         TSession::setValue('VwProfessordisciplinassemestreList_filter_NomeDisciplina',   NULL);
  174.         TSession::setValue('VwProfessordisciplinassemestreList_filter_Identificacao',   NULL);
  175.         TSession::setValue('VwProfessordisciplinassemestreList_filter_Ano',   NULL);
  176.         TSession::setValue('VwProfessordisciplinassemestreList_filter_Semestre',   NULL);
  177.         TSession::setValue('VwProfessordisciplinassemestreList_filter_NomeEntidade',   NULL);
  178.  
  179.         if (isset($data->NomeProfessor) AND ($data->NomeProfessor)) {
  180.             $filter = new TFilter('NomeProfessor', 'like', "%{$data->NomeProfessor}%"); // create the filter
  181.             TSession::setValue('VwProfessordisciplinassemestreList_filter_NomeProfessor',   $filter); // stores the filter in the session
  182.         }
  183.  
  184.  
  185.         if (isset($data->NomeCurso) AND ($data->NomeCurso)) {
  186.             $filter = new TFilter('NomeCurso', 'like', "%{$data->NomeCurso}%"); // create the filter
  187.             TSession::setValue('VwProfessordisciplinassemestreList_filter_NomeCurso',   $filter); // stores the filter in the session
  188.         }
  189.  
  190.  
  191.         if (isset($data->Etapa) AND ($data->Etapa)) {
  192.             $filter = new TFilter('Etapa', 'like', "%{$data->Etapa}%"); // create the filter
  193.             TSession::setValue('VwProfessordisciplinassemestreList_filter_Etapa',   $filter); // stores the filter in the session
  194.         }
  195.  
  196.  
  197.         if (isset($data->NomeDisciplina) AND ($data->NomeDisciplina)) {
  198.             $filter = new TFilter('NomeDisciplina', 'like', "%{$data->NomeDisciplina}%"); // create the filter
  199.             TSession::setValue('VwProfessordisciplinassemestreList_filter_NomeDisciplina',   $filter); // stores the filter in the session
  200.         }
  201.  
  202.  
  203.         if (isset($data->Identificacao) AND ($data->Identificacao)) {
  204.             $filter = new TFilter('Identificacao', 'like', "%{$data->Identificacao}%"); // create the filter
  205.             TSession::setValue('VwProfessordisciplinassemestreList_filter_Identificacao',   $filter); // stores the filter in the session
  206.         }
  207.  
  208.  
  209.         if (isset($data->Ano) AND ($data->Ano)) {
  210.             $filter = new TFilter('Ano', 'like', "%{$data->Ano}%"); // create the filter
  211.             TSession::setValue('VwProfessordisciplinassemestreList_filter_Ano',   $filter); // stores the filter in the session
  212.         }
  213.  
  214.  
  215.         if (isset($data->Semestre) AND ($data->Semestre)) {
  216.             $filter = new TFilter('Semestre', 'like', "%{$data->Semestre}%"); // create the filter
  217.             TSession::setValue('VwProfessordisciplinassemestreList_filter_Semestre',   $filter); // stores the filter in the session
  218.         }
  219.  
  220.  
  221.         if (isset($data->NomeEntidade) AND ($data->NomeEntidade)) {
  222.             $filter = new TFilter('NomeEntidade', 'like', "%{$data->NomeEntidade}%"); // create the filter
  223.             TSession::setValue('VwProfessordisciplinassemestreList_filter_NomeEntidade',   $filter); // stores the filter in the session
  224.         }
  225.  
  226.        
  227.         // fill the form with data again
  228.         $this->form->setData($data);
  229.        
  230.         // keep the search data in the session
  231.         TSession::setValue('VwProfessordisciplinassemestre_filter_data', $data);
  232.        
  233.         $param=array();
  234.         $param['offset']    =0;
  235.         $param['first_page']=1;
  236.         $this->onReload($param);
  237.     }
  238.    
  239.     /**
  240.      * Load the datagrid with data
  241.      */
  242.     public function onReload($param = NULL)
  243.     {
  244.         try
  245.         {
  246.             // open a transaction with database 'Dados_Fei_T'
  247.             TTransaction::open('Dados_Fei_T');
  248.            
  249.             // creates a repository for VwProfessordisciplinassemestre
  250.             $repository = new TRepository('VwProfessordisciplinassemestre');
  251.             $limit = 50;
  252.             // creates a criteria
  253.             $criteria = new TCriteria;
  254.            
  255.             // default order
  256.             if (empty($param['order']))
  257.             {
  258.                 $param['order'] = 'CodProfessor';
  259.                 $param['direction'] = 'asc';
  260.             }
  261.             $criteria->setProperties($param); // order, offset
  262.             $criteria->setProperty('limit', $limit);
  263.            
  264.  
  265.             if (TSession::getValue('VwProfessordisciplinassemestreList_filter_NomeProfessor')) {
  266.                 $criteria->add(TSession::getValue('VwProfessordisciplinassemestreList_filter_NomeProfessor')); // add the session filter
  267.             }
  268.  
  269.  
  270.             if (TSession::getValue('VwProfessordisciplinassemestreList_filter_NomeCurso')) {
  271.                 $criteria->add(TSession::getValue('VwProfessordisciplinassemestreList_filter_NomeCurso')); // add the session filter
  272.             }
  273.  
  274.  
  275.             if (TSession::getValue('VwProfessordisciplinassemestreList_filter_Etapa')) {
  276.                 $criteria->add(TSession::getValue('VwProfessordisciplinassemestreList_filter_Etapa')); // add the session filter
  277.             }
  278.  
  279.  
  280.             if (TSession::getValue('VwProfessordisciplinassemestreList_filter_NomeDisciplina')) {
  281.                 $criteria->add(TSession::getValue('VwProfessordisciplinassemestreList_filter_NomeDisciplina')); // add the session filter
  282.             }
  283.  
  284.  
  285.             if (TSession::getValue('VwProfessordisciplinassemestreList_filter_Identificacao')) {
  286.                 $criteria->add(TSession::getValue('VwProfessordisciplinassemestreList_filter_Identificacao')); // add the session filter
  287.             }
  288.  
  289.  
  290.             if (TSession::getValue('VwProfessordisciplinassemestreList_filter_Ano')) {
  291.                 $criteria->add(TSession::getValue('VwProfessordisciplinassemestreList_filter_Ano')); // add the session filter
  292.             }
  293.  
  294.  
  295.             if (TSession::getValue('VwProfessordisciplinassemestreList_filter_Semestre')) {
  296.                 $criteria->add(TSession::getValue('VwProfessordisciplinassemestreList_filter_Semestre')); // add the session filter
  297.             }
  298.  
  299.  
  300.             if (TSession::getValue('VwProfessordisciplinassemestreList_filter_NomeEntidade')) {
  301.                 $criteria->add(TSession::getValue('VwProfessordisciplinassemestreList_filter_NomeEntidade')); // add the session filter
  302.             }
  303.  
  304.            
  305.             // load the objects according to criteria
  306.             $objects = $repository->load($criteria, FALSE);
  307.            
  308.             if (is_callable($this->transformCallback))
  309.             {
  310.                 call_user_func($this->transformCallback, $objects, $param);
  311.             }
  312.            
  313.             $this->datagrid->clear();
  314.             if ($objects)
  315.             {
  316.                 // iterate the collection of active records
  317.                 foreach ($objects as $object)
  318.                 {
  319.                     // add the object inside the datagrid
  320.                     $this->datagrid->addItem($object);
  321.                 }
  322.             }
  323.            
  324.             // reset the criteria for record count
  325.             $criteria->resetProperties();
  326.             $count= $repository->count($criteria);
  327.            
  328.             $this->pageNavigation->setCount($count); // count of records
  329.             $this->pageNavigation->setProperties($param); // order, page
  330.             $this->pageNavigation->setLimit($limit); // limit
  331.            
  332.             // close the transaction
  333.             TTransaction::close();
  334.             $this->loaded = true;
  335.         }
  336.         catch (Exception $e) // in case of exception
  337.         {
  338.             // shows the exception error message
  339.             new TMessage('error', $e->getMessage());
  340.             // undo all pending operations
  341.             TTransaction::rollback();
  342.         }
  343.     }
  344.    
  345.     /**
  346.      * Ask before deletion
  347.      */
  348.     public function onDelete($param)
  349.     {
  350.         // define the delete action
  351.         $action = new TAction(array($this, 'Delete'));
  352.         $action->setParameters($param); // pass the key parameter ahead
  353.        
  354.         // shows a dialog to the user
  355.         new TQuestion(AdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  356.     }
  357.    
  358.     /**
  359.      * Delete a record
  360.      */
  361.     public function Delete($param)
  362.     {
  363.         try
  364.         {
  365.             $key=$param['key']; // get the parameter $key
  366.             TTransaction::open('Dados_Fei_T'); // open a transaction with database
  367.             $object = new VwProfessordisciplinassemestre($key, FALSE); // instantiates the Active Record
  368.             $object->delete(); // deletes the object from the database
  369.             TTransaction::close(); // close the transaction
  370.             $this->onReload( $param ); // reload the listing
  371.             new TMessage('info', AdiantiCoreTranslator::translate('Record deleted')); // success message
  372.         }
  373.         catch (Exception $e) // in case of exception
  374.         {
  375.             new TMessage('error', $e->getMessage()); // shows the exception error message
  376.             TTransaction::rollback(); // undo all pending operations
  377.         }
  378.     }
  379.    
  380.  
  381.  
  382.  
  383.    
  384.     /**
  385.      * method show()
  386.      * Shows the page
  387.      */
  388.     public function show()
  389.     {
  390.         // check if the datagrid is already loaded
  391.         if (!$this->loaded AND (!isset($_GET['method']) OR !(in_array($_GET['method'],  array('onReload', 'onSearch')))) )
  392.         {
  393.             if (func_num_args() > 0)
  394.             {
  395.                 $this->onReload( func_get_arg(0) );
  396.             }
  397.             else
  398.             {
  399.                 $this->onReload();
  400.             }
  401.         }
  402.         parent::show();
  403.     }
  404. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement