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

include_once "ilios_base_model.php";

/**
 * Data Access Object (DAO) providing read-only access to various sets of data in the
 * Ilios database.
 */
class Canned_Queries extends Ilios_Base_Model
{
    /**
     * Constructor
     */
    public function __construct ()
    {
        parent::__construct();
    }

    /**
     * Retrieves a list of course-titles and -ids for courses that are associated with a given learner group via
     * session-offerings.
     * Note: Archived courses are excluded.
     * @param int $groupId The learner group id.
     * @return array A nested array of associative arrays. Each item contains a course title (key: 'title') and a course
     *      identifier (key: 'course_id').
     */
    public function getCourseIdAndTitleForLearnerGroup ($groupId)
    {
        $rhett = array();
        $clean = array();
        $clean['group_id'] = (int) $groupId;

        $sql =<<< EOL
SELECT DISTINCT c.`course_id`, c.`title`
FROM `offering_learner` ol
JOIN `offering` o ON o.`offering_id` = ol.`offering_id`
JOIN `session` s ON s.`session_id` = o.`session_id`
JOIN `course` c ON c.`course_id` = s.`course_id`
WHERE ol.`group_id` = {$clean['group_id']}
AND o.`deleted` = 0
AND s.`deleted` = 0
AND c.`deleted` = 0
AND c.`archived` = 0
EOL;
        $query = $this->db->query($sql);
        if (0 < $query->num_rows()) {
            foreach ($query->result_array() as $row) {
                $rhett[] = $row;
            }
        }
        $query->free_result();
        return $rhett;
    }

    /**
     * Retrieves a list of learner groups that are associated with independent learning sessions and offerings
     * in a given course.
     * @param int $courseId The course id.
     * @return array A nested array of associative arrays. Each item represents a learner group, containing the group's
     *      identifier (key: 'group_id') and the group's name (key: 'title').
     */
    public function getLearnerGroupIdAndTitleForCourse ($courseId)
    {
        $rhett = array();
        $clean = array();
        $clean['course_id'] = (int) $courseId;

        $sql =<<< EOL<commit_msg>altered SQL query to include courses linked to groups via independent learning sessions. refs #3525<commit_after><?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

include_once "ilios_base_model.php";

/**
 * Data Access Object (DAO) providing read-only access to various sets of data in the
 * Ilios database.
 */
class Canned_Queries extends Ilios_Base_Model
{
    /**
     * Constructor
     */
    public function __construct ()
    {
        parent::__construct();
    }

    /**
     * Retrieves a list of course-titles and -ids for courses that are associated with a given learner group via
     * session-offerings and independent-learning-sessions.
     * Note: Archived courses are excluded.
     * @param int $groupId The learner group id.
     * @return array A nested array of associative arrays. Each item contains a course title (key: 'title') and a course
     *      identifier (key: 'course_id').
     */
    public function getCourseIdAndTitleForLearnerGroup ($groupId)
    {
        $rhett = array();
        $clean = array();
        $clean['group_id'] = (int) $groupId;

        $sql =<<< EOL
SELECT c.`course_id`, c.`title`
FROM `offering_learner` ol
JOIN `offering` o ON o.`offering_id` = ol.`offering_id`
JOIN `session` s ON s.`session_id` = o.`session_id`
JOIN `course` c ON c.`course_id` = s.`course_id`
WHERE ol.`group_id` = {$clean['group_id']}
AND o.`deleted` = 0
AND s.`deleted` = 0
AND c.`deleted` = 0
AND c.`archived` = 0
UNION
SELECT c.`course_id`, c.`title`
FROM `ilm_session_facet_learner` isfl
JOIN `ilm_session_facet` isf ON isf.`ilm_session_facet_id` = isfl.`ilm_session_facet_id`
JOIN `session` s ON s.`ilm_session_facet_id` = isf.`ilm_session_facet_id`
JOIN `course` c ON c.`course_id` = s.`course_id`
WHERE isfl.`group_id` = {$clean['group_id']}
AND s.`deleted` = 0
AND c.`deleted` = 0
AND c.`archived` = 0
EOL;
        $query = $this->db->query($sql);
        if (0 < $query->num_rows()) {
            foreach ($query->result_array() as $row) {
                $rhett[] = $row;
            }
        }
        $query->free_result();
        return $rhett;
    }

    /**
     * Retrieves a list of learner groups that are associated with independent learning sessions and offerings
     * in a given course.
     * @param int $courseId The course id.
     * @return array A nested array of associative arrays. Each item represents a learner group, containing the group's
     *      identifier (key: 'group_id') and the group's name (key: 'title').
     */
    public function getLearnerGroupIdAndTitleForCourse ($courseId)
    {
        $rhett = array();
        $clean = array();
        $clean['course_id'] = (int) $courseId;

        $sql =<<< EOL
{'fraction_non_alphanumeric': 0.12583586626139817, 'fraction_numerical': 0.0034447821681864235, 'mean_word_length': 2.8412451361867705, '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': '6975062', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1590, 'n_words': 491}