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
519844
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;
    }
565515
protected function create_item_folder(cc_i_organization &$org, DOMDocument &$doc, DOMElement &$xmlnode = null) {

        $itemfoldernode = $doc->createElementNS($this->ccnamespaces['imscc'], 'item');
        $this->update_attribute($doc, 'identifier', "root", $itemfoldernode);

        if ($org->has_items()) {
            $this->update_items($org->itemlist, $doc, $itemfoldernode);
        }
        if (is_null($this->organizations)) {
            $this->organizations = array();
        }
        $this->organizations[$org->identifier] = $org;

        $xmlnode->appendChild($itemfoldernode);
    }
1052512
public function addMemberByInvitation(OrganizationInterface $organization, User $user, Invitation $invitation)
    {
        $this->addMember($organization, $user, $invitation->getRoles());

        $invitation->setStatus('accepted');
        $invitation->setTo($user);
        $this->dm->persist($invitation);
        $this->dm->flush();
    }
946390
public function getUserOrg($user, $org)
	{
		// Build the request path.
		$path = '/users/' . $user . '/events/orgs/' . $org;

		return $this->processResponse(
			$this->client->get($this->fetchUrl($path))
		);
	}
1070011
public function serialize(Organization $organization, array $options = [])
    {
        $data = [
            'id' => $organization->getUuid(),
            'name' => $organization->getName(),
            'code' => $organization->getCode(),
            'email' => $organization->getEmail(),
            'type' => $organization->getType(),
            'parent' => !empty($organization->getParent()) ? [
                'id' => $organization->getParent()->getUuid(),
                'name' => $organization->getParent()->getName(),
            ] : null,
            'meta' => [
                'default' => $organization->getDefault(),
                'position' => $organization->getPosition(),
            ],
            'managers' => array_map(function (User $administrator) {
                return [
                    'id' => $administrator->getId(),
                    'username' => $administrator->getUsername(),
                ];
            }, $organization->getAdministrators()->toArray()),
            'locations' => array_map(function (Location $location) {
                return [
                    'id' => $location->getId(),
                    'name' => $location->getName(),
                ];
            }, $organization->getLocations()->toArray()),
        ];

        if (in_array(Options::IS_RECURSIVE, $options)) {
            $data['children'] = array_map(function (Organization $child) use ($options) {
                return $this->serialize($child, $options);
            }, $organization->getChildren()->toArray());
        }

        return $data;
    }
1068672
public function addUser(User $user)
    {
        if (!$this->users->contains($user)) {
            $this->users->add($user);
        }

        return $this;
    }
1154861
public function teamCreateFormAction(Workspace $workspace, User $user)
    {
        $this->checkWorkspaceManager($workspace, $user);
        $params = $this->teamManager->getParametersByWorkspace($workspace);
        $team = new Team();
        $team->setIsPublic($params->getIsPublic());
        $team->setSelfRegistration($params->getSelfRegistration());
        $team->setSelfUnregistration($params->getSelfUnregistration());

        $form = $this->formFactory->create(new TeamType(), $team);

        return array(
            'form' => $form->createView(),
            'workspace' => $workspace
        );
    }
1132739
private function doDeleteFolder(FolderInterface $folder, $userId)
    {
        foreach ($this->findFoldersByParentFolder($folder) as $subFolder) {
            $this->deleteFolder($subFolder, $userId);
        }

        foreach ($this->findFilesByFolder($folder) as $file) {
            $this->deleteFile($file, $userId);
        }

        $event = new FolderEvent($folder);
        if ($this->eventDispatcher->dispatch(VolumeEvents::BEFORE_DELETE_FOLDER, $event)->isPropagationStopped()) {
            throw new IOException("Delete folder {$folder->getName()} cancelled.");
        }

        $this->driver->deleteFolder($folder, $userId);

        $event = new FolderEvent($folder);
        $this->eventDispatcher->dispatch(VolumeEvents::DELETE_FOLDER, $event);

        return $folder;
    }
1023652
def user_organization_membership_create(self, user_id, data, **kwargs):
        ""
        api_path = "/api/v2/users/{user_id}/organization_memberships.json"
        api_path = api_path.format(user_id=user_id)
        return self.call(api_path, method="POST", data=data, **kwargs)
1243922
protected function createPersonalWorkspace(User $user, Account $account)
    {
        $userWorkspaceName = UserUtility::getPersonalWorkspaceNameForUsername($account->getAccountIdentifier());
        $userWorkspace = $this->workspaceRepository->findByIdentifier($userWorkspaceName);
        if ($userWorkspace === null) {
            $liveWorkspace = $this->workspaceRepository->findByIdentifier('live');
            if (!($liveWorkspace instanceof Workspace)) {
                $liveWorkspace = new Workspace('live');
                $liveWorkspace->setTitle('Live');
                $this->workspaceRepository->add($liveWorkspace);
            }

            $userWorkspace = new Workspace($userWorkspaceName, $liveWorkspace, $user);
            $userWorkspace->setTitle((string)$user->getName());
            $this->workspaceRepository->add($userWorkspace);
        }
    }
99200
public function createOrganization(Organization $org, $createDefaultUsers = true)
	{
        $url = self::makeUrl(null, array('createDefaultUsers' => $createDefaultUsers));
        $data = json_encode($org);
        $this->service->prepAndSend($url, array(201), 'POST', $data, false, 'application/json', 'application/json');
    }
221003
private function createAddLinkGroupCenterForm(User $user)
    {
        return $this->createFormBuilder()
                ->setAction($this->generateUrl('admin_user_add_group_center', 
                        array('uid' => $user->getId())))
                ->setMethod('POST')
                ->add(self::FORM_GROUP_CENTER_COMPOSED, new ComposedGroupCenterType())
                ->add('submit', 'submit', array('label' => 'Add a new groupCenter'))
                ->getForm()
                ;
    }
29007
protected function processUserGroups(UserInterface $user, $userGroups)
    {
        $get = function($entity) {
            /* @var UserInterface $entity */
            return $entity->getId();
        };

        $delete = function($userGroup) use ($user) {
            $user->removeUserGroup($userGroup);
            $this->em->remove($userGroup);
        };

        $update = function($userGroup, $userGroupData) {
            return $this->updateUserGroup($userGroup, $userGroupData);
        };

        $add = function($userGroup) use ($user) {
            return $this->addUserGroup($user, $userGroup);
        };

        $entities = $user->getUserGroups();

        $result = $this->processSubEntities(
            $entities,
            $userGroups,
            $get,
            $add,
            $update,
            $delete
        );

        $this->resetIndexOfSubentites($entities);

        return $result;
    }
438232
public function getFavouriteAccountsForUser(UserInterface $user)
    {
        $criteria = new Criteria();
        $criteria
            ->where($criteria->expr()->in(
                'id',
                $user->getMyFavouriteAccountIds()
            ))
        ;

        return $this->oh->getOrganization()
            ->getAccounts()
            ->matching($criteria)
        ;
    }
255106
public function create(UserInterface $user)
    {
        $entity = static::ENTITY_CLASSNAME;

        $reminder = new $entity($user);

        $this->save($reminder);

        return $reminder;
    }
684216
public function createDefaultOrganization()
    {
        $organization = new Organization();
        $organization->setName($this->getUsername());

        $this->organizations[] = $organization;
    }
943462
public function addUser(\FOM\UserBundle\Entity\User $user)
    {
        $this->users[] = $user;
        $user->addGroup($this);
        return $this;
    }