public function render(Graph $graph, Query $query)
 {
     $paths = [];
     /** @var Path $path */
     foreach ($query->getPaths() as $path) {
         $results = $this->edgeRepository->getPaths($graph->getId(), $path->getStart(), $path->getEnd());
         $paths[] = ['path' => $path, 'results' => $results];
     }
     $cheapest = [];
     /** @var Path $path */
     foreach ($query->getCheapest() as $path) {
         $results = $this->edgeRepository->getPaths($graph->getId(), $path->getStart(), $path->getEnd());
         $cheapest[] = ['path' => $path, 'result' => array_shift($results)];
     }
     return $this->templateEngine->render($this->template(), ['paths' => $paths, 'cheapest' => $cheapest]);
 }
Example #2
0
 /**
  * @param Graph $g
  * @return EntityGraph
  */
 public function getGraph(Graph $g)
 {
     $graph = new EntityGraph();
     $graph->setId($g->getId());
     $graph->setName($g->getName());
     /** @var Node $n */
     foreach ($g->getNodes() as $n) {
         $node = $this->castNode($n);
         $graph->addNode($node);
     }
     /** @var Edge $e */
     foreach ($g->getEdges() as $e) {
         $edge = $this->castEdge($e, $graph);
         $graph->addEdge($edge);
     }
     return $graph;
 }