getPreferences() public method

Returns all preferences for the given user.
public getPreferences ( User $user ) : UserPreference[]
$user PartKeepr\AuthBundle\Entity\User The user
return PartKeepr\AuthBundle\Entity\UserPreference[] An array of UserPreference objects
 /**
  * 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);
 }
Example #2
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;
 }