Esempio n. 1
0
 /**
  * Sets the incidents on a session instance
  *
  * @param  Sesssion  $session
  */
 protected function setIncidents(Session $session)
 {
     // No incidents by default
     $incidents = array();
     // Get incidents from XML
     $incidents_dom = $this->dom->getElementsByTagName('Incident');
     // Way to many incidents!
     if ($incidents_dom->length > 2000) {
         // Create new dummy incident
         $incident = new Incident();
         $session->setIncidents(array($incident->setMessage('Sorry, way too many incidents to show!')->setDate(clone $session->getDate())));
         return;
     }
     // Loop each incident (if any)
     /* @var $incident_xml \DOMNode */
     foreach ($incidents_dom as $incident_xml) {
         // Create new incident
         $incident = new Incident();
         // Set message
         $incident->setMessage($incident_xml->nodeValue);
         // Clone session date
         $date = clone $session->getDate();
         // Add the seconds to date, ignoring any decimals
         $date->modify(sprintf('+%d seconds', (int) $incident_xml->getAttribute('et')));
         // Set real estimated seconds
         $incident->setElapsedSeconds((double) $incident_xml->getAttribute('et'));
         // Add date to incident
         $incident->setDate($date);
         // Is incident with another vehicle
         if (strpos(strtolower($incident->getMessage()), 'with another vehicle')) {
             // Match impact
             preg_match('/reported contact \\((.*)\\) with another vehicle/i', $incident->getMessage(), $matches);
             // Worth reviewing when impact is >= 60%
             $incident->setForReview(isset($matches[1]) and (double) $matches[1] >= 0.6);
         }
         // Add incident to incidents
         $incidents[] = $incident;
     }
     // Set incidents on session
     $session->setIncidents($incidents);
 }