/**
  * Notify the service about a test status
  *
  * @param string $event
  * @param tx_caretaker_AbstractNode $node
  * @param tx_caretaker_TestResult $result
  * @param tx_caretaKer_TestResult $lastResult
  */
 public function addNotification($event, $node, $result = NULL, $lastResult = NULL)
 {
     $indent = $this->getCliIndentation($node);
     if (is_a($node, 'tx_caretaker_TestNode')) {
         $infotext = $result->getLocallizedInfotext();
         $msg = $indent . '--+ ' . $node->getTitle() . ' [' . $node->getCaretakerNodeId() . ']';
         $msg .= str_replace(chr(10), chr(10) . $indent . '  | ', chr(10) . $infotext);
         $msg .= chr(10) . $indent . '  +-> ' . $result->getLocallizedStateInfo() . ' (' . $event . ')';
     } else {
         if ($result == NULL) {
             $msg = $indent . '--+ ' . $node->getTitle() . ' [' . $node->getCaretakerNodeId() . ']' . $infotext . ' ' . $event;
         } else {
             $msg = $indent . '  +-> ' . $result->getLocallizedStateInfo() . ' ' . $event . ' [' . $node->getCaretakerNodeId() . ']';
         }
     }
     echo $msg . chr(10);
     flush();
 }
 /**
  * Notify the service about a test status
  *
  * @param string $event Event Identifier
  * @param tx_caretaker_AbstractNode $node
  * @param tx_caretaker_TestResult $result
  * @param tx_caretaker_TestResult $lastResult
  */
 public function addNotification($event, $node, $result = NULL, $lastResult = NULL)
 {
     // stop if event is not updatedTestResult of a TestNode
     if ($event != 'updatedTestResult' || is_a($node, 'tx_caretaker_TestNode') == false) {
         return;
     }
     // Check that the result is not equal to the previous one
     if ($lastResult && $result->getState() == $lastResult->getState()) {
         return;
     }
     // collect the recipients from the node rootline
     $recipientIds = array();
     if (count($this->mail_roles) > 0) {
         $contacts = array();
         foreach ($this->mail_roles as $role) {
             $contacts = array_merge($contacts, $node->getContacts($role));
         }
     } else {
         $contacts = $node->getContacts();
     }
     foreach ($contacts as $contact) {
         $address = $contact->getAddress();
         if (!$this->recipients_addresses[$address['uid']]) {
             $this->recipients_addresses[$address['uid']] = $address;
         }
         $recipientIds[] = $address['uid'];
     }
     $recipientIds = array_unique($recipientIds);
     // store the notifications for the recipients
     foreach ($recipientIds as $recipientId) {
         if (!isset($this->recipients_messages[$recipientId])) {
             $this->recipients_messages[$recipientId] = array('messages' => array(), 'num_undefined' => 0, 'num_ok' => 0, 'num_warning' => 0, 'num_error' => 0, 'num_ack' => 0, 'num_due' => 0);
         }
         switch ($result->getState()) {
             case tx_caretaker_Constants::state_undefined:
                 $this->recipients_messages[$recipientId]['num_undefined']++;
                 break;
             case tx_caretaker_Constants::state_ok:
                 $this->recipients_messages[$recipientId]['num_ok']++;
                 break;
             case tx_caretaker_Constants::state_warning:
                 $this->recipients_messages[$recipientId]['num_warning']++;
                 break;
             case tx_caretaker_Constants::state_error:
                 $this->recipients_messages[$recipientId]['num_error']++;
                 break;
             case tx_caretaker_Constants::state_ack:
                 $this->recipients_messages[$recipientId]['num_ack']++;
                 break;
             case tx_caretaker_Constants::state_due:
                 $this->recipients_messages[$recipientId]['num_due']++;
                 break;
         }
         array_unshift($this->recipients_messages[$recipientId]['messages'], '*' . ($lastResult ? $lastResult->getLocallizedStateInfo() . '->' : '') . $result->getLocallizedStateInfo() . ' ' . $node->getInstance()->getTitle() . ':' . $node->getTitle() . '* ' . $node->getCaretakerNodeId() . chr(10) . chr(10) . $result->getLocallizedInfotext() . chr(10) . str_replace('###', $node->getCaretakerNodeId(), $this->mail_link) . chr(10));
     }
 }