/**
  * 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();
 }
 /**
  * Creates a new MEntityProviderViewController instance
  *
  * Creates a new instance of the MEntityProviderViewController class which
  * you can use to serve your entities directly to your clients using
  * RESTful standards
  *
  * @param MEntityDescription $entity The entity you wish to create an interface for
  * @param MManagedObjectContext $context The Managed Object Context to connect this
  * entity provider to
  *
  * @return MEntityProviderViewController A new instance of the MEntityProviderViewController class
  */
 public function __construct(MEntityDescription $entity, MManagedObjectContext $context)
 {
     parent::__construct();
     $this->entity = $entity;
     $this->context = $context;
     $this->objectID = null;
     $this->predicate = null;
     $this->outputType = MEntityProviderViewController::OUTPUT_TYPE_XML;
     foreach ($entity->properties()->toArray() as $property) {
         if ($property->type() == MEntityDescriptionProperty::StringType) {
             $this->addFormField(new MFormViewControllerField($property->name(), MFormViewControllerField::StringType));
         } else {
             if ($property->type() == MEntityDescriptionProperty::IntegerType) {
                 $this->addFormField(new MFormViewControllerField($property->name(), MFormViewControllerField::IntegerType));
             } else {
                 if ($property->type() == MEntityDescriptionProperty::FloatType) {
                     $this->addFormField(new MFormViewControllerField($property->name(), MFormViewControllerField::FloatType));
                 } else {
                     if ($property->type() == MEntityDescriptionProperty::BooleanType) {
                         $this->addFormField(new MFormViewControllerField($property->name(), MFormViewControllerField::BooleanType));
                     } else {
                         if ($property->type() == MEntityDescriptionProperty::DateType) {
                             $this->addFormField(new MFormViewControllerField($property->name(), MFormViewControllerField::DateType));
                         } else {
                             if ($property->type() == MEntityDescriptionProperty::BinaryType) {
                                 $this->addFormField(new MFormViewControllerField($property->name(), MFormViewControllerField::BinaryType));
                             } else {
                                 throw new MManagedObjectException($object, Sf("Unknown attribute type '%s'", $attribute->type()));
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * Creates a new Managed Object instance with the class type specified by the entity
  *
  * This creates a new instance of an MManagedObject subclass specified in entity,
  * inserts it into this context and returns it.
  *
  * @param MEntityDescription $entity The entity to create a new instance of
  * @param int $objectID An optional ID to use for the object. This should only
  * be used when manullay constructing a representation of the object from the
  * data store.
  *
  * @return MManagedObject The new MManagedObject subclass instance
  */
 public function newObjectForEntity(MEntityDescription $entity, $objectID = MManagedObject::UNKNOWN_ID)
 {
     MAssertTypes('int', $objectID);
     return MObject::newInstanceOfClassWithParameters($entity->entityClassName(), A(array($entity, $this, $objectID)));
 }
 /**
  * @internal
  *
  * @return MDictionary
  */
 protected function unpackData(MDictionary $data, MEntityDescription $entity)
 {
     $unpackedData = new MMutableDictionary();
     foreach ($data->allKeys()->toArray() as $key) {
         $value = $data->objectForKey($key);
         $unboxedValue = null;
         if (!is_null($value)) {
             $property = $entity->attributeWithName($key);
             if ($property->type() == MEntityDescriptionProperty::StringType) {
                 $unboxedValue = $value->stringValue();
             } else {
                 if ($property->type() == MEntityDescriptionProperty::IntegerType) {
                     $unboxedValue = $value->intValue();
                 } else {
                     if ($property->type() == MEntityDescriptionProperty::FloatType) {
                         $unboxedValue = $value->floatValue();
                     } else {
                         if ($property->type() == MEntityDescriptionProperty::BooleanType) {
                             $unboxedValue = $value->boolValue();
                         } else {
                             if ($property->type() == MEntityDescriptionProperty::DateType) {
                                 $unboxedValue = $value->timestamp();
                             } else {
                                 if ($property->type() == MEntityDescriptionProperty::BinaryType) {
                                     $unboxedValue = $value->getBytes();
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $unpackedData->setObjectForKey($key->stringValue(), $unboxedValue);
     }
     return $unpackedData;
 }