--- /dev/null
+<?php
+/**
+ * @package Horde_Rdo
+ * @subpackage UnitTests
+ *
+ * $Horde: framework/Rdo/examples/Horde/Rdo/Clotho.php,v 1.2 2008/09/02 17:24:59 chuck Exp $
+ */
+
+require_once 'Horde/Autoloader.php';
+
+/* additional things to handle:
+-- clotho_resource_availability has a one to many from resources to availabilities
+-- clotho_resources.resource_base_calendar is a foreign key to clotho_calendars.calendar_id
+
+ item_parent INTEGER NOT NULL, -- item_id of WBS parent in
+ -- heirarchy
+
+ dependency_lhs_item INTEGER NOT NULL, -- clotho_wbs_items.item_id
+ dependency_rhs_item INTEGER NOT NULL, -- clotho_wbs_items.item_id
+*/
+
+
+/**
+ * Base Mapper class for Clotho - defines getAdapter() so subclasses
+ * stay simple.
+ */
+class Clotho_Mapper extends Horde_Rdo_Mapper {
+
+ public function getAdapter()
+ {
+ return Horde_Rdo_Adapter::factory('pdo', $GLOBALS['conf']['sql']);
+ }
+
+}
+
+/**
+ * Items
+ */
+class Item extends Horde_Rdo_Base {
+}
+
+/**
+ * Item Mapper
+ */
+class ItemMapper extends Clotho_Mapper {
+
+ protected $_relationships = array(
+ 'resources' => array('type' => Horde_Rdo::MANY_TO_MANY,
+ 'mapper' => 'ResourceMapper',
+ 'through' => 'clotho_wbs_resources'),
+ 'parent' => array('type' => Horde_Rdo::ONE_TO_ONE,
+ 'foreignKey' => 'item_parent',
+ 'mapper' => 'ItemMapper'),
+ );
+
+ protected $_table = 'clotho_wbs_items';
+
+}
+
+/**
+ * Dependencies
+ */
+class Dependency extends Horde_Rdo_Base {
+}
+
+/**
+ * Dependency Mapper.
+ */
+class DependencyMapper extends Clotho_Mapper {
+
+ protected $_table = 'clotho_wbs_dependencies';
+
+}
+
+/**
+ * Calendars
+ */
+class Calendar extends Horde_Rdo_Base {
+}
+
+/**
+ * Calendar Mapper.
+ */
+class CalendarMapper extends Clotho_Mapper {
+
+ protected $_table = 'clotho_calendars';
+
+}
+
+/**
+ * Resources
+ */
+class Resource extends Horde_Rdo_Base {
+}
+
+/**
+ * Resource Mapper.
+ */
+class ResourceMapper extends Clotho_Mapper {
+
+ protected $_relationships = array(
+ 'availabilities' => array('type' => Horde_Rdo::ONE_TO_MANY,
+ 'foreignKey' => 'resource_id',
+ 'mapper' => 'ResourceAvailabilityMapper'),
+ 'items' => array('type' => Horde_Rdo::MANY_TO_MANY,
+ 'mapper' => 'ItemMapper',
+ 'through' => 'clotho_wbs_resources'),
+ );
+
+ protected $_table = 'clotho_resources';
+
+}
+
+/**
+ * ResourceAvailability
+ */
+class ResourceAvailability extends Horde_Rdo_Base {
+}
+
+/**
+ * ResourceAvailability Mapper.
+ */
+class ResourceAvailabilityMapper extends Clotho_Mapper {
+
+ protected $_relationships = array(
+ 'resource' => array('type' => Horde_Rdo::MANY_TO_ONE,
+ 'foreignKey' => 'resource_id',
+ 'mapper' => 'ResourceMapper'),
+ );
+
+ protected $_table = 'clotho_resource_availability';
+
+}
--- /dev/null
+<?php
+/**
+ * @package Horde_Rdo
+ */
+
+require './Clotho.php';
+
+$im = new ItemMapper();
+$dm = new DependencyMapper();
+$cm = new CalendarMapper();
+$rm = new ResourceMapper();
+$ram = new ResourceAvailabilityMapper();
+
+echo count($im) . "\n";
+echo count($dm) . "\n";
+echo count($cm) . "\n";
+echo count($rm) . "\n";
+echo count($ram) . "\n";
--- /dev/null
+<?php
+/**
+ * @package Horde_Rdo
+ */
+
+require_once './Clotho.php';
+
+class XmlItemMapper extends ItemMapper {
+}
+
+class XmlItem extends Item {
+
+ /**
+ * Return an XML representation of this object. The default
+ * implementation is unlikely to be useful in most cases and
+ * should be overridden by subclasses to be domain-appropriate.
+ *
+ * @TODO: see http://pear.php.net/pepr/pepr-proposal-show.php?id=361 ?
+ *
+ * @return string XML representation of $this.
+ */
+ public function toXml()
+ {
+ $doc = new DOMDocument('1.0');
+
+ $root = $doc->appendChild($doc->createElement(get_class($this)));
+ foreach ($this as $field => $value) {
+ $f = $root->appendChild($doc->createElement($field));
+ $f->appendChild($doc->createTextNode($value));
+ }
+
+ return $doc->saveXML();
+ }
+
+}
+
+$im = new XmlItemMapper();
+
+$i = $im->find(1);
+echo $i->toXml();
--- /dev/null
+<?php
+/**
+ * @package Horde_Rdo
+ * @subpackage UnitTests
+ *
+ * $Horde: framework/Rdo/examples/Horde/Rdo/RelationshipTest.php,v 1.1 2008/03/05 20:37:32 chuck Exp $
+ */
+
+// class definitions.
+require './Clotho.php';
+
+
+// one-to-one
+$im = new ItemMapper();
+
+$i = $im->find(3);
+echo "({$i->item_id}) {$i->item_name} has parent:\n";
+echo " ({$i->parent->item_id}) {$i->parent->item_name}\n";
+
+
+// one-to-many
+$rm = new ResourceMapper();
+
+$r = $rm->find(1);
+echo "Resource ({$r->resource_id}) {$r->resource_name} has " . $r->availabilities->count() . " availabilities:\n";
+foreach ($r->availabilities as $ra) {
+ echo ' (' . $ra->availability_id . ') ' . $ra->resource->resource_name . " on " . strftime('%x %X', $ra->availability_date) . " (" . $ra->availability_hours . " hours)\n";
+}
+
+
+// many-to-one
+$ram = new ResourceAvailabilityMapper();
+
+$ra = $ram->find(1);
+echo "Resource Availability ({$ra->availability_id}) " . strftime('%x %X', $ra->availability_date) . " has resource:\n";
+echo " ({$ra->resource->resource_id}) {$ra->resource->resource_name}\n";
+
+
+// many-to-many
+echo "Listing all Items and their Resources:\n\n";
+$im = new ItemMapper();
+foreach ($im->find(Horde_Rdo::FIND_ALL) as $i) {
+ if (count($i->resources)) {
+ echo " (" . $i->item_id . ") " . $i->item_name . " has resources:\n";
+ foreach ($i->resources as $r) {
+ echo ' (' . $r->resource_id . ') ' . $r->resource_name . "\n";
+ }
+ }
+}
+
+echo "\n\nListing all Resources and their Items:\n\n";
+$rm = new ResourceMapper();
+foreach ($rm->find(Horde_Rdo::FIND_ALL) as $r) {
+ if (count($r->items)) {
+ echo " (" . $r->resource_id . ") " . $r->resource_name . " has items:\n";
+ foreach ($r->items as $i) {
+ echo ' (' . $i->item_id . ') ' . $i->item_name . "\n";
+ }
+ }
+}
--- /dev/null
+<?php
+/**
+ * $Horde: framework/Rdo/examples/Horde/Rdo/Task.php,v 1.2 2008/09/02 17:24:59 chuck Exp $
+ *
+ * @package Horde_Rdo
+ */
+
+@include './conf.php';
+if (empty($conf['sql'])) {
+ die('No sql configuration found.');
+}
+
+require_once 'Horde/Autoloader.php';
+
+/**
+ */
+class Task extends Horde_Rdo_Base {
+}
+
+/**
+ */
+class TaskMapper extends Horde_Rdo_Mapper {
+
+ protected $_table = 'nag_tasks';
+
+ public function getAdapter()
+ {
+ return Horde_Rdo_Adapter::factory('pdo', $GLOBALS['conf']['sql']);
+ }
+
+}
+
+$tm = new TaskMapper();
+
+// Count all tasks.
+$count = $tm->count();
+echo "# tasks: $count\n";
+
+// List all tasks.
+echo "Looking for all tasks:\n";
+foreach ($tm->find(Horde_Rdo::FIND_ALL) as $task) {
+ echo " " . $task->task_name . "\n";
+}
+
+// List all of Chuck's tasks.
+$chuck = $tm->find(Horde_Rdo::FIND_ALL, array('task_owner' => 'chuck'));
+echo "\nChuck's tasks:\n";
+foreach ($chuck as $task) {
+ echo " " . $task->task_name . "\n";
+}
--- /dev/null
+<?php
+/**
+ * $Horde: framework/Rdo/examples/Horde/Rdo/User.php,v 1.3 2008/09/02 17:24:59 chuck Exp $
+ *
+ * @package Horde_Rdo
+ */
+
+require_once 'Horde/Autoloader.php';
+
+@include './conf.php';
+if (empty($conf['sql'])) {
+ die('No sql configuration found.');
+}
+
+/**
+ */
+class User extends Horde_Rdo_Base {
+}
+
+/**
+ */
+class UserMapper extends Horde_Rdo_Mapper {
+
+ public function getAdapter()
+ {
+ return Horde_Db_Adapter::factory($GLOBALS['conf']['sql']);
+ }
+
+}
+
+$um = new UserMapper();
+
+// Count all users.
+$userCount = $um->count();
+echo "# users: $userCount\n";
+
+// Get the number of new users in May 2005
+//$userCount = $um->count('created > \'2005-05-01\' AND created <= \'2005-05-31\'');
+//echo "# new: $userCount\n";
+
+// Check if id 1 exists.
+$exists = $um->exists(1);
+echo "exists: " . ($exists ? 'yes' : 'no') . "\n";
+
+// Look for Alice
+$userTwo = $um->findOne(array('name' => 'Alice'));
+if ($userTwo) {
+ echo "Found Alice: id $userTwo->id\n";
+} else {
+ echo "No Alice found, creating:\n";
+ $userOne = $um->create(array('name' => 'Alice', 'phone' => '212-555-6565'));
+ $userOneId = $userOne->id;
+ echo "Created new user with id: $userOneId\n";
+}
+
+// Change the name of the user and save.
+if ($userTwo) {
+ $userTwo->name = 'Bob';
+ $result = $userTwo->save();
+ var_dump($result);
+}
+
+// List all users.
+echo "Looking for all:\n";
+foreach ($um->find() as $userOb) {
+ echo " (" . $userOb->id . ") " . $userOb->name . "\n";
+}
+
+// Fetch id 2.
+//$user = $um->findOne(2);
+// Try to delete it.
+//$result = $user->delete();
+//var_dump($result);
+
+/*
+// $user->billingAddresses is an Iterator.
+foreach ($user->billingAddresses as $billingAddress) {
+ echo $billingAddress->zipCode . "\n";
+}
+
+if ($user->favorite) {
+ echo $user->favorite->name . "\n";
+} else {
+ $user->favorite = new User(array('name' => 'Charles'));
+}
+*/
--- /dev/null
+<?php
+/**
+ * @package Horde_Rdo
+ */
+
+require_once './Clotho.php';
+
+$im = new ItemMapper();
+$dm = new DependencyMapper();
+$cm = new CalendarMapper();
+$rm = new ResourceMapper();
+$ram = new ResourceAvailabilityMapper();
+
+$item = $im->create(array('item_name' => 'Test Item', 'item_parent' => 0));
+echo get_class($item) . "\n";
+$item = $im->create(array('item_name' => 'Test Item 2', 'item_parent' => 0));
+echo get_class($item) . "\n";
+$item = $im->create(array('item_name' => 'Child Item', 'item_parent' => 1));
+echo get_class($item) . "\n";
+
+$dep = $dm->create(array('dependency_type' => 'S', 'dependency_lhs_item' => 1, 'dependency_rhs_item' => 2));
+echo get_class($dep) . "\n";
+
+$cal = $cm->create(array('calendar_name' => 'Test Calendar', 'calendar_hoursinday' => 8,
+ 'calendar_hoursinweek' => 40, 'calendar_type' => 'weekly', 'calendar_data' => ''));
+echo get_class($cal) . "\n";
+
+$res = $rm->create(array('resource_type' => 'M', 'resource_name' => 'Test Resource', 'resource_base_calendar' => 1));
+echo get_class($res) . "\n";
+
+$resavail = $ram->create(array('resource_id' => 1, 'availability_date' => 1121404095, 'availability_hours' => 2));
+echo get_class($resavail) . "\n";
--- /dev/null
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<database>
+
+ <name><variable>name</variable></name>
+ <create>true</create>
+ <overwrite>false</overwrite>
+
+ <table>
+
+ <name>clotho_calendars</name>
+
+ <declaration>
+
+ <field>
+ <name>calendar_id</name>
+ <type>integer</type>
+ <unsigned>false</unsigned>
+ <length>4</length>
+ <notnull>true</notnull>
+ <default>0</default>
+ <autoincrement>1</autoincrement>
+ </field>
+
+ <field>
+ <name>calendar_name</name>
+ <type>text</type>
+ <length>128</length>
+ <notnull>true</notnull>
+ <default></default>
+ </field>
+
+ <field>
+ <name>calendar_hoursinday</name>
+ <type>integer</type>
+ <unsigned>false</unsigned>
+ <length>4</length>
+ <notnull>true</notnull>
+ <default></default>
+ </field>
+
+ <field>
+ <name>calendar_hoursinweek</name>
+ <type>integer</type>
+ <unsigned>false</unsigned>
+ <length>4</length>
+ <notnull>true</notnull>
+ <default></default>
+ </field>
+
+ <field>
+ <name>calendar_type</name>
+ <type>text</type>
+ <length>32</length>
+ <notnull>true</notnull>
+ <default></default>
+ </field>
+
+ <field>
+ <name>calendar_data</name>
+ <type>text</type>
+ <notnull>true</notnull>
+ <default></default>
+ </field>
+
+ </declaration>
+
+ </table>
+
+ <table>
+
+ <name>clotho_resource_availability</name>
+
+ <declaration>
+
+ <field>
+ <name>availability_id</name>
+ <type>integer</type>
+ <unsigned>false</unsigned>
+ <length>4</length>
+ <notnull>true</notnull>
+ <default>0</default>
+ <autoincrement>1</autoincrement>
+ </field>
+
+ <field>
+ <name>resource_id</name>
+ <type>integer</type>
+ <unsigned>false</unsigned>
+ <length>4</length>
+ <notnull>true</notnull>
+ <default></default>
+ </field>
+
+ <field>
+ <name>availability_date</name>
+ <type>integer</type>
+ <unsigned>false</unsigned>
+ <length>4</length>
+ <notnull>true</notnull>
+ <default></default>
+ </field>
+
+ <field>
+ <name>availability_hours</name>
+ <type>decimal</type>
+ <length>524290</length>
+ <notnull>true</notnull>
+ <default></default>
+ </field>
+
+ </declaration>
+
+ </table>
+
+ <table>
+
+ <name>clotho_resources</name>
+
+ <declaration>
+
+ <field>
+ <name>resource_id</name>
+ <type>integer</type>
+ <unsigned>false</unsigned>
+ <length>4</length>
+ <notnull>true</notnull>
+ <default>0</default>
+ <autoincrement>1</autoincrement>
+ </field>
+
+ <field>
+ <name>resource_type</name>
+ <type>text</type>
+ <length>1</length>
+ <notnull>true</notnull>
+ <default></default>
+ </field>
+
+ <field>
+ <name>resource_name</name>
+ <type>text</type>
+ <length>128</length>
+ <notnull>true</notnull>
+ <default></default>
+ </field>
+
+ <field>
+ <name>resource_uid</name>
+ <type>text</type>
+ <length>64</length>
+ <notnull>false</notnull>
+ <default></default>
+ </field>
+
+ <field>
+ <name>resource_base_calendar</name>
+ <type>integer</type>
+ <unsigned>false</unsigned>
+ <length>4</length>
+ <notnull>true</notnull>
+ <default></default>
+ </field>
+
+ <field>
+ <name>resource_start</name>
+ <type>integer</type>
+ <unsigned>false</unsigned>
+ <length>4</length>
+ <notnull>false</notnull>
+ <default></default>
+ </field>
+
+ <field>
+ <name>resource_finish</name>
+ <type>integer</type>
+ <unsigned>false</unsigned>
+ <length>4</length>
+ <notnull>false</notnull>
+ <default></default>
+ </field>
+
+ </declaration>
+
+ </table>
+
+ <table>
+
+ <name>clotho_wbs_dependencies</name>
+
+ <declaration>
+
+ <field>
+ <name>dependency_id</name>
+ <type>integer</type>
+ <unsigned>false</unsigned>
+ <length>4</length>
+ <notnull>true</notnull>
+ <default>0</default>
+ <autoincrement>1</autoincrement>
+ </field>
+
+ <field>
+ <name>dependency_type</name>
+ <type>text</type>
+ <length>1</length>
+ <notnull>true</notnull>
+ <default></default>
+ </field>
+
+ <field>
+ <name>dependency_lhs_item</name>
+ <type>integer</type>
+ <unsigned>false</unsigned>
+ <length>4</length>
+ <notnull>true</notnull>
+ <default></default>
+ </field>
+
+ <field>
+ <name>dependency_rhs_item</name>
+ <type>integer</type>
+ <unsigned>false</unsigned>
+ <length>4</length>
+ <notnull>true</notnull>
+ <default></default>
+ </field>
+
+ <field>
+ <name>dependency_duration</name>
+ <type>text</type>
+ <length>20</length>
+ <notnull>false</notnull>
+ <default></default>
+ </field>
+
+ </declaration>
+
+ </table>
+
+ <table>
+
+ <name>clotho_wbs_items</name>
+
+ <declaration>
+
+ <field>
+ <name>item_id</name>
+ <type>integer</type>
+ <unsigned>false</unsigned>
+ <length>4</length>
+ <notnull>true</notnull>
+ <default>0</default>
+ <autoincrement>1</autoincrement>
+ </field>
+
+ <field>
+ <name>item_name</name>
+ <type>text</type>
+ <length>128</length>
+ <notnull>true</notnull>
+ <default></default>
+ </field>
+
+ <field>
+ <name>item_parent</name>
+ <type>integer</type>
+ <unsigned>false</unsigned>
+ <length>4</length>
+ <notnull>true</notnull>
+ <default></default>
+ </field>
+
+ <field>
+ <name>item_duration</name>
+ <type>text</type>
+ <length>20</length>
+ <notnull>false</notnull>
+ <default></default>
+ </field>
+
+ <field>
+ <name>item_start</name>
+ <type>integer</type>
+ <unsigned>false</unsigned>
+ <length>4</length>
+ <notnull>false</notnull>
+ <default></default>
+ </field>
+
+ <field>
+ <name>item_start_fixed</name>
+ <type>integer</type>
+ <unsigned>false</unsigned>
+ <length>4</length>
+ <notnull>true</notnull>
+ <default>0</default>
+ </field>
+
+ <field>
+ <name>item_finish</name>
+ <type>integer</type>
+ <unsigned>false</unsigned>
+ <length>4</length>
+ <notnull>false</notnull>
+ <default></default>
+ </field>
+
+ <field>
+ <name>item_finish_fixed</name>
+ <type>integer</type>
+ <unsigned>false</unsigned>
+ <length>4</length>
+ <notnull>true</notnull>
+ <default>0</default>
+ </field>
+
+ </declaration>
+
+ </table>
+
+ <table>
+
+ <name>clotho_wbs_resources</name>
+
+ <declaration>
+
+ <field>
+ <name>item_id</name>
+ <type>integer</type>
+ <unsigned>false</unsigned>
+ <length>4</length>
+ <notnull>true</notnull>
+ <default></default>
+ </field>
+
+ <field>
+ <name>resource_id</name>
+ <type>integer</type>
+ <unsigned>false</unsigned>
+ <length>4</length>
+ <notnull>true</notnull>
+ <default></default>
+ </field>
+
+ </declaration>
+
+ </table>
+
+</database>
--- /dev/null
+<?php
+
+// Dist config file for Rdo examples.
+$conf['sql']['adapter'] = 'pdo_mysql';
+$conf['sql']['dsn'] = 'host=127.0.0.1';
+$conf['sql']['database'] = 'horde';
+$conf['sql']['username'] = 'horde';
+$conf['sql']['password'] = '';
+$conf['sql']['charset'] = 'utf-8';
--- /dev/null
+-- $Horde: framework/Rdo/examples/Horde/Rdo/users.mysql.sql,v 1.1 2008/03/05 20:37:32 chuck Exp $
+CREATE TABLE users (
+ id INT(11) auto_increment NOT NULL,
+ name varchar(255),
+ favorite_id int(11),
+ phone varchar(20),
+ created varchar(10),
+ updated varchar(10),
+
+ PRIMARY KEY (id)
+);
--- /dev/null
+-- $Horde: framework/Rdo/examples/Horde/Rdo/users.pgsql.sql,v 1.1 2008/03/05 20:37:32 chuck Exp $
+CREATE TABLE users (
+ id bigserial NOT NULL,
+ name varchar(255),
+ favorite_id integer,
+ phone varchar(20),
+ created varchar(10),
+ updated varchar(10),
+
+ PRIMARY KEY (id)
+);
--- /dev/null
+-- $Horde: framework/Rdo/examples/Horde/Rdo/users.sqlite.sql,v 1.1 2008/03/05 20:37:32 chuck Exp $
+CREATE TABLE users (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name VARCHAR(255),
+ favorite_id INTEGER,
+ phone VARCHAR(20),
+ created VARCHAR(10),
+ updated VARCHAR(10)
+);