|
@@ -2,20 +2,20 @@
|
|
|
|
|
|
* Wrap an OpenDocument spreadsheet cell
|
|
|
*
|
|
|
- * Requires PHP 5.2
|
|
|
+ * Requires PHP 5.3
|
|
|
*
|
|
|
- * @version $Id: Calc_Cell.php,v 1.3 2007-09-09 19:50:22 marand Exp $
|
|
|
* @license CeCILL 2.0
|
|
|
- * @copyright 2005-2006 Ouest Systemes Informatiques
|
|
|
+ * @copyright 2005-2012 Ouest Systemes Informatiques
|
|
|
*/
|
|
|
|
|
|
+namespace OSInet\Open_Document\Calc;
|
|
|
+
|
|
|
+use OSInet\Open_Document\Calc\Reader;
|
|
|
+
|
|
|
|
|
|
* OpenDocument Spreadsheet cell
|
|
|
*/
|
|
|
-$erCalc_Cell = error_reporting(E_ALL | E_STRICT);
|
|
|
-
|
|
|
-class Calc_Cell
|
|
|
- {
|
|
|
+class Cell {
|
|
|
|
|
|
* Values of the 'office:value-type' attribute
|
|
|
*/
|
|
@@ -28,22 +28,18 @@ class Calc_Cell
|
|
|
public $displayValue;
|
|
|
|
|
|
|
|
|
- * @param DOMNode $cellNode
|
|
|
+ * @param \DOMNode $cellNode
|
|
|
*/
|
|
|
- function __construct(DOMNode $cellNode)
|
|
|
- {
|
|
|
- if ($cellNode instanceof DOMElement)
|
|
|
- {
|
|
|
- $this->dataType = $cellNode->getAttributeNS(Calc_Reader::NS_OFFICE, 'value-type');
|
|
|
+ function __construct(\DOMNode $cellNode) {
|
|
|
+ if ($cellNode instanceof \DOMElement) {
|
|
|
+ $this->dataType = $cellNode->getAttributeNS(Reader::NS_OFFICE, 'value-type');
|
|
|
|
|
|
- if ($cellNode->childNodes->length == 0)
|
|
|
- {
|
|
|
- $this->dataType = Calc_Cell::TYPE_EMPTY;
|
|
|
+ if ($cellNode->childNodes->length == 0) {
|
|
|
+ $this->dataType = self::TYPE_EMPTY;
|
|
|
$this->dataValue = NULL;
|
|
|
$this->displayValue = '';
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ }
|
|
|
+ else {
|
|
|
$p = $cellNode->childNodes->item(0);
|
|
|
$this->displayValue = $p->textContent;
|
|
|
unset($p);
|
|
@@ -51,52 +47,47 @@ class Calc_Cell
|
|
|
|
|
|
* Note: cells with office:value-type==string don't have a office:value
|
|
|
*/
|
|
|
- if ($this->dataType == Calc_Cell::TYPE_STRING)
|
|
|
- {
|
|
|
+ if ($this->dataType == self::TYPE_STRING) {
|
|
|
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- $this->dataValue = $cellNode->getAttributeNS(Calc_Reader::NS_OFFICE, 'value');
|
|
|
- }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $this->dataValue = $cellNode->getAttributeNS(Reader::NS_OFFICE, 'value');
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
. ", type = " . $this->dataType
|
|
|
. ", value = " . substr($this->dataValue, 0, 20)
|
|
|
. ", display = <" . substr($this->displayValue, 0, 20)
|
|
|
. ">" . PHP_EOL; */
|
|
|
-
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
* Convert a PHP value to a wrapped OpenDocument cell value
|
|
|
*
|
|
|
* @param mixed $x
|
|
|
*/
|
|
|
- function set($x = NULL)
|
|
|
- {
|
|
|
+ function set($x = NULL) {
|
|
|
$type = gettype($x);
|
|
|
- switch ($type)
|
|
|
- {
|
|
|
+ switch ($type) {
|
|
|
case 'NULL':
|
|
|
- $this->dataType = Calc_Cell::TYPE_EMPTY;
|
|
|
+ $this->dataType = self::TYPE_EMPTY;
|
|
|
$this->dataValue = NULL;
|
|
|
$this->displayValue = NULL;
|
|
|
break;
|
|
|
case 'string':
|
|
|
- $this->dataType = Calc_Cell::TYPE_STRING;
|
|
|
+ $this->dataType = self::TYPE_STRING;
|
|
|
$this->dataValue = NULL;
|
|
|
$this->displayValue = $x;
|
|
|
break;
|
|
|
case 'double':
|
|
|
- $this->dataType = Calc_Cell::TYPE_FLOAT;
|
|
|
+ $this->dataType = self::TYPE_FLOAT;
|
|
|
$this->dataValue = $x;
|
|
|
$this->displayValue = number_format($x);
|
|
|
break;
|
|
|
default:
|
|
|
$this->set();
|
|
|
- throw new Exception('Calc_Cell::set unsupported value type ', $type);
|
|
|
+ throw new \Exception('Cell::set unsupported value type ', $type);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -106,11 +97,7 @@ class Calc_Cell
|
|
|
*
|
|
|
* @return string
|
|
|
*/
|
|
|
- function __toString()
|
|
|
- {
|
|
|
+ function __toString() {
|
|
|
return (string) $this->displayValue;
|
|
|
- }
|
|
|
}
|
|
|
-
|
|
|
-error_reporting($erCalc_Cell);
|
|
|
-unset($erCalc_Cell);
|
|
|
+}
|