Example #1
0
 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 static function fromJson($data)
 {
     $id = null;
     if (array_key_exists('beneficiary_id', $data)) {
         $id = $data['beneficiary_id'];
     } elseif (array_key_exists('id', $data)) {
         $id = $data['id'];
     }
     $user = new BeneficiaryUser($id, @$data['title'], @$data['first_name'], @$data['last_name'], @$data['maiden_name'], array('address' => @$data['address'], 'zipcode' => @$data['zipcode'], 'city' => @$data['city']), @$data['email'], @$data['fixed_phone'], @$data['mobile_phone'], '', @$data['date_of_birth'], @$data['place_of_birth'], @$data['photo']);
     $user->setId($id);
     return $user;
 }
Example #3
0
 public function getBeneficiary($beneficiaryId, $profileType = 'FULL')
 {
     if (empty($beneficiaryId)) {
         throw new \Exception('Unknown beneficiary\'s profile with these given criteria');
     }
     $data = null;
     try {
         $request = $this->client->get('beneficiaries/' . $beneficiaryId, array(), array('query' => array('profile_type' => $profileType)));
         $response = $request->send()->json();
         // - Wrong result
         if (null == $response || !isset($response['status'])) {
             throw new \Exception(@$response['message'] . @$response['data']['message'], StatusConstants::UNKNWON_ERROR);
         }
         if (StatusConstants::OK != $response['status']) {
             throw new \Exception($response['message'], StatusConstants::toCode($response['status']));
         }
         $data = BeneficiaryUser::fromJson($response['beneficiary']);
     } catch (\Exception $e) {
         throw new \Exception('Erreur lors de la recherche du profil du bénéficiaire.', StatusConstants::toCode($e->getCode()), $e);
     }
     return $data;
 }