public function fillUser($data) { // Org User if (UserConstants::ROLE_ORG_USER == $data['role'] || UserConstants::ROLE_ORG_ADMIN_USER == $data['role']) { $user = OrganizationUser::fromJson($data); } else { $user = BeneficiaryUser::fromJson($data); } // Add common data $roleRepository = $this->em->getRepository('AmisureP4SApiBundle:Role'); $user->addRole($roleRepository->findOneBy(array('role' => UserConstants::ROLE_USER))); $user->addRole($roleRepository->findOneBy(array('role' => $data['role']))); return $user; }
public function getOrganizationUserProfile($criteria = array()) { if (empty($criteria)) { throw new \Exception('Unknown beneficiary\'s contact with these empty criteria'); } $data = null; try { $request = null; if (array_key_exists('organizationType', $criteria) || array_key_exists('beneficiaryId', $criteria) || array_key_exists('id', $criteria)) { $request = $this->client->get('organizations/users', array(), array('query' => $criteria)); } else { throw new \Exception('Unknown beneficiary\'s contact with these given criteria'); } $response = $request->send()->json(); if (StatusConstants::OK == $response['status']) { if (empty($response['data'])) { return null; } $data = array(); foreach ($response['data'] as $user) { $data[] = OrganizationUser::fromJson($user); } } else { throw new \Exception($response['message'], StatusConstants::toCode($response['status'])); } } catch (\Exception $e) { throw new \Exception('Erreur lors de l\'appel au P4S : getOrganizationUserProfile()', StatusConstants::toCode(StatusConstants::UNKNOWN_ERROR), $e); } return $data; }