Example #1
0
 /**
  * @param Entity              $entity
  * @param array               $record
  * @param Metadata\Relation[] $relations
  * @param                     $readOnly
  *
  * @return mixed
  */
 private function createObject(Entity $entity, array $record, array $relations, $readOnly)
 {
     $fields = $entity->getFieldNames();
     $object = $entity->create(array_intersect_key($record, $fields), true);
     $entity->setReadOnly($object, $readOnly);
     foreach ($relations as $relation) {
         $relation->set($object, $relation->getEmptyValue());
     }
     return $object;
 }
Example #2
0
 public static function sync($e)
 {
     $entity = Entity::load($e->entity_service, $e->entity_type, $e->entity_id);
     if (empty($entity)) {
         // create
         echo "CREATE {$e->entity_service}, {$e->entity_type}, {$e->entity_id}\n";
         Entity::create($e);
     } else {
         echo "UPDATE {$e->entity_service}, {$e->entity_type}, {$e->entity_id}\n";
         // sync
         $entity->update($e);
     }
 }
 /**
  * Create a new amenity.
  * @param $clustername : cluster's name from the url
  * @param $name : the name of the amenity to be created
  *
  */
 public function createAmenity(Cluster $cluster, $name)
 {
     $content = Request::instance()->getContent();
     if (empty($content)) {
         return $this->_sendErrorMessage(400, "Payload.Null", "Received payload is empty.");
     }
     if (Input::json() == null) {
         return $this->_sendErrorMessage(400, "Payload.Invalid", "Received payload is invalid.");
     }
     if (!strcmp($cluster->clustername, Auth::user()->clustername) || Auth::user()->isAdmin()) {
         /* This Validator verify that the schema value is a valid json-schema
            definition. */
         $amenity_validator = Validator::make(Input::json()->all(), array('description' => 'required', 'schema' => 'required|schema'));
         if (!$amenity_validator->fails()) {
             $amenity = Entity::where('name', '=', $name)->first();
             if (isset($amenity)) {
                 $amenity->body = json_encode(Input::json()->get('schema'));
                 $amenity->save();
             } else {
                 return Entity::create(array('name' => $name, 'type' => 'amenity', 'body' => json_encode(Input::json()->get('schema')), 'user_id' => $cluster->user->id));
             }
         } else {
             return $this->_sendValidationErrorMessage($amenity_validator);
         }
     } else {
         return $this->_sendErrorMessage(403, "WriteAccessForbiden", "You can't create amenities on behalf of another user.");
     }
 }
 public static function sync($e)
 {
     $entity = Entity::load($e->entity_service, $e->entity_type, $e->entity_id);
     if (empty($entity)) {
         // create
         Entity::create($e);
     } else {
         // sync
         $entity->update($e);
     }
 }
Example #5
0
 /**
  *  @param $id Order id description 
  */
 public function create($attributes = array())
 {
     return parent::create($attributes);
 }