diff develop/models/extractapp.php @ 14:ac77748bb813

- Load regex files based on current topic. Only show the regex in this topic. To do that, it needs to lookup a table called 'topic_regex_relation' which has the relation of topic and regex filename in filesystem. - Extractapp UI with some layout modification: button, popup window, responsive (by bootstrap now). It was just for quick prototyping.
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Thu, 19 Feb 2015 11:07:27 +0100
parents cc36a20a68ab
children 1f98c92ebbfb
line wrap: on
line diff
--- a/develop/models/extractapp.php	Tue Feb 17 15:25:11 2015 +0100
+++ b/develop/models/extractapp.php	Thu Feb 19 11:07:27 2015 +0100
@@ -8,7 +8,8 @@
 		return array("Index Value 1", "Value 2", "Value 3");
 	}
     
-    protected $section_id=0, $data_path, $file_id=0, $branch_id=0, $user_id=0, $lg_text="";
+    protected $section_id = 0, $data_path, $file_id = 0, $branch_id = 0, $user_id = 0, $lg_text = "";
+    public $messages = "";
 
     private function Initialize($_urlvalues) {
         $this->SetSectionId($_urlvalues);
@@ -61,7 +62,7 @@
 
     public function GetTextFromLocal($_id){
         $this->section_id = $_id;
-        echo "DEBUG: from my local"."<br>";
+        $this->messages .= "DEBUG: from my local"."<br>";
         $this->lg_text = $this->GetSectionContent();
 
     }
@@ -157,7 +158,8 @@
         $data['topic_tag'] = $this->GetTopicTag($this->GetTopic());
         
         $data['info'] = array('file_id'=>$this->file_id, 'user_id'=>$this->user_id, 'branch_id'=>$this->branch_id, 'section_id'=>$this->section_id);
-        
+        $data['messages'] = $this->messages;
+
         return $data;
         
     }
@@ -191,12 +193,11 @@
         $response_file = $response["file"];
         $response_branch = $response["branch"];
 
-        $this->file_id = (string)$response_file["id"];  // should updated
-        echo "file_id: ".$this->file_id;
-        echo "<br>";
+        $this->file_id = (string)$response_file["id"]; 
         $this->branch_id = (string)$response_branch["id"];
-        echo "branch_id: ".$this->branch_id;
-        echo "<br>";
+
+        $this->messages .= "file_id: ".$this->file_id."<br>";
+        $this->messages .= "branch_id: ".$this->branch_id."<br>";
 
     }
     public function SaveFullTextToLGService($_postdata) {
@@ -225,7 +226,6 @@
             file_put_contents("data/parsing_files/".$_postdata['sectionId'].".txt", $require);
         } 
 
-        echo getcwd()."<br>";
         // ------
 
 
@@ -250,9 +250,9 @@
                 //"userId" => $_postdata['userId'],
                 // TODO: change userId when we can query by sectionId from LGService using search
                 "userId" => "12",
-                // "label" => $_postdata['label'],
+                "label" => $_postdata['label'],
                 // TODO: ask user for lable
-                "label" => "label for section ".$_postdata['sectionId'],
+                //"label" => "label for section ".$_postdata['sectionId'],
             ); 
             $save_url = $this->save_new_to_LGService_url;
         }   
@@ -286,7 +286,68 @@
         return $response;
 
     }
-    
+
+    // --- for regex ----
+    public function GetRegexFilenameById($topic_id) {
+        $query = sprintf("SELECT regex_filename FROM `topic_regex_relation` WHERE  topic_id=\"%s\"", $topic_id);
+        $result = mysql_query($query);
+        if (!$result) {
+            return json_encode("Failed during selecting topic_regex_relation table.");
+        }
+
+        $filenames = array();
+        while ($row = mysql_fetch_assoc($result)) {
+            array_push($filenames, $row['regex_filename']);
+        }
+
+        return $filenames;
+    }
+    public function SmartRegexLoad($topic_id) {
+
+        // Load regex file based on current topic. Only shows the regex in this topic --
+        $filenames = $this->GetRegexFilenameById($topic_id);
+        
+        // Get regex file from filesystem ----
+        $data_path = "./data/"; // get the current file path, which is getcwd(), and concatenate with "/data/"
+        $returnArray = array();
+        $files1 = scandir($data_path."regex_files");
+        foreach ( $files1 as $file ) {
+            if ( $file != "." && $file != ".." && $file != ".DS_Store") {
+                foreach ($filenames as $filename) {
+                    if ($file == $filename) {
+                        $returnArray[preg_replace("/\.txt/", "", $file)] = file_get_contents( $data_path."regex_files/".$file );
+                        break;
+                    }
+                }
+            }
+        }
+        echo json_encode($returnArray);
+        return;
+    }
+
+
+    public function SmartRegexSave($_postdata) {
+        if ($_postdata['text']){
+            /*
+            $date = date('Y_m_d_H_i_s', time());
+            if ( file_exists("regex_files/".$_POST['filename'].".txt") ) {
+                $oldFile = file_get_contents("regex_files/".$_POST['filename'].".txt");
+                file_put_contents("regex_files/".$_POST['filename']."_".$date.".txt", $oldFile);
+            }
+            */
+            $data_path = "./data/"; // get the current file path, which is getcwd(), and concatenate with "/data/"
+            
+            if (get_magic_quotes_gpc()) {
+                $require = stripslashes($_postdata['text']);
+            } else {
+                $require = $_postdata['text'];
+            }
+
+            file_put_contents( $data_path."regex_files/".$_postdata['filename'].".txt", $require);   
+        }
+    }
+
+
     // === for export table ===
     public function ExportTable($postdata) {
         // $this->Initialize($urlvalues);
@@ -413,7 +474,7 @@
     }
     
     // === for manage tag list ===
-    public function EditTaglist($urlvalues) {
+    public function EditTaglist() {
         // $this->Initialize($urlvalues);
         $result = $this->GetTaglist();
         $taglistArray = array();
@@ -565,7 +626,7 @@
     // =========================== 
 
     // === for manage wordlist ===
-    public function EditWordlist($urlvalues) {
+    public function EditWordlist() {
         $result = $this->GetWordlist();
         $wordlistArray = array();
         while ($row = mysql_fetch_assoc($result)) {
@@ -702,9 +763,6 @@
         $section_id = $this->GetSectionId();
         $section_info = $this->GetSectionInfo();
 
-        var_dump($section_id);
-        var_dump($section_info);
-
         $bookId = $section_info['bookId'];
         $startPage = $section_info['startPage'];
         $endPage = $section_info['endPage'];