Lançado Adianti Framework 8.1!
Clique aqui para saber mais
Ajuda com Barra de progresso com dados do DB. Por favor amigos, me ajudem cria uma barra de progresso para colocar em "% Completo" na foto em anexo. Agradeço quem puder me ajudar....
JE
Ajuda com Barra de progresso com dados do DB.  
Fechado
Por favor amigos, me ajudem cria uma barra de progresso para colocar em "% Completo" na foto em anexo.

Agradeço quem puder me ajudar.

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (7)


AN

Olá como funciona, você tem este valor em % ou outro valor no seu banco de dados?
AN

  1. <?php
  2. /**
  3.  * Description of TProgressBar
  4.  *
  5.  * @author ademilson Nunes
  6.  */
  7. class TProgressBar extends TElement
  8. {
  9.     private $value;
  10.     
  11.     public function __construct() 
  12.     {
  13.         parent::__construct('div');
  14.         $this->class 'progress';
  15.         $this->id 'bar_' uniqid();          
  16.     }
  17.     
  18.     
  19.     public function setValue($value)
  20.     {
  21.        $this->value $value;
  22.     }
  23.             
  24.     /**
  25.      * Shows the widget at the screen
  26.      */       
  27.     public function show()
  28.     {                   
  29.          $progressBar = new TElement('div');
  30.          $progressBar->class 'progress-bar';
  31.          $progressBar->role 'progressbar';
  32.          $progressBar->{'arial-valuenow'} = $this->value;
  33.          $progressBar->{'arial-valuemin'} = '0';
  34.          $progressBar->{'arial-valuemax'} = '100';
  35.          $progressBar->style='width: ' $this->value '%;';
  36.          $progressBar->add($this->value);
  37.          parent::add($progressBar);
  38.        
  39.         parent::show();
  40.     }
  41. }
  42. ?>
JE

Olá amigo, agradeço por responder, é o seguinte, tenho informações no banco onde são: concluída e em atraso, gostaria de somar todas e mostra a % das concluídas. Tipo 60% concluido
AN

Eu escrevi esta classe quando li sua dúvida, acho que pode lhe atender. Monta em sua model os procedimentos para calcular este valor em seguida tente usar a classe TProgressBar seguindo o exemplo:

  1. <?php
  2. class Teste extends TPage
  3. {
  4.     private $form;
  5.     private $progressBar;
  6.     
  7.     public function __construct() 
  8.     {
  9.         parent::__construct();                       
  10.         $table = new TTable;        
  11.         
  12.         $this->form = new TForm('myForm');        
  13.         $this->form->add($table);
  14.         
  15.         $entry = new TEntry('teste');   
  16.                 
  17.         $this->progressBar = new TProgressBar();
  18.         $this->progressBar->setValue(0);
  19.         
  20.         $button  = new TButton('onEntry');
  21.         $button->setAction(new TAction(array($this'onEntry')), 'onEntry');
  22.         $button->setImage('ico_apply.png');
  23.         
  24.         $row $table->addRow();
  25.         $row->addCell($this->progressBar);
  26.         $row $table->addRow();
  27.         $row->addCell($entry);        
  28.         $row->addCell($button);          
  29.                                         
  30.         $this->form->setFields(array($button$entry));
  31.                                         
  32.         parent::add($this->form);        
  33.         
  34.     }
  35.     
  36.     
  37.     public function onEntry()
  38.     {
  39.         $obj = new stdClass();
  40.         $obj $this->form->getData();
  41.         $this->progressBar->setValue($obj->teste);
  42.     }
  43. }
  44. ?>


Você pode criar um médodo 'getter' na model para retornar a progressBar direto no seu datagrid.

# Classe - Componente
pastebin.com/uh15TkKb
# View - Teste
pastebin.com/UBDS5ndv

*******Lembre se colocar armazenar o arquivo da classe no diretório : app/lib/TProgressbar/TProgressBar.class.php
#Exemplo
s10.postimg.org/ihkzbhb5l/Config.jpg

******Teste
s14.postimg.org/5haiwc8kx/Teste.jpg



JE

