diff models/extractapp.php @ 81:f1f849d31272 extractapp

book_id as string
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Thu, 23 Apr 2015 14:58:27 +0200
parents e6e213b26454
children 23b6bd897777
line wrap: on
line diff
--- a/models/extractapp.php	Tue Apr 21 16:41:36 2015 +0200
+++ b/models/extractapp.php	Thu Apr 23 14:58:27 2015 +0200
@@ -1,7 +1,27 @@
 <?php
+/*
+ * extractapp.php
+ * This file is part of Extraction-interface.
+ *
+ * Extraction-interface is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Extraction-interface is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Extraction-interface.  If not, see <http://www.gnu.org/licenses/>.
+*/
 /** 
-    * ExtractappModel is extended from the BaseModel.
-    * This is where we implement the functions/models that related to extraction-interface.
+ * ExtractappModel class is extended from the BaseModel class.
+ * This is where we implement the functions/models to prepare data that been sent to views.
+ * ExtractappModel is notified by Extractapp controller when there has been a change in its state,
+ * and produces the output/data to the corresponding view in "views/Extractapp/". 
+ * 
 */
 
 class ExtractappModel extends BaseModel{
@@ -11,7 +31,13 @@
     public $messages = array('info'=>"",'error'=>"",'warning'=>"",'debug'=>"");
 
 
-    public function GetTextFromFileId() {   // remove $_postdata as input
+    public function SetTextFromFileId() {   // remove $_postdata as input
+        /**
+         * Get text content from LGService by $this->file_id. 
+         * After preprocessing the text string (replace space to circle symbol, link for page number, etc),
+         * set $this->lg_text to the processed text gotten from LGService.
+         */
+
         /*
         $this->file_id = $_postdata['fileId'];
         $branch_id = $_postdata['branchId'];
@@ -59,7 +85,13 @@
 
     }
 
-    public function GetTextFromSectionId() {  // remove $_postdata as input
+    public function SetTextFromSectionId() {  // remove $_postdata as input
+        /**
+         * Get text content from LGService by $this->section_id. 
+         * After preprocessing the text string (replace space to circle symbol, link for page number, etc),
+         * set $this->lg_text to the processed text gotten from LGService.
+         */
+
         /*
         $section_id = $_postdata['sectionId'];
         $this->section_id = $section_id;
@@ -87,7 +119,7 @@
     }
 
     // This is only used on localhost
-    public function GetTextFromLocal($_id){     
+    public function SetTextFromLocal($_id){     
         $this->section_id = $_id;
         //$this->branch_id = 1;   // local test sets branch_id to 1
         $this->messages['debug'] .= "[Debug] from my local"."<br>";
@@ -95,7 +127,16 @@
     }
 
 
-    public function GetInfoFromPreviousPage($_postdata) {
+    public function SetInfoFromPreviousPage($_postdata) {
+        /**
+         * Get information from post data passsed by the previous page, and set variables in $this.
+         * The previous page could be: 
+         *
+         * (1) LGService: the first time user enters Extraction-interface, which should linked from LGService. 
+         *
+         * (2) Extraction-interface itself: changing topic then continue to tag, saving text to LGService, reload the text from LGService.
+         * 
+         */
 
         if (isset($_postdata['fileId'])) {
             $this->file_id = $_postdata['fileId'];
@@ -122,7 +163,15 @@
             $this->book_name = $_postdata['bookName'];
         }
         if (isset($_postdata['bookId'])) {
-            $this->book_id = $_postdata['bookId'];
+            $book_id = $_postdata['bookId'];
+            if ($book_id < 10000) {
+                $book_id = '0'.(string)$book_id;
+            } else if ($book_id < 1000) {
+                $book_id = '00'.(string)$book_id;
+            }
+
+            $this->book_id = (string)$book_id;
+            
         }
         if (isset($_postdata['currentFileId'])) {
             $this->current_fileId = $_postdata['currentFileId'];
@@ -175,6 +224,10 @@
 
     // === for tagging ===
     public function StartTagging() {
+        /**
+         * This is the main method for tagging text. It passes all the information to "views/Extractapp/TaggingText.php" view.
+         * The information contain the text string, taglist array, wordlis array, topic, etc.
+         */
        
         $section_id = $this->section_id;
         $stringInput = $this->lg_text;
@@ -237,6 +290,7 @@
     }
 
     public function SaveFullText($postdata) {
+        // locally
         if ($postdata['text']){
             $date = date('Y_m_d_H_i_s', time());
             if ( file_exists("data/parsing_files/".$postdata['filename'].".txt") ) {
@@ -261,7 +315,11 @@
     }
 
     public function UpdateInfoResponsedFromLGService($response) {
-        
+        /**
+         *
+         */
+
+
         if (isset($response["file"])) {
             $response_file = $response["file"];
         }
@@ -351,7 +409,11 @@
     }
 
     public function SaveFullTextToLGService($_postdata) {
-        // save tagged text (full text) by Jorge's API to lg service
+        /**
+         * It saves the full tagged text string in postdata to LGService.
+         * The responses returned by LGService will later be handled in 
+         */
+
         // --------
         global $AT_LOCAL;
 
@@ -1227,7 +1289,7 @@
 
 
     private function GetSectionContent() {  
-        /** This is only been called by GetTextFromLocal().
+        /** This is only been called by SetTextFromLocal().
         */
 
         $section_id = $this->GetSectionId();