Commit 6a90ac636e9dc66763390a488c47ded3f51ce8cb
1 parent
735d7109
Exists in
master
and in
2 other branches
Correcoes impressoras
Showing
7 changed files
with
105 additions
and
31 deletions
Show diff stats
Controller/PrinterController.php
| @@ -26,18 +26,73 @@ class PrinterController extends Controller | @@ -26,18 +26,73 @@ class PrinterController extends Controller | ||
| 26 | /** | 26 | /** |
| 27 | * Lists all Printer entities. | 27 | * Lists all Printer entities. |
| 28 | * | 28 | * |
| 29 | - * @Route("/", name="printer") | 29 | + * @Route("/", name="printer_index") |
| 30 | * @Method("GET") | 30 | * @Method("GET") |
| 31 | * @Template() | 31 | * @Template() |
| 32 | */ | 32 | */ |
| 33 | - public function indexAction() | 33 | + public function indexAction(Request $request) |
| 34 | { | 34 | { |
| 35 | $em = $this->getDoctrine()->getManager(); | 35 | $em = $this->getDoctrine()->getManager(); |
| 36 | 36 | ||
| 37 | - $entities = $em->getRepository('CocarBundle:Printer')->findAll(); | 37 | + $form = $request->query->get('form'); |
| 38 | 38 | ||
| 39 | + if($form) | ||
| 40 | + { | ||
| 41 | + $start = new \DateTime($form['startDate']); | ||
| 42 | + $start = $start->format('U'); | ||
| 43 | + | ||
| 44 | + $end = new \DateTime($form['endDate']); | ||
| 45 | + $end = $end->format('U'); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + $start = isset($start) ? $start : (time() - ((60*60*24)*30)); | ||
| 49 | + $end = isset($end) ? $end : time(); | ||
| 50 | + | ||
| 51 | + $printers = $em->getRepository('CocarBundle:Printer')->findAll(); | ||
| 52 | + | ||
| 53 | + $printerCounter = array(); | ||
| 54 | + | ||
| 55 | + foreach ($printers as $printer) | ||
| 56 | + { | ||
| 57 | + $printerCounter[$printer->getId()] = $em->createQuery( | ||
| 58 | + "SELECT pc.id, pc.prints, pc.blackInk, pc.coloredInk FROM CocarBundle:PrinterCounter pc | ||
| 59 | + WHERE (pc.date >= :start AND pc.date <= :end) AND (pc.printer = :id) | ||
| 60 | + ORDER BY pc.id ASC" | ||
| 61 | + ) | ||
| 62 | + ->setParameter('start', $start) | ||
| 63 | + ->setParameter('end', $end) | ||
| 64 | + ->setParameter('id', $printer->getId()) | ||
| 65 | + ->getResult(); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + $pCounter = array(); | ||
| 69 | + | ||
| 70 | + foreach ($printerCounter as $key => $counter) | ||
| 71 | + { | ||
| 72 | + $size = sizeof($counter)-1; | ||
| 73 | + | ||
| 74 | + if(isset($counter[$size])) | ||
| 75 | + { | ||
| 76 | + $pCounter[$key]['prints'] = $counter[$size]['prints'] - $counter[0]['prints']; | ||
| 77 | + $pCounter[$key]['blackInk'] = $counter[$size]['blackInk']; | ||
| 78 | + $pCounter[$key]['coloredInk'] = $counter[$size]['coloredInk']; | ||
| 79 | + } | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + $displayAll = ($request->query->get('all')) ? $request->query->get('all') : 0; | ||
| 83 | + | ||
| 84 | + if(!$displayAll) | ||
| 85 | + { | ||
| 86 | + $paginator = $this->get('knp_paginator'); | ||
| 87 | + $printers = $paginator->paginate($printers, $this->get('request')->query->get('page', 1), 10); | ||
| 88 | + } | ||
| 39 | return array( | 89 | return array( |
| 40 | - 'entities' => $entities, | 90 | + "printer" => $printers, |
| 91 | + "printerCounter" => $pCounter, | ||
| 92 | + "form" => $this->createCalendarForm(0, new \DateTime(date("Y-m-d", $start)), new \DateTime(date("Y-m-d", $end)))->createView(), | ||
| 93 | + "start" => $start, | ||
| 94 | + "end" => $end, | ||
| 95 | + "displayAll" => $displayAll | ||
| 41 | ); | 96 | ); |
| 42 | } | 97 | } |
| 43 | /** | 98 | /** |
| @@ -258,12 +313,14 @@ class PrinterController extends Controller | @@ -258,12 +313,14 @@ class PrinterController extends Controller | ||
| 258 | { | 313 | { |
| 259 | $em = $this->getDoctrine()->getManager(); | 314 | $em = $this->getDoctrine()->getManager(); |
| 260 | 315 | ||
| 316 | + $form = $request->request->get('form'); | ||
| 317 | + | ||
| 261 | if($request->request->get('form')) | 318 | if($request->request->get('form')) |
| 262 | { | 319 | { |
| 263 | - $start = new \DateTime($request->request->get('form')['startDate']); | 320 | + $start = new \DateTime($form['startDate']); |
| 264 | $start = $start->format('U'); | 321 | $start = $start->format('U'); |
| 265 | 322 | ||
| 266 | - $end = new \DateTime($request->request->get('form')['endDate']); | 323 | + $end = new \DateTime($form['endDate']); |
| 267 | $end = $end->format('U'); | 324 | $end = $end->format('U'); |
| 268 | } | 325 | } |
| 269 | 326 | ||
| @@ -282,24 +339,17 @@ class PrinterController extends Controller | @@ -282,24 +339,17 @@ class PrinterController extends Controller | ||
| 282 | 339 | ||
| 283 | $pCounter = array(); | 340 | $pCounter = array(); |
| 284 | 341 | ||
| 342 | + $size = sizeof($printerCounter)-1; | ||
| 343 | + | ||
| 285 | foreach ($printerCounter as $counter) | 344 | foreach ($printerCounter as $counter) |
| 286 | { | 345 | { |
| 287 | - if($counter === reset($printerCounter)) | ||
| 288 | - { | ||
| 289 | - $pCounter['prints'] = $counter['prints']; | ||
| 290 | - } | ||
| 291 | - | ||
| 292 | - if ($counter === end($printerCounter)) | ||
| 293 | - { | ||
| 294 | - $pCounter['prints'] = $counter['prints'] - $pCounter['prints']; | ||
| 295 | - $pCounter['blackInk'] = $counter['blackInk']; | ||
| 296 | - $pCounter['coloredInk'] = $counter['coloredInk']; | ||
| 297 | - } | 346 | + $pCounter['prints'] = $printerCounter[$size]['prints'] - $printerCounter[0]['prints']; |
| 347 | + $pCounter['blackInk'] = $counter['blackInk']; | ||
| 348 | + $pCounter['coloredInk'] = $counter['coloredInk']; | ||
| 298 | } | 349 | } |
| 299 | 350 | ||
| 300 | $printer = $em->getRepository('CocarBundle:Printer')->find($id); | 351 | $printer = $em->getRepository('CocarBundle:Printer')->find($id); |
| 301 | 352 | ||
| 302 | - | ||
| 303 | return array( | 353 | return array( |
| 304 | "printer" => $printer, | 354 | "printer" => $printer, |
| 305 | "printerCounter" => $pCounter, | 355 | "printerCounter" => $pCounter, |
Resources/public/css/pagination.css
| @@ -396,7 +396,7 @@ a:link, a:visited, | @@ -396,7 +396,7 @@ a:link, a:visited, | ||
| 396 | 396 | ||
| 397 | 397 | ||
| 398 | 398 | ||
| 399 | -ul.tsc_pagination { margin:4px 0; padding-left:414px; height:100%; overflow:hidden; font:12px 'Tahoma'; list-style-type:none; } | 399 | +ul.tsc_pagination { margin:4px 0; padding-left:377px; height:100%; overflow:hidden; font:12px 'Tahoma'; list-style-type:none; } |
| 400 | ul.tsc_pagination li { float:left; margin:0px; padding:0px; margin-left:5px; } | 400 | ul.tsc_pagination li { float:left; margin:0px; padding:0px; margin-left:5px; } |
| 401 | ul.tsc_pagination li:first-child { margin-left:0px; } | 401 | ul.tsc_pagination li:first-child { margin-left:0px; } |
| 402 | ul.tsc_pagination li a { color:black; display:block; text-decoration:none; padding:7px 10px 7px 10px; } | 402 | ul.tsc_pagination li a { color:black; display:block; text-decoration:none; padding:7px 10px 7px 10px; } |
Resources/views/Printer/index.html.twig
| @@ -2,25 +2,38 @@ | @@ -2,25 +2,38 @@ | ||
| 2 | 2 | ||
| 3 | {% block main -%} | 3 | {% block main -%} |
| 4 | <h2 class="general-title">Impressoras cadastradas</h2> | 4 | <h2 class="general-title">Impressoras cadastradas</h2> |
| 5 | - | 5 | + <center> |
| 6 | + <ul> | ||
| 7 | + <li> | ||
| 8 | + <form action="{{ path('printer_index') }}" method="get" {{ form_enctype(form) }}> | ||
| 9 | + {{ form_errors(form) }} | ||
| 10 | + {{ form_widget(form.startDate) }} | ||
| 11 | + {{ form_widget(form.endDate) }} | ||
| 12 | + <button type="submit">Enviar</button> | ||
| 13 | + </form> | ||
| 14 | + </li> | ||
| 15 | + </ul> | ||
| 16 | + </center> | ||
| 6 | <table class="records_list"> | 17 | <table class="records_list"> |
| 7 | <thead> | 18 | <thead> |
| 8 | <tr> | 19 | <tr> |
| 9 | <th>Id</th> | 20 | <th>Id</th> |
| 10 | - <th>Name</th> | ||
| 11 | - <th>Description</th> | ||
| 12 | - <th>Community</th> | 21 | + <th>Impressões</th> |
| 22 | + <th>Nome</th> | ||
| 13 | <th>Host</th> | 23 | <th>Host</th> |
| 14 | - <th>Actions</th> | 24 | + <th>Ações</th> |
| 15 | </tr> | 25 | </tr> |
| 16 | </thead> | 26 | </thead> |
| 17 | <tbody> | 27 | <tbody> |
| 18 | - {% for entity in entities %} | 28 | + {% for entity in printer %} |
| 19 | <tr> | 29 | <tr> |
| 20 | <td><a href="{{ path('printer_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td> | 30 | <td><a href="{{ path('printer_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td> |
| 31 | + <td> | ||
| 32 | + {% if printerCounter[entity.id] is defined %} | ||
| 33 | + {{ printerCounter[entity.id]['prints'] }} | ||
| 34 | + {% endif %} | ||
| 35 | + </td> | ||
| 21 | <td>{{ entity.name }}</td> | 36 | <td>{{ entity.name }}</td> |
| 22 | - <td>{{ entity.description }}</td> | ||
| 23 | - <td>{{ entity.communitySnmpPrinter }}</td> | ||
| 24 | <td>{{ entity.host }}</td> | 37 | <td>{{ entity.host }}</td> |
| 25 | <td> | 38 | <td> |
| 26 | <ul> | 39 | <ul> |
| @@ -39,8 +52,17 @@ | @@ -39,8 +52,17 @@ | ||
| 39 | {% endfor %} | 52 | {% endfor %} |
| 40 | </tbody> | 53 | </tbody> |
| 41 | </table> | 54 | </table> |
| 42 | - | ||
| 43 | - <ul class="button"> | 55 | + {% if displayAll == 0 %} |
| 56 | + {{ knp_pagination_render(printer, "CocarBundle::pagination.html.twig") }} | ||
| 57 | + <div style="padding-top:30px"> | ||
| 58 | + <ul class="tsc_paginationB tsc_paginationB09"> | ||
| 59 | + <li> | ||
| 60 | + <a href="{{ path('printer_index', {all: true}) }}">Visualizar todas as impressoras</a> | ||
| 61 | + </li> | ||
| 62 | + </ul> | ||
| 63 | + </div> | ||
| 64 | + {% endif %} | ||
| 65 | + <ul class="button"> | ||
| 44 | <li> | 66 | <li> |
| 45 | <a href="{{ path('printer_new') }}"> | 67 | <a href="{{ path('printer_new') }}"> |
| 46 | Cadastrar uma nova impressora | 68 | Cadastrar uma nova impressora |
Resources/views/Printer/show.html.twig
Resources/views/base.html.twig
Resources/views/layout.html.twig
| @@ -19,7 +19,7 @@ | @@ -19,7 +19,7 @@ | ||
| 19 | </a> | 19 | </a> |
| 20 | </li> | 20 | </li> |
| 21 | <li> | 21 | <li> |
| 22 | - <a href="{{ path('printer') }}" onmouseover="showHideLayers('descricao','Impressoras','show')" onmouseout="showHideLayers('descricao','','hide')"> | 22 | + <a href="{{ path('printer_index') }}" onmouseover="showHideLayers('descricao','Impressoras','show')" onmouseout="showHideLayers('descricao','','hide')"> |
| 23 | <img border="0" src="{{asset('bundles/cocar/images/impressoras.png')}}" align="middle"> | 23 | <img border="0" src="{{asset('bundles/cocar/images/impressoras.png')}}" align="middle"> |
| 24 | <span>Impressoras</span> | 24 | <span>Impressoras</span> |
| 25 | </a> | 25 | </a> |
schedules.txt
| @@ -6,3 +6,4 @@ | @@ -6,3 +6,4 @@ | ||
| 6 | 0 20 * * * php /var/www/cocar/app/console perform:task --endalarm | 6 | 0 20 * * * php /var/www/cocar/app/console perform:task --endalarm |
| 7 | 1,6,11,16,21,26,31,36,41,46,51,56 7-19 * * * php /var/www/projeto-cocar/app/console perform:task --status | 7 | 1,6,11,16,21,26,31,36,41,46,51,56 7-19 * * * php /var/www/projeto-cocar/app/console perform:task --status |
| 8 | * * * * * php /var/www/cocar/app/console perform:task --monitor | 8 | * * * * * php /var/www/cocar/app/console perform:task --monitor |
| 9 | +0 20 * * * php /var/www/cocar/app/console perform:task --printer | ||
| 9 | \ No newline at end of file | 10 | \ No newline at end of file |