diff controllers/extractapp.php @ 114:7d6a107c37da extractapp

refactoring, make it more condensed.
author Calvin Yeh <cyeh@mpiwg-berlin.mpg.de>
date Thu, 28 Sep 2017 14:01:59 +0200
parents e542b161d907
children
line wrap: on
line diff
--- a/controllers/extractapp.php	Thu Sep 28 13:44:57 2017 +0200
+++ b/controllers/extractapp.php	Thu Sep 28 14:01:59 2017 +0200
@@ -16,47 +16,47 @@
  * along with Extraction-interface.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-/** 
+/**
  * Extractapp class is extended from the BaseController class.
- * It sends commands to the ExtractappModel to process or update the ExtractappModel's state. 
- * It can also pass the commands or data (from ExtractappModel) to the associated view (files in views/Extractapp/), 
+ * It sends commands to the ExtractappModel to process or update the ExtractappModel's state.
+ * It can also pass the commands or data (from ExtractappModel) to the associated view (files in views/Extractapp/),
  * for example views/Extractapp/TaggingText.php , to change the view's presentation.
- * 
+ *
  * There are five actions in Extractapp: tagging text, exporting a table,
  * editing the wordlist, editing the taglist, and configurating tags in one topic.
  * Each action is one of the methods in Extractapp.
- * 
+ *
 */
 
 class Extractapp extends BaseController {
-	
+
 
     protected $viewmodel;
 
-       
+
     public function __construct($action, $urlvalues, $postdata){
-        parent::__construct($action, $urlvalues, $postdata); 
+        parent::__construct($action, $urlvalues, $postdata);
         $this->viewmodel = new ExtractappModel();
     }
 
     protected function TaggingText() {
         /**
-         * TaggingText action in Extractapp handles the taging related actions, for example, 
+         * TaggingText action in Extractapp handles the taging related actions, for example,
          * tagging itself, saving tag results, loading and saving regular expression for tagging.
          * They are handled by 'func' variable in postdata, which could come from LGService or from extraction-interface application itself.
          *
          * From LGService, the postdata contains essential information about the file/section of local gazetteers data.
          * This happens when user entering to extraction-interface the first time, or after s/he saved her/is tagging results to LGService.
          * (default one, SaveFullTextToLGService, SmartRegexLoad, SmartRegexSave case)
-         * 
+         *
          * From extraction-interface itself, it contains the information from previous page.
-         * This happens when user choosing another topic in the extraction-interface, 
+         * This happens when user choosing another topic in the extraction-interface,
          * the page need to retrieve related information from database for the topic.
          * (ContinueTagging case)
          */
 
         $viewmodel = $this->viewmodel;
-        
+
         if (isset($this->postdata['func'])) {
             $func = $this->postdata['func'];
         } else {
@@ -64,30 +64,28 @@
         }
         switch ($func) {
             case 'SaveFullText':
-                $viewmodel->SaveFullText($this->postdata);          
-                $this->ReturnView($viewmodel->StartTagging(), true); 
-                break;   
+                $viewmodel->SaveFullText($this->postdata);
+                $this->ReturnView($viewmodel->StartTagging(), true);
+                break;
             case 'SaveFullTextToLGService':
-                global $AT_LOCAL;
-                if ($AT_LOCAL) {
-                    $viewmodel->messages['info'] .= "SaveFullTextToLGService! (local test) ";
-                    $viewmodel->SetInfoFromPreviousPage($this->postdata);
-                    $response = $viewmodel->SaveFullTextToLGService($this->postdata);
+
+			    $viewmodel->messages['info'] .= "SaveFullTextToLGService! ";
+
+			    global $AT_LOCAL;
 
-                    $viewmodel->UpdateInfoResponsedFromLGService($response);    // update file_id, branch_id, user_id
-                    $viewmodel->SetTextFromFileId();     
-                    
-                } else {
+                if ($AT_LOCAL) {
+                    $viewmodel->messages['info'] .= "(local test) ";
+                }
+
+				$viewmodel->SetInfoFromPreviousPage($this->postdata);
 
-                    $viewmodel->messages['info'] .= "SaveFullTextToLGService! ";
-                    $viewmodel->SetInfoFromPreviousPage($this->postdata);
-                    $response = $viewmodel->SaveFullTextToLGService($this->postdata);
+				$response = $viewmodel->SaveFullTextToLGService($this->postdata);
+
+				$viewmodel->UpdateInfoResponsedFromLGService($response);    // update file_id, branch_id, user_id
 
-                    $viewmodel->UpdateInfoResponsedFromLGService($response);    // update file_id, branch_id, user_id
-                    
-                    $viewmodel->SetTextFromFileId();     
-                }
-                $this->ReturnView($viewmodel->StartTagging(), true); 
+				$viewmodel->SetTextFromFileId();
+
+                $this->ReturnView($viewmodel->StartTagging(), true);
                 break;
 
             case 'SmartRegexLoad':
@@ -106,43 +104,43 @@
 
             case 'ContinueTagging':
                 $viewmodel->messages['info'] .= "(Countinue tagging) ";
-                $viewmodel->SetInfoFromPreviousPage($this->postdata);  
-                
+                $viewmodel->SetInfoFromPreviousPage($this->postdata);
+
                 // when new section hasn't been saved to LGServices, no fileId and no branchId
                 if ($this->postdata['fileId'] == 0) {
-                    $viewmodel->SetTextFromSectionId();  
+                    $viewmodel->SetTextFromSectionId();
                 } else {
                     $viewmodel->SetTextFromFileId();    // get text by fileId, from LGService
                 }
-                 
+
                 $viewmodel->SetTopic($this->postdata['topic']);
-        
-                $this->ReturnView($viewmodel->StartTagging(), true); 
+
+                $this->ReturnView($viewmodel->StartTagging(), true);
                 break;
 
             case 'CreateNewTopic':
-                $result = $viewmodel->CreateNewTopic($this->postdata); 
+                $result = $viewmodel->CreateNewTopic($this->postdata);
                 if ($result == "error") {
                     $viewmodel->messages['error'] .= "Fail to create the new topic <br> ";
                 } else {
                     // then act like ContinueTagging
                     $viewmodel->messages['info'] .= "Created a new topic <br>";
-                    $viewmodel->SetInfoFromPreviousPage($result);  
+                    $viewmodel->SetInfoFromPreviousPage($result);
 
                     // when new section hasn't been saved to LGServices, no fileId and no branchId
                     if ($this->postdata['fileId'] == 0) {
-                        $viewmodel->SetTextFromSectionId(); 
+                        $viewmodel->SetTextFromSectionId();
                     } else {
                         $viewmodel->SetTextFromFileId();    // get text by fileId, from LGService
                     }
                     $viewmodel->SetTopic($result['topic']);
 
                 }
-                $this->ReturnView($viewmodel->StartTagging(), true);  
-                
+                $this->ReturnView($viewmodel->StartTagging(), true);
+
                 break;
 
-            default:    
+            default:
                 // This is where the first time user visit extraction interface from LGService
                 $viewmodel->messages['info'] .= "Welcome to Extraction Interface. ";
 
@@ -160,9 +158,9 @@
                     $viewmodel->SetInfoFromPreviousPage($this->postdata);
                     $viewmodel->SetBookMetadataBySectionId();
                     // get text by sectionId from LGService
-                    $viewmodel->SetTextFromSectionId();  
+                    $viewmodel->SetTextFromSectionId();
 
-                } else if ($this->postdata['sectionId'] != 0) { 
+                } else if ($this->postdata['sectionId'] != 0) {
                     $viewmodel->SetTextFromLocal($this->postdata['sectionId']);
                     $viewmodel->SetBookMetadataBySectionId();
 
@@ -170,20 +168,20 @@
                     // get text from local file system (for development stage only)
                     $viewmodel->SetTextFromLocal($this->urlvalues['id']);
                     $viewmodel->SetBookMetadataBySectionId();
-                    $this->ReturnView_localtest($viewmodel->StartTagging(), true); 
-                    break;                    
+                    $this->ReturnView_localtest($viewmodel->StartTagging(), true);
+                    break;
 
                 } else {
                     $viewmodel->messages['error'] .= "wrong url!!";
                     return;
                 }
 
-                $this->ReturnView($viewmodel->StartTagging(), true); 
+                $this->ReturnView($viewmodel->StartTagging(), true);
                 break;
         }
 
-       
-        
+
+
     }
 
 
