diff models/extractapp.php @ 67:3ada9334ebfc extractapp

New: check taglist is deprecated or not
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Tue, 07 Apr 2015 14:45:31 +0200
parents e71a437ae49f
children edb8a2e8ce84
line wrap: on
line diff
--- a/models/extractapp.php	Thu Apr 02 16:33:46 2015 +0200
+++ b/models/extractapp.php	Tue Apr 07 14:45:31 2015 +0200
@@ -48,9 +48,15 @@
 
     }
 
-    public function GetBookMetaData($_postdata) {
-        // TODO: get book_meta from $_postdata, depended on LGService
-        
+
+
+
+    public function GetBookMetaDataBySectionId() {
+
+        // TODO: get book_meta from $$this->get_section_metadata_by_sectionId_url ...
+        $section_meta_url = $this->get_section_metadata_by_sectionId_url.$this->section_id;
+        $section_meta = file_get_contents($section_meta_url);
+
 
         // TODO: set $this->book_meta to an array(book_id,book_name,author,year,pagenumber,dynasty)
         $book_meta = array();
@@ -140,30 +146,44 @@
 
     }
 
-    // TODO: comparison not correct
-    private function Taglist_infileUpToDate($taglistArray) {
-        // compare $this->taglist_infile is the same as $taglistArray
-        $taglist_infile = $this->taglist_infile;
-        if (count($taglist_infile) != count($taglistArray)) {
+
+
+    private function TaglistSubsetIn($list1, $list2) {    // $l1 is a subset of $l2 or not
+        // l1 and l2: array( $row['id'], $row['name'], $row['tag'], $row['color'] )
+        $cnt_list1 = count($list1);
+        $cnt_list2 = count($list2);
+
+        if ($cnt_list1 > $cnt_list2) {
             return false;
         }
-
-        foreach ($taglistArray as $row_indb) {
+        foreach ($list1 as $v1) {
             $cnt = 0;
-            foreach ($taglist_infile as $row) {
-                //$taglistArray: array( $row['id'], $row['name'], $row['tag'], $row['color'] )
-                if ($row[0] == $row_indb[0] && $row[1] == $row_indb[1] && $row[2] == $row_indb[2] && $row[3] == $row_indb[3]) {
+            foreach ($list2 as $v2) {
+                $num_field = count($v2);
+                $matched = true;
+                for ($i=0; $i < $num_field; $i++) { 
+                    if ($v1[$i] != $v2[$i]) {
+                        $matched = false;
+                        break;
+                    }
+                }
 
+                if (!$matched) {
+                    // not match with this v2
+                    $cnt += 1;
                 } else {
-                    $cnt ++;
+                    break;
                 }
+
             }
-            if ($cnt == count($row)) {
-                return false;
+            if ($cnt == $cnt_list2) {
+                return false; 
             }
         }
         return true;
+       
     }
+
     // === for tagging ===
     public function StartTagging() {
        
@@ -176,15 +196,13 @@
         //for GetTaglistByTopicID: 
         $taglistArray = $this->GetTaglistByTopicID($this->GetTopic());
         
-        $data['taglist_infile'] = $this->taglist_infile;
-        // TODO: check if taglist_infile is up-to-date
-        /*
-        if ( !$this->Taglist_infileUpToDate($taglistArray)) {
-            $data['taglist_infile'] = $this->taglist_infile;
-        } else {
-            $data['taglist_infile'] = "";
-        }
-        */
+        // $this->taglist_infile is set (1) from file or (2) from _postdata['taglistArray'] which comes from frontend that user decided
+        // $this->taglist_infile is the most up-to-date taglist decided by user. Should be written into file.
+        if( $this->TaglistSubsetIn($this->taglist_infile, $taglistArray) ) {    // TaglistSubsetIn($l1,$l2): $l1 is a subset of $l2 or not
+            $this->taglist_infile = "";
+        } 
+        $data['taglist_infile'] = $this->taglist_infile;    // if taglist_infile == "" means taglist in file is up-to-date (will use taglist in db), otherwise means the taglist in file
+
         
         // book_meta
         $data['book_meta'] = $this->book_meta;
@@ -209,8 +227,6 @@
                 'branch_id'=>$this->branch_id, 'section_id'=>$this->section_id, 'book_id'=>$this->book_id, 
                 'book_name'=>$this->book_name, 'section_name'=>$this->section_name,
                 'current_fileId'=>$this->current_fileId);
-                //'current_fileId'=>$this->file_id);
-                //'current_fileId'=>'123');
 
         $this->messages['debug'] .= "[Debug] ";
         $this->messages['debug'] .= "file_id=".$this->file_id.", section_id=".$this->section_id;
@@ -670,7 +686,7 @@
        
     }
 
-    private function _GetTag($_postdata) {
+    private function GetTag($_postdata) {
         if (get_magic_quotes_gpc()) {
             $id = stripslashes($_postdata['id']);
             $name = stripslashes($_postdata['name']);
@@ -687,7 +703,7 @@
 
     public function NewTagElement($postdata) {
         if ($postdata['id']){   
-            list($id, $name, $tag, $color) = $this->_GetTag($postdata);
+            list($id, $name, $tag, $color) = $this->GetTag($postdata);
 
             $query1 = sprintf("INSERT INTO `taglist` (`id`, `name`, `tag`, `color`, `systemName`) VALUES (%s, %s, %s, %s, %s)",
                                 $this->GetSQLValueString($id, "int"),
@@ -713,7 +729,7 @@
 
     public function SaveTagElement($postdata) {
         if ($postdata['id']){   
-            list($id, $name, $tag, $color) = $this->_GetTag($postdata);
+            list($id, $name, $tag, $color) = $this->GetTag($postdata);
             
             $query = sprintf("UPDATE taglist SET `name`=%s, `tag`=%s, `color`=%s WHERE `id`=%s",
                                 $this->GetSQLValueString($name, "text"),