/** * Contructs a new XML Managed Object View that represents the object specified in * XML format * * @param MManagedObject $managedObject The Managed Object to be represented as * an XML Element View * * @return MXMLManagedObjectView The new XML Element View instance */ public function __construct(MManagedObject $managedObject) { parent::__construct($managedObject->entity()->name()); $this->managedObject = $managedObject; $this->dynamicFields = new MMutableDictionary(); $this->dynamicFieldViews = new MMutableDictionary(); $this->setValueForProperty(S("objectID"), S((string) $this->managedObject()->objectID())); if (!$managedObject->isFault()) { foreach ($managedObject->entity()->attributes()->toArray() as $attribute) { if ($attribute instanceof MEntityDescriptionProperty) { $object = $managedObject->objectForAttribute($attribute); $propertyElement = new MXMLElementView($attribute->name(), $object ? $object->toString() : S("")); $propertyElement->setValueForProperty(S("type"), S($attribute->type())); $this->addSubview($propertyElement); } else { if ($attribute instanceof MEntityDescriptionRelationship) { $relationshipElement = new MXMLElementView($attribute->name()); $relationshipElement->setValueForProperty(S("type"), $attribute->type()); $relationshipValues = $managedObject->objectForAttribute($attribute); if (!$relationshipValues instanceof MArray) { $relationshipValues = A(array($relationshipValues)); } foreach ($relationshipValues->toArray() as $object) { $objectElement = new MXMLElementView($attribute->singular()); $objectElement->setValueForProperty(S("objectID"), Sf("%d", $object->objectID())); $relationshipElement->addSubview($objectElement); } } else { throw new MManagedObjectException($managedObject, S("Unsupported Attribute Type")); } } } } }
/** * Creates a new XML Entity Collection view instance with the specified * entity type * * @param MEntityDescription $entity The entity this collection will represent * * @return MXMLEntityCollectionView The newly created instance */ public function __construct(MEntityDescription $entity) { parent::__construct($entity->plural()); $this->entity = $entity; $this->fireFaults = false; $this->managedObjects = new MMutableDictionary(); $this->dynamicFields = new MMutableDictionary(); }