@@ -196,14 +194,14 @@
 
         if (isset($this->postdata['fileId'])) {
             $viewmodel->SetInfoFromPreviousPage($this->postdata);   // fileId in postdata
-            
-            $viewmodel->SetTextFromFileId();       // this will also set section_id  
+
+            $viewmodel->SetTextFromFileId();       // this will also set section_id
             $viewmodel->SetBookMetadataBySectionId();
         }
 
         $this->ReturnView($viewmodel->ExportTable($this->postdata, true), false);
-            
-            
+
+
     }
 
     protected function ExportTable() {
@@ -220,7 +218,7 @@
         switch ($func) {
             case 'exportFromExtractionInterface':
                 $viewmodel->SetInfoFromPreviousPage($this->postdata);
-    
+
                 $this->ReturnView($viewmodel->ExportTable($this->postdata, false), true);
                 break;
 
@@ -228,8 +226,8 @@
                 // exportFromLGServicesHtmlTable
                 if (isset($this->postdata['fileId'])) {
                     $viewmodel->SetInfoFromPreviousPage($this->postdata);   // only fileId in postdata
-                    
-                    $viewmodel->SetTextFromFileId();       // this will also set section_id  
+
+                    $viewmodel->SetTextFromFileId();       // this will also set section_id
                     $viewmodel->SetBookMetadataBySectionId();
                 }
 
@@ -244,7 +242,7 @@
 
     protected function EditWordlist() {
         /**
-         * EditWordlist action returns "./views/Extractapp/EditWordlist.php" view, 
+         * EditWordlist action returns "./views/Extractapp/EditWordlist.php" view,
          * It adds or saves wordlist based on the 'func' variable in postdata.
          */
 
@@ -262,9 +260,9 @@
                 $this->ReturnView($viewmodel->SaveWordlist($this->postdata), true);
                 break;
             default:    // EditWordlist
-                $this->ReturnView($viewmodel->EditWordlist(), true);    
+                $this->ReturnView($viewmodel->EditWordlist(), true);
             break;
-         } 
+         }
     }
 
 
