/**
  * Retrieves the report document for a given curriculum inventory report.
  *
  * @param CurriculumInventoryReportInterface $report
  * @return string
  */
 protected function getExportedDocument(CurriculumInventoryReportInterface $report)
 {
     // check if the report has been exported.
     // if so, pull the document from the database.
     $export = $this->getCurriculumInventoryExportHandler()->findCurriculumInventoryExportBy(['report' => $report->getId()]);
     if ($export) {
         return $export->getDocument();
     }
     // otherwise, generate a document on the fly.
     return $this->generateReportDocument($report);
 }
 /**
  * Retrieves the report document for a given curriculum inventory report.
  *
  * @param CurriculumInventoryReportInterface $report
  * @return string
  */
 protected function getExportedDocument(CurriculumInventoryReportInterface $report)
 {
     // check if the report has been exported.
     // if so, pull the document from the database.
     $manager = $this->container->get('ilioscore.curriculuminventoryexport.manager');
     $export = $manager->findOneBy(['report' => $report->getId()]);
     if ($export) {
         return $export->getDocument();
     }
     // otherwise, generate a document on the fly.
     return $this->generateReportDocument($report);
 }
示例#3
0
文件: Exporter.php 项目: Okami-/ilios
 /**
  * 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();
 }
 /**
  * @return int
  */
 public function getId()
 {
     return $this->report->getId();
 }
    /**
     * Retrieves a list of events (derived from published sessions/offerings and independent learning sessions)
     * in a given curriculum inventory report.
     *
     * @param CurriculumInventoryReportInterface $report
     * @return array An assoc. array of assoc. arrays, each item representing an event, keyed off by event id.
     */
    protected function getEventsFromSessionOfferings(CurriculumInventoryReportInterface $report)
    {
        $rhett = [];
        $sql = <<<EOL
SELECT
  s.session_id AS 'event_id',
  s.title,
  sd.description,
  stxam.method_id,
  st.assessment AS is_assessment_method,
  ao.name AS assessment_option_name,
  sbs.count_offerings_once,
  o.start_date,
  o.end_date
FROM
  `session` s
  JOIN session_type st ON st.session_type_id = s.session_type_id
  JOIN course c ON c.course_id = s.course_id
  JOIN curriculum_inventory_sequence_block sb ON sb.course_id = c.course_id
  LEFT JOIN offering o ON o.session_id = s.session_id AND o.deleted = 0
  LEFT JOIN session_description sd ON sd.session_id = s.session_id
  LEFT JOIN session_type_x_aamc_method stxam ON stxam.session_type_id = st.session_type_id
  LEFT JOIN assessment_option ao ON ao.assessment_option_id = st.assessment_option_id
  LEFT JOIN ilm_session_facet sf ON sf.session_id = s.session_id
  LEFT JOIN curriculum_inventory_sequence_block_session sbs ON sbs.session_id = s.session_id
WHERE
  c.deleted = 0
  AND s.deleted = 0
  AND s.publish_event_id IS NOT NULL
  AND sf.ilm_session_facet_id IS NULL
  AND sb.report_id = :report_id
ORDER BY
  s.session_id
EOL;
        $conn = $this->getEntityManager()->getConnection();
        $stmt = $conn->prepare($sql);
        $stmt->bindValue("report_id", $report->getId());
        $stmt->execute();
        $rows = $stmt->fetchAll();
        foreach ($rows as $row) {
            $row['duration'] = 0;
            if ($row['start_date']) {
                $startDate = new \Datetime($row['start_date'], new \DateTimeZone('UTC'));
                $endDate = new \DateTime($row['end_date'], new \DateTimeZone('UTC'));
                $duration = floor(($endDate->getTimestamp() - $startDate->getTimestamp()) / 60);
                $row['duration'] = $duration;
            }
            if (!array_key_exists($row['event_id'], $rhett)) {
                $rhett[$row['event_id']] = $row;
            } else {
                if ($row['count_offerings_once']) {
                    if ($rhett[$row['event_id']]['duration'] < $row['duration']) {
                        $rhett[$row['event_id']]['duration'] = $row['duration'];
                    }
                } else {
                    $rhett[$row['event_id']]['duration'] += $row['duration'];
                }
            }
        }
        array_walk($rhett, function (&$row) {
            unset($row['count_offerings_once']);
            unset($row['start_date']);
            unset($row['end_date']);
        });
        $stmt->closeCursor();
        return $rhett;
    }