/** * 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; }
/** * Retrieves a curriculum inventory in a data structure that lends itself for an easy transformation into * XML-formatted report. * * @param CurriculumInventoryReportInterface $invReport The report object. * @return array An associated array, containing the inventory. * Data is keyed off by: * 'report' ... The inventory report entity. * 'institution' ... An object representing the curriculum inventory's owning institution * 'events' ... An array of events, keyed off by event id. Each event is represented as assoc. array. * 'expectations' ... An associative array of arrays, each sub-array containing a * list of a different type of "competency object" within the curriculum. * These types are program objectives, course objectives and session objectives. * The keys for these type-specific sub-arrays are: * 'program_objectives' * 'course_objectives' * 'session_objectives' * 'framework' ... The competency framework data set. * 'includes' ... Identifiers of the various competency objects referenced in the framework. * 'pcrs_ids' * 'program_objective_ids' * 'course_objective_ids' * 'session_objective_ids' * 'relations' ... Relations between the various competencies within the framework * 'program_objectives_to_pcrs' * 'course_objectives_to_program_objectives' * 'session_objectives_to_course_objectives' * 'sequence_block_references' ...relationships maps between sequence blocks and other curricular entities. * 'events' ... maps sequence blocks to events * 'competency_objects' .. maps sequence blocks to competency objects * * @throws \Exception */ public function getCurriculumInventory(CurriculumInventoryReportInterface $invReport) { // report validation $program = $invReport->getProgram(); if (!$program) { throw new \Exception('No program found for report with id ' . $invReport->getId() . '.'); } $school = $program->getSchool(); if (!$school) { throw new \Exception('No school found for program with id = ' . $program->getId() . '.'); } /** @var CurriculumInventoryInstitutionInterface $institution */ $institution = $this->institutionManager->findCurriculumInventoryInstitutionBy(['school' => $school->getId()]); if (!$institution) { throw new \Exception('No curriculum inventory institution found for school with id = ' . $school->getId() . '.'); } $events = $this->reportManager->getEvents($invReport); $keywords = $this->reportManager->getEventKeywords($invReport); $eventRefsForSeqBlocks = $this->reportManager->getEventReferencesForSequenceBlocks($invReport); $programObjectives = $this->reportManager->getProgramObjectives($invReport); $sessionObjectives = $this->reportManager->getSessionObjectives($invReport); $courseObjectives = $this->reportManager->getCourseObjectives($invReport); $compObjRefsForSeqBlocks = $this->reportManager->getCompetencyObjectReferencesForSequenceBlocks($invReport); $compRefsForEvents = $this->reportManager->getCompetencyObjectReferencesForEvents($invReport); // The various objective type are all "Competency Objects" in the context of reporting the curriculum inventory. // The are grouped in the "Expectations" section of the report, lump 'em together here. $expectations = []; $expectations['program_objectives'] = $programObjectives; $expectations['session_objectives'] = $sessionObjectives; $expectations['course_objectives'] = $courseObjectives; // Build out the competency framework information and added to $expectations. $pcrs = $this->reportManager->getPcrs($invReport); $pcrsIds = array_keys($pcrs); $programObjectiveIds = array_keys($programObjectives); $courseObjectiveIds = array_keys($courseObjectives); $sessionObjectiveIds = array_keys($sessionObjectives); $includes = ['pcrs_ids' => [], 'program_objective_ids' => [], 'course_objective_ids' => [], 'session_objective_ids' => []]; $relations = ['program_objectives_to_pcrs' => [], 'course_objectives_to_program_objectives' => [], 'session_objectives_to_course_objectives' => []]; $rel = $this->reportManager->getProgramObjectivesToPcrsRelations($programObjectiveIds, $pcrsIds); $relations['program_objectives_to_pcrs'] = $rel['relations']; $includes['pcrs_ids'] = $rel['pcrs_ids']; $includes['program_objective_ids'] = $rel['program_objective_ids']; $rel = $this->reportManager->getCourseObjectivesToProgramObjectivesRelations($courseObjectiveIds, $programObjectiveIds); $relations['course_objectives_to_program_objectives'] = $rel['relations']; $includes['program_objective_ids'] = array_values(array_unique(array_merge($includes['program_objective_ids'], $rel['program_objective_ids']))); $includes['course_objective_ids'] = $rel['course_objective_ids']; $rel = $this->reportManager->getSessionObjectivesToCourseObjectivesRelations($sessionObjectiveIds, $courseObjectiveIds); $relations['session_objectives_to_course_objectives'] = $rel['relations']; $includes['course_objective_ids'] = array_values(array_unique(array_merge($includes['course_objective_ids'], $rel['course_objective_ids']))); $includes['session_objective_ids'] = $rel['session_objective_ids']; $expectations['framework'] = ['includes' => $includes, 'relations' => $relations]; // // transmogrify inventory data for reporting and fill in the blanks // // add keywords to event $events = $this->addKeywordsToEvents($events, $keywords); $events = $this->addCompetencyObjectReferencesToEvents($events, $compRefsForEvents); // // aggregate inventory into single return-array // $rhett = []; $rhett['report'] = $invReport; $rhett['expectations'] = $expectations; $rhett['institution'] = $institution; $rhett['events'] = $events; $rhett['sequence_block_references'] = ['events' => $eventRefsForSeqBlocks, 'competency_objects' => $compObjRefsForSeqBlocks]; return $rhett; }
/** * @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(); }
/** * @param CurriculumInventoryReportInterface $report * @param UserInterface $user * @return bool */ protected function isCreateGranted($report, $user) { // Only grant CREATE, permissions to users with at least one of // 'Course Director' and 'Developer' roles. // - and - // the user must be associated with the school owning the report's program // either by its primary school attribute // - or - by WRITE rights for the school // via the permissions system. return $this->userHasRole($user, ['Course Director', 'Developer']) && ($this->schoolsAreIdentical($user->getSchool(), $report->getProgram()->getSchool()) || $this->permissionManager->userHasWritePermissionToSchool($user, $report->getProgram()->getSchool())); }