<?php\r
\r
class wsConversionSession {\r
+ protected $documentsId = array();\r
protected $documents = array();\r
protected $guid;\r
protected $progress = 0;\r
+ protected $processing = false;\r
+ protected $complete = false;\r
+ protected $totalPages = null;\r
\r
public function __construct($guid)\r
{\r
\r
public function setDocuments($documents)\r
{\r
- $this->documents = $documents;\r
+ $this->documentsId = $documents;\r
}\r
\r
- public function process()\r
+ public function initDocuments()\r
{\r
- for($i = 1;$i <= 100;$i++) {\r
- cubePHP::sleep(0.1);\r
- $i++;\r
+ global $core;\r
+\r
+ $dao = new wsDAODocument($core->con);\r
+ $this->documents = $dao->selectInList($this->documentsId);\r
+ $this->totalPages = 0;\r
+\r
+ foreach($this->documents as $doc) {\r
+ $this->totalPages += $doc->getPagesNumber;\r
}\r
}\r
\r
+ public function process()\r
+ {\r
+ $this->processing = true;\r
+ $this->initDocuments();\r
+\r
+ $this->complete = true;\r
+ $this->processing = false;\r
+ }\r
+\r
public function getProgress()\r
{\r
return $this->progress;\r
\r
public static function getCachePath($guid)\r
{\r
- return CACHE . '/conversionSessions/' . $guid;\r
+ return CACHE . '/conversionSessions/' . $guid . '.obj';\r
}\r
}\r
\r
$_SESSION['sessionConversionGUID'] = $sessionConversionGUID = uniqid('conversion_', true);\r
$session = new wsConversionSession($sessionConversionGUID);\r
$session->setDocuments($_SESSION['conversionSession']);\r
- $conversion->serialize();\r
+ $session->serialize();\r
\r
$http = new cubeHTTP($_SERVER['HTTP_HOST']);\r
- $http->setDataTimeout(3);\r
- $http->post('/flash/processConversionSessionAsync', array('user_email' => $_SESSION['user_email'], 'user_password' => $_SESSION['user_password'], 'sessionConversionGUID' => $sessionConversionGUID));\r
+ $http->setDataTimeout(1);\r
+ try {\r
+ $http->post('/flash/processConversionSessionAsync', array('user_email' => $_SESSION['user_email'], 'user_password' => $_SESSION['user_password'], 'sessionConversionGUID' => $sessionConversionGUID));\r
+ }\r
+ catch(Exception $e) {\r
+ }\r
}\r
\r
public function processConversionSessionAsync()\r
\r
public function getConversionSessionProgress()\r
{\r
+ set_time_limit(1);\r
$session = wsConversionSession::openFromGUID($_SESSION['sessionConversionGUID']);\r
$this->xml->addChild('progress', $session->getProgress());\r
}\r
<?php\r
+/**\r
+ * wsDocument\r
+ *\r
+ * @package\r
+ * @author Vincent\r
+ * @copyright Copyright (c) 2010\r
+ * @version $Id$\r
+ * @access public\r
+ */\r
class wsDocument extends cubeMetier {\r
protected $document_id;\r
protected $file;\r
protected $infos;\r
protected $textes;\r
\r
+ private $_basicInfos = null;\r
+ private $_advancedInfos = null;\r
+\r
public function copyOriginal($tmp_file)\r
{\r
$this->out = ROOT . '/docs/' . $this->document_id . '/';\r
\r
public function getInfos()\r
{\r
- $pdfinfo = new cubeCommandLine('pdfinfo', null, false);\r
- $pdfinfo->setArg('-box');\r
- $pdfinfo->setArg('f', 1);\r
- $pdfinfo->setArg('l', 10000);\r
- $pdfinfo->setArg(null, $this->in);\r
- $pdfinfo->execute();\r
- $this->addToLog($pdfinfo);\r
-\r
- $pdftk = new cubeCommandLine('pdftk', null, true);\r
- $pdftk->setArg(null, $this->in);\r
- $pdftk->setArg(null, 'dump_data');\r
- $pdftk->execute();\r
- $this->addToLog($pdftk);\r
-\r
- $this->parseInfos($pdfinfo->output . $pdftk->output);\r
-\r
- file_put_contents($this->infos, $pdfinfo->output . $pdftk->output);\r
+ $pdfinfo = $this->getBasicInfos();\r
+ $pdftk = $this->getAdvancedInfos();\r
+\r
+ $this->parseInfos($pdfinfo . $pdftk);\r
+\r
+ file_put_contents($this->infos, $pdfinfo . $pdftk);\r
+ }\r
+\r
+ public function getBasicInfos()\r
+ {\r
+ if (is_null($this->_basicInfos)) {\r
+ $pdfinfo = new cubeCommandLine('pdfinfo', null, false);\r
+ $pdfinfo->setArg('-box');\r
+ $pdfinfo->setArg('f', 1);\r
+ $pdfinfo->setArg('l', 10000);\r
+ $pdfinfo->setArg(null, $this->in);\r
+ $pdfinfo->execute();\r
+ $this->addToLog($pdfinfo);\r
+\r
+ $this->_basicInfos = $pdfinfo->output;\r
+ }\r
+ return $this->_basicInfos;\r
+ }\r
+\r
+ public function getAdvancedInfos()\r
+ {\r
+ if (is_null($this->_advancedInfos)) {\r
+ $pdftk = new cubeCommandLine('pdftk', null, true);\r
+ $pdftk->setArg(null, $this->in);\r
+ $pdftk->setArg(null, 'dump_data');\r
+ $pdftk->execute();\r
+ $this->addToLog($pdftk);\r
+ $this->_advancedInfos = $pdftk->output;\r
+ }\r
+ return $this->_advancedInfos;\r
}\r
\r
public function parseInfos($data)\r
return $res;\r
}\r
\r
+ public function getPagesNumber()\r
+ {\r
+ $this->parseInfos($this->getBasicInfos());\r
+ return $this->generalInfos['pages'];\r
+ }\r
+\r
public function getTexts()\r
{\r
$pdftotext = new cubeCommandLine('pdftotext', null, true);\r