public function init($options = array()) { // TODO: dont depend on zend_db_model $componentTable = new Blerby_Entity_Model_Component(); $components = $componentTable->fetchAll($componentTable->getAdapter()->quoteInto("entity_id = ?", $this->id), "id ASC"); // TODO: move towards a "object set" for iteration and array ops $aComponents = array(); foreach ($components as $component) { // TODO: handle this all in the type! $found = false; foreach ($this->components as $typeComponent) { if ((string) $typeComponent->part == (string) $component->part) { $found = $typeComponent; break; } } if (!$found) { continue; } $oComponent = Blerby_Entity_Component::factory($found->uri); $oComponent->parent($this); // add type config $oComponent->fromArray($found->toArray()); // merge in component data $oComponent->fromArray($component->toArray()); // TODO: move this into the component (functionally complete objects) $componentConfigTable = new Blerby_Entity_Model_Component_Config(); $componentConfig = $componentConfigTable->fetchAll($componentTable->getAdapter()->quoteInto("entity_component_id = ?", $oComponent->id), "id ASC"); foreach ($componentConfig as $configItem) { $oComponent->set($configItem->name, $configItem->value); } $aComponents[] = $oComponent; } $this->bind('entity.save', $this); $this->set("components", $aComponents); parent::init($options); }