public function createOrganization(User $user)
    {
        $organization = new $this->organizationClass;
        $organization->setOwner($user);
        $organization->addUser($user);

        $role = new Role;
        $role->setRoles(array('ROLE_ORGANIZATION_OWNER'));
        $role->setUser($user);
        $role->setOrganization($organization);

        $contact = $user->getContact();

        if (!$contact) {
            $contact = new Contact;
            $user->setContact($contact);
        }

        $organizationContact = clone $user->getContact();
        $organization->setContact($organizationContact);
        $user->setActiveOrganization($organization);
        $user->setActiveRole($role);

        $this->dm->persist($user);
        $this->dm->persist($role);
        $this->dm->persist($contact);
        $this->dm->persist($organizationContact);
        $this->dm->persist($organization);
        $this->dm->flush();

        $this->eventDispatcher->dispatch(
            'wc_user.organization.create',
            new GenericEvent('wc_user.organization.create', array(
                'notifyUser'                => $user,
                'notifyOrganizationTrigger' => $organization,
                'notifyOrganizations'       => [$organization],
                'data'                      => [
                    'organization' => $organization
                ]
            ))
        );

        return $organization;
    }
public function createOrganization(User $user)
    {
        $organization = new $this->organizationClass;
        $organization->setOwner($user);
        $organization->addUser($user);

        $role = new Role;
        $role->setRoles(array('ROLE_ORGANIZATION_OWNER'));
        $role->setUser($user);
        $role->setOrganization($organization);

        $contact = $user->getContact();

        if (!$contact) {
            $contact = new Contact;
            $user->setContact($contact);
        }

        $organizationContact = clone $user->getContact();
        $organization->setContact($organizationContact);
        $user->setActiveOrganization($organization);
        $user->setActiveRole($role);

        $this->dm->persist($user);
        $this->dm->persist($role);
        $this->dm->persist($contact);
        $this->dm->persist($organizationContact);
        $this->dm->persist($organization);
        $this->dm->flush();

        $this->eventDispatcher->dispatch(
            'wc_user.organization.create',
            new GenericEvent('wc_user.organization.create', array(
                'notifyUser'                => $user,
                'notifyOrganizationTrigger' => $organization,
                'notifyOrganizations'       => [$organization],
                'data'                      => [
                    'organization' => $organization
                ]
            ))
        );

        return $organization;
    }
public function createOrganization ( User $ user ) { $ organization = new $ this -> organizationClass ; $ organization -> setOwner ( $ user ) ; $ organization -> addUser ( $ user ) ; $ role = new Role ; $ role -> setRoles ( array ( 'ROLE_ORGANIZATION_OWNER' ) ) ; $ role -> setUser ( $ user ) ; $ role -> setOrganization ( $ organization ) ; $ contact = $ user -> getContact ( ) ; if ( ! $ contact ) { $ contact = new Contact ; $ user -> setContact ( $ contact ) ; } $ organizationContact = clone $ user -> getContact ( ) ; $ organization -> setContact ( $ organizationContact ) ; $ user -> setActiveOrganization ( $ organization ) ; $ user -> setActiveRole ( $ role ) ; $ this -> dm -> persist ( $ user ) ; $ this -> dm -> persist ( $ role ) ; $ this -> dm -> persist ( $ contact ) ; $ this -> dm -> persist ( $ organizationContact ) ; $ this -> dm -> persist ( $ organization ) ; $ this -> dm -> flush ( ) ; $ this -> eventDispatcher -> dispatch ( 'wc_user.organization.create' , new GenericEvent ( 'wc_user.organization.create' , array ( 'notifyUser' => $ user , 'notifyOrganizationTrigger' => $ organization , 'notifyOrganizations' => [ $ organization ] , 'data' => [ 'organization' => $ organization ] ) ) ) ; return $ organization ; }
It creates and completes a new Organization

@param OrganizationInterface $organization New empty organization
@param User         $user         User that owns the organizartion

@return Organization The new organization
It creates and completes a new Organization