public static function fromJson($data)
 {
     $id = null;
     if (array_key_exists('org_user_id', $data)) {
         $id = $data['org_user_id'];
     } elseif (array_key_exists('id', $data)) {
         $id = $data['id'];
     }
     $user = new OrganizationUser($id, @$data['title'], @$data['first_name'], @$data['last_name'], array('address' => @$data['address'], 'zipcode' => @$data['zipcode'], 'city' => @$data['city']), @$data['email'], @$data['fixed_phone'], @$data['mobile_phone'], '', @$data['organization_type'], @$data['role'], @$data['sub_role']);
     $user->setId($id);
     return $user;
 }
示例#2
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 function addOrganization(OrganizationUser $organization)
 {
     $organization->addBeneficiary($this);
     if (!$this->organizations->contains($organization)) {
         $this->organizations->add($organization);
     }
     return $this;
 }
示例#4
0
 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;
 }