<commit_before><?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

include_once "ilios_base_model.php";

/**
 * Data Access Object (DAO).
 * Provides various query methods that support building and managing a curriculum inventory
 * but are not primarily selecting from the "curriculum_inventory_*" tables.
 */
class Curriculum_Inventory extends Ilios_Base_Model
{
    /**
     * Constructor.
     */
    public function __construct ()
    {
        parent::__construct();
    }

    /**
     * Retrieves a map of courses that are linked to sequence blocks in a given curriculum inventory report.
     * @param int $reportId the report id
     * @return array an assoc array of course records, keyed off by course id.
     */
    public function getLinkedCourses ($reportId)
    {
        $rhett = array();
        $clean =array();
        $clean['report_id'] = (int) $reportId;
        $sql =<<<EOL
SELECT c.*
FROM course c
JOIN curriculum_inventory_sequence_block sb ON sb.course_id = c.course_id
WHERE sb.report_id = {$clean['report_id']}
EOL;
        $query = $this->db->query($sql);
        if (0 < $query->num_rows()) {
            foreach ($query->result_array() as $row) {
                $rhett[$row['course_id']] = $row;
            }
        }
        $query->free_result();
        return $rhett;
    }

    /**
     * Retrieves a map of courses that qualify as linkable to sequence blocks in a given inventory report
     * by the matching the given year and owning school id, and that are not already linked to a given report that report.
     * @param int $year The academic year.
     * @param int $schoolId The owning school id.
     * @param int $reportId The report id.
     * @return array an assoc array of course records, keyed off by course id.
     */
    public function getLinkableCourses ($year, $schoolId, $reportId)
    {
        $rhett = array();
        $clean =array();
        $clean['year'] = (int) $year;
        $clean['school_id'] = (int) $schoolId;
        $clean['report_id'] = (int) $reportId;
        $sql =<<<EOL
SELECT c.*
FROM course c
JOIN course_x_cohort cxc ON cxc.course_id = c.course_id
WHERE c.deleted = 0
AND c.year = {$clean['year']}
AND c.owning_school_id = {$clean['school_id']}
AND c.course_id NOT IN (
    SELECT course_id
    FROM curriculum_inventory_sequence_block
    WHERE course_id IS NOT NULL<commit_msg>fixed minor bug in getLinkableCourses() function that was requiring courses to be linked to cohorts.<commit_after><?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

include_once "ilios_base_model.php";

/**
 * Data Access Object (DAO).
 * Provides various query methods that support building and managing a curriculum inventory
 * but are not primarily selecting from the "curriculum_inventory_*" tables.
 */
class Curriculum_Inventory extends Ilios_Base_Model
{
    /**
     * Constructor.
     */
    public function __construct ()
    {
        parent::__construct();
    }

    /**
     * Retrieves a map of courses that are linked to sequence blocks in a given curriculum inventory report.
     * @param int $reportId the report id
     * @return array an assoc array of course records, keyed off by course id.
     */
    public function getLinkedCourses ($reportId)
    {
        $rhett = array();
        $clean =array();
        $clean['report_id'] = (int) $reportId;
        $sql =<<<EOL
SELECT c.*
FROM course c
JOIN curriculum_inventory_sequence_block sb ON sb.course_id = c.course_id
WHERE sb.report_id = {$clean['report_id']}
EOL;
        $query = $this->db->query($sql);
        if (0 < $query->num_rows()) {
            foreach ($query->result_array() as $row) {
                $rhett[$row['course_id']] = $row;
            }
        }
        $query->free_result();
        return $rhett;
    }

    /**
     * Retrieves a map of courses that qualify as linkable to sequence blocks in a given inventory report
     * by the matching the given year and owning school id, and that are not already linked to a given report that report.
     * @param int $year The academic year.
     * @param int $schoolId The owning school id.
     * @param int $reportId The report id.
     * @return array an assoc array of course records, keyed off by course id.
     */
    public function getLinkableCourses ($year, $schoolId, $reportId)
    {
        $rhett = array();
        $clean =array();
        $clean['year'] = (int) $year;
        $clean['school_id'] = (int) $schoolId;
        $clean['report_id'] = (int) $reportId;
        $sql =<<<EOL
SELECT c.*
FROM course c
WHERE c.deleted = 0
AND c.year = {$clean['year']}
AND c.owning_school_id = {$clean['school_id']}
AND c.course_id NOT IN (
    SELECT course_id
    FROM curriculum_inventory_sequence_block
    WHERE course_id IS NOT NULL
{'fraction_non_alphanumeric': 0.11090342679127727, 'fraction_numerical': 0.0008307372793354102, 'mean_word_length': 2.8071146245059286, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7384005', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1431, 'n_words': 501}