]> git.parisson.com Git - telemeta.git/commitdiff
eztelemeta: add base extension folders, ini files and Telemeta Item datatype class
authorolivier <>
Wed, 8 Apr 2009 17:00:24 +0000 (17:00 +0000)
committerolivier <>
Wed, 8 Apr 2009 17:00:24 +0000 (17:00 +0000)
tools/eztelemeta/datatypes/telemetaitem/telemetaitem.php [new file with mode: 0644]
tools/eztelemeta/exceptions/invalidparams.php [new file with mode: 0644]
tools/eztelemeta/settings/content.ini.append [new file with mode: 0644]
tools/eztelemeta/settings/design.ini.append [new file with mode: 0644]

diff --git a/tools/eztelemeta/datatypes/telemetaitem/telemetaitem.php b/tools/eztelemeta/datatypes/telemetaitem/telemetaitem.php
new file mode 100644 (file)
index 0000000..bfad138
--- /dev/null
@@ -0,0 +1,109 @@
+<?php
+/**
+ * Definition of the Telemeta Item datatype
+ *
+ * @package     eztelemeta
+ * @author      Olivier Guilyardi
+ * @copyright   2009 Samalyse
+ * @license     CeCILL Free Software License Agreement
+ */
+
+
+/**
+ * Class definining the Telemeta Item datatype
+ *
+ * @package     eztelemeta
+ * @author      Olivier Guilyardi
+ * @copyright   2009 Samalyse
+ * @license     CeCILL Free Software License Agreement
+ */
+class telemetaItem
+{
+    private $cacheTimeout = 3600;
+
+    private $properties = array(
+        'id'            => null,
+        'title'         => null,
+        'description'   => null,
+        'rights'        => null,
+        'duration'      => null,
+        'creator'       => null,
+        'timeFetched'   => null
+    );
+
+
+    /**
+     * Constructs a new Telemeta item data type
+     *
+     * @param   string $data Serialized data
+     * @throws  telemetaDatatypeInvalidParamsError
+     */
+    public function __construct($data = null)
+    {
+        if ($data) {
+            $data = unserialize($data);
+            if (!$data) {
+                throw new telemetaInvalidParamsError("Couldn't unserialize Telemeta Item data");
+            }
+            $this->properties = array_merge($this->properties, $data);
+        }
+    }
+
+    private function fetch($itemId)
+    {
+        if ($itemId == 1000) {
+            $this->properties['id']             = 1000;
+            $this->properties['title']          = "Pulp Fiction";
+            $this->properties['description']    = "A crazy movie";
+            $this->properties['rights']         = "Copyright Holywood";
+            $this->properties['duration']       = 3600 + 1800;
+            $this->properties['creator']        = "Quentin Tarantino";
+            $this->properties['timeFetched']    = time();
+            return true;
+        }
+        return false;
+    }
+
+    public function __toString()
+    {
+        return serialize($this->properties);
+    }
+
+    public static function createFromString($str)
+    {
+        return new self($str);
+    }
+
+    public function attribute($name)
+    {
+        return $this->__get($name);
+    }
+
+    public function hasAttribute($name)
+    {
+        return $this->__isset($name);
+    }
+
+    public function __get($name)
+    {
+        if ($this->__isset($name)) {
+            return $this->properties[$name];
+        } else {
+            throw new ezcBasePropertyNotFoundException($name);
+        }
+    }
+
+    public function __isset($name)
+    {
+        return (array_key_exists($name, $this->properties) and !is_null($this->properties[$name]));
+    }
+
+    public function hasContent()
+    {
+        return $this->__isset('id');
+    }
+}
+
+
+?>
+
diff --git a/tools/eztelemeta/exceptions/invalidparams.php b/tools/eztelemeta/exceptions/invalidparams.php
new file mode 100644 (file)
index 0000000..ac85e7d
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+/**
+ * Definition of the Telemeta invalid params error
+ *
+ * @package     eztelemeta
+ * @author      Olivier Guilyardi
+ * @copyright   2009 Samalyse
+ * @license     CeCILL Free Software License Agreement
+ */
+
+
+/**
+ * Class defining the Telemeta invalid params error
+ *
+ * @package     eztelemeta
+ * @author      Olivier Guilyardi
+ * @copyright   2009 Samalyse
+ * @license     CeCILL Free Software License Agreement
+ */
+class telemetaInvalidParamsError extends ezcBaseException
+{
+    public function __construct($msg)
+    {
+        parent::__construct($msg);
+    }
+}
+?>
diff --git a/tools/eztelemeta/settings/content.ini.append b/tools/eztelemeta/settings/content.ini.append
new file mode 100644 (file)
index 0000000..95000c2
--- /dev/null
@@ -0,0 +1,4 @@
+[DataTypeSettings]
+ExtensionDirectories[]=eztelemeta
+AvailableDataTypes[]=telemetaitem
+
diff --git a/tools/eztelemeta/settings/design.ini.append b/tools/eztelemeta/settings/design.ini.append
new file mode 100644 (file)
index 0000000..dd406b3
--- /dev/null
@@ -0,0 +1,2 @@
+[ExtensionSettings]
+DesignExtensions[]=eztelemeta