From b4306c6117c05b38a498996915d545fde99c692e Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Thu, 6 Jan 2011 17:14:23 +0000 Subject: [PATCH] --- .../Controlleur/class.extranet.core.php | 17 ++- .../class.ws.conversion.session.php | 1 + inc/ws/Controlleur/class.ws.flash.php | 8 +- inc/ws/DAO/class.ws.dao.book.php | 52 -------- inc/ws/DAO/class.ws.dao.document.php | 123 ++++++++++++++++++ inc/ws/Metier/class.ws.book.php | 4 +- inc/ws/Metier/class.ws.document.php | 1 - 7 files changed, 138 insertions(+), 68 deletions(-) diff --git a/inc/extranet/Controlleur/class.extranet.core.php b/inc/extranet/Controlleur/class.extranet.core.php index 365ec2d0e..374abfa2e 100644 --- a/inc/extranet/Controlleur/class.extranet.core.php +++ b/inc/extranet/Controlleur/class.extranet.core.php @@ -314,9 +314,7 @@ class extranetCore extends cubeCore { $db->documents->localInfos('text', 0, false); $db->documents->generalInfos('text', 0, false); $db->documents->conversionInfos('text', 0, false); - $db->documents->bookmarks('text', 0, false); $db->documents->numberSections('text', 0, false); - $db->documents->links('text', 0, false); $db->documents->localHash('varchar', 64, false); // Clés $db->documents->primary('pk_documents', 'document_id'); @@ -326,12 +324,15 @@ class extranetCore extends cubeCore { $db->documents->reference('fk_documents_proprietaire', 'proprietaire', 'utilisateurs', 'utilisateur_id'); // . // Table pages des documents - $db->document_pages->document_id('integer', 0, false); - $db->document_pages->document_page('integer', 0, false); - $db->document_pages->text('text', 0, false); - $db->document_pages->links('text', 0, false); + $db->document_links->document_id('integer', 0, false); + $db->document_links->document_page('integer', 0, false); + $db->document_links->links('text', 0, false); + $db->document_links->rulers('text', 0, false); + $db->document_links->update('integer', 0, false); // Clés - $db->document_pages->primary('pk_document_pages', 'document_id', 'document_page'); + $db->document_links->primary('pk_document_links', 'document_id', 'document_page', 'update'); + $db->document_links->index('index_document_links_date', 'BTREE', 'update'); + $db->document_links->index('index_document_links_document_id', 'BTREE', 'document_id'); // . // Table Books $db->books->book_id('integer', 0, false); @@ -346,8 +347,6 @@ class extranetCore extends cubeCore { $db->books->date_status('integer', 0, false); $db->books->parametres('text', 0, false); $db->books->chapters('text', 0, false); - $db->books->links('text', 0, false); - $db->books->rulers('text', 0, false); $db->books->extras('text', 0, false); $db->books->traductions('text', 0, false); $db->books->date('integer', 0, false); diff --git a/inc/ws/Controlleur/class.ws.conversion.session.php b/inc/ws/Controlleur/class.ws.conversion.session.php index 933340ca8..2a2f2f36f 100644 --- a/inc/ws/Controlleur/class.ws.conversion.session.php +++ b/inc/ws/Controlleur/class.ws.conversion.session.php @@ -67,6 +67,7 @@ class wsConversionSession { $this->serialize(); if (!$this->reload) { $this->currentDoc->globalOperations(); + $dao->putLinksFromCSV($this->currentDoc->document_id); } if ($this->documentsPages[$doc->document_id] == 'all') { $docPages = range(1, $doc->generalInfos['pages']); diff --git a/inc/ws/Controlleur/class.ws.flash.php b/inc/ws/Controlleur/class.ws.flash.php index cdcb04590..42d01d70b 100644 --- a/inc/ws/Controlleur/class.ws.flash.php +++ b/inc/ws/Controlleur/class.ws.flash.php @@ -425,7 +425,7 @@ class wsFlash extends cubeFlashGateway { global $core; $dao = new wsDAOBook($core->con); $book = $dao->selectById($this->args['book_id']); - $this->xml->addChild('links', json_encode($book->links)); + $pages = $dao->getPagesOfBook($this->args['book_id']); $nb_pages = count($pages); $this->xml->addChild('pages', $nb_pages); @@ -434,16 +434,18 @@ class wsFlash extends cubeFlashGateway { $daoDoc = new wsDAODocument($core->con); $firstDoc = $daoDoc->selectById($pages[1]['document_id']); $size = $firstDoc->generalInfos['size']; + $daoDoc->getLinksAndRulers($this->args['book_id'], $links , $rulers); $this->xml->addChild('width', $size[0]); $this->xml->addChild('height', $size[1]); - $this->xml->addChild('rulers', json_encode($book->rulers)); + $this->xml->addChild('links', json_encode($links)); + $this->xml->addChild('rulers', json_encode($rulers)); } public function saveLinks() { global $core; - $dao = new wsDAOBook($core->con); + $dao = new wsDAODocument($core->con); $dao->setLinksAndRulers($this->args['book_id'], $this->args['links'], $this->args['rulers']); } diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index 42b6b191d..71449467d 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -16,8 +16,6 @@ class wsDAOBook extends extranetDAO { $book->date = $r->date; $book->pages = array(); $book->chapters = $r->chapters; - $book->links = $r->links; - $book->rulers = $r->rulers; $book->traductions = $r->traductions; $book->parametres = $r->parametres; $book->extras = $r->extras; @@ -285,15 +283,6 @@ class wsDAOBook extends extranetDAO { $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); } - public function setLinksAndRulers($book_id, $links, $rulers) - { - $c = $this->con->openCursor('books'); - $c->links = json_encode(json_decode($links, false)); - $c->rulers = json_encode(json_decode($rulers, false)); - $c->changedate = TIME; - $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - } - public function setExtras($book_id, $extras) { if ($extras != '') { @@ -403,47 +392,6 @@ class wsDAOBook extends extranetDAO { } } - public function getLinksFromCSV($book_id) - { - $booleans = array('video_loop', 'video_auto_start', 'video_controls', 'video_sound_on'); - $pages = $this->getPagesOfBook($book_id); - $res = array(); - foreach($pages as $page => $p) { - $csv = WS_DOCS . '/' . $p['document_id'] . '/p' . $p['document_page'] . '.csv'; - $fp = fopen($csv, 'rb'); - - while (true) { - $line = fgetcsv($fp, 512, ';', '"'); - // End of file - if (!$line) { - break; - } - // Commentaire || ligne vide - if (substr($line[0], 0, 1) == '#' || is_null($line[0])) { - continue; - } - $link = array(); - $cols = array('page' => '', 'type' => '', 'to' => '', 'left' => '', 'top' => '', 'width' => '', 'height' => '', 'target' => '_blank', 'video_loop' => true, 'video_auto_start' => true, 'video_controls' => true, 'video_sound_on' => true, 'infobulle' => '', 'numerotation' => 'physical'); - $k = 0; - foreach($cols as $col => $default) { - if (isset($line[$k])) { - if (in_array($k, $booleans)) { - $link[$col] = ($line[$k] == '1'); - } else { - $link[$col] = $line[$k]; - } - } else { - $link[$col] = $default; - } - $k++; - } - $link['page'] = $page; - $res[] = $link; - } - } - return $res; - } - public function makeTextsIndexes($book_id, &$index, &$textes) { $pages = $this->getPagesOfBook($book_id); diff --git a/inc/ws/DAO/class.ws.dao.document.php b/inc/ws/DAO/class.ws.dao.document.php index 8e476223d..dece1f35c 100644 --- a/inc/ws/DAO/class.ws.dao.document.php +++ b/inc/ws/DAO/class.ws.dao.document.php @@ -18,6 +18,129 @@ class wsDAODocument extends extranetDAO { return $document; } + public function putLinksFromCSV($document_id) + { + $document = $this->selectById($document_id); + + $booleans = array('video_loop', 'video_auto_start', 'video_controls', 'video_sound_on'); + + $c = $core->con->openCursor('document_links'); + $c->document_id = $document->document_id; + $c->rulers = json_encode(array()); + $c->links = json_encode(array()); + + for($page = 1;$page <= $document->generalInfos['pages'];$page++) { + $csv = WS_DOCS . '/' . $document->document_id . '/p' . $page . '.csv'; + $c->update = filemtime($csv); + $fp = fopen($csv, 'rb'); + $links = array(); + while (true) { + $line = fgetcsv($fp, 512, ';', '"'); + // End of file + if (!$line) { + break; + } + // Commentaire || ligne vide + if (substr($line[0], 0, 1) == '#' || is_null($line[0])) { + continue; + } + $link = array(); + $cols = array('page' => '', 'type' => '', 'to' => '', 'left' => '', 'top' => '', 'width' => '', 'height' => '', 'target' => '_blank', 'video_loop' => true, 'video_auto_start' => true, 'video_controls' => true, 'video_sound_on' => true, 'infobulle' => '', 'numerotation' => 'physical'); + $k = 0; + foreach($cols as $col => $default) { + if (isset($line[$k])) { + if (in_array($k, $booleans)) { + $link[$col] = ($line[$k] == '1'); + } else { + $link[$col] = $line[$k]; + } + } else { + $link[$col] = $default; + } + $k++; + } + $link['page'] = $page; + $links[] = $link; + } + $c->links = json_encode($links); + $c->insert(); + } + } + + public function setLinksAndRulers($book_id, $links, $rulers) + { + $daoBook = new wsDAOBook($this->con); + $pages = $daoBook->getPagesOfBook($book_id); + + $links = json_decode($links, false); + $rulers = json_decode($rulers, false); + + $t = array(); + + foreach($links as $link) { + if (!isset($t[$link->page])) { + $t[$link->page] = array('links' => array(), 'rulers' => array()); + } + $t[$link->page]['links'][] = $link; + } + foreach($rulers as $ruler) { + if (!isset($t[$ruler->page])) { + $t[$ruler->page] = array('links' => array(), 'rulers' => array()); + } + $t[$ruler->page]['rulers'][] = $ruler; + } + + $c = $this->con->openCursor('document_links'); + $c->update = TIME; + + foreach($pages as $page => $infos) { + $c->document_id = $infos['document_id']; + $c->document_page = $infos['document_page']; + if (isset($t[$page])) { + $elements = $t[$page]; + $c->links = json_encode($elements['links']); + $c->rulers = json_encode($elements['rulers']); + } else { + $c->links = json_encode(array()); + $c->rulers = json_encode(array()); + } + $c->insert(); + } + } + + public function getLinksAndRulers($book_id, &$links, &$rulers) + { + $daoBook = new wsDAOBook($this->con); + $pages = $daoBook->getPagesOfBook($book_id); + + $couples = array(); + $couples_order = array(); + foreach($pages as $p => $infos) { + $couples[$p] = '(' . $infos['document_id'] . ',' . $infos['document_page'] . ')'; + $couples_order[] = "'" . $infos['document_id'] . ',' . $infos['document_page'] . "'"; + } + + $links = array(); + $rulers = array(); + + $sql = 'SELECT *,CONCAT(document_id,\',\',document_page) AS doc_page FROM document_links WHERE (document_id,document_page) IN(' . implode(',', $couples) . ') ORDER BY `update` DESC, FIELD(doc_page,' . implode(',', $couples_order) . ') LIMIT ' . count($pages); + $r = $this->con->select($sql); + $i = 1; + while ($r->fetch()) { + $l = json_decode($r->links); + foreach($l as $link) { + $link->page = $i; + $links[] = $link; + } + $ru = json_decode($r->rulers); + foreach($ru as $ruler) { + $ruler->page = $i; + $rulers[] = $ruler; + } + $i++; + } + } + public function getNextId() { $r = $this->con->select('SELECT MAX(document_id) AS document_id FROM documents'); diff --git a/inc/ws/Metier/class.ws.book.php b/inc/ws/Metier/class.ws.book.php index 93df8706e..074a879e3 100644 --- a/inc/ws/Metier/class.ws.book.php +++ b/inc/ws/Metier/class.ws.book.php @@ -26,8 +26,6 @@ class wsBook extends cubeMetier { protected $pages; protected $chapters; - protected $links; - protected $rulers; protected $extras; protected $traductions; protected $numerotation; @@ -43,7 +41,7 @@ class wsBook extends cubeMetier { throw new Exception($msg); } - $classic = array('chapters', 'links', 'rulers', 'traductions'); + $classic = array('chapters', 'traductions'); if (in_array($varname, $classic)) { if (is_array($this->$varname) || is_object($this->$varname)) { diff --git a/inc/ws/Metier/class.ws.document.php b/inc/ws/Metier/class.ws.document.php index 0737e39c8..f30a700ce 100644 --- a/inc/ws/Metier/class.ws.document.php +++ b/inc/ws/Metier/class.ws.document.php @@ -20,7 +20,6 @@ class wsDocument extends cubeMetier { protected $conversionInfos; protected $bookmarks; protected $numberSections; - protected $links; protected $localHash; // Crop & cut protected $autocrop; -- 2.39.5