Boa noite Ademilson Nunes, não sei como te agradecer. Mas te peço mais um favor. Me ajude a implantar a na minha class:
  1. <?php
  1. <?php
  2. /**
  3.  * PlanoperativoLista Listing
  4.  * @author  <Jurandir G Marques>
  5.  */
  6. class PlanoperativoLista extends TPage
  7. {
  8.     private $form;     // registration form
  9.     private $datagrid// listing
  10.     private $pageNavigation;
  11.     private $loaded;
  12.     private $progressBar;
  13.     
  14.     /**
  15.      * Class constructor
  16.      * Creates the page, the form and the listing
  17.      */
  18.     public function __construct()
  19.     {
  20.         parent::__construct();
  21.         
  22.         // creates the form
  23.         $this->form = new TForm('form_search_Planoperativo');
  24.         $this->form->class 'tform'// CSS class
  25.         
  26.         // creates a table
  27.         $table = new TTable;
  28.         
  29.         // add the table inside the form
  30.         $this->form->add($table);
  31.         
  32.         // create the form fields
  33.         $filter = new TEntry('id');
  34.         //$filter = new TDBMultiSearch('objetivo','permission', 'Planoperativo', 'id','objetivo');
  35.         $filter->setValue(TSession::getValue('Planoperativo_id'));
  36.         
  37.         // add a row for the filter field
  38.         $row=$table->addRowSet( new TLabel('P.O:'), $filter);
  39.         
  40.         // create two action buttons to the form
  41.         $find_button = new TButton('find');
  42.         $new_button  = new TButton('new');
  43.         $find_button->setAction(new TAction(array($this'onSearch')), ('Buscar'));
  44.         $new_button->setAction(new TAction(array('PlanoperativoForm''onEdit')), ('Novo'));
  45.         $find_button->setImage('ico_find.png');
  46.         $new_button->setImage('ico_new.png');
  47.         
  48.         // add a row for the form actions
  49.         $row=$table->addRowSet$find_button$new_button );
  50.         
  51.         // define wich are the form fields
  52.         $this->form->setFields(array($filter$find_button$new_button));
  53.         
  54.         // creates a DataGrid
  55.         $this->datagrid = new TDataGrid;
  56.         //$this->datagrid->setHeight(320);
  57.         $this->datagrid->style 'width: 100%';
  58.         //-------------
  59.         $this->progressBar = new TProgressBar();
  60.         $this->progressBar->setValue(0);
  61.         //-------------
  62.         // creates the datagrid columns
  63.         $id                   = new TDataGridColumn('id''ID''left'40);
  64.         $objetivo             = new TDataGridColumn('objetivo''Meta Prioritária''left'500);
  65.         $data_atual           = new TDataGridColumn('data_atual''Criado Em''right'90);
  66.         $this->progressBar    = new TDataGridColumn('progressBar''% Completo''center'150);
  67.         
  68.         $data_atual->setTransformer(array($this'formatDate'));
  69.         // add the columns to the DataGrid
  70.         $this->datagrid->addColumn($id);
  71.         $this->datagrid->addColumn($objetivo);
  72.         $this->datagrid->addColumn($data_atual);
  73.         $this->datagrid->addColumn($this->progressBar);
  74.         // creates two datagrid actions
  75.         $action1 = new TDataGridAction(array('PlanejamentoLista''onSetProject'));
  76.         $action1->setLabel('Detalhar o Plano');
  77.         $action1->setImage('bs:search blue');
  78.         $action1->setField('id');
  79.         
  80.         $action2 = new TDataGridAction(array($this'onDelete'));
  81.         $action2->setLabel('Deletar');
  82.         $action2->setImage('bs:remove red');
  83.         $action2->setField('id');
  84.         
  85.         $action3 = new TDataGridAction(array($this'onView'));
  86.         $action3->setLabel('Ver a data');
  87.         $action3->setImage('bs:hand-right green');
  88.         $action3->setField('data_atual');
  89.         
  90.         $action4 = new TDataGridAction(array('PlanoperativoForm''onEdit'));
  91.         $action4->setLabel(('Editar'));
  92.         $action4->setImage('bs:hand-right blue');
  93.         $action4->setField('id');
  94.         
  95.         $action_group = new TDataGridActionGroup('Opções''bs:th red');
  96.         
  97.         $action_group->addHeader('Opções do Plano');
  98.         $action_group->addAction($action1);
  99.         
  100.         $action_group->addSeparator();
  101.         $action_group->addHeader('Ações do Plano');
  102.         $action_group->addAction($action4);
  103.         $action_group->addAction($action2);
  104.         
  105.         // add the actions to the datagrid
  106.         $this->datagrid->addActionGroup($action_group);
  107.         // create the datagrid model
  108.         $this->datagrid->createModel();
  109.         
  110.         // creates the page navigation
  111.         $this->pageNavigation = new TPageNavigation;
  112.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  113.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  114.         
  115.         // create the page container
  116.         $container = new TVBox;
  117.         $container->add($this->form);
  118.         $container->add($this->datagrid);
  119.         $container->add($this->pageNavigation);
  120.         
  121.         parent::add($container);
  122.     }
  123.     /**
  124.     *
  125.     *
  126.     **/
  127.         public function formatDate($data_atual$object)
  128.     {
  129.         $dt = new DateTime($data_atual);
  130.         return $dt->format('d/m/Y');
  131.     }
  132.     
  133.     
  134.     
  135.     /**
  136.      * method onInlineEdit()
  137.      * Inline record editing
  138.      * @param $param Array containing:
  139.      *              key: object ID value
  140.      *              field name: object attribute to be updated
  141.      *              value: new attribute content 
  142.      */
  143.     function onInlineEdit($param)
  144.     {
  145.         try
  146.         {
  147.             // get the parameter $key
  148.             $field $param['field'];
  149.             $key   $param['key'];
  150.             $value $param['value'];
  151.             
  152.             // open a transaction with database 'permission'
  153.             TTransaction::open('permission');
  154.             
  155.             // instantiates object Planoperativo
  156.             $object = new Planoperativo($key);
  157.             
  158.             // update the object in the database
  159.             $object->{$field} = $value;
  160.             $object->store();
  161.             
  162.             // close the transaction
  163.             TTransaction::close();
  164.             
  165.             
  166.             $this->onReload($param); // reload the listing
  167.             new TMessage('info'"Record Updated");
  168.         }
  169.         catch (Exception $e// in case of exception
  170.         {
  171.             // shows the exception error message
  172.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  173.             // undo all pending operations
  174.             TTransaction::rollback();
  175.         }
  176.     }
  177.     
  178.     /**
  179.      * method onSearch()
  180.      * Register the filter in the session when the user performs a search
  181.      */
  182.     function onSearch()
  183.     {
  184.         // get the search form data
  185.         $data $this->form->getData();
  186.         
  187.         TSession::setValue('Planoperativo_filter',   NULL);
  188.         TSession::setValue('Planoperativo_id''');
  189.         
  190.         // check if the user has filled the form
  191.         if (isset($data->id) AND ($data->id))
  192.         {
  193.             // creates a filter using what the user has typed
  194.             $filter = new TFilter('objetivo''like'"%{$data->id}%");
  195.             
  196.             // stores the filter in the session
  197.             TSession::setValue('Planoperativo_filter',   $filter);
  198.             TSession::setValue('Planoperativo_id'$data->id);
  199.         }
  200.         else
  201.         {
  202.             TSession::setValue('Planoperativo_filter',   NULL);
  203.             TSession::setValue('Planoperativo_id''');
  204.         }
  205.         
  206.         // fill the form with data again
  207.         $this->form->setData($data);
  208.         
  209.         $param=array();
  210.         $param['offset']    =0;
  211.         $param['first_page']=1;
  212.         $this->onReload($param);
  213.     }
  214.     
  215.     /**
  216.      * method onReload()
  217.      * Load the datagrid with the database objects
  218.      */
  219.     function onReload($param NULL)
  220.     {
  221.         try
  222.         {
  223.         
  224.             // open a transaction with database 'permission'
  225.             TTransaction::open('permission');
  226.             
  227.             // creates a repository for Planoperativo
  228.             $repository = new TRepository('Planoperativo');
  229.             $limit 20;
  230.             // creates a criteria
  231.             $criteria = new TCriteria;
  232.             
  233.             // default order
  234.             if (empty($param['order']))
  235.             {
  236.                 $param['order'] = 'id';
  237.                 $param['direction'] = 'desc';
  238.             }
  239.             $criteria->setProperties($param); // order, offset
  240.             $criteria->setProperty('limit'$limit);
  241.             
  242.             if (TSession::getValue('Planoperativo_filter'))
  243.             {
  244.                 // add the filter stored in the session to the criteria
  245.                 $criteria->add(TSession::getValue('Planoperativo_filter'));
  246.             }
  247.             
  248.             // load the objects according to criteria
  249.             $objects $repository->load($criteriaFALSE);
  250.             
  251.             $this->datagrid->clear();
  252.             if ($objects)
  253.             {
  254.                 // iterate the collection of active records
  255.                 foreach ($objects as $object)
  256.                 {
  257.                     // add the object inside the datagrid
  258.                     $this->datagrid->addItem($object);
  259.                 }
  260.             }
  261.             
  262.             // reset the criteria for record count
  263.             $criteria->resetProperties();
  264.             $count$repository->count($criteria);
  265.             
  266.             $this->pageNavigation->setCount($count); // count of records
  267.             $this->pageNavigation->setProperties($param); // order, page
  268.             $this->pageNavigation->setLimit($limit); // limit
  269.             
  270.             // close the transaction
  271.             TTransaction::close();
  272.             $this->loaded true;
  273.         }
  274.         catch (Exception $e// in case of exception
  275.         {
  276.             // shows the exception error message
  277.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  278.             
  279.             // undo all pending operations
  280.             TTransaction::rollback();
  281.         }
  282.     }
  283.     
  284.     /**
  285.      * method onDelete()
  286.      * executed whenever the user clicks at the delete button
  287.      * Ask if the user really wants to delete the record
  288.      */
  289.     function onDelete($param)
  290.     {
  291.         // define the delete action
  292.         $action = new TAction(array($this'Delete'));
  293.         $action->setParameters($param); // pass the key parameter ahead
  294.         
  295.         // shows a dialog to the user
  296.         new TQuestion('Você realmente quer apagar ?'$action);
  297.     }
  298.     
  299.     /**
  300.      * method Delete()
  301.      * Delete a record
  302.      */
  303.     function Delete($param)
  304.     {
  305.         try
  306.         {
  307.             // get the parameter $key
  308.             $key=$param['key'];
  309.             // open a transaction with database 'permission'
  310.             TTransaction::open('permission');
  311.             
  312.             // instantiates object Planoperativo
  313.             $object = new Planoperativo($key);
  314.             
  315.             // deletes the object from the database
  316.             $object->delete();
  317.             
  318.             // close the transaction
  319.             TTransaction::close();
  320.             
  321.             // reload the listing
  322.             $this->onReload$param );
  323.             // shows the success message
  324.             new TMessage('info''Registro deletado', new TAction(array('PlanoperativoLista''onReload')));
  325.         }
  326.         catch (Exception $e// in case of exception
  327.         {
  328.             // shows the exception error message
  329.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  330.             
  331.             // undo all pending operations
  332.             TTransaction::rollback();
  333.         }
  334.     }
  335.         /**
  336.      * method onView()
  337.      * Executed when the user clicks at the view button
  338.      */
  339.     function onView($param)
  340.     {
  341.         // get the parameter and shows the message
  342.         $key=$param['key'];
  343.         new TMessage('info'"The information is : $key");
  344.     }
  345.     
  346.     /**
  347.      * method show()
  348.      * Shows the page
  349.      */
  350.     function show()
  351.     {
  352.         // check if the datagrid is already loaded
  353.         if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
  354.         {
  355.             $this->onReloadfunc_get_arg(0) );
  356.         }
  357.         parent::show();
  358.     }
  359. }
  360. ?>

