/**
  * @param tx_caretaker_AbstractNode $node
  * @param int $depth
  * @return array
  */
 protected function nodeToArray($node, $depth = 1)
 {
     // show node and icon
     $result = array();
     $uid = $node->getUid();
     $title = $node->getTitle();
     $hidden = $node->getHidden();
     $id = $node->getCaretakerNodeId();
     $testResult = $node->getTestResult();
     $resultClass = 'caretaker-state-' . strtolower($testResult->getStateInfo());
     $typeClass = 'caretaker-type-' . strtolower($node->getType());
     $result['type'] = strtolower($node->getType());
     $result['id'] = $id;
     $result['uid'] = $uid;
     $result['disabled'] = $hidden;
     $result['text'] = $title ? $title : '[no title]';
     $result['cls'] = $resultClass . ' ' . $typeClass;
     $result['iconCls'] = 'icon-' . $typeClass . ($hidden ? '-hidden' : '');
     if (strtolower($node->getType()) == 'instance' && $node instanceof tx_caretaker_InstanceNode) {
         $result['url'] = $node->getUrl();
     } else {
         $result['url'] = false;
     }
     // show subitems of tx_caretaker_AggregatorNodes
     if ($node instanceof tx_caretaker_AggregatorNode) {
         $children = $node->getChildren(true);
         $result['leaf'] = count($children) == 0 ? true : false;
         if ($depth > 0) {
             $result['children'] = array();
             foreach ($children as $child) {
                 $result['children'][] = $this->nodeToArray($child, $depth - 1);
             }
         }
     } else {
         $result['leaf'] = TRUE;
     }
     return $result;
 }
 /**
  * Get the ResultRange for the given Aggregator and the timerange
  *
  * @param tx_caretaker_AbstractNode $node
  * @param integer $start_timestamp
  * @param integer $stop_timestamp
  * @return tx_caretaker_AggregatorResultRange
  */
 public function getRangeByNode($node, $start_timestamp, $stop_timestamp)
 {
     $result_range = new tx_caretaker_AggregatorResultRange($start_timestamp, $stop_timestamp);
     $instance = $node->getInstance();
     if ($instance) {
         $instanceUid = $instance->getUid();
     } else {
         $instanceUid = 0;
     }
     $nodeType = $node->getType();
     $nodeUid = $node->getUid();
     $base_condition = 'aggregator_uid=' . $nodeUid . ' AND aggregator_type="' . $nodeType . '" AND instance_uid=' . $instanceUid;
     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tx_caretaker_aggregatorresult', $base_condition . ' AND tstamp >=' . $start_timestamp . ' AND tstamp <=' . $stop_timestamp, '', 'tstamp ASC');
     while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
         $result = $this->dbrow2instance($row);
         $result_range->addResult($result);
     }
     // add first value if needed
     $first = $result_range->getFirst();
     if (!$first || $first && $first->getTstamp() > $start_timestamp) {
         $GLOBALS['TYPO3_DB']->store_lastBuiltQuery = TRUE;
         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tx_caretaker_aggregatorresult', $base_condition . ' AND tstamp <' . $start_timestamp, '', 'tstamp DESC', 1);
         if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
             $row['tstamp'] = $start_timestamp;
             $result = $this->dbrow2instance($row);
             $result_range->addResult($result);
         }
     }
     // add last value if needed
     $last = $result_range->getLast();
     if ($last && $last->getTstamp() < $stop_timestamp) {
         $real_last = new tx_caretaker_AggregatorResult($stop_timestamp, $last->getState(), $last->getNumUNDEFINED(), $last->getNumOK(), $last->getNumWARNING(), $last->getNumERROR(), $last->getMessage()->getText());
         $result_range->addResult($real_last);
     }
     return $result_range;
 }
 /**
  * Get All Contacts for the given node that match the given role
  *
  * @param tx_caretaker_AbstractNode $node
  * @param tx_caretaker_ContactRole $role
  * @return array
  */
 public function getContactsByNodeAndRole(tx_caretaker_AbstractNode $node, tx_caretaker_ContactRole $role)
 {
     $contacts = array();
     // only Instancegroups and Instances store Contacts
     $nodeType = $node->getType();
     if ($nodeType != tx_caretaker_Constants::nodeType_Instance && $nodeType != tx_caretaker_Constants::nodeType_Instancegroup) {
         return $contacts;
     }
     $storageTable = $node->getStorageTable();
     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', tx_caretaker_Constants::relationTable_Node2Address, 'uid_node=' . $node->getUid() . ' AND node_table=\'' . $storageTable . '\'' . ' AND role=' . $role->getUid());
     while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
         if ($contact = $this->dbrow2contact($row)) {
             $contacts[] = $contact;
         }
     }
     return $contacts;
 }
 /**
  *
  * @param tx_caretaker_AbstractNode $node
  * @return array
  */
 function getNodeData($node)
 {
     $data = array();
     // node data
     $data['uid'] = $node->getUid();
     $data['node_id'] = $node->getCaretakerNodeId();
     $data['node_type'] = $node->getType();
     $data['type'] = $node->getTypeDescription();
     $data['configuration'] = $node->getConfigurationInfo();
     $data['title'] = $node->getTitle();
     $data['description'] = $node->getDescription();
     // add state Infos
     $result = $node->getTestResult();
     $data['state'] = $result->getState();
     $data['state_info'] = $result->getStateInfo();
     $data['state_show'] = $result->getLocallizedStateInfo();
     $data['state_msg'] = $result->getLocallizedInfotext();
     $data['state_tstamp'] = $result->getTimestamp();
     if ($result instanceof tx_caretaker_TestResult) {
         $data['state_value'] = $result->getValue();
     }
     // instance data
     if (is_a($node, 'tx_caretaker_TestNode') || is_a($node, 'tx_caretaker_TestgroupNode')) {
         $data['instance'] = $node->getInstance()->getTitle();
     }
     $data['link_parameters'] = '&tx_caretaker_pi_singleview[id]=' . $node->getCaretakerNodeId();
     return $data;
 }
 /**
  * @param tx_caretaker_AbstractNode $node
  * @param int $offset
  * @param int $limit
  * @return tx_caretaker_AggregatorResultRange
  */
 public function getResultRangeByNodeAndOffset($node, $offset = 0, $limit = 10)
 {
     $result_range = new tx_caretaker_AggregatorResultRange(NULL, NULL);
     $instance = $node->getInstance();
     if ($instance) {
         $instanceUid = $instance->getUid();
     } else {
         $instanceUid = 0;
     }
     $nodeType = $node->getType();
     $nodeUid = $node->getUid();
     $base_condition = 'aggregator_uid=' . $nodeUid . ' AND aggregator_type="' . $nodeType . '" AND instance_uid=' . $instanceUid;
     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tx_caretaker_aggregatorresult', $base_condition, '', 'tstamp DESC', (int) $offset . ',' . (int) $limit);
     while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
         $result = $this->dbrow2instance($row);
         $result_range->addResult($result);
     }
     return $result_range;
 }
 /**
  * Get the latest Testresult for the given Instance and Test
  *
  * @param tx_caretaker_AbstractNode $testNode
  * @param $currentResult
  * @return tx_caretaker_TestResult
  */
 public function getPreviousDifferingResult($testNode, $currentResult)
 {
     $row = NULL;
     if ($testNode instanceof tx_caretaker_TestNode) {
         $testUID = $testNode->getUid();
         $instanceUID = $testNode->getInstance()->getUid();
         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tx_caretaker_testresult', 'test_uid = ' . $testUID . ' AND instance_uid = ' . $instanceUID . ' AND result_status <> ' . $currentResult->getState() . ' AND tstamp < ' . $currentResult->getTimestamp(), 'tstamp DESC, uid DESC', '', '1');
         $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
     }
     if ($row) {
         $result = $this->dbrow2instance($row);
         return $result;
     } else {
         return new tx_caretaker_TestResult();
     }
 }