diff develop/controllers/extractapp.php @ 12:e82ca7375e93

Integration with LocalGazetteerService (LGService), getting text from LGService and saving text to LGService. Adjust the control flow (controller).
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Mon, 16 Feb 2015 16:51:39 +0100
parents 3d6fba07bfbd
children cc36a20a68ab
line wrap: on
line diff
--- a/develop/controllers/extractapp.php	Wed Feb 11 12:33:59 2015 +0100
+++ b/develop/controllers/extractapp.php	Mon Feb 16 16:51:39 2015 +0100
@@ -5,35 +5,79 @@
 		$viewmodel = new ExtractappModel();
         $this->ReturnView($viewmodel->Index(), true);
 	}
+    protected $viewmodel;
+
+       
+    public function __construct($action, $urlvalues, $postdata){
+        parent::__construct($action, $urlvalues, $postdata); 
+        $this->viewmodel = new ExtractappModel();
+    }
 
     protected function TaggingText() {
-        $viewmodel = new ExtractappModel();
+        //$viewmodel = new ExtractappModel();
+        $viewmodel = $this->viewmodel;
+               
         switch ($this->postdata['func']) {
             case 'SaveFullText':
                 $viewmodel->SaveFullText($this->postdata);          
-                $this->ReturnView($viewmodel->StartTagging($this->urlvalues), false); 
+                $this->ReturnView($viewmodel->StartTagging(), false); 
                 break;   
-        
-            default:
+            case 'SaveFullTextToLGService':
+                echo "[Z] SaveFullTextToLGService! ";
+                $viewmodel->GetInfoFromPreviousPage($this->postdata);
+                $response = $viewmodel->SaveFullTextToLGService($this->postdata);
+                
+                $viewmodel->UpdateInfoByResonseFromLGService($response);    // update file_id, branch_id, user_id
+                
+                $this->ReturnView($viewmodel->StartTagging(), false); 
+                break;
+
+            case 'ContinueTagging':
+                echo "[Z] (Countinue tagging) ";
                 if ($this->postdata['topic']) {
                     $viewmodel->SetTopic($this->postdata['topic']);
                 }
+                $viewmodel->GetInfoFromPreviousPage($this->postdata);
+                $this->ReturnView($viewmodel->StartTagging(), false); 
+                break;
+            default:    // first time visit extraction interface from LGService
                 // TODO: get the _post data from Jorge's service
-                $this->ReturnView($viewmodel->StartTagging($this->urlvalues), false); 
+                echo "[Z] Welcome to Extraction Interface. ";
+
+                if ($this->postdata['fileId'] != 0) { // ($this->postdata['branchId'] != 0) {
+                    // get text from fileId, from LGService
+                    $viewmodel->GetTextFromFileId($this->postdata);
+                } else if ($this->postdata['sectionId'] != 0) {
+                    // get text from sectionId from LGService
+                    $viewmodel->GetTextFromSectionId($this->postdata); 
+                } else if (is_numeric($this->urlvalues['id'])) {
+                    // get text from local file system (for development stage only)
+                    $viewmodel->GetTextFromLocal($this->urlvalues['id']);
+
+                    // $this->ReturnView($viewmodel->StartTagging($this->urlvalues), false); 
+                } else {
+                    echo "wrong url!!";
+                    return;
+                }
+
+                $this->ReturnView($viewmodel->StartTagging(), false); 
                 break;
         }
-        // $this->ReturnView($viewmodel->StartTagging($this->urlvalues), false); 
 
+       
+        
     }
 
     protected function ExportTable() {
-        $viewmodel = new ExtractappModel();
+        //$viewmodel = new ExtractappModel();
+        $viewmodel = $this->viewmodel;
         $this->ReturnView($viewmodel->ExportTable($this->urlvalues, $this->postdata), false);
 
     }
 
     protected function EditWordlist() {
-        $viewmodel = new ExtractappModel();
+        // $viewmodel = new ExtractappModel();
+        $viewmodel = $this->viewmodel;
         switch ($this->postdata['func']) {
             case 'AddNewList':
                 $this->ReturnView($viewmodel->AddNewList($this->postdata), false);
@@ -49,7 +93,8 @@
 
 
     protected function EditTaglist() {
-        $viewmodel = new ExtractappModel();
+        //$viewmodel = new ExtractappModel();
+        $viewmodel = $this->viewmodel;
         switch ($this->postdata['func']) {
             case 'NewTagElement':
                 $this->ReturnView($viewmodel->NewTagElement($this->postdata), false);
@@ -68,13 +113,14 @@
 
  
     protected function ConfigTagsInTopic() {
-        $viewmodel = new ExtractappModel();
+        //$viewmodel = new ExtractappModel();
+        $viewmodel = $this->viewmodel;
         switch ($this->postdata['func']) {
-            case '':
+            case 'somefunc':
                 
                 break;
             default:    
-                $this->ReturnView($viewmodel->ConfigTagsInTopic($this->urlvalues,$this->postdata), false);  
+                $this->ReturnView($viewmodel->ConfigTagsInTopic($this->postdata), false);  
             break;
          } 
     }