예제 #1
0
 /**
  * Rolls over (clones) a given curriculum inventory report and a subset of its associated data points.
  * @param CurriculumInventoryReportInterface $report The report to roll over.
  * @param string|null $newName Name override for the rolled-over report.
  * @param string|null $newDescription Description override for the rolled-over report.
  * @param int|null $newYear Academic year override for the rolled-over report.
  * @return CurriculumInventoryReportInterface The report created during rollover.
  */
 public function rollover(CurriculumInventoryReportInterface $report, $newName = null, $newDescription = null, $newYear = null)
 {
     /* @var CurriculumInventoryReportInterface $newReport */
     $newReport = $this->reportManager->create();
     $newReport->setStartDate($report->getStartDate());
     $newReport->setEndDate($report->getEndDate());
     $newReport->setProgram($report->getProgram());
     if (isset($newName)) {
         $newReport->setName($newName);
     } else {
         $newReport->setName($report->getName());
     }
     if (isset($newDescription)) {
         $newReport->setDescription($newDescription);
     } else {
         $newReport->setDescription($report->getDescription());
     }
     if (isset($newYear)) {
         $newReport->setYear($newYear);
     } else {
         $newReport->setYear($report->getYear());
     }
     $this->reportManager->update($newReport, false, false);
     $newLevels = [];
     $levels = $report->getAcademicLevels();
     foreach ($levels as $level) {
         /* @var CurriculumInventoryAcademicLevelInterface $newLevel */
         $newLevel = $this->academicLevelManager->create();
         $newLevel->setLevel($level->getLevel());
         $newLevel->setName($level->getName());
         $newLevel->setDescription($level->getDescription());
         $newReport->addAcademicLevel($newLevel);
         $newLevel->setReport($newReport);
         $this->academicLevelManager->update($newLevel, false, false);
         $newLevels[$newLevel->getLevel()] = $newLevel;
     }
     // recursively rollover sequence blocks.
     $topLevelBlocks = $report->getSequenceBlocks()->filter(function (CurriculumInventorySequenceBlockInterface $block) {
         return is_null($block->getParent());
     });
     foreach ($topLevelBlocks as $block) {
         $this->rolloverSequenceBlock($block, $newReport, $newLevels, null);
     }
     $sequence = $report->getSequence();
     /* @var  CurriculumInventorySequenceInterface $newSequence */
     $newSequence = $this->sequenceManager->create();
     $newSequence->setDescription($sequence->getDescription());
     $newReport->setSequence($newSequence);
     $newSequence->setReport($newReport);
     $this->sequenceManager->update($newSequence, true, false);
     // flush here.
     // generate token after the fact and persist report once more.
     $newReport->generateToken();
     $this->reportManager->update($newReport, true, true);
     return $newReport;
 }
 /**
  * @param CurriculumInventoryReportInterface $report
  * @param Router $router
  */
 public function __construct(CurriculumInventoryReportInterface $report, Router $router)
 {
     $this->absoluteFileUri = $router->generate('ilios_core_downloadcurriculuminventoryreport', ['token' => $report->getToken()], UrlGenerator::ABSOLUTE_URL);
     $this->id = $report->getId();
     $this->name = $report->getName();
     $this->description = $report->getDescription();
     $this->year = $report->getYear();
     $this->startDate = $report->getStartDate();
     $this->endDate = $report->getEndDate();
     $this->export = (string) $report->getExport();
     $this->sequence = (string) $report->getSequence();
     $this->program = (string) $report->getProgram();
     $sequenceBlockIds = $report->getSequenceBlocks()->map(function (CurriculumInventorySequenceBlockInterface $block) {
         return (string) $block;
     });
     $this->sequenceBlocks = $sequenceBlockIds->toArray();
     $academicLevelIds = $report->getAcademicLevels()->map(function (CurriculumInventoryAcademicLevelInterface $level) {
         return (string) $level;
     });
     $this->academicLevels = $academicLevelIds->toArray();
 }