當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::setOrganizations方法代碼示例

本文整理匯總了PHP中Claroline\CoreBundle\Entity\User::setOrganizations方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::setOrganizations方法的具體用法?PHP User::setOrganizations怎麽用?PHP User::setOrganizations使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Claroline\CoreBundle\Entity\User的用法示例。


在下文中一共展示了User::setOrganizations方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: createUser

 /**
  * Create a user.
  * Its basic properties (name, username,... ) must already be set.
  *
  * @param \Claroline\CoreBundle\Entity\User $user
  * @param boolean                           $sendMail         do we need to mail the new user ?
  * @param array                             $additionnalRoles a list of additionalRoles
  * @param Model                             $model            a model to create workspace
  *
  * @return \Claroline\CoreBundle\Entity\User
  */
 public function createUser(User $user, $sendMail = true, $rolesToAdd = array(), $model = null, $publicUrl = null, $organizations = array())
 {
     $additionnalRoles = [];
     foreach ($rolesToAdd as $roleToAdd) {
         if (is_string($roleToAdd)) {
             $additionnalRoles[] = $this->roleManager->getRoleByName($roleToAdd);
         }
     }
     if (count($organizations) === 0 && count($user->getOrganizations()) === 0) {
         $organizations = array($this->organizationManager->getDefault());
         $user->setOrganizations($organizations);
     }
     $this->objectManager->startFlushSuite();
     if ($this->personalWorkspaceAllowed($additionnalRoles)) {
         $this->setPersonalWorkspace($user, $model);
     }
     $user->setGuid($this->container->get('claroline.utilities.misc')->generateGuid());
     $user->setEmailValidationHash($this->container->get('claroline.utilities.misc')->generateGuid());
     $this->objectManager->persist($user);
     $publicUrl ? $user->setPublicUrl($publicUrl) : $user->setPublicUrl($this->generatePublicUrl($user));
     $this->toolManager->addRequiredToolsToUser($user, 0);
     $this->toolManager->addRequiredToolsToUser($user, 1);
     $this->roleManager->setRoleToRoleSubject($user, PlatformRoles::USER);
     $this->objectManager->persist($user);
     $this->strictEventDispatcher->dispatch('log', 'Log\\LogUserCreate', array($user));
     $this->roleManager->createUserRole($user);
     foreach ($additionnalRoles as $role) {
         if ($role) {
             $this->roleManager->associateRole($user, $role);
         }
     }
     if ($this->mailManager->isMailerAvailable() && $sendMail) {
         //send a validation by hash
         $mailValidation = $this->platformConfigHandler->getParameter('registration_mail_validation');
         if ($mailValidation === PlatformConfiguration::REGISTRATION_MAIL_VALIDATION_FULL) {
             $password = sha1(rand(1000, 10000) . $user->getUsername() . $user->getSalt());
             $user->setResetPasswordHash($password);
             $user->setIsEnabled(false);
             $this->objectManager->persist($user);
             $this->objectManager->flush();
             $this->mailManager->sendEnableAccountMessage($user);
         } elseif ($mailValidation === PlatformConfiguration::REGISTRATION_MAIL_VALIDATION_PARTIAL) {
             //don't change anything
             $this->mailManager->sendCreationMessage($user);
         }
     }
     $this->container->get('claroline.event.event_dispatcher')->dispatch('user_created_event', 'UserCreated', array('user' => $user));
     $this->objectManager->endFlushSuite();
     return $user;
 }
開發者ID:ngydat,項目名稱:CoreBundle,代碼行數:61,代碼來源:UserManager.php


注:本文中的Claroline\CoreBundle\Entity\User::setOrganizations方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。