@@ -282,10 +280,10 @@
         }
         switch ($func) {
             case 'NewTagElement':
-                $this->ReturnView($viewmodel->NewTagElement($this->postdata), true);
+                $this->ReturnView($viewmodel->NewTagElement($this->postdata), false);
                 break;
             case 'SaveTagElement':
-                $this->ReturnView($viewmodel->SaveTagElement($this->postdata), true);
+                $this->ReturnView($viewmodel->SaveTagElement($this->postdata), false);
                 break;
             case 'DeleteTag':
                 $this->ReturnView($viewmodel->DeleteTag($this->postdata), true);
@@ -296,7 +294,7 @@
         }
     }
 
- 
+
     protected function ConfigTagsInTopic() {
         /**
          * ConfigTagsInTopic action returns "./views/Extractapp/ConfigTagsInTopic.php" view.
@@ -315,23 +313,23 @@
                 break;
             /*
             case 'CreateNewTopic':
-                $result = $viewmodel->CreateNewTopic($this->postdata); 
+                $result = $viewmodel->CreateNewTopic($this->postdata);
                 if ($result == "error") {
                     echo "Fail to create the new topic. Please contact us.";
                 } else {
-                    $this->ReturnView($viewmodel->ConfigTagsInTopic($result), true);  
+                    $this->ReturnView($viewmodel->ConfigTagsInTopic($result), true);
                 }
                 break;
             */
-            default:    
-                $this->ReturnView($viewmodel->ConfigTagsInTopic($this->postdata), true);  
+            default:
+                $this->ReturnView($viewmodel->ConfigTagsInTopic($this->postdata), true);
                 break;
-        } 
+        }
     }
 
 
-    
-	
+
+
 }