MTrackWeb/Wiki.php
[web.mtrack] / MTrackWeb / Wiki.php
index 2f056c0..3aadd6c 100644 (file)
@@ -36,20 +36,45 @@ class MTrackWeb_Wiki extends MTrackWeb
     function get($pi='')
     {
         // non 'json' request...
+      
         if (!isset($_REQUEST['ajax_body'])) {
             $this->title = "Browse: " . $pi;
             return;
         }
-        //DB_DataObject::debugLevel(1);
+        
         $p = DB_DataObject::Factory('Mtrack_wiki');
         $p->project_id =  $this->currentProject();
+        
+        var_dump($p->project_id);
 
         $p->path = $pi;
-        
+       
+        // we add stuff on the end..
+        if (empty($pi)) {
+            $px = DB_DataObject::Factory('Mtrack_wiki');
+            $px->project_id =  $this->currentProject();
+            $px->orderBy('path');
+            
+            $pr = DB_DataObject::factory('core_project');
+            $pr->get($px->project_id);
+            
+            $ar = $px->fetchAll('path');
+            $wikidata = "## Index of pages in Wiki - {$pr->name} \n\n";
+            foreach($ar as $pp) {
+                $wikidata .= " * [$pp](wiki:$pp)\n";
+            }
+            $p->wikidata = $wikidata;
+            $this->jdata($p->toArray());
+            
+            
+            
+            
+        }
         
         //var_dump($p);
         if (!$p->find(true)) {
-            $this->returnNotFound($pi);
+            $p->id = 0;
+            $this->jdata($p->toArray());
         }
         $this->jdata($p->toArray());
  
@@ -57,13 +82,9 @@ class MTrackWeb_Wiki extends MTrackWeb
     }
  
  
-    function returnNotFound($pi) {
-        $this->jdata(array(
-            'id' => 0,
-            'path' => $pi,
-            'wikidata' => ''
+    function returnNotFound($p) {
+        
         
-        ));
         
         
         
@@ -71,7 +92,8 @@ class MTrackWeb_Wiki extends MTrackWeb
  
     function post()
     {
-        
+        //DB_DataObject::debugLevel(1);
+  
         $au = $this->getAuthUser();
         if (!$au) {
             // autherr?
@@ -104,7 +126,7 @@ class MTrackWeb_Wiki extends MTrackWeb
         }
         
         
-        call_user_func(array($p, $o->id ? 'update' : 'insert'), $p, $o);
+        call_user_func(array($p, $o->id ? 'update' : 'insert'),  $o);
         
         $this->jok($p->toArray());