当前位置: 首页>>代码示例>>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;未经允许,请勿转载。