?>
</Jurandir>
JE

Não tem o
  1. <?php e ?>
, é que eu não sabia como colocar o código em php. por isso ficou sobrando...

te agradeço por mais esta ajuda... será de grande valia pra mim..
PD

Jurandir,

Use o método setTransformer() sobre a coluna que contém o percentual.
Ele lerá o percentual e poderá retornar um conteúdo para "substituir" o conteúdo da coluna.

Aqui tem um exemplo:
www.adianti.com.br/framework_files/tutor/index.php?class=DatagridTra

Supondo que que você aplique a função de transformação sobre uma coluna que tenha o %,
e cuja largura padrão é 200 pixels. Neste caso, o tamanho da barra vai ser relativo à 200.

  1. <?php
  2.     // aplica função de transformação na coluna
  3.     $perc = new TDataGridColumn('perc',       'Percentual',       'right'200);
  4.     $perc->setTransformer(array($this'formatPercentual'));
  5.     // função de transformação
  6.     public function formatPercentual($perc$object$row// imagine que $perc é 0.8 para representar 80%
  7.     {
  8.         $width 200 $perc;
  9.         $label $perc 100;
  10.         return "<div style='float:left;text-align:center;width:{$width}px;background:green'> {$label}% </div>";
  11.     }
  12. ?>


Eu faria melhor com mais tempo, mas isso deve atender por hora.

Att,
Pablo