/**
  * Retrieves a collection of resources.
  *
  * @param Request $request
  *
  * @throws \Exception                                 If the format is invalid
  * @throws RuntimeException|RootNodeNotFoundException
  *
  * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
  */
 public function __invoke(Request $request)
 {
     $user = $this->userService->getUser();
     if ($request->request->has('preferenceKey')) {
         $this->userPreferenceService->deletePreference($user, $request->request->get('preferenceKey'));
     } else {
         throw new \Exception('Invalid format');
     }
 }
Пример #2
0
 /**
  * Retrieves a collection of resources.
  *
  * @param Request $request
  *
  * @throws RuntimeException|RootNodeNotFoundException
  *
  * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
  */
 public function __invoke(Request $request)
 {
     $user = $this->userService->getUser();
     $preferences = $this->userPreferenceService->getPreferences($user);
     list($resourceType) = $this->extractAttributes($request);
     /*
      * @var ResourceInterface $resourceType
      */
     $serializedData = $this->serializer->normalize($preferences, 'json', $resourceType->getNormalizationContext());
     return new JsonResponse($serializedData);
 }
Пример #3
0
 public function __invoke(Request $request)
 {
     $user = $this->userService->getUser();
     $userPreferences = $this->userPreferenceService->getPreferences($user);
     $arrayUserPreferences = array();
     foreach ($userPreferences as $userPreference) {
         $arrayUserPreferences[] = array("preferenceKey" => $userPreference->getPreferenceKey(), "preferenceValue" => $userPreference->getPreferenceValue());
     }
     $user->setInitialUserPreferences(json_encode($arrayUserPreferences));
     return $user;
 }
Пример #4
0
 /**
  * Returns an item to delete.
  *
  * @param Request    $request
  * @param string|int $id
  *
  * @throws NotFoundHttpException
  * @throws RuntimeException
  * @throws UserProtectedException
  *
  * @return mixed
  */
 public function __invoke(Request $request, $id)
 {
     list($resourceType) = $this->extractAttributes($request);
     /**
      * @var User
      */
     $item = $this->getItem($this->dataProvider, $resourceType, $id);
     if ($item->isProtected()) {
         throw new UserProtectedException();
     }
     $this->userService->deleteFOSUser($item);
     $this->userPreferenceService->deletePreferences($item);
     return $item;
 }
Пример #5
0
 /**
  * Retrieves a collection of resources.
  *
  * @param Request $request
  *
  * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
  * @throws \Exception If the format is invalid
  *
  * @throws RuntimeException|RootNodeNotFoundException
  */
 public function __invoke(Request $request)
 {
     $user = $this->userService->getUser();
     $data = json_decode($request->getContent());
     if (property_exists($data, "preferenceKey") && property_exists($data, "preferenceValue")) {
         $preference = $this->userPreferenceService->setPreference($user, $data->preferenceKey, $data->preferenceValue);
     } else {
         throw new \Exception("Invalid format");
     }
     list($resourceType) = $this->extractAttributes($request);
     /**
      * @var ResourceInterface $resourceType
      */
     $serializedData = $this->serializer->normalize($preference, 'json', $resourceType->getNormalizationContext());
     return new JsonResponse($serializedData);
 }