Commit c1ddd566cb7785aed5c32db52613aa943f6babc6
Exists in
master
and in
2 other branches
Adiciona método para exportar as impressoras
Showing
1 changed file
with
33 additions
and
0 deletions
Show diff stats
Controller/ApiController.php
... | ... | @@ -140,4 +140,37 @@ class ApiController extends Controller { |
140 | 140 | return $response; |
141 | 141 | } |
142 | 142 | |
143 | + /** | |
144 | + * @Route("/printer", name="printer_list") | |
145 | + * @Method("GET") | |
146 | + */ | |
147 | + public function printerListAction(Request $request) { | |
148 | + $em = $this->getDoctrine()->getManager(); | |
149 | + $logger = $this->get('logger'); | |
150 | + | |
151 | + $printer = $em->getRepository('CocarBundle:Printer')->findAll(); | |
152 | + | |
153 | + $teste = array(); | |
154 | + foreach($printer as $elm) { | |
155 | + $saida = array( | |
156 | + 'network_ip' => $elm->getHost(), | |
157 | + 'community' => $elm->getCommunitySnmpPrinter() | |
158 | + ); | |
159 | + array_push($teste, $saida); | |
160 | + } | |
161 | + | |
162 | + $dados = json_encode(array( | |
163 | + 'printers'=> $teste | |
164 | + ), | |
165 | + true); | |
166 | + | |
167 | + $logger->debug("Enviando lista de impressoras \n".$dados); | |
168 | + | |
169 | + $response = new JsonResponse(); | |
170 | + $response->setStatusCode('200'); | |
171 | + $response->setContent($dados); | |
172 | + return $response; | |
173 | + | |
174 | + } | |
175 | + | |
143 | 176 | } |
144 | 177 | \ No newline at end of file | ... | ... |