示例#1
0
 /**
  * Recursively copies nested sequence blocks for rollover.
  *
  * @param CurriculumInventorySequenceBlockInterface $block The block to copy.
  * @param CurriculumInventoryReportInterface $newReport The new report to roll over into.
  * @param CurriculumInventoryAcademicLevelInterface[] $newLevels A map of new academic levels, indexed by level.
  * @param CurriculumInventorySequenceBlockInterface|null $newParent The new parent block for this copy.
  */
 protected function rolloverSequenceBlock(CurriculumInventorySequenceBlockInterface $block, CurriculumInventoryReportInterface $newReport, array $newLevels, CurriculumInventorySequenceBlockInterface $newParent = null)
 {
     /* @var CurriculumInventorySequenceBlockInterface $newBlock */
     $newBlock = $this->sequenceBlockManager->create();
     $newBlock->setReport($newReport);
     $newBlock->setAcademicLevel($newLevels[$block->getAcademicLevel()->getLevel()]);
     $newBlock->setDescription($block->getDescription());
     $newBlock->setEndDate($block->getEndDate());
     $newBlock->setStartDate($block->getStartDate());
     $newBlock->setChildSequenceOrder($block->getChildSequenceOrder());
     $newBlock->setDuration($block->getDuration());
     $newBlock->setTitle($block->getTitle());
     $newBlock->setOrderInSequence($block->getOrderInSequence());
     $newBlock->setMinimum($block->getMinimum());
     $newBlock->setMaximum($block->getMaximum());
     $newBlock->setTrack($block->hasTrack());
     $newBlock->setRequired($block->getRequired());
     if ($newParent) {
         $newBlock->setParent($newParent);
         $newParent->addChild($newBlock);
     }
     $newReport->addSequenceBlock($newBlock);
     $this->sequenceBlockManager->update($newBlock, false, false);
     foreach ($block->getChildren() as $child) {
         $this->rolloverSequenceBlock($child, $newReport, $newLevels, $newBlock);
     }
 }
示例#2
0
 /**
  * @param SessionInterface     $newSession
  * @param SessionInterface     $origSession
  * @param $daysOffset
  */
 protected function rolloverIlmSession(SessionInterface $newSession, SessionInterface $origSession, $daysOffset)
 {
     /* @var IlmSessionInterface $origIlmSession */
     if ($origIlmSession = $origSession->getIlmSession()) {
         /* @var IlmSessionInterface $newIlmSession */
         $newIlmSession = $this->ilmSessionManager->create();
         $newIlmSession->setHours($origIlmSession->getHours());
         $newSession->setIlmSession($newIlmSession);
         $newDueDate = $this->getAdjustedDate($origIlmSession->getDueDate(), $daysOffset);
         $newIlmSession->setDueDate($newDueDate);
         $this->ilmSessionManager->update($newIlmSession, false, false);
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // prevent this command to run on a non-empty user store.
     $existingUser = $this->userManager->findOneBy([]);
     if (!empty($existingUser)) {
         throw new \Exception('Sorry, at least one user record already exists. Cannot create a "first" user account.');
     }
     $schools = $this->schoolManager->findBy([], ['title' => 'ASC']);
     // check if any school data is present before invoking the form helper
     // to prevent the form from breaking on missing school data further downstream.
     if (empty($schools)) {
         throw new \Exception('No schools found. Please load schools into this Ilios instance first.');
     }
     $schoolId = $input->getOption('school');
     if (!$schoolId) {
         $schoolTitles = [];
         /* @var SchoolInterface $school */
         foreach ($schools as $school) {
             $schoolTitles[$school->getTitle()] = $school->getId();
         }
         $helper = $this->getHelper('question');
         $question = new ChoiceQuestion("What is this user's primary school?", array_keys($schoolTitles));
         $question->setErrorMessage('School %s is invalid.');
         $schoolTitle = $helper->ask($input, $output, $question);
         $schoolId = $schoolTitles[$schoolTitle];
     }
     $school = $this->schoolManager->findOneBy(['id' => $schoolId]);
     if (!$school) {
         throw new \Exception("School with id {$schoolId} could not be found.");
     }
     $email = $input->getOption('email');
     if (!$email) {
         $question = new Question("What is the user's Email Address? ");
         $question->setValidator(function ($answer) {
             if (!filter_var($answer, FILTER_VALIDATE_EMAIL)) {
                 throw new \RuntimeException("Email is not valid");
             }
             return $answer;
         });
         $email = $this->getHelper('question')->ask($input, $output, $question);
     }
     $user = $this->userManager->create();
     $user->setFirstName(self::FIRST_NAME);
     $user->setMiddleName(date('Y-m-d_h.i.s'));
     $user->setLastName(self::LAST_NAME);
     $user->setEmail($email);
     $user->setAddedViaIlios(true);
     $user->setEnabled(true);
     $user->setUserSyncIgnore(false);
     $user->addRole($this->userRoleManager->findOneBy(['title' => 'Developer']));
     $user->addRole($this->userRoleManager->findOneBy(['title' => 'Course Director']));
     $user->setSchool($school);
     $this->userManager->update($user);
     $authentication = $this->authenticationManager->create();
     $authentication->setUser($user);
     $user->setAuthentication($authentication);
     $encodedPassword = $this->passwordEncoder->encodePassword($user, self::PASSWORD);
     $authentication->setUsername(self::USERNAME);
     $authentication->setPasswordBcrypt($encodedPassword);
     $this->authenticationManager->update($authentication);
     $output->writeln('Success!');
     $output->writeln('A user account has been created.');
     $output->writeln(sprintf("You may now log in as '%s' with the password '%s'.", self::USERNAME, self::PASSWORD));
     $output->writeln('Please change this password as soon as possible.');
 }