1: <?php
2:
3: namespace Mapbender\MonitoringBundle\EventListener;
4: use Symfony\Component\EventDispatcher\Event;
5:
6: class WmsListListener {
7:
8: protected $doctrine;
9:
10: public function __construct($doctrine) {
11: $this->doctrine = $doctrine;
12: }
13:
14:
15: public function onWmsListLoaded(Event $event){
16: $repository = $this->doctrine
17: ->getRepository('Mapbender\MonitoringBundle\Entity\MonitoringDefinition');
18: $data = array();
19: $wmsIds = array();
20: foreach($event->getWmsList() as $wms){
21: $wmsIds[] = $wms->getId();
22: $data[$wms->getId()] = "unmonitored";
23: }
24: if( count($wmsIds) < 1){
25: return;
26: }
27: $mds = $repository->findBy(array(
28: "typeId" =>$wmsIds,
29: "type" => get_class(new \Mapbender\WmsBundle\Entity\WMSService())
30: ));
31: foreach($mds as $md){
32: if($lastJob = $md->getLastMonitoringJob()){
33: if ($lastJob->getStatus() == "SUCCESS"){
34: $data[$md->getTypeId()] =
35: '<span class="monitoring success">Everything is fine</span>';
36: }else{
37: $data[$md->getTypeId()] =
38: '<span class="monitoring failure">Something is broken</span>';
39:
40: }
41: }else{
42: $data[$md->getTypeId()] = '<span class="monitoring success">No runs yet</span>';
43: }
44: }
45: $event->addColumn("status",$data);
46: }
47: }
48: