diff models/extractapp.php @ 63:3395385476d1 extractapp

bug fixed: popup tag window is closed automatically when saving text file
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Wed, 01 Apr 2015 15:10:35 +0200
parents 3fb9e3884401
children f9ae94a9b041
line wrap: on
line diff
--- a/models/extractapp.php	Tue Mar 31 14:55:58 2015 +0200
+++ b/models/extractapp.php	Wed Apr 01 15:10:35 2015 +0200
@@ -9,13 +9,9 @@
 	}
     
     protected $section_id = 0, $data_path, $file_id = 0, $current_fileId=0, 
-        $branch_id = 0, $user_id = 0, $lg_text = "", $topic, $taglist_infile = "", $book_meta = "";
+        $branch_id = 0, $user_id = 0, $lg_text = "", $topic, $taglist_infile = "", $book_meta = "",$book_dynasty="";
     public $messages = array('info'=>"",'error'=>"",'warning'=>"",'debug'=>"");
 
-    private function Initialize($_urlvalues) {
-        $this->SetSectionId($_urlvalues);
-
-    }
 
     public function GetTextFromFileId() {   // remove $_postdata as input
         /*
@@ -52,6 +48,19 @@
 
     }
 
+    public function GetBookMetaData($_postdata) {
+        // TODO: get book_meta from $_postdata, depended on LGService
+        
+
+        // TODO: set $this->book_meta to an array(book_id,book_name,author,year,pagenumber,dynasty)
+        $book_meta = array();
+        array_push($book_meta, array($this->book_id,$this->book_name,"no_data","no_data","no_data","no_data"));    // missing author,year,pagenumber
+        
+        $this->book_meta = $book_meta;
+
+    }
+
+
     public function GetTextFromSectionId() {  // remove $_postdata as input
         /*
         $section_id = $_postdata['sectionId'];
@@ -68,13 +77,7 @@
         $lg_text_url = $this->get_text_from_sectionId_url.$this->section_id;
         $lg_text = file_get_contents($lg_text_url);
 
-        // TODO: get book_meta from $_postdata and set $this->book_meta: book_id,book_name,author,year,pagenumber
-        $book_meta = array();
-        array_push($book_meta, array($this->book_id,$this->book_name,"no_data","no_data","no_data"));    // missing author,year,pagenumber
         
-        $this->book_meta = $book_meta;
-
-
 
         $stringInput = $lg_text;
         $stringInput = preg_replace("/<(.*?)>/u", "○", $stringInput);
@@ -88,8 +91,7 @@
 
     public function GetTextFromLocal($_id){
         $this->section_id = $_id;
-        $this->branch_id = 1;   // local test sets branch_id to 1
-        // $this->messages .= "DEBUG: from my local"."<br>";
+        //$this->branch_id = 1;   // local test sets branch_id to 1
         $this->messages['debug'] .= "[Debug] from my local"."<br>";
         $this->lg_text = $this->GetSectionContent();
 
@@ -135,50 +137,8 @@
             $this->book_meta = json_decode($_postdata['book_meta']);
         }
 
-    }
-    public function InitData($_postdata) {
-        $file_id = $_postdata['fileId'];
-        $branch_id = $_postdata['branchId'];
-        $section_id = $_postdata['sectionId'];
-
-        $this->branch_id = $branch_id;
-        $this->file_id = $file_id;
-        $this->user_id = $_postdata['userId'];
-        $this->section_id = $section_id;
-        
-        if ($file_id != 0 && $branch_id != 0) {
-            // get from URL with file_id
-            $lg_text_url = $this->get_text_from_fileId_url.$file_id;
-        } else if ($section_id != 0) {
-            // get from URL with section_id
-            $lg_text_url = $this->get_text_from_sectionId_url.$section_id;
-        } else {
-            echo "wrong url!!";
-            return;
-        }
-       
-
-        $lg_text = file_get_contents($lg_text_url);
-
-        /*
-        $stringInput = preg_replace("/ /u", "○", $stringInput);
-        $stringInput = preg_replace("/\n/u", "<br>", $stringInput);
-        $stringInput = preg_replace("/【(.*?)】/u", "【<a href=\"review_index_xml_images.php?books_id=".$bookId."&pages=\\1&entry=0\" target=\"_bookImg\">\\1</a>】", $stringInput);
-        */
-
-        // the text is from database
-        $stringInput = $lg_text;
-        $stringInput = preg_replace("/<(.*?)>/u", "○", $stringInput);
-        $stringInput = preg_replace("/ /u", "○", $stringInput);
-        $stringInput = preg_replace("/\n/u", "<br>", $stringInput);
-        $stringInput = preg_replace("/【(.*?)】/u", "【<a href=\"review_index_xml_images.php?books_id=".$bookId."&pages=\\1&entry=0\" target=\"_bookImg\">\\1</a>】", $stringInput);
-        $lg_text = $stringInput;
-
-        $this->lg_text = $lg_text;
-        
 
     }
-  
 
     // TODO: comparison not correct
     private function Taglist_infileUpToDate($taglistArray) {
@@ -340,6 +300,7 @@
             $text .= "<author>".$b[2]."</author>\n";
             $text .= "<year>".$b[3]."</year>\n";
             $text .= "<pagenumber>".$b[4]."</pagenumber>\n";
+            $text .= "<dynasty>".$b[5]."</dynasty>\n";
             $text .= "</book>\n";
         }
         // taglist
@@ -553,33 +514,18 @@
 
     // === for export table ===
     public function ExportTable($postdata) {
-        // $this->Initialize($urlvalues);
 
         $content = $postdata['content'];
         $topic = $postdata['topic'];
         $section_id = $postdata['sectionId'];
 
         //$section_id = $this->section_id;
-        
 
-        // TODO: this should be get from LGService: sectionName, bookId, bookName
         $sectionName = $postdata['sectionName'];
         $bookId = $postdata['bookId'];
         $bookName = $postdata['bookName'];
 
-
-        // --- replace if get info from LGService
-        /*
-        $section_info = $this->GetSectionInfo();
-
-        $sectionName = $section_info['sectionName'];
-        $bookId = $section_info['bookId'];
-
-        $books_info = $this->GetBooksInfo($bookId);
-        $bookName = $books_info['bookName'];
-        */
-        // =====
-
+       // =====
 
         $outputTableArray = array();
 
@@ -644,10 +590,6 @@
             $value = preg_replace("/</u", "&lt;", $value);
             $outputTableArray[$count]["full"] = $value;
         }
-        /*
-        echo "<br>"."DEBUG: outputTableArray:"."<br>";
-        var_dump($outputTableArray);
-        */
         
         $topic_tag = $this->GetTopicTag($topic);
 
@@ -705,7 +647,6 @@
         foreach ($result as $row) {
             $taglistArray[$row[0]] = array($row[1], $row[2], $row[3]);
             //$taglistArray[$row['id']] = array($row['name'], $row['tag'], $row['color']);
-            // TODO: the format is not good, so I use $row[0], $row[1],... This could be changed some time.
         }
 
         $topic_tag_name = $this->GetTopicTag($topic_id);
@@ -1129,25 +1070,6 @@
         return strlen($b)-strlen($a);
     }
 
-    // TODO: delete this
-    private function SetSectionId($_urlvalues) {
-        // TODO: maybe get user info also
-        // get book id from url
-        if ($_urlvalues['id'] != "") {
-            $section_id = $_urlvalues['id'];
-        } else {
-            return json_encode("Error: No section id");
-            /* ???? */
-            /* 
-            $get_book_id = $urlvalues['book'];
-            $get_start = $urlvalues['start'];
-            $get_end = $urlvalues['end'];
-            */
-        }
-        $this->section_id = $section_id;
-        
-    }
-
     private function GetSectionId() {
 
         if (is_numeric($this->section_id)) {
@@ -1207,7 +1129,7 @@
         $book_meta = $xml->book;
         $book_metaArray = array();
         foreach ($book_meta as $row) {
-            array_push($book_metaArray, array((string)$row->id,(string)$row->name,(string)$row->author,(string)$row->year,(string)$row->pagenumber ));
+            array_push($book_metaArray, array((string)$row->id,(string)$row->name,(string)$row->author,(string)$row->year,(string)$row->pagenumber,(string)$row->dynasty ));
         }
         if ($book_metaArray) {
             $this->book_meta = $book_metaArray;
@@ -1243,6 +1165,9 @@
             $stringInput = preg_replace("/ /u", "○", $stringInput);
             $stringInput = preg_replace("/\n/u", "<br>", $stringInput);
             $stringInput = preg_replace("/【(.*?)】/u", "【<a href=\"review_index_xml_images.php?books_id=".$bookId."&pages=\\1&entry=0\" target=\"_bookImg\">\\1</a>】", $stringInput);
+            
+            $this->branch_id = 1;   // testing at local
+
         } else {
             $query = sprintf("SELECT `content`, `line`, `books_id` FROM `contents` WHERE `books_id`=\"%s\" AND `line`>=%d AND `line`<=%d", $bookId, $startPage, $endPage);
             $result = mysql_query($query);
@@ -1265,7 +1190,7 @@
         $book_meta = array();
         $books_result = $this->GetBooksByID($bookId);
         while ($row = mysql_fetch_assoc($books_result)) {
-            array_push($book_meta, array($row['id'],$row['name'],$row['author'],(string)$row['start_year'],(string)$row['line']));
+            array_push($book_meta, array($row['id'],$row['name'],$row['author'],(string)$row['start_year'],(string)$row['line'],(string)$row['dynasty']));
                                     // use 'start_year' as year, 'line' is pagenumber
         }