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. public function __construct()
  11. {
  12. parent::__construct('div');
  13. $this->class = 'progress';
  14. $this->id = 'bar_' . uniqid();
  15. }
  16. public function setValue($value)
  17. {
  18. $this->value = $value;
  19. }
  20. /**
  21. * Shows the widget at the screen
  22. */
  23. public function show()
  24. {
  25. $progressBar = new TElement('div');
  26. $progressBar->class = 'progress-bar';
  27. $progressBar->role = 'progressbar';
  28. $progressBar->{'arial-valuenow'} = $this->value;
  29. $progressBar->{'arial-valuemin'} = '0';
  30. $progressBar->{'arial-valuemax'} = '100';
  31. $progressBar->style='width: ' . $this->value . '%;';
  32. $progressBar->add($this->value);
  33. parent::add($progressBar);
  34. parent::show();
  35. }
  36. }
  37. ?>
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. public function __construct()
  7. {
  8. parent::__construct();
  9. $table = new TTable;
  10. $this->form = new TForm('myForm');
  11. $this->form->add($table);
  12. $entry = new TEntry('teste');
  13. $this->progressBar = new TProgressBar();
  14. $this->progressBar->setValue(0);
  15. $button = new TButton('onEntry');
  16. $button->setAction(new TAction(array($this, 'onEntry')), 'onEntry');
  17. $button->setImage('ico_apply.png');
  18. $row = $table->addRow();
  19. $row->addCell($this->progressBar);
  20. $row = $table->addRow();
  21. $row->addCell($entry);
  22. $row->addCell($button);
  23. $this->form->setFields(array($button, $entry));
  24. parent::add($this->form);
  25. }
  26. public function onEntry()
  27. {
  28. $obj = new stdClass();
  29. $obj = $this->form->getData();
  30. $this->progressBar->setValue($obj->teste);
  31. }
  32. }
  33. ?>


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

?>
</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