Commit 0d187465dbf3cedbc1d8c71075f78efc7f2ddabe

Authored by Eduardo Santos
1 parent 4bc36699
Exists in master and in 2 other branches 3,1, 3.1

Adiciona restrição de unicidade ao campo host da impressora

Entity/Printer.php
@@ -51,7 +51,7 @@ class Printer @@ -51,7 +51,7 @@ class Printer
51 /** 51 /**
52 * @var string 52 * @var string
53 * 53 *
54 - * @ORM\Column(name="host", type="string", length=255) 54 + * @ORM\Column(name="host", type="string", length=255, unique=true)
55 */ 55 */
56 private $host; 56 private $host;
57 57
Entity/PrinterCounterRepository.php
@@ -32,10 +32,11 @@ class PrinterCounterRepository extends EntityRepository @@ -32,10 +32,11 @@ class PrinterCounterRepository extends EntityRepository
32 printer.name, 32 printer.name,
33 printer.description, 33 printer.description,
34 printer.host 34 printer.host
35 - FROM CocarBundle:PrinterCounter pc1  
36 - INNER JOIN CocarBundle:Printer printer WITH pc1.printer = printer.id  
37 - INNER JOIN CocarBundle:PrinterCounter pc2 WITH (pc1.printer = pc2.printer AND pc2.date >= :start) 35 + FROM CocarBundle:Printer printer
  36 + LEFT JOIN CocarBundle:PrinterCounter pc1 WITH pc1.printer = printer.id
  37 + LEFT JOIN CocarBundle:PrinterCounter pc2 WITH (pc1.printer = pc2.printer AND pc2.date >= :start)
38 WHERE pc1.date <= :end 38 WHERE pc1.date <= :end
  39 + OR pc1.date IS NULL
39 GROUP BY printer.id, 40 GROUP BY printer.id,
40 pc1.blackInk, 41 pc1.blackInk,
41 pc1.coloredInk, 42 pc1.coloredInk,
@@ -69,10 +70,11 @@ class PrinterCounterRepository extends EntityRepository @@ -69,10 +70,11 @@ class PrinterCounterRepository extends EntityRepository
69 printer.name, 70 printer.name,
70 printer.host, 71 printer.host,
71 (max(pc1.prints) - min(pc2.prints)) as totalPrints 72 (max(pc1.prints) - min(pc2.prints)) as totalPrints
72 - FROM CocarBundle:PrinterCounter pc1  
73 - INNER JOIN CocarBundle:Printer printer WITH pc1.printer = printer.id  
74 - INNER JOIN CocarBundle:PrinterCounter pc2 WITH (pc1.printer = pc2.printer AND pc2.date >= :start) 73 + FROM CocarBundle:Printer printer
  74 + LEFT JOIN CocarBundle:PrinterCounter pc1 WITH pc1.printer = printer.id
  75 + LEFT JOIN CocarBundle:PrinterCounter pc2 WITH (pc1.printer = pc2.printer AND pc2.date >= :start)
75 WHERE pc1.date <= :end 76 WHERE pc1.date <= :end
  77 + OR pc1.date IS NULL
76 GROUP BY printer.id, 78 GROUP BY printer.id,
77 printer.name, 79 printer.name,
78 printer.description, 80 printer.description,
Resources/config/validation.yml 0 → 100644
@@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
  1 +Swpb\Bundle\CocarBundle\Entity\Printer:
  2 + constraints:
  3 + - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: host
0 \ No newline at end of file 4 \ No newline at end of file
Resources/views/Printer/new.html.twig
@@ -22,6 +22,8 @@ @@ -22,6 +22,8 @@
22 <div class="item-form"> 22 <div class="item-form">
23 <label>Host:</label> 23 <label>Host:</label>
24 {{ form_widget(form.host) }} 24 {{ form_widget(form.host) }}
  25 + <br>
  26 + {{ form_errors(form.host) }}
25 </div> 27 </div>
26 <div class="item-form"> 28 <div class="item-form">
27 <button type="submit">Cadastrar</button> 29 <button type="submit">Cadastrar</button>