Example #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);
     }
 }
 /**
  * Reorders child sequence blocks if the parent's child sequence order changes.
  * @param int $oldValue
  * @param CurriculumInventorySequenceBlockInterface $block
  * @param ManagerInterface $manager
  */
 protected function reorderChildrenOnChildSequenceOrderChange($oldValue, CurriculumInventorySequenceBlockInterface $block, ManagerInterface $manager)
 {
     /* @var CurriculumInventorySequenceBlockInterface[] $children */
     $children = $block->getChildren()->toArray();
     if (empty($children)) {
         return;
     }
     $newValue = $block->getChildSequenceOrder();
     if ($newValue === $oldValue) {
         return;
     }
     switch ($newValue) {
         case CurriculumInventorySequenceBlockInterface::ORDERED:
             usort($children, [CurriculumInventorySequenceBlock::class, 'compareSequenceBlocksWithDefaultStrategy']);
             for ($i = 0, $n = count($children); $i < $n; $i++) {
                 $children[$i]->setOrderInSequence($i + 1);
                 $manager->update($children[$i]);
             }
             break;
         case CurriculumInventorySequenceBlockInterface::UNORDERED:
         case CurriculumInventorySequenceBlockInterface::PARALLEL:
             if ($oldValue === CurriculumInventorySequenceBlockInterface::ORDERED) {
                 for ($i = 0, $n = count($children); $i < $n; $i++) {
                     $children[$i]->setOrderInSequence(0);
                     $manager->update($children[$i]);
                 }
             }
             break;
         default:
             // do nothing
     }
 }