Commit d7186fd397af457a2ecd105ed43b42edaf8a8e83
1 parent
c2496183
Exists in
master
and in
2 other branches
Adiciona impressora
Showing
21 changed files
with
1170 additions
and
1 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,437 @@ |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace Swpb\Bundle\CocarBundle\Controller; | |
| 4 | + | |
| 5 | +use Symfony\Component\HttpFoundation\Request; | |
| 6 | +use Symfony\Component\HttpFoundation\Response; | |
| 7 | + | |
| 8 | +use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
| 9 | + | |
| 10 | +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; | |
| 11 | +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
| 12 | +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | |
| 13 | + | |
| 14 | +use Swpb\Bundle\CocarBundle\Entity\Printer; | |
| 15 | +use Swpb\Bundle\CocarBundle\Entity\PrinterCounter; | |
| 16 | +use Swpb\Bundle\CocarBundle\Form\PrinterType; | |
| 17 | + | |
| 18 | +/** | |
| 19 | + * Printer controller. | |
| 20 | + * | |
| 21 | + * @Route("/printer") | |
| 22 | + */ | |
| 23 | +class PrinterController extends Controller | |
| 24 | +{ | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * Lists all Printer entities. | |
| 28 | + * | |
| 29 | + * @Route("/", name="printer") | |
| 30 | + * @Method("GET") | |
| 31 | + * @Template() | |
| 32 | + */ | |
| 33 | + public function indexAction() | |
| 34 | + { | |
| 35 | + $em = $this->getDoctrine()->getManager(); | |
| 36 | + | |
| 37 | + $entities = $em->getRepository('CocarBundle:Printer')->findAll(); | |
| 38 | + | |
| 39 | + return array( | |
| 40 | + 'entities' => $entities, | |
| 41 | + ); | |
| 42 | + } | |
| 43 | + /** | |
| 44 | + * Creates a new Printer entity. | |
| 45 | + * | |
| 46 | + * @Route("/", name="printer_create") | |
| 47 | + * @Method("POST") | |
| 48 | + * @Template("CocarBundle:Printer:new.html.twig") | |
| 49 | + */ | |
| 50 | + public function createAction(Request $request) | |
| 51 | + { | |
| 52 | + $entity = new Printer(); | |
| 53 | + $form = $this->createCreateForm($entity); | |
| 54 | + $form->handleRequest($request); | |
| 55 | + | |
| 56 | + if ($form->isValid()) | |
| 57 | + { | |
| 58 | + $em = $this->getDoctrine()->getManager(); | |
| 59 | + $em->persist($entity); | |
| 60 | + $em->flush(); | |
| 61 | + | |
| 62 | + return $this->redirect($this->generateUrl('printer_show', array('id' => $entity->getId()))); | |
| 63 | + } | |
| 64 | + | |
| 65 | + return array( | |
| 66 | + 'entity' => $entity, | |
| 67 | + 'form' => $form->createView(), | |
| 68 | + ); | |
| 69 | + } | |
| 70 | + | |
| 71 | + /** | |
| 72 | + * Creates a form to create a Printer entity. | |
| 73 | + * | |
| 74 | + * @param Printer $entity The entity | |
| 75 | + * | |
| 76 | + * @return \Symfony\Component\Form\Form The form | |
| 77 | + */ | |
| 78 | + private function createCreateForm(Printer $entity) | |
| 79 | + { | |
| 80 | + $form = $this->createForm(new PrinterType(), $entity, array( | |
| 81 | + 'action' => $this->generateUrl('printer_create'), | |
| 82 | + 'method' => 'POST', | |
| 83 | + )); | |
| 84 | + | |
| 85 | + $form->add('submit', 'submit', array('label' => 'Create')); | |
| 86 | + | |
| 87 | + return $form; | |
| 88 | + } | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * Displays a form to create a new Printer entity. | |
| 92 | + * | |
| 93 | + * @Route("/new", name="printer_new") | |
| 94 | + * @Method("GET") | |
| 95 | + * @Template() | |
| 96 | + */ | |
| 97 | + public function newAction() | |
| 98 | + { | |
| 99 | + $entity = new Printer(); | |
| 100 | + $form = $this->createCreateForm($entity); | |
| 101 | + | |
| 102 | + return array( | |
| 103 | + 'entity' => $entity, | |
| 104 | + 'form' => $form->createView(), | |
| 105 | + ); | |
| 106 | + } | |
| 107 | + | |
| 108 | + /** | |
| 109 | + * Finds and displays a Printer entity. | |
| 110 | + * | |
| 111 | + * @Route("/{id}", name="printer_show") | |
| 112 | + * @Method("GET") | |
| 113 | + * @Template() | |
| 114 | + */ | |
| 115 | + public function showAction($id) | |
| 116 | + { | |
| 117 | + $em = $this->getDoctrine()->getManager(); | |
| 118 | + | |
| 119 | + $entity = $em->getRepository('CocarBundle:Printer')->find($id); | |
| 120 | + | |
| 121 | + if (!$entity) { | |
| 122 | + throw $this->createNotFoundException('Unable to find Printer entity.'); | |
| 123 | + } | |
| 124 | + | |
| 125 | + $deleteForm = $this->createDeleteForm($id); | |
| 126 | + | |
| 127 | + return array( | |
| 128 | + 'entity' => $entity, | |
| 129 | + 'delete_form' => $deleteForm->createView(), | |
| 130 | + ); | |
| 131 | + } | |
| 132 | + | |
| 133 | + /** | |
| 134 | + * Displays a form to edit an existing Printer entity. | |
| 135 | + * | |
| 136 | + * @Route("/{id}/edit", name="printer_edit") | |
| 137 | + * @Method("GET") | |
| 138 | + * @Template() | |
| 139 | + */ | |
| 140 | + public function editAction($id) | |
| 141 | + { | |
| 142 | + $em = $this->getDoctrine()->getManager(); | |
| 143 | + | |
| 144 | + $entity = $em->getRepository('CocarBundle:Printer')->find($id); | |
| 145 | + | |
| 146 | + if (!$entity) { | |
| 147 | + throw $this->createNotFoundException('Unable to find Printer entity.'); | |
| 148 | + } | |
| 149 | + | |
| 150 | + $editForm = $this->createEditForm($entity); | |
| 151 | + $deleteForm = $this->createDeleteForm($id); | |
| 152 | + | |
| 153 | + return array( | |
| 154 | + 'entity' => $entity, | |
| 155 | + 'edit_form' => $editForm->createView(), | |
| 156 | + 'delete_form' => $deleteForm->createView(), | |
| 157 | + ); | |
| 158 | + } | |
| 159 | + | |
| 160 | + /** | |
| 161 | + * Creates a form to edit a Printer entity. | |
| 162 | + * | |
| 163 | + * @param Printer $entity The entity | |
| 164 | + * | |
| 165 | + * @return \Symfony\Component\Form\Form The form | |
| 166 | + */ | |
| 167 | + private function createEditForm(Printer $entity) | |
| 168 | + { | |
| 169 | + $form = $this->createForm(new PrinterType(), $entity, array( | |
| 170 | + 'action' => $this->generateUrl('printer_update', array('id' => $entity->getId())), | |
| 171 | + 'method' => 'PUT', | |
| 172 | + )); | |
| 173 | + | |
| 174 | + $form->add('submit', 'submit', array('label' => 'Update')); | |
| 175 | + | |
| 176 | + return $form; | |
| 177 | + } | |
| 178 | + /** | |
| 179 | + * Edits an existing Printer entity. | |
| 180 | + * | |
| 181 | + * @Route("/{id}", name="printer_update") | |
| 182 | + * @Method("PUT") | |
| 183 | + * @Template("CocarBundle:Printer:edit.html.twig") | |
| 184 | + */ | |
| 185 | + public function updateAction(Request $request, $id) | |
| 186 | + { | |
| 187 | + $em = $this->getDoctrine()->getManager(); | |
| 188 | + | |
| 189 | + $entity = $em->getRepository('CocarBundle:Printer')->find($id); | |
| 190 | + | |
| 191 | + if (!$entity) { | |
| 192 | + throw $this->createNotFoundException('Unable to find Printer entity.'); | |
| 193 | + } | |
| 194 | + | |
| 195 | + $deleteForm = $this->createDeleteForm($id); | |
| 196 | + $editForm = $this->createEditForm($entity); | |
| 197 | + $editForm->handleRequest($request); | |
| 198 | + | |
| 199 | + if ($editForm->isValid()) { | |
| 200 | + $em->flush(); | |
| 201 | + | |
| 202 | + return $this->redirect($this->generateUrl('printer_edit', array('id' => $id))); | |
| 203 | + } | |
| 204 | + | |
| 205 | + return array( | |
| 206 | + 'entity' => $entity, | |
| 207 | + 'edit_form' => $editForm->createView(), | |
| 208 | + 'delete_form' => $deleteForm->createView(), | |
| 209 | + ); | |
| 210 | + } | |
| 211 | + /** | |
| 212 | + * Deletes a Printer entity. | |
| 213 | + * | |
| 214 | + * @Route("/{id}", name="printer_delete") | |
| 215 | + * @Method("DELETE") | |
| 216 | + */ | |
| 217 | + public function deleteAction(Request $request, $id) | |
| 218 | + { | |
| 219 | + $form = $this->createDeleteForm($id); | |
| 220 | + $form->handleRequest($request); | |
| 221 | + | |
| 222 | + if ($form->isValid()) { | |
| 223 | + $em = $this->getDoctrine()->getManager(); | |
| 224 | + $entity = $em->getRepository('CocarBundle:Printer')->find($id); | |
| 225 | + | |
| 226 | + if (!$entity) { | |
| 227 | + throw $this->createNotFoundException('Unable to find Printer entity.'); | |
| 228 | + } | |
| 229 | + | |
| 230 | + $em->remove($entity); | |
| 231 | + $em->flush(); | |
| 232 | + } | |
| 233 | + | |
| 234 | + return $this->redirect($this->generateUrl('printer')); | |
| 235 | + } | |
| 236 | + | |
| 237 | + /** | |
| 238 | + * Creates a form to delete a Printer entity by id. | |
| 239 | + * | |
| 240 | + * @param mixed $id The entity id | |
| 241 | + * | |
| 242 | + * @return \Symfony\Component\Form\Form The form | |
| 243 | + */ | |
| 244 | + private function createDeleteForm($id) | |
| 245 | + { | |
| 246 | + return $this->createFormBuilder() | |
| 247 | + ->setAction($this->generateUrl('printer_delete', array('id' => $id))) | |
| 248 | + ->setMethod('DELETE') | |
| 249 | + ->getForm() | |
| 250 | + ; | |
| 251 | + } | |
| 252 | + | |
| 253 | + /** | |
| 254 | + * @Route("/reports/{id}", name="cocar_printer_reports") | |
| 255 | + * @Template() | |
| 256 | + */ | |
| 257 | + public function reportsAction($id, Request $request) | |
| 258 | + { | |
| 259 | + $em = $this->getDoctrine()->getManager(); | |
| 260 | + | |
| 261 | + if($request->request->get('form')) | |
| 262 | + { | |
| 263 | + $start = new \DateTime($request->request->get('form')['startDate']); | |
| 264 | + $start = $start->format('U'); | |
| 265 | + | |
| 266 | + $end = new \DateTime($request->request->get('form')['endDate']); | |
| 267 | + $end = $end->format('U'); | |
| 268 | + } | |
| 269 | + | |
| 270 | + $start = isset($start) ? $start : (time() - ((60*60*24)*30)); | |
| 271 | + $end = isset($end) ? $end : time(); | |
| 272 | + | |
| 273 | + $printerCounter = $em->createQuery( | |
| 274 | + "SELECT pc.id, pc.prints, pc.blackInk, pc.coloredInk FROM CocarBundle:PrinterCounter pc | |
| 275 | + WHERE (pc.date >= :start AND pc.date <= :end) AND (pc.printer = :id) | |
| 276 | + ORDER BY pc.id ASC" | |
| 277 | + ) | |
| 278 | + ->setParameter('start', $start) | |
| 279 | + ->setParameter('end', $end) | |
| 280 | + ->setParameter('id', $id) | |
| 281 | + ->getResult(); | |
| 282 | + | |
| 283 | + $pCounter = array(); | |
| 284 | + | |
| 285 | + foreach ($printerCounter as $counter) | |
| 286 | + { | |
| 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 | + } | |
| 298 | + } | |
| 299 | + | |
| 300 | + $printer = $em->getRepository('CocarBundle:Printer')->find($id); | |
| 301 | + | |
| 302 | + | |
| 303 | + return array( | |
| 304 | + "printer" => $printer, | |
| 305 | + "printerCounter" => $pCounter, | |
| 306 | + "form" => $this->createCalendarForm($id, new \DateTime(date("Y-m-d", $start)), new \DateTime(date("Y-m-d", $end)))->createView(), | |
| 307 | + "start" => $start, | |
| 308 | + "end" => $end | |
| 309 | + ); | |
| 310 | + } | |
| 311 | + | |
| 312 | + /** | |
| 313 | + * Creates a form to reports | |
| 314 | + * | |
| 315 | + * @param mixed $id The entity id | |
| 316 | + * | |
| 317 | + * @return \Symfony\Component\Form\Form The form | |
| 318 | + */ | |
| 319 | + private function createCalendarForm($id, $start, $end) | |
| 320 | + { | |
| 321 | + return $this->createFormBuilder() | |
| 322 | + ->add('startDate', 'date', array('widget' => 'single_text', 'data' => $start)) | |
| 323 | + ->add('endDate', 'date', array('widget' => 'single_text', 'data' => $end)) | |
| 324 | + ->add('printer', 'hidden', array( | |
| 325 | + 'data' => $id | |
| 326 | + )) | |
| 327 | + ->getForm(); | |
| 328 | + } | |
| 329 | + | |
| 330 | + /** | |
| 331 | + * @Route("/totalizer/info", name="cocar_totalizer_info") | |
| 332 | + * @Template() | |
| 333 | + */ | |
| 334 | + public function totalizerAction() | |
| 335 | + { | |
| 336 | + $em = $this->getDoctrine()->getManager(); | |
| 337 | + | |
| 338 | + $printers = $em->getRepository('CocarBundle:Printer')->findAll(); | |
| 339 | + | |
| 340 | + foreach($printers as $printer) | |
| 341 | + { | |
| 342 | + try | |
| 343 | + { | |
| 344 | + $community = $printer->getCommunitySnmpPrinter(); | |
| 345 | + $host = $printer->getHost(); | |
| 346 | + | |
| 347 | + $com = "snmpwalk -O qv -v 1 -c $community $host 1.3.6.1.2.1.43.10.2.1.4.1.1"; | |
| 348 | + | |
| 349 | + if($outPut = shell_exec($com)) | |
| 350 | + { | |
| 351 | + $this->updateCounter($printer, $outPut); | |
| 352 | + $this->createOrUpdateGraph($printer, $outPut); | |
| 353 | + } | |
| 354 | + } | |
| 355 | + catch(Exception $e) | |
| 356 | + { | |
| 357 | + return new Response($e->getMessage()); | |
| 358 | + } | |
| 359 | + } | |
| 360 | + return new Response(); | |
| 361 | + } | |
| 362 | + | |
| 363 | + /** | |
| 364 | + * Update table by id | |
| 365 | + */ | |
| 366 | + private function updateCounter($printer, $prints) | |
| 367 | + { | |
| 368 | + try | |
| 369 | + { | |
| 370 | + $em = $this->getDoctrine()->getManager(); | |
| 371 | + | |
| 372 | + $counter = new PrinterCounter; | |
| 373 | + | |
| 374 | + $counter->setPrinter($printer); | |
| 375 | + $counter->setPrints($prints); | |
| 376 | + $counter->setDate(time()); | |
| 377 | + | |
| 378 | + $em->persist($counter); | |
| 379 | + $em->flush(); | |
| 380 | + } | |
| 381 | + catch(\Exception $e) | |
| 382 | + { | |
| 383 | + return false; | |
| 384 | + } | |
| 385 | + return true; | |
| 386 | + } | |
| 387 | + | |
| 388 | + /** | |
| 389 | + * Update graphic counter by id | |
| 390 | + */ | |
| 391 | + private function createOrUpdateGraph($printer, $prints) | |
| 392 | + { | |
| 393 | + try | |
| 394 | + { | |
| 395 | + $this->dir = $this->get('kernel')->getRootDir() . "/../web/rrd/graficos/"; | |
| 396 | + | |
| 397 | + $arqRrd = $this->dir . "printer_" . $printer->getId() . '.rrd'; | |
| 398 | + | |
| 399 | + if (!file_exists($arqRrd)) | |
| 400 | + $this->createRrd($arqRrd); | |
| 401 | + $this->updateRrd($arqRrd, $prints); | |
| 402 | + | |
| 403 | + } | |
| 404 | + catch(\Exception $e) | |
| 405 | + { | |
| 406 | + return false; | |
| 407 | + } | |
| 408 | + return true; | |
| 409 | + } | |
| 410 | + | |
| 411 | + public function createRrd($arqRrd) | |
| 412 | + { | |
| 413 | + $create = "rrdtool create $arqRrd --step 60 " . | |
| 414 | + "DS:ds0:COUNTER:120:0:125000000 " . | |
| 415 | + "DS:ds1:COUNTER:120:0:125000000 " . | |
| 416 | + "RRA:AVERAGE:0.5:1:4320 " . | |
| 417 | + "RRA:AVERAGE:0.5:5:2016 " . | |
| 418 | + "RRA:AVERAGE:0.5:20:2232 " . | |
| 419 | + "RRA:AVERAGE:0.5:90:2976 " . | |
| 420 | + "RRA:AVERAGE:0.5:360:1460 " . | |
| 421 | + "RRA:AVERAGE:0.5:1440:730 " . | |
| 422 | + "RRA:MAX:0.5:1:4320 " . | |
| 423 | + "RRA:MAX:0.5:5:2016 " . | |
| 424 | + "RRA:MAX:0.5:20:2232 " . | |
| 425 | + "RRA:MAX:0.5:90:2976 " . | |
| 426 | + "RRA:MAX:0.5:360:1460 " . | |
| 427 | + "RRA:MAX:0.5:1440:730"; | |
| 428 | + echo $create;die; | |
| 429 | + shell_exec($create); | |
| 430 | + } | |
| 431 | + | |
| 432 | + public function updateRrd($arqRrd, $prints, $date = null) | |
| 433 | + { | |
| 434 | + $date = empty($date) ? date('U') : $date; | |
| 435 | + shell_exec("rrdtool update $arqRrd $date:$prints:0"); | |
| 436 | + } | |
| 437 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,200 @@ |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace Swpb\Bundle\CocarBundle\Entity; | |
| 4 | + | |
| 5 | +use Doctrine\ORM\Mapping as ORM; | |
| 6 | +use Doctrine\Common\Collections\ArrayCollection; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * Printer | |
| 10 | + * | |
| 11 | + * @ORM\Table("tb_printer") | |
| 12 | + * @ORM\Entity(repositoryClass="Swpb\Bundle\CocarBundle\Entity\PrinterRepository") | |
| 13 | + */ | |
| 14 | +class Printer | |
| 15 | +{ | |
| 16 | + /** | |
| 17 | + * @var integer | |
| 18 | + * | |
| 19 | + * @ORM\Column(name="id", type="integer") | |
| 20 | + * @ORM\Id | |
| 21 | + * @ORM\GeneratedValue(strategy="AUTO") | |
| 22 | + */ | |
| 23 | + private $id; | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * @ORM\OneToMany(targetEntity="PrinterCounter", mappedBy="printer") | |
| 27 | + */ | |
| 28 | + protected $printerCounter; | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * @var string | |
| 32 | + * | |
| 33 | + * @ORM\Column(name="name", type="string", length=255) | |
| 34 | + */ | |
| 35 | + private $name; | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * @var string | |
| 39 | + * | |
| 40 | + * @ORM\Column(name="description", type="text") | |
| 41 | + */ | |
| 42 | + private $description; | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * @var string | |
| 46 | + * | |
| 47 | + * @ORM\Column(name="communitySnmpPrinter", type="string", length=255) | |
| 48 | + */ | |
| 49 | + private $communitySnmpPrinter; | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * @var string | |
| 53 | + * | |
| 54 | + * @ORM\Column(name="host", type="string", length=255) | |
| 55 | + */ | |
| 56 | + private $host; | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * Construct | |
| 60 | + */ | |
| 61 | + public function __construct() | |
| 62 | + { | |
| 63 | + $this->printerCounter = new ArrayCollection(); | |
| 64 | + } | |
| 65 | + | |
| 66 | + /** | |
| 67 | + * Get id | |
| 68 | + * | |
| 69 | + * @return integer | |
| 70 | + */ | |
| 71 | + public function getId() | |
| 72 | + { | |
| 73 | + return $this->id; | |
| 74 | + } | |
| 75 | + | |
| 76 | + /** | |
| 77 | + * Set name | |
| 78 | + * | |
| 79 | + * @param string $name | |
| 80 | + * @return Printer | |
| 81 | + */ | |
| 82 | + public function setName($name) | |
| 83 | + { | |
| 84 | + $this->name = $name; | |
| 85 | + | |
| 86 | + return $this; | |
| 87 | + } | |
| 88 | + | |
| 89 | + /** | |
| 90 | + * Get name | |
| 91 | + * | |
| 92 | + * @return string | |
| 93 | + */ | |
| 94 | + public function getName() | |
| 95 | + { | |
| 96 | + return $this->name; | |
| 97 | + } | |
| 98 | + | |
| 99 | + /** | |
| 100 | + * Set description | |
| 101 | + * | |
| 102 | + * @param string $description | |
| 103 | + * @return Printer | |
| 104 | + */ | |
| 105 | + public function setDescription($description) | |
| 106 | + { | |
| 107 | + $this->description = $description; | |
| 108 | + | |
| 109 | + return $this; | |
| 110 | + } | |
| 111 | + | |
| 112 | + /** | |
| 113 | + * Get description | |
| 114 | + * | |
| 115 | + * @return string | |
| 116 | + */ | |
| 117 | + public function getDescription() | |
| 118 | + { | |
| 119 | + return $this->description; | |
| 120 | + } | |
| 121 | + | |
| 122 | + /** | |
| 123 | + * Set communitySnmpPrinter | |
| 124 | + * | |
| 125 | + * @param string $communitySnmpPrinter | |
| 126 | + * @return Printer | |
| 127 | + */ | |
| 128 | + public function setCommunitySnmpPrinter($communitySnmpPrinter) | |
| 129 | + { | |
| 130 | + $this->communitySnmpPrinter = $communitySnmpPrinter; | |
| 131 | + | |
| 132 | + return $this; | |
| 133 | + } | |
| 134 | + | |
| 135 | + /** | |
| 136 | + * Get communitySnmpPrinter | |
| 137 | + * | |
| 138 | + * @return string | |
| 139 | + */ | |
| 140 | + public function getCommunitySnmpPrinter() | |
| 141 | + { | |
| 142 | + return $this->communitySnmpPrinter; | |
| 143 | + } | |
| 144 | + | |
| 145 | + /** | |
| 146 | + * Set host | |
| 147 | + * | |
| 148 | + * @param string $host | |
| 149 | + * @return Printer | |
| 150 | + */ | |
| 151 | + public function setHost($host) | |
| 152 | + { | |
| 153 | + $this->host = $host; | |
| 154 | + | |
| 155 | + return $this; | |
| 156 | + } | |
| 157 | + | |
| 158 | + /** | |
| 159 | + * Get host | |
| 160 | + * | |
| 161 | + * @return string | |
| 162 | + */ | |
| 163 | + public function getHost() | |
| 164 | + { | |
| 165 | + return $this->host; | |
| 166 | + } | |
| 167 | + | |
| 168 | + /** | |
| 169 | + * Add printerCounter | |
| 170 | + * | |
| 171 | + * @param \Cocar\CocarBundle\Entity\PrinterCounter $printerCounter | |
| 172 | + * @return Entity | |
| 173 | + */ | |
| 174 | + public function addPrinterCounter(\Swpb\Bundle\CocarBundle\Entity\PrinterCounter $printerCounter) | |
| 175 | + { | |
| 176 | + $this->printerCounter[] = $printerCounter; | |
| 177 | + | |
| 178 | + return $this; | |
| 179 | + } | |
| 180 | + | |
| 181 | + /** | |
| 182 | + * Remove printerCounter | |
| 183 | + * | |
| 184 | + * @param \Cocar\CocarBundle\Entity\PrinterCounter $printerCounter | |
| 185 | + */ | |
| 186 | + public function removePrinterCounter(\Swpb\Bundle\CocarBundle\Entity\PrinterCounter $printerCounter) | |
| 187 | + { | |
| 188 | + $this->printerCounter->removeElement($printerCounter); | |
| 189 | + } | |
| 190 | + | |
| 191 | + /** | |
| 192 | + * Get printerCounter | |
| 193 | + * | |
| 194 | + * @return \Doctrine\Common\Collections\Collection | |
| 195 | + */ | |
| 196 | + public function getPrinterCounter() | |
| 197 | + { | |
| 198 | + return $this->printerCounter; | |
| 199 | + } | |
| 200 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,189 @@ |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace Swpb\Bundle\CocarBundle\Entity; | |
| 4 | + | |
| 5 | +use Doctrine\ORM\Mapping as ORM; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * PrinterCounter | |
| 9 | + * | |
| 10 | + * @ORM\Table("tb_printer_counter") | |
| 11 | + * @ORM\Entity(repositoryClass="Swpb\Bundle\CocarBundle\Entity\PrinterCounterRepository") | |
| 12 | + */ | |
| 13 | +class PrinterCounter | |
| 14 | +{ | |
| 15 | + /** | |
| 16 | + * @var integer | |
| 17 | + * | |
| 18 | + * @ORM\Column(name="id", type="integer") | |
| 19 | + * @ORM\Id | |
| 20 | + * @ORM\GeneratedValue(strategy="AUTO") | |
| 21 | + */ | |
| 22 | + private $id; | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * @ORM\ManyToOne(targetEntity="Printer", inversedBy="printerCounter") | |
| 26 | + * @ORM\JoinColumn(name="printer_id", referencedColumnName="id") | |
| 27 | + */ | |
| 28 | + protected $printer; | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * @var integer | |
| 32 | + * | |
| 33 | + * @ORM\Column(name="blackInk", type="integer") | |
| 34 | + */ | |
| 35 | + private $blackInk; | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * @var integer | |
| 39 | + * | |
| 40 | + * @ORM\Column(name="coloredInk", type="integer") | |
| 41 | + */ | |
| 42 | + private $coloredInk; | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * @var integer | |
| 46 | + * | |
| 47 | + * @ORM\Column(name="prints", type="integer") | |
| 48 | + */ | |
| 49 | + private $prints; | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * @var integer | |
| 53 | + * | |
| 54 | + * @ORM\Column(name="date", type="integer") | |
| 55 | + */ | |
| 56 | + private $date; | |
| 57 | + | |
| 58 | + public function __construct() | |
| 59 | + { | |
| 60 | + $this->printer = 0; | |
| 61 | + $this->coloredInk = 0; | |
| 62 | + $this->blackInk = 0; | |
| 63 | + } | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * Get id | |
| 67 | + * | |
| 68 | + * @return integer | |
| 69 | + */ | |
| 70 | + public function getId() | |
| 71 | + { | |
| 72 | + return $this->id; | |
| 73 | + } | |
| 74 | + | |
| 75 | + /** | |
| 76 | + * Set blackInk | |
| 77 | + * | |
| 78 | + * @param integer $blackInk | |
| 79 | + * @return PrinterCounter | |
| 80 | + */ | |
| 81 | + public function setBlackInk($blackInk) | |
| 82 | + { | |
| 83 | + $this->blackInk = $blackInk; | |
| 84 | + | |
| 85 | + return $this; | |
| 86 | + } | |
| 87 | + | |
| 88 | + /** | |
| 89 | + * Get blackInk | |
| 90 | + * | |
| 91 | + * @return integer | |
| 92 | + */ | |
| 93 | + public function getBlackInk() | |
| 94 | + { | |
| 95 | + return $this->blackInk; | |
| 96 | + } | |
| 97 | + | |
| 98 | + /** | |
| 99 | + * Set coloredInk | |
| 100 | + * | |
| 101 | + * @param integer $coloredInk | |
| 102 | + * @return PrinterCounter | |
| 103 | + */ | |
| 104 | + public function setColoredInk($coloredInk) | |
| 105 | + { | |
| 106 | + $this->coloredInk = $coloredInk; | |
| 107 | + | |
| 108 | + return $this; | |
| 109 | + } | |
| 110 | + | |
| 111 | + /** | |
| 112 | + * Get coloredInk | |
| 113 | + * | |
| 114 | + * @return integer | |
| 115 | + */ | |
| 116 | + public function getColoredInk() | |
| 117 | + { | |
| 118 | + return $this->coloredInk; | |
| 119 | + } | |
| 120 | + | |
| 121 | + /** | |
| 122 | + * Set prints | |
| 123 | + * | |
| 124 | + * @param integer $prints | |
| 125 | + * @return PrinterCounter | |
| 126 | + */ | |
| 127 | + public function setPrints($prints) | |
| 128 | + { | |
| 129 | + $this->prints = $prints; | |
| 130 | + | |
| 131 | + return $this; | |
| 132 | + } | |
| 133 | + | |
| 134 | + /** | |
| 135 | + * Get prints | |
| 136 | + * | |
| 137 | + * @return integer | |
| 138 | + */ | |
| 139 | + public function getPrints() | |
| 140 | + { | |
| 141 | + return $this->prints; | |
| 142 | + } | |
| 143 | + | |
| 144 | + /** | |
| 145 | + * Set date | |
| 146 | + * | |
| 147 | + * @param integer $date | |
| 148 | + * @return PrinterCounter | |
| 149 | + */ | |
| 150 | + public function setDate($date) | |
| 151 | + { | |
| 152 | + $this->date = $date; | |
| 153 | + | |
| 154 | + return $this; | |
| 155 | + } | |
| 156 | + | |
| 157 | + /** | |
| 158 | + * Get date | |
| 159 | + * | |
| 160 | + * @return integer | |
| 161 | + */ | |
| 162 | + public function getDate() | |
| 163 | + { | |
| 164 | + return $this->date; | |
| 165 | + } | |
| 166 | + | |
| 167 | + /** | |
| 168 | + * Set printer | |
| 169 | + * | |
| 170 | + * @param \Cocar\CocarBundle\Entity\Printer $printer | |
| 171 | + * @return Circuits | |
| 172 | + */ | |
| 173 | + public function setPrinter(\Swpb\Bundle\CocarBundle\Entity\Printer $printer = null) | |
| 174 | + { | |
| 175 | + $this->printer = $printer; | |
| 176 | + | |
| 177 | + return $this; | |
| 178 | + } | |
| 179 | + | |
| 180 | + /** | |
| 181 | + * Get printer | |
| 182 | + * | |
| 183 | + * @return \Cocar\CocarBundle\Entity\Printer | |
| 184 | + */ | |
| 185 | + public function getPrinter() | |
| 186 | + { | |
| 187 | + return $this->printer; | |
| 188 | + } | |
| 189 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace Swpb\Bundle\CocarBundle\Entity; | |
| 4 | + | |
| 5 | +use Doctrine\ORM\EntityRepository; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * PrinterCounterRepository | |
| 9 | + * | |
| 10 | + * This class was generated by the Doctrine ORM. Add your own custom | |
| 11 | + * repository methods below. | |
| 12 | + */ | |
| 13 | +class PrinterCounterRepository extends EntityRepository | |
| 14 | +{ | |
| 15 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace Swpb\Bundle\CocarBundle\Entity; | |
| 4 | + | |
| 5 | +use Doctrine\ORM\EntityRepository; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * PrinterRepository | |
| 9 | + * | |
| 10 | + * This class was generated by the Doctrine ORM. Add your own custom | |
| 11 | + * repository methods below. | |
| 12 | + */ | |
| 13 | +class PrinterRepository extends EntityRepository | |
| 14 | +{ | |
| 15 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,42 @@ |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace Swpb\Bundle\CocarBundle\Form; | |
| 4 | + | |
| 5 | +use Symfony\Component\Form\AbstractType; | |
| 6 | +use Symfony\Component\Form\FormBuilderInterface; | |
| 7 | +use Symfony\Component\OptionsResolver\OptionsResolverInterface; | |
| 8 | + | |
| 9 | +class PrinterType extends AbstractType | |
| 10 | +{ | |
| 11 | + /** | |
| 12 | + * @param FormBuilderInterface $builder | |
| 13 | + * @param array $options | |
| 14 | + */ | |
| 15 | + public function buildForm(FormBuilderInterface $builder, array $options) | |
| 16 | + { | |
| 17 | + $builder | |
| 18 | + ->add('name') | |
| 19 | + ->add('description') | |
| 20 | + ->add('communitySnmpPrinter') | |
| 21 | + ->add('host') | |
| 22 | + ; | |
| 23 | + } | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * @param OptionsResolverInterface $resolver | |
| 27 | + */ | |
| 28 | + public function setDefaultOptions(OptionsResolverInterface $resolver) | |
| 29 | + { | |
| 30 | + $resolver->setDefaults(array( | |
| 31 | + 'data_class' => 'Swpb\Bundle\CocarBundle\Entity\Printer' | |
| 32 | + )); | |
| 33 | + } | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * @return string | |
| 37 | + */ | |
| 38 | + public function getName() | |
| 39 | + { | |
| 40 | + return 'swpb_bundle_cocarbundle_printer'; | |
| 41 | + } | |
| 42 | +} | ... | ... |
4.62 KB
4.49 KB
1.51 KB
4.25 KB
4.68 KB
4.13 KB
4.46 KB
886 Bytes
| ... | ... | @@ -0,0 +1,47 @@ |
| 1 | +{% extends 'CocarBundle::layout.html.twig' %} | |
| 2 | + | |
| 3 | +{% block main -%} | |
| 4 | + <h2 class="general-title">{{ entity.description }}</h2> | |
| 5 | + <center> | |
| 6 | + <form action="{{ path('printer_update', { 'id': entity.id }) }}" method="post" {{ form_enctype(edit_form) }}> | |
| 7 | + <input type="hidden" name="_method" value="PUT" /> | |
| 8 | + <div class="records_list"> | |
| 9 | + {{ form_errors(edit_form) }} | |
| 10 | + {{ form_widget(edit_form._token) }} | |
| 11 | + <div class="item-form"> | |
| 12 | + <label>Nome:</label> | |
| 13 | + {{ form_widget(edit_form.name) }} | |
| 14 | + </div> | |
| 15 | + <div class="item-form"> | |
| 16 | + <label>Descrição da impressora:</label> | |
| 17 | + {{ form_widget(edit_form.description) }} | |
| 18 | + </div> | |
| 19 | + <div class="item-form"> | |
| 20 | + <label>Community da impressora:</label> | |
| 21 | + {{ form_widget(edit_form.communitySnmpPrinter) }} | |
| 22 | + </div> | |
| 23 | + <div class="item-form"> | |
| 24 | + <label>Host:</label> | |
| 25 | + {{ form_widget(edit_form.host) }} | |
| 26 | + </div> | |
| 27 | + <div class="item-form"> | |
| 28 | + <button type="submit">Editar</button> | |
| 29 | + </div> | |
| 30 | + </div> | |
| 31 | + </form> | |
| 32 | + </center> | |
| 33 | + <ul class="record_actions"> | |
| 34 | + <li> | |
| 35 | + <a href="{{ path('entity') }}"> | |
| 36 | + Voltar a lista | |
| 37 | + </a> | |
| 38 | + </li> | |
| 39 | + <li> | |
| 40 | + <form action="{{ path('printer_delete', { 'id': entity.id }) }}" method="post"> | |
| 41 | + <input type="hidden" name="_method" value="DELETE" /> | |
| 42 | + {{ form_widget(delete_form) }} | |
| 43 | + <button type="submit" class="deletar">Deletar</button> | |
| 44 | + </form> | |
| 45 | + </li> | |
| 46 | +</ul> | |
| 47 | +{% endblock %} | ... | ... |
| ... | ... | @@ -0,0 +1,50 @@ |
| 1 | +{% extends 'CocarBundle::layout.html.twig' %} | |
| 2 | + | |
| 3 | +{% block main -%} | |
| 4 | + <h2 class="general-title">Impressoras cadastradas</h2> | |
| 5 | + | |
| 6 | + <table class="records_list"> | |
| 7 | + <thead> | |
| 8 | + <tr> | |
| 9 | + <th>Id</th> | |
| 10 | + <th>Name</th> | |
| 11 | + <th>Description</th> | |
| 12 | + <th>Community</th> | |
| 13 | + <th>Host</th> | |
| 14 | + <th>Actions</th> | |
| 15 | + </tr> | |
| 16 | + </thead> | |
| 17 | + <tbody> | |
| 18 | + {% for entity in entities %} | |
| 19 | + <tr> | |
| 20 | + <td><a href="{{ path('printer_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td> | |
| 21 | + <td>{{ entity.name }}</td> | |
| 22 | + <td>{{ entity.description }}</td> | |
| 23 | + <td>{{ entity.communitySnmpPrinter }}</td> | |
| 24 | + <td>{{ entity.host }}</td> | |
| 25 | + <td> | |
| 26 | + <ul> | |
| 27 | + <li> | |
| 28 | + <a href="{{ path('cocar_printer_reports', { 'id': entity.id }) }}">Relatórios</a> | |
| 29 | + </li> | |
| 30 | + <li> | |
| 31 | + <a href="{{ path('printer_show', { 'id': entity.id }) }}">Visualizar</a> | |
| 32 | + </li> | |
| 33 | + <li> | |
| 34 | + <a href="{{ path('printer_edit', { 'id': entity.id }) }}">Editar</a> | |
| 35 | + </li> | |
| 36 | + </ul> | |
| 37 | + </td> | |
| 38 | + </tr> | |
| 39 | + {% endfor %} | |
| 40 | + </tbody> | |
| 41 | + </table> | |
| 42 | + | |
| 43 | + <ul class="button"> | |
| 44 | + <li> | |
| 45 | + <a href="{{ path('printer_new') }}"> | |
| 46 | + Cadastrar uma nova impressora | |
| 47 | + </a> | |
| 48 | + </li> | |
| 49 | + </ul> | |
| 50 | + {% endblock %} | ... | ... |
| ... | ... | @@ -0,0 +1,32 @@ |
| 1 | +{% extends 'CocarBundle::layout.html.twig' %} | |
| 2 | + | |
| 3 | +{% block main -%} | |
| 4 | + <h2 class="general-title">Cadastro de Impressoras</h2> | |
| 5 | + <center> | |
| 6 | + <form action="{{ path('printer_create') }}" method="post" {{ form_enctype(form) }}> | |
| 7 | + <div class="records_list"> | |
| 8 | + {{ form_errors(form) }} | |
| 9 | + {{ form_widget(form._token) }} | |
| 10 | + <div class="item-form"> | |
| 11 | + <label>Nome:</label> | |
| 12 | + {{ form_widget(form.name) }} | |
| 13 | + </div> | |
| 14 | + <div class="item-form"> | |
| 15 | + <label>Descrição da impressora:</label> | |
| 16 | + {{ form_widget(form.description) }} | |
| 17 | + </div> | |
| 18 | + <div class="item-form"> | |
| 19 | + <label>Community da impressora:</label> | |
| 20 | + {{ form_widget(form.communitySnmpPrinter) }} | |
| 21 | + </div> | |
| 22 | + <div class="item-form"> | |
| 23 | + <label>Host:</label> | |
| 24 | + {{ form_widget(form.host) }} | |
| 25 | + </div> | |
| 26 | + <div class="item-form"> | |
| 27 | + <button type="submit">Cadastrar</button> | |
| 28 | + </div> | |
| 29 | + </div> | |
| 30 | + </form> | |
| 31 | + </center> | |
| 32 | +{% endblock %} | ... | ... |
| ... | ... | @@ -0,0 +1,35 @@ |
| 1 | +{% extends 'CocarBundle::layout.html.twig' %} | |
| 2 | + | |
| 3 | +{% block main -%} | |
| 4 | + <h2 class="general-title">{{ printer.name }}</h2> | |
| 5 | + <h2 class="general-title">{{ start|date("d/m/Y") }} a {{ end|date("d/m/Y") }}</h2> | |
| 6 | + <center> | |
| 7 | + <ul> | |
| 8 | + <li> | |
| 9 | + <form action="{{ path('cocar_printer_reports', {id: printer.id}) }}" method="post" {{ form_enctype(form) }}> | |
| 10 | + {{ form_errors(form) }} | |
| 11 | + {{ form_widget(form.startDate) }} | |
| 12 | + {{ form_widget(form.endDate) }} | |
| 13 | + <button type="submit">Enviar</button> | |
| 14 | + </form> | |
| 15 | + </li> | |
| 16 | + </ul> | |
| 17 | + </center> | |
| 18 | + <table class="records_list"> | |
| 19 | + <thead> | |
| 20 | + <tr> | |
| 21 | + <th>Total de impressões</th> | |
| 22 | + <th>Nível de tinta Preta</th> | |
| 23 | + <th>Nível de tinta Colorida</th> | |
| 24 | + </tr> | |
| 25 | + </thead> | |
| 26 | + <tbody> | |
| 27 | + <tr> | |
| 28 | + {% for p in printerCounter %} | |
| 29 | + <td>{{ p }}</td> | |
| 30 | + {% endfor %} | |
| 31 | + </tr> | |
| 32 | + | |
| 33 | + </tbody> | |
| 34 | + </table> | |
| 35 | +{% endblock %} | ... | ... |
| ... | ... | @@ -0,0 +1,46 @@ |
| 1 | +{% extends 'CocarBundle::layout.html.twig' %} | |
| 2 | + | |
| 3 | +{% block main -%} | |
| 4 | + <h2 class="general-title">Impressora</h2> | |
| 5 | + | |
| 6 | + <table class="records_list"> | |
| 7 | + <thead> | |
| 8 | + <tr> | |
| 9 | + <th>Id</th> | |
| 10 | + <th>Name</th> | |
| 11 | + <th>Description</th> | |
| 12 | + <th>Community</th> | |
| 13 | + <th>Host</th> | |
| 14 | + </tr> | |
| 15 | + </thead> | |
| 16 | + <tbody> | |
| 17 | + <tr> | |
| 18 | + <td>{{ entity.id }}</td> | |
| 19 | + <td>{{ entity.name }}</td> | |
| 20 | + <td>{{ entity.description }}</td> | |
| 21 | + <td>{{ entity.communitySnmpPrinter }}</td> | |
| 22 | + <td>{{ entity.host }}</td> | |
| 23 | + </tr> | |
| 24 | + </tbody> | |
| 25 | + </table> | |
| 26 | + | |
| 27 | + <ul class="record_actions"> | |
| 28 | + <li> | |
| 29 | + <a href="{{ path('printer') }}"> | |
| 30 | + Lista de impressoras | |
| 31 | + </a> | |
| 32 | + </li> | |
| 33 | + <li> | |
| 34 | + <a href="{{ path('printer_edit', { 'id': entity.id }) }}"> | |
| 35 | + Editar | |
| 36 | + </a> | |
| 37 | + </li> | |
| 38 | + <li> | |
| 39 | + <form action="{{ path('printer_delete', { 'id': entity.id }) }}" method="post"> | |
| 40 | + <input type="hidden" name="_method" value="DELETE" /> | |
| 41 | + {{ form_widget(delete_form) }} | |
| 42 | + <button type="submit" class="deletar">Deletar</button> | |
| 43 | + </form> | |
| 44 | + </li> | |
| 45 | +</ul> | |
| 46 | +{% endblock %} | ... | ... |
Resources/views/layout.html.twig
| ... | ... | @@ -19,6 +19,12 @@ |
| 19 | 19 | </a> |
| 20 | 20 | </li> |
| 21 | 21 | <li> |
| 22 | + <a href="{{ path('printer') }}" onmouseover="showHideLayers('descricao','Impressoras','show')" onmouseout="showHideLayers('descricao','','hide')"> | |
| 23 | + <img border="0" src="{{asset('bundles/cocar/images/impressoras.png')}}" align="middle"> | |
| 24 | + <span>Impressoras</span> | |
| 25 | + </a> | |
| 26 | + </li> | |
| 27 | + <li> | |
| 22 | 28 | <a href="{{ path('circuits') }}" onmouseover="showHideLayers('descricao','Circuitos','show')" onmouseout="showHideLayers('descricao','','hide')"> |
| 23 | 29 | <img border="0" src="{{asset('bundles/cocar/images/circuitos.png')}}" align="middle"> |
| 24 | 30 | <span>Circuitos</span> |
| ... | ... | @@ -82,7 +88,7 @@ |
| 82 | 88 | <td align="right" class="menu"> |
| 83 | 89 | <B><font face="Verdana" color=#ffffff size="2"> | </font><B> |
| 84 | 90 | <a href="{{ path('cocar_map') }}" target="_top" onmouseover="showHideLayers('descricao','Página Inicial','show')" onmouseout="showHideLayers('descricao','','hide')"> |
| 85 | - {% image '@CocarBundle/Resources/public/images/home.gif' %} | |
| 91 | + {% image '@CocarBundle/Resources/public/images/home.png' %} | |
| 86 | 92 | <img border="0" src="{{ asset_url }}" align="middle"></a> |
| 87 | 93 | {% endimage %} |
| 88 | 94 | <B><font face="Verdana" color=#ffffff size="2"> | </font><B> | ... | ... |
| ... | ... | @@ -0,0 +1,55 @@ |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace Swpb\Bundle\CocarBundle\Tests\Controller; | |
| 4 | + | |
| 5 | +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | |
| 6 | + | |
| 7 | +class PrinterControllerTest extends WebTestCase | |
| 8 | +{ | |
| 9 | + /* | |
| 10 | + public function testCompleteScenario() | |
| 11 | + { | |
| 12 | + // Create a new client to browse the application | |
| 13 | + $client = static::createClient(); | |
| 14 | + | |
| 15 | + // Create a new entry in the database | |
| 16 | + $crawler = $client->request('GET', '/printer/'); | |
| 17 | + $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /printer/"); | |
| 18 | + $crawler = $client->click($crawler->selectLink('Create a new entry')->link()); | |
| 19 | + | |
| 20 | + // Fill in the form and submit it | |
| 21 | + $form = $crawler->selectButton('Create')->form(array( | |
| 22 | + 'swpb_bundle_cocarbundle_printertype[field_name]' => 'Test', | |
| 23 | + // ... other fields to fill | |
| 24 | + )); | |
| 25 | + | |
| 26 | + $client->submit($form); | |
| 27 | + $crawler = $client->followRedirect(); | |
| 28 | + | |
| 29 | + // Check data in the show view | |
| 30 | + $this->assertGreaterThan(0, $crawler->filter('td:contains("Test")')->count(), 'Missing element td:contains("Test")'); | |
| 31 | + | |
| 32 | + // Edit the entity | |
| 33 | + $crawler = $client->click($crawler->selectLink('Edit')->link()); | |
| 34 | + | |
| 35 | + $form = $crawler->selectButton('Edit')->form(array( | |
| 36 | + 'swpb_bundle_cocarbundle_printertype[field_name]' => 'Foo', | |
| 37 | + // ... other fields to fill | |
| 38 | + )); | |
| 39 | + | |
| 40 | + $client->submit($form); | |
| 41 | + $crawler = $client->followRedirect(); | |
| 42 | + | |
| 43 | + // Check the element contains an attribute with value equals "Foo" | |
| 44 | + $this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]'); | |
| 45 | + | |
| 46 | + // Delete the entity | |
| 47 | + $client->submit($crawler->selectButton('Delete')->form()); | |
| 48 | + $crawler = $client->followRedirect(); | |
| 49 | + | |
| 50 | + // Check the entity has been delete on the list | |
| 51 | + $this->assertNotRegExp('/Foo/', $client->getResponse()->getContent()); | |
| 52 | + } | |
| 53 | + | |
| 54 | + */ | |
| 55 | +} | ... | ... |