]> _ Git - cubeextranet.git/commitdiff
(no commit message)
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Mon, 19 Mar 2012 09:12:17 +0000 (09:12 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Mon, 19 Mar 2012 09:12:17 +0000 (09:12 +0000)
inc/ws/DAO/class.ws.dao.book.php

index 7cab8b482c97604d1c2fb59d549606d78d32969e..aeec005711c027107dc7583e555a237089bd66e3 100644 (file)
@@ -35,7 +35,9 @@ class wsDAOBook extends commonDAO {
                $book->facturable = $r->facturable;\r
                $book->facturable_id = $r->facturable_id;\r
                $book->tache = $r->tache;\r
-               $book->projet = $r->projet;\r
+               if (isset($r->projet)) {\r
+                       $book->projet = $r->projet;\r
+               }\r
                $book->version = $r->version;\r
                $book->composition_update = $r->composition_update;\r
                $book->dir_references = $r->dir_references;\r
@@ -79,7 +81,7 @@ class wsDAOBook extends commonDAO {
                        return $this->cree();\r
                }\r
                $sql = 'SELECT * FROM books_vue WHERE book_id=\'' . $this->con->escape($book_id) . '\' LIMIT 1';\r
-               $r = $this->con->select('SELECT * FROM books_vue WHERE book_id=\'' . $this->con->escape($book_id) . '\' LIMIT 1');\r
+               $r = $this->con->select($sql);\r
                return $this->singleton($r);\r
        }\r
 \r
@@ -410,8 +412,18 @@ class wsDAOBook extends commonDAO {
        }\r
 \r
        public function setChapters($book_id, $json) {\r
+               $chapters = json_decode($json,TRUE);\r
+               $res = array();\r
+\r
+               foreach ($chapters as $c) {\r
+                       $c['label'] = trim($c['label']);\r
+                       $n = (string) $c['page'];\r
+                       $c['label'] = trim(preg_replace('|' . $n . '$|', '', $c['label']));\r
+                       $res[] = $c;\r
+               }\r
+\r
                $c = $this->con->openCursor('books');\r
-               $c->chapters = json_encode(json_decode($json, false));\r
+               $c->chapters = json_encode($res);\r
                $c->changedate = TIME;\r
                $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\'');\r
        }\r
@@ -648,6 +660,23 @@ class wsDAOBook extends commonDAO {
 \r
        public function makeTextsIndexes($book, $pages, &$index, &$textes) {\r
 \r
+               $dir = WS_BOOKS . '/index/' . $book->book_id;\r
+               if ($book->parametres->ignoreSearchSeparators != '') {\r
+                       $dir.='/' . sha1($book->parametres->ignoreSearchSeparators);\r
+               }\r
+               if (!file_exists($dir)) {\r
+                       mkdir($dir, 0777, true);\r
+               }\r
+\r
+               $ifilec = $dir . '/index.json';\r
+               $tfilec = $dir . '/textes.json';\r
+\r
+               if (file_exists($ifilec) && file_exists($tfilec) && (min(filemtime($ifilec), filemtime($tfilec)) >= $book->composition_update)) {\r
+                       $index = file_get_contents($ifilec);\r
+                       $textes = file_get_contents($tfilec);\r
+                       return;\r
+               }\r
+\r
                if ($book->parametres->ignoreSearchSeparators != "") {\r
                        $docs = array();\r
                        foreach ($pages as $p => $i) {\r
@@ -679,6 +708,13 @@ class wsDAOBook extends commonDAO {
                        $textes[$book_page] = $text;\r
                }\r
                ksort($index);\r
+\r
+\r
+               $textes = json_encode($textes);\r
+               $index = json_encode($index);\r
+\r
+               file_put_contents($tfilec, $textes);\r
+               file_put_contents($ifilec, $index);\r
        }\r
 \r
        protected function fillIndexWithWords(&$index, $page, $ipage) {\r
@@ -690,7 +726,11 @@ class wsDAOBook extends commonDAO {
                                continue;\r
                        }\r
                        list($woa, $worddata) = $w1;\r
-                       list($total, $wordslist) = explode("\t", $worddata, 2);\r
+                       $e = explode("\t", $worddata, 2);\r
+                       if (count($e) < 2) {\r
+                               continue;\r
+                       }\r
+                       list($total, $wordslist) = $e;\r
 \r
                        if ($woa == '') {\r
                                continue;\r
@@ -738,7 +778,7 @@ class wsDAOBook extends commonDAO {
                $packager->makePackage(false);\r
        }\r
 \r
-       public function compile3($book_id, $complete) {\r
+       public function compile3($book_id, $complete, &$book) {\r
                $res = '';\r
 \r
                $compilerDir = WS_BOOKS . '/datasCompiler/' . $book_id . '/';\r