当前位置: 首页>>代码示例>>PHP>>正文


PHP User::setAdministrativeCode方法代码示例

本文整理汇总了PHP中Claroline\CoreBundle\Entity\User::setAdministrativeCode方法的典型用法代码示例。如果您正苦于以下问题:PHP User::setAdministrativeCode方法的具体用法?PHP User::setAdministrativeCode怎么用?PHP User::setAdministrativeCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Claroline\CoreBundle\Entity\User的用法示例。


在下文中一共展示了User::setAdministrativeCode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: load

 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $objectManager)
 {
     /** @var \Claroline\CoreBundle\Manager\UserManager $userCreator */
     $userCreator = $this->container->get('claroline.manager.user_manager');
     /** @var \Claroline\CoreBundle\Manager\RoleManager $roleManager */
     $roleManager = $this->container->get('claroline.manager.role_manager');
     /** @var \Claroline\CoreBundle\Repository\ResourceNodeRepository $resourceRepo */
     $resourceRepo = $objectManager->getRepository('ClarolineCoreBundle:Resource\\ResourceNode');
     foreach ($this->users as $names => $role) {
         $namesArray = explode(' ', $names);
         $firstName = $namesArray[0];
         $lastName = isset($namesArray[1]) ? $namesArray[1] : '';
         $username = $firstName . ucfirst($lastName);
         $user = new User();
         $user->setAdministrativeCode('UCL-' . $username . '-' . rand(0, 1000));
         $user->setFirstName($firstName);
         $lastName = $lastName == '' ? 'Doe' : $lastName;
         $user->setLastName($lastName);
         $user->setUserName($username);
         $user->setPlainPassword($username);
         $user->setMail('mail_' . uniqid() . '@claroline.net');
         $objectManager->persist($user);
         $roleManager->associateRole($user, $this->getReference("role/{$role}"));
         if ($this->withWorkspace) {
             $userCreator->createUser($user);
             $this->addReference("workspace/{$names}", $user->getPersonalWorkspace());
             $this->addReference("directory/{$names}", $resourceRepo->findWorkspaceRoot($user->getPersonalWorkspace()));
         } else {
             $objectManager->persist($user);
         }
         $this->addReference("user/{$names}", $user);
         $objectManager->flush();
     }
 }
开发者ID:ngydat,项目名称:CoreBundle,代码行数:37,代码来源:LoadUserData.php

示例2: importUsers

 /**
  * Import users from an array.
  * There is the array format:
  * @todo some batch processing
  *
  * array(
  *     array(firstname, lastname, username, pwd, email, code, phone),
  *     array(firstname2, lastname2, username2, pwd2, email2, code2, phone2),
  *     array(firstname3, lastname3, username3, pwd3, email3, code3, phone3),
  * )
  *
  * @param array    $users
  * @param string   $authentication an authentication source
  * @param boolean  $mail           do the users need to be mailed
  * @param \Closure $logger         an anonymous function allowing to log actions
  *
  * @return array
  */
 public function importUsers(array $users, $sendMail = true, $logger = null, $additionalRoles = array())
 {
     $returnValues = array();
     //keep these roles before the clear() will mess everything up. It's not what we want.
     $tmpRoles = $additionalRoles;
     $additionalRoles = [];
     //I need to do that to import roles from models. Please don't ask why, I have no fucking idea.
     $this->objectManager->clear();
     foreach ($tmpRoles as $role) {
         if ($role) {
             $additionalRoles[] = $this->objectManager->merge($role);
         }
     }
     $roleUser = $this->roleManager->getRoleByName('ROLE_USER');
     $max = $roleUser->getMaxUsers();
     $total = $this->countUsersByRoleIncludingGroup($roleUser);
     if ($total + count($users) > $max) {
         throw new AddRoleException();
     }
     $lg = $this->platformConfigHandler->getParameter('locale_language');
     $this->objectManager->startFlushSuite();
     $i = 1;
     $j = 0;
     foreach ($users as $user) {
         $firstName = $user[0];
         $lastName = $user[1];
         $username = $user[2];
         $pwd = $user[3];
         $email = trim($user[4]);
         if (isset($user[5])) {
             $code = trim($user[5]) === '' ? null : $user[5];
         } else {
             $code = null;
         }
         if (isset($user[6])) {
             $phone = trim($user[6]) === '' ? null : $user[6];
         } else {
             $phone = null;
         }
         if (isset($user[7])) {
             $authentication = trim($user[7]) === '' ? null : $user[7];
         } else {
             $authentication = null;
         }
         if (isset($user[8])) {
             $modelName = trim($user[8]) === '' ? null : $user[8];
         } else {
             $modelName = null;
         }
         if ($modelName) {
             $model = $this->objectManager->getRepository('Claroline\\CoreBundle\\Entity\\Model\\WorkspaceModel')->findOneByName($modelName);
         } else {
             $model = null;
         }
         $newUser = new User();
         $newUser->setFirstName($firstName);
         $newUser->setLastName($lastName);
         $newUser->setUsername($username);
         $newUser->setPlainPassword($pwd);
         $newUser->setMail($email);
         $newUser->setAdministrativeCode($code);
         $newUser->setPhone($phone);
         $newUser->setLocale($lg);
         $newUser->setAuthentication($authentication);
         $this->createUser($newUser, $sendMail, $additionalRoles, $model, $username . uniqid());
         $this->objectManager->persist($newUser);
         $returnValues[] = $firstName . ' ' . $lastName;
         if ($logger) {
             $logger(" [UOW size: " . $this->objectManager->getUnitOfWork()->size() . "]");
         }
         if ($logger) {
             $logger(" User {$j} ({$username}) being created");
         }
         $i++;
         $j++;
         if ($i % self::MAX_USER_BATCH_SIZE === 0) {
             if ($logger) {
                 $logger(" [UOW size: " . $this->objectManager->getUnitOfWork()->size() . "]");
             }
             $this->objectManager->forceFlush();
             if ($logger) {
                 $logger(" flushing users...");
//.........这里部分代码省略.........
开发者ID:ngydat,项目名称:CoreBundle,代码行数:101,代码来源:UserManager.php

示例3: validate

 public function validate($value, Constraint $constraint)
 {
     $mode = $constraint->getDefaultOption();
     $lines = str_getcsv(file_get_contents($value), PHP_EOL);
     $authDrivers = $this->authenticationManager->getDrivers();
     foreach ($lines as $line) {
         $linesTab = explode(';', $line);
         $nbElements = count($linesTab);
         if (trim($line) != '') {
             if ($nbElements < 5) {
                 $this->context->addViolation($constraint->message);
                 return;
             }
         }
     }
     $usernames = array();
     $mails = array();
     if ($mode === 1) {
         $currentDate = new \DateTime();
         $timestamp = $currentDate->getTimestamp();
         $fakeUsername = '@@@fake_username_' . $timestamp . '@@@';
         $fakeMail = 'fake_email_' . $timestamp . '@fake-' . $timestamp . '-claroline-connect.com';
     }
     foreach ($lines as $i => $line) {
         if (trim($line) != '') {
             $user = explode(';', $line);
             $firstName = $user[0];
             $lastName = $user[1];
             $username = $user[2];
             $pwd = $user[3];
             $email = $user[4];
             if (isset($user[5])) {
                 $code = trim($user[5]) === '' ? null : $user[5];
             } else {
                 $code = null;
             }
             if (isset($user[6])) {
                 $phone = trim($user[6]) === '' ? null : $user[6];
             } else {
                 $phone = null;
             }
             if (isset($user[7])) {
                 $authentication = trim($user[7]) === '' ? null : $user[7];
             } else {
                 $authentication = null;
             }
             if (isset($user[8])) {
                 $modelName = trim($user[7]) === '' ? null : $user[7];
             } else {
                 $modelName = null;
             }
             !array_key_exists($email, $mails) ? $mails[$email] = array($i + 1) : ($mails[$email][] = $i + 1);
             !array_key_exists($username, $usernames) ? $usernames[$username] = array($i + 1) : ($usernames[$username][] = $i + 1);
             $existingUser = null;
             if ($mode === 1) {
                 try {
                     $existingUser = $this->userManager->getUserByUsernameOrMail($username, $email);
                 } catch (NonUniqueResultException $e) {
                     $msg = $this->translator->trans('line_number', array('%line%' => $i + 1), 'platform');
                     $msg .= ' ' . $this->translator->trans('username_and_email_from_two_different_users', array('%username%' => $username, '%email%' => $email), 'platform');
                     $this->context->addViolation($msg);
                     continue;
                 }
             }
             if (!is_null($existingUser)) {
                 // For an update, we will validate user with a fake username and email
                 $upperExistingUsername = strtoupper(trim($existingUser->getUsername()));
                 $upperExistingMail = strtoupper(trim($existingUser->getMail()));
                 $upperUsername = strtoupper(trim($username));
                 $upperMail = strtoupper(trim($email));
                 if ($upperExistingUsername === $upperUsername && $upperExistingMail === $upperMail) {
                     $existingUser->setUsername($fakeUsername);
                     $existingUser->setMail($fakeMail);
                 } elseif ($upperExistingUsername === $upperUsername) {
                     $existingUser->setUsername($fakeUsername);
                     $existingUser->setMail($email);
                 } else {
                     $existingUser->setUsername($username);
                     $existingUser->setMail($fakeMail);
                 }
                 $existingUser->setFirstName($firstName);
                 $existingUser->setLastName($lastName);
                 $existingUser->setPlainPassword($pwd);
                 $existingUser->setAdministrativeCode($code);
                 $existingUser->setPhone($phone);
                 $errors = $this->validator->validate($existingUser, array('registration', 'Default'));
                 $existingUser->setUsername($username);
                 $existingUser->setMail($email);
             } else {
                 $newUser = new User();
                 $newUser->setFirstName($firstName);
                 $newUser->setLastName($lastName);
                 $newUser->setUsername($username);
                 $newUser->setPlainPassword($pwd);
                 $newUser->setMail($email);
                 $newUser->setAdministrativeCode($code);
                 $newUser->setPhone($phone);
                 $errors = $this->validator->validate($newUser, array('registration', 'Default'));
             }
             if ($authentication) {
//.........这里部分代码省略.........
开发者ID:ChMat,项目名称:CoreBundle,代码行数:101,代码来源:CsvUserValidator.php

示例4: importUsers


//.........这里部分代码省略.........
         } else {
             $group = null;
         }
         $userEntity = $this->userRepo->findOneByMail($email);
         if (!$userEntity) {
             $userEntity = $this->userRepo->findOneByUsername($username);
             if (!$userEntity && $code !== null) {
                 //the code isn't required afaik
                 $userEntity = $this->userRepo->findOneByAdministrativeCode($code);
             }
         }
         if ($userEntity && $options['ignore-update']) {
             if ($logger) {
                 $logger(" Skipping  {$userEntity->getUsername()}...");
             }
             continue;
         }
         $isNew = false;
         if (!$userEntity) {
             $isNew = true;
             $userEntity = new User();
             $userEntity->setPlainPassword($pwd);
             ++$countCreated;
         } else {
             if (!empty($pwd)) {
                 $userEntity->setPlainPassword($pwd);
             }
             ++$countUpdated;
         }
         $userEntity->setUsername($username);
         $userEntity->setMail($email);
         $userEntity->setFirstName($firstName);
         $userEntity->setLastName($lastName);
         $userEntity->setAdministrativeCode($code);
         $userEntity->setPhone($phone);
         $userEntity->setLocale($lg);
         $userEntity->setAuthentication($authentication);
         $userEntity->setIsMailNotified($isMailNotified);
         $userEntity->setIsMailValidated($isMailValidated);
         if ($options['single-validate']) {
             $errors = $this->validator->validate($userEntity);
             if (count($errors) > 0) {
                 $skipped[$i] = $userEntity;
                 if ($isNew) {
                     --$countCreated;
                 } else {
                     --$countUpdated;
                 }
                 continue;
             }
         }
         if (!$isNew && $logger) {
             $logger(" User {$j} ({$username}) being updated...");
             $this->roleManager->associateRoles($userEntity, $additionalRoles);
         }
         if ($isNew) {
             if ($logger) {
                 $logger(" User {$j} ({$username}) being created...");
             }
             $this->createUser($userEntity, $sendMail, $additionalRoles, $model, $username . uniqid(), $organizations, $hasPersonalWorkspace, false);
         }
         $this->objectManager->persist($userEntity);
         $returnValues[] = $firstName . ' ' . $lastName;
         if ($group) {
             $this->groupManager->addUsersToGroup($group, [$userEntity]);
         }
开发者ID:claroline,项目名称:distribution,代码行数:67,代码来源:UserManager.php


注:本文中的Claroline\CoreBundle\Entity\User::setAdministrativeCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。