summaryrefslogtreecommitdiffstats
path: root/src/datasets
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-05-10 15:47:46 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-05-10 15:47:46 +0000
commit9b1f82b08a5fb5b6cbc6f8f478dd987df9b02053 (patch)
tree01b6027151314286e051f07ae7ce29f98856c3f2 /src/datasets
parentabea356249129ec79d757b514781695b248dcb92 (diff)
downloadzetacomponents-graph-9b1f82b08a5fb5b6cbc6f8f478dd987df9b02053.zip
zetacomponents-graph-9b1f82b08a5fb5b6cbc6f8f478dd987df9b02053.tar.gz
- Added tests to retrieve and set single data in datasets
- Implemented datasets as far as tested
Diffstat (limited to 'src/datasets')
-rw-r--r--src/datasets/base.php112
-rw-r--r--src/datasets/property/color.php30
-rw-r--r--src/datasets/property/integer.php30
-rw-r--r--src/datasets/property/string.php30
4 files changed, 194 insertions, 8 deletions
diff --git a/src/datasets/base.php b/src/datasets/base.php
index 03d53eb..c643855 100644
--- a/src/datasets/base.php
+++ b/src/datasets/base.php
@@ -12,9 +12,24 @@
*
* @package Graph
*/
-class eczGraphDataset
+class ezcGraphDataset implements ArrayAccess
{
+ protected $label;
+
+ protected $color;
+
+ protected $symbol;
+
+ protected $data;
+
+ public function __construct()
+ {
+ $this->label = new ezcGraphDatasetStringProperty( $this );
+ $this->color = new ezcGraphDatasetColorProperty( $this );
+ $this->symbol = new ezcGraphDatasetIntProperty( $this );
+ }
+
/**
* setData
*
@@ -22,21 +37,102 @@ class eczGraphDataset
* @access public
* @return void
*/
- public function setData( $data = array() )
+ public function createFromArray( $data = array() )
{
-
+ foreach ( $data as $key => $value )
+ {
+ if ( is_numeric( $value ) )
+ {
+ $this->data[$key] = (float) $value;
+ }
+ }
}
+ public function __set( $propertyName, $propertyValue )
+ {
+ switch ( $propertyName )
+ {
+ case 'label':
+ $this->label->default = $propertyValue;
+ break;
+ case 'color':
+ $this->color->default = $propertyValue;
+ break;
+ case 'symbol':
+ $this->symbol->default = $propertyValue;
+ break;
+ }
+ }
+
+ public function __get( $propertyName )
+ {
+ if ( isset( $this->$propertyName ) ) {
+ return $this->$propertyName;
+ } else {
+ throw new ezcBasePropertyNotFoundException( $propertyName );
+ }
+ }
+
/**
- * addData
+ * Returns if an option exists.
+ * Allows isset() using ArrayAccess.
*
- * @param array $data
- * @access public
+ * @param string $key The name of the option to get.
+ * @return bool Wether the option exists.
+ */
+ final public function offsetExists( $key )
+ {
+ return isset( $this->data[$key] );
+ }
+
+ /**
+ * Returns an option value.
+ * Get an option value by ArrayAccess.
+ *
+ * @param string $key The name of the option to get.
+ * @return mixed The option value.
+ *
+ * @throws ezcBasePropertyNotFoundException
+ * If a the value for the property options is not an instance of
+ */
+ final public function offsetGet( $key )
+ {
+ return $this->data[$key];
+ }
+
+ /**
+ * Set an option.
+ * Sets an option using ArrayAccess.
+ *
+ * @param string $key The option to set.
+ * @param mixed $value The value for the option.
+ * @return void
+ *
+ * @throws ezcBasePropertyNotFoundException
+ * If a the value for the property options is not an instance of
+ * @throws ezcBaseValueException
+ * If a the value for a property is out of range.
+ */
+ final public function offsetSet( $key, $value )
+ {
+ $this->data[$key] = (float) $value;
+ }
+
+ /**
+ * Unset an option.
+ * Unsets an option using ArrayAccess.
+ *
+ * @param string $key The options to unset.
* @return void
+ *
+ * @throws ezcBasePropertyNotFoundException
+ * If a the value for the property options is not an instance of
+ * @throws ezcBaseValueException
+ * If a the value for a property is out of range.
*/
- public function addData( $data = array() )
+ final public function offsetUnset( $key )
{
-
+ unset( $this->data[$key] );
}
}
diff --git a/src/datasets/property/color.php b/src/datasets/property/color.php
new file mode 100644
index 0000000..a177c4b
--- /dev/null
+++ b/src/datasets/property/color.php
@@ -0,0 +1,30 @@
+<?php
+/**
+ * File containing the abstract ezcGraphDatasetColorProperty class
+ *
+ * @package Graph
+ * @version $id$
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * Class for color properties of datasets
+ *
+ * @package Graph
+ */
+class ezcGraphDatasetColorProperty extends ezcGraphDatasetProperty
+{
+ /**
+ * Converts value to an ezcGraphColor object
+ *
+ * @param & $value
+ * @return void
+ */
+ protected function checkValue( &$value )
+ {
+ $value = ezcGraphColor::create( $value );
+ return true;
+ }
+}
+
+?>
diff --git a/src/datasets/property/integer.php b/src/datasets/property/integer.php
new file mode 100644
index 0000000..67c9c73
--- /dev/null
+++ b/src/datasets/property/integer.php
@@ -0,0 +1,30 @@
+<?php
+/**
+ * File containing the abstract ezcGraphDatasetIntProperty class
+ *
+ * @package Graph
+ * @version $id$
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * Class for integer properties of datasets
+ *
+ * @package Graph
+ */
+class ezcGraphDatasetIntProperty extends ezcGraphDatasetProperty
+{
+ /**
+ * Converts value to an ezcGraphColor object
+ *
+ * @param & $value
+ * @return void
+ */
+ protected function checkValue( &$value )
+ {
+ $value = (int) $value;
+ return true;
+ }
+}
+
+?>
diff --git a/src/datasets/property/string.php b/src/datasets/property/string.php
new file mode 100644
index 0000000..a96dab1
--- /dev/null
+++ b/src/datasets/property/string.php
@@ -0,0 +1,30 @@
+<?php
+/**
+ * File containing the abstract ezcGraphDatasetStringProperty class
+ *
+ * @package Graph
+ * @version $id$
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * Class for string properties of datasets
+ *
+ * @package Graph
+ */
+class ezcGraphDatasetStringProperty extends ezcGraphDatasetProperty
+{
+ /**
+ * Converts value to an ezcGraphColor object
+ *
+ * @param & $value
+ * @return void
+ */
+ protected function checkValue( &$value )
+ {
+ $value = (string) $value;
+ return true;
+ }
+}
+
+?>
OpenPOWER on IntegriCloud