/**
  * @param Request $request
  * @param Created $payload
  */
 public function created(Request $request, Created $payload)
 {
     $serializer = ActivityObject::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 201, ['Location' => $resource->getLinks()['self']]);
 }
Ejemplo n.º 2
0
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $serializer = ActivityObject::getSerializer();
     $resource = new Resource($payload->getModel(), $serializer);
     $resource = $resource->with($params->getInclude(['activities']));
     $resource = $resource->fields($params->getFields(['activity-object' => ActivityObject::getSerializer()->getFields(), 'activity' => Activity::getSerializer()->getFields()]));
     $document = new Document($resource);
     return new JsonResponse($document->toArray(), 200);
 }
 /**
  * @param Request $request
  * @param Found $payload
  */
 public function found(Request $request, Found $payload)
 {
     $params = new Parameters($request->query->all());
     $data = $payload->getModel();
     $serializer = ActivityObject::getSerializer();
     $resource = new Collection($data, $serializer);
     $resource = $resource->with($params->getInclude(['activities']));
     $resource = $resource->fields($params->getFields(['activity-object' => ActivityObject::getSerializer()->getFields(), 'activity' => Activity::getSerializer()->getFields()]));
     $document = new Document($resource);
     // meta
     if ($params->getPage('size') != -1) {
         $document->setMeta(['total' => $data->getNbResults(), 'first' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getFirstPage()]]), 'next' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getNextPage()]]), 'previous' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getPreviousPage()]]), 'last' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getLastPage()]])]);
     }
     // return response
     return new JsonResponse($document->toArray());
 }
 /**
  * @param Request $request
  * @param Updated $payload
  */
 public function updated(Request $request, Updated $payload)
 {
     $serializer = ActivityObject::getSerializer();
     $relationship = $serializer->activities($payload->getModel());
     return new JsonResponse($relationship->toArray());
 }
Ejemplo n.º 5
0
 /**
  * @param mixed $model
  * @return Relationship
  */
 public function target($model)
 {
     $serializer = ActivityObject::getSerializer();
     $id = $serializer->getId($model->getTarget());
     if ($id !== null) {
         $relationship = new Relationship(new Resource($model->getTarget(), $serializer));
         $relationship->setLinks(['related' => '%apiurl%' . $serializer->getType(null) . '/' . $id]);
         return $this->addRelationshipSelfLink($relationship, $model, 'target');
     }
     return null;
 }
Ejemplo n.º 6
0
 /**
  * Updates a ActivityObject with the given idand the provided data
  * 
  * @param mixed $id
  * @param mixed $data
  * @return PayloadInterface
  */
 public function update($id, $data)
 {
     // find
     $model = $this->get($id);
     if ($model === null) {
         return new NotFound(['message' => 'ActivityObject not found.']);
     }
     // hydrate
     $data = $this->normalize($data);
     $serializer = ActivityObject::getSerializer();
     $model = $serializer->hydrate($model, $data);
     $this->hydrateRelationships($model, $data);
     // dispatch pre save hooks
     $this->dispatch(ActivityObjectEvent::PRE_UPDATE, $model, $data);
     $this->dispatch(ActivityObjectEvent::PRE_SAVE, $model, $data);
     // validate
     $validator = $this->getValidator($model);
     if ($validator !== null && !$validator->validate($model)) {
         return new NotValid(['errors' => $validator->getValidationFailures()]);
     }
     // save and dispath post save hooks
     $rows = $model->save();
     $this->dispatch(ActivityObjectEvent::POST_UPDATE, $model, $data);
     $this->dispatch(ActivityObjectEvent::POST_SAVE, $model, $data);
     $payload = ['model' => $model];
     if ($rows === 0) {
         return new NotUpdated($payload);
     }
     return new Updated($payload);
 }