You are here

function hansel_export_dot in Hansel breadcrumbs 8

Same name and namespace in other branches
  1. 7 export/hansel_export.module \hansel_export_dot()

Generete an export to dot format for the current configuration.

2 calls to hansel_export_dot()
hansel_export_dot_form in export/hansel_export.module
Form providing the export to dot format.
hansel_export_dot_form_submit in export/hansel_export.module
Form submit handler. Provides the dot export as a download.

File

export/hansel_export.module, line 261

Code

function hansel_export_dot() {
  $rules = array();
  $pids = array(
    0,
  );
  while (count($pids)) {
    $pid = array_shift($pids);
    $new_rules = _hansel_get_rules($pid);
    foreach ($new_rules as $rule) {
      $rid = $rule->rid;
      if (!isset($rules[$rid])) {
        $rules[$rid] = $rule;
        $pids[] = $rid;
      }
    }
  }

  // It is a directed graph
  $result = 'digraph {';

  // Generate dot-nodes
  foreach ($rules as $rule) {
    $result .= _hansel_export_dot_node($rule);
  }

  // Generate links
  foreach ($rules as $rule) {

    // A link from parent rule to rule
    if (isset($rule->pid) && $rule->pid != 0) {
      $result .= _hansel_dot_link($rule->pid, $rule->rid, 'p', 'black');
    }

    // A goto introduces an extra link from rule to destination
    if ($rule->action == 'goto') {
      $result .= _hansel_dot_link($rule->rid, $rule->destination, $rule->action, 'red');
    }
  }
  $result .= "\n}";
  return $result;
}