/** * 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")); } } } } }
/** * Adds a fault object to the request * * Use this method to add fault objects to your request. This way * you can fetch them all at once and save in performance compared * to fetching them one by one. * * @see MFaultRequest::removeFault() * @see MFaultRequest::faults() * * @param MManagedObject $fault The fault Managed Object to add * * @return void */ public function addFault(MManagedObject $fault) { if (!$fault->isFault()) { throw new MPersistentStoreException(S("Managed Object is not a valid fault")); } $this->faults->addObject($fault); }