From 3feb0b288be437210ae10f0fbdb9fc14e6c252a8 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 5 Nov 2008 09:50:20 +0000 Subject: Add info section with MPTT graphs --- core/controllers/welcome.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'core/controllers') diff --git a/core/controllers/welcome.php b/core/controllers/welcome.php index f421ffc5..c8b76a0f 100644 --- a/core/controllers/welcome.php +++ b/core/controllers/welcome.php @@ -45,6 +45,34 @@ class Welcome_Controller extends Template_Controller { url::redirect("welcome"); } + function mptt() { + $this->auto_render = false; + $items = ORM::factory("item")->orderby("id")->find_all(); + $data = "digraph G {\n"; + foreach ($items as $item) { + $data .= " $item->parent_id -> $item->id\n"; + $data .= " $item->id [label=\"$item->id <$item->left, $item->right>\"]\n"; + } + $data .= "}\n"; + + if ($this->input->get("type") == "text") { + print "
$data";
+    } else {
+      $proc = proc_open("/usr/bin/dot -Tsvg",
+			array(array("pipe", "r"),
+			      array("pipe", "w")),
+			$pipes,
+			VARPATH . "tmp");
+      fwrite($pipes[0], $data);
+      fclose($pipes[0]);
+
+      header("Content-Type: image/svg+xml");
+      print(stream_get_contents($pipes[1]));
+      fclose($pipes[1]);
+      proc_close($proc);
+    }
+  }
+
   function add($count) {
     srand(time());
     $parents = ORM::factory("item")->where("type", "album")->find_all()->as_array();
-- 
cgit v1.2.3