From: stronk7 Date: Mon, 29 Sep 2003 15:27:30 +0000 (+0000) Subject: Simply, move the XXXX_get_participants() function from X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=0585509135cf1dc98712c10a9f5f0b09c9022603;p=moodle.git Simply, move the XXXX_get_participants() function from bottom to the common function area. See bug 807 --- diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index 710acfb53c..8dfacf800c 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -262,6 +262,35 @@ function assignment_grades($assignmentid) { return $return; } +function assignment_get_participants($assignmentid) { +//Returns the users with data in one assignment +//(users with records in assignment_submissions, students and teachers) + + global $CFG; + + //Get students + $students = get_records_sql("SELECT DISTINCT u.* + FROM {$CFG->prefix}user u, + {$CFG->prefix}assignment_submissions a + WHERE a.assignment = '$assignmentid' and + u.id = a.userid"); + //Get teachers + $teachers = get_records_sql("SELECT DISTINCT u.* + FROM {$CFG->prefix}user u, + {$CFG->prefix}assignment_submissions a + WHERE a.assignment = '$assignmentid' and + u.id = a.teacher"); + + //Add teachers to students + if ($teachers) { + foreach ($teachers as $teacher) { + $students[$teacher->id] = $teacher; + } + } + //Return students array (it contains an array of unique users) + return ($students); +} + /// SQL STATEMENTS ////////////////////////////////////////////////////////////////// function assignment_log_info($log) { @@ -500,33 +529,4 @@ function assignment_print_upload_form($assignment) { echo ""; } -function assignment_get_participants($assignmentid) { -//Returns the users with data in one assignment -//(users with records in assignment_submissions, students and teachers) - - global $CFG; - - //Get students - $students = get_records_sql("SELECT DISTINCT u.* - FROM {$CFG->prefix}user u, - {$CFG->prefix}assignment_submissions a - WHERE a.assignment = '$assignmentid' and - u.id = a.userid"); - //Get teachers - $teachers = get_records_sql("SELECT DISTINCT u.* - FROM {$CFG->prefix}user u, - {$CFG->prefix}assignment_submissions a - WHERE a.assignment = '$assignmentid' and - u.id = a.teacher"); - - //Add teachers to students - if ($teachers) { - foreach ($teachers as $teacher) { - $students[$teacher->id] = $teacher; - } - } - //Return students array (it contains an array of unique users) - return ($students); -} - ?> diff --git a/mod/attendance/lib.php b/mod/attendance/lib.php index 54ab5f3d16..f26f42f201 100755 --- a/mod/attendance/lib.php +++ b/mod/attendance/lib.php @@ -329,6 +329,34 @@ function attendance_grades($attendanceid) { return $return; } +/** +* Returns user records for all users who have DATA in a given attendance instance +* +* This function is present only for the backup routines. It won't return meaningful data +* for an attendance roll because it only returns records for users who have been counted as +* tardy or absent in the rolls for a single attendance instance, since these are the only +* records I store in the database - for brevity's sake of course. +* +* @param int $attendanceid the id of the attendance record we're looging for student data from +* @return (object)recordset associative array of records containing the student records we wanted +*/ +function attendance_get_participants($attendanceid) { +//Returns the users with data in one attendance +//(users with records in attendance_roll, students) + + global $CFG; + + //Get students + $students = get_records_sql("SELECT DISTINCT u.* + FROM {$CFG->prefix}user u, + {$CFG->prefix}attendance_roll a + WHERE a.dayid = '$attendanceid' and + u.id = a.userid"); + + //Return students array (it contains an array of unique users) + return ($students); +} + ////////////////////////////////////////////////////////////////////////////////////// /// Any other attendance functions go here. Each of them must have a name that @@ -536,34 +564,6 @@ function get_attendance_for_week($id, $courseid) { return get_records_sql($sql); } -/** -* Returns user records for all users who have DATA in a given attendance instance -* -* This function is present only for the backup routines. It won't return meaningful data -* for an attendance roll because it only returns records for users who have been counted as -* tardy or absent in the rolls for a single attendance instance, since these are the only -* records I store in the database - for brevity's sake of course. -* -* @param int $attendanceid the id of the attendance record we're looging for student data from -* @return (object)recordset associative array of records containing the student records we wanted -*/ -function attendance_get_participants($attendanceid) { -//Returns the users with data in one attendance -//(users with records in attendance_roll, students) - - global $CFG; - - //Get students - $students = get_records_sql("SELECT DISTINCT u.* - FROM {$CFG->prefix}user u, - {$CFG->prefix}attendance_roll a - WHERE a.dayid = '$attendanceid' and - u.id = a.userid"); - - //Return students array (it contains an array of unique users) - return ($students); -} - /** * Determines if two dates are on the same day * diff --git a/mod/chat/lib.php b/mod/chat/lib.php index 20919684a5..6d26c5d6d0 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -161,7 +161,22 @@ function chat_cron () { return true; } +function chat_get_participants($chatid) { +//Returns the users with data in one chat +//(users with records in chat_messages, students) + + global $CFG; + + //Get students + $students = get_records_sql("SELECT DISTINCT u.* + FROM {$CFG->prefix}user u, + {$CFG->prefix}chat_messages c + WHERE c.chatid = '$chatid' and + u.id = c.userid"); + //Return students array (it contains an array of unique users) + return ($students); +} ////////////////////////////////////////////////////////////////////// /// Functions that require some SQL @@ -545,21 +560,4 @@ function chat_format_message($message, $courseid=0) { } -function chat_get_participants($chatid) { -//Returns the users with data in one chat -//(users with records in chat_messages, students) - - global $CFG; - - //Get students - $students = get_records_sql("SELECT DISTINCT u.* - FROM {$CFG->prefix}user u, - {$CFG->prefix}chat_messages c - WHERE c.chatid = '$chatid' and - u.id = c.userid"); - - //Return students array (it contains an array of unique users) - return ($students); -} - ?> diff --git a/mod/choice/lib.php b/mod/choice/lib.php index 25ba513acd..2ca987dd63 100644 --- a/mod/choice/lib.php +++ b/mod/choice/lib.php @@ -82,6 +82,23 @@ function choice_delete_instance($id) { return $result; } +function choice_get_participants($choiceid) { +//Returns the users with data in one choice +//(users with records in choice_answers, students) + + global $CFG; + + //Get students + $students = get_records_sql("SELECT DISTINCT u.* + FROM {$CFG->prefix}user u, + {$CFG->prefix}choice_answers c + WHERE c.choice = '$choiceid' and + u.id = c.userid"); + + //Return students array (it contains an array of unique users) + return ($students); +} + function choice_get_answer($choice, $code) { // Returns text string which is the answer that matches the code @@ -119,21 +136,4 @@ function choice_get_choice($choiceid) { } } -function choice_get_participants($choiceid) { -//Returns the users with data in one choice -//(users with records in choice_answers, students) - - global $CFG; - - //Get students - $students = get_records_sql("SELECT DISTINCT u.* - FROM {$CFG->prefix}user u, - {$CFG->prefix}choice_answers c - WHERE c.choice = '$choiceid' and - u.id = c.userid"); - - //Return students array (it contains an array of unique users) - return ($students); -} - ?> diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 5d706689c6..b5053c6610 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -504,6 +504,53 @@ function forum_grades($forumid) { return $return; } +function forum_get_participants($forumid) { +//Returns the users with data in one forum +//(users with records in forum_subscriptions, forum_posts and forum_ratings, students) + + global $CFG; + + //Get students from forum_subscriptions + $st_subscriptions = get_records_sql("SELECT DISTINCT u.* + FROM {$CFG->prefix}user u, + {$CFG->prefix}forum_subscriptions s + WHERE s.forum = '$forumid' and + u.id = s.userid"); + //Get students from forum_posts + $st_posts = get_records_sql("SELECT DISTINCT u.* + FROM {$CFG->prefix}user u, + {$CFG->prefix}forum_discussions d, + {$CFG->prefix}forum_posts p + WHERE d.forum = '$forumid' and + p.discussion = d.id and + u.id = p.userid"); + + //Get students from forum_ratings + $st_ratings = get_records_sql("SELECT DISTINCT u.* + FROM {$CFG->prefix}user u, + {$CFG->prefix}forum_discussions d, + {$CFG->prefix}forum_posts p, + {$CFG->prefix}forum_ratings r + WHERE d.forum = '$forumid' and + p.discussion = d.id and + r.post = p.id and + u.id = r.userid"); + + //Add st_posts to st_subscriptions + if ($st_posts) { + foreach ($st_posts as $st_post) { + $st_subscriptions[$st_post->id] = $st_post; + } + } + //Add st_ratings to st_subscriptions + if ($st_ratings) { + foreach ($st_ratings as $st_rating) { + $st_subscriptions[$st_rating->id] = $st_rating; + } + } + //Return st_subscriptions array (it contains an array of unique users) + return ($st_subscriptions); +} /// SQL FUNCTIONS /////////////////////////////////////////////////////////// @@ -2132,52 +2179,4 @@ function forum_set_display_mode($mode=0) { } } -function forum_get_participants($forumid) { -//Returns the users with data in one forum -//(users with records in forum_subscriptions, forum_posts and forum_ratings, students) - - global $CFG; - - //Get students from forum_subscriptions - $st_subscriptions = get_records_sql("SELECT DISTINCT u.* - FROM {$CFG->prefix}user u, - {$CFG->prefix}forum_subscriptions s - WHERE s.forum = '$forumid' and - u.id = s.userid"); - //Get students from forum_posts - $st_posts = get_records_sql("SELECT DISTINCT u.* - FROM {$CFG->prefix}user u, - {$CFG->prefix}forum_discussions d, - {$CFG->prefix}forum_posts p - WHERE d.forum = '$forumid' and - p.discussion = d.id and - u.id = p.userid"); - - //Get students from forum_ratings - $st_ratings = get_records_sql("SELECT DISTINCT u.* - FROM {$CFG->prefix}user u, - {$CFG->prefix}forum_discussions d, - {$CFG->prefix}forum_posts p, - {$CFG->prefix}forum_ratings r - WHERE d.forum = '$forumid' and - p.discussion = d.id and - r.post = p.id and - u.id = r.userid"); - - //Add st_posts to st_subscriptions - if ($st_posts) { - foreach ($st_posts as $st_post) { - $st_subscriptions[$st_post->id] = $st_post; - } - } - //Add st_ratings to st_subscriptions - if ($st_ratings) { - foreach ($st_ratings as $st_rating) { - $st_subscriptions[$st_rating->id] = $st_rating; - } - } - //Return st_subscriptions array (it contains an array of unique users) - return ($st_subscriptions); -} - ?> diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 9b00916df9..5a90ecf948 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -145,6 +145,22 @@ function glossary_grades($glossaryid) { return $return; } +function glossary_get_participants($glossaryid) { +//Returns the users with data in one glossary +//(users with records in glossary_entries, students) + + global $CFG; + + //Get students + $students = get_records_sql("SELECT DISTINCT u.* + FROM {$CFG->prefix}user u, + {$CFG->prefix}glossary_entries g + WHERE g.glossaryid = '$glossaryid' and + u.id = g.userid"); + + //Return students array (it contains an array of unique users) + return ($students); +} ////////////////////////////////////////////////////////////////////////////////////// /// Any other glossary functions go here. Each of them must have a name that @@ -327,24 +343,6 @@ function glossary_search_entries($searchterms, $glossary, $includedefinition) { $selectsql ORDER BY e.concept ASC $limit"); } -function glossary_get_participants($glossaryid) { -//Returns the users with data in one glossary -//(users with records in glossary_entries, students) - - global $CFG; - - //Get students - $students = get_records_sql("SELECT DISTINCT u.* - FROM {$CFG->prefix}user u, - {$CFG->prefix}glossary_entries g - WHERE g.glossaryid = '$glossaryid' and - u.id = g.userid"); - - //Return students array (it contains an array of unique users) - return ($students); -} - - function glossary_file_area_name($entry) { // Creates a directory file name, suitable for make_upload_directory() global $CFG; diff --git a/mod/journal/lib.php b/mod/journal/lib.php index a8451b4f18..65a7809b5b 100644 --- a/mod/journal/lib.php +++ b/mod/journal/lib.php @@ -253,6 +253,34 @@ function journal_grades($journalid) { return $return; } +function journal_get_participants($journalid) { +//Returns the users with data in one journal +//(users with records in journal_entries, students and teachers) + + global $CFG; + + //Get students + $students = get_records_sql("SELECT DISTINCT u.* + FROM {$CFG->prefix}user u, + {$CFG->prefix}journal_entries j + WHERE j.journal = '$journalid' and + u.id = j.userid"); + //Get teachers + $teachers = get_records_sql("SELECT DISTINCT u.* + FROM {$CFG->prefix}user u, + {$CFG->prefix}journal_entries j + WHERE j.journal = '$journalid' and + u.id = j.teacher"); + + //Add teachers to students + if ($teachers) { + foreach ($teachers as $teacher) { + $students[$teacher->id] = $teacher; + } + } + //Return students array (it contains an array of unique users) + return ($students); +} // SQL FUNCTIONS /////////////////////////////////////////////////////////////////// @@ -428,33 +456,4 @@ function journal_print_feedback($course, $entry, $grades) { echo ""; } -function journal_get_participants($journalid) { -//Returns the users with data in one journal -//(users with records in journal_entries, students and teachers) - - global $CFG; - - //Get students - $students = get_records_sql("SELECT DISTINCT u.* - FROM {$CFG->prefix}user u, - {$CFG->prefix}journal_entries j - WHERE j.journal = '$journalid' and - u.id = j.userid"); - //Get teachers - $teachers = get_records_sql("SELECT DISTINCT u.* - FROM {$CFG->prefix}user u, - {$CFG->prefix}journal_entries j - WHERE j.journal = '$journalid' and - u.id = j.teacher"); - - //Add teachers to students - if ($teachers) { - foreach ($teachers as $teacher) { - $students[$teacher->id] = $teacher; - } - } - //Return students array (it contains an array of unique users) - return ($students); -} - ?> diff --git a/mod/survey/lib.php b/mod/survey/lib.php index 40e6d6e5a9..650f549cfa 100644 --- a/mod/survey/lib.php +++ b/mod/survey/lib.php @@ -144,6 +144,34 @@ function survey_print_recent_activity($course, $isteacher, $timestart) { return $content; } +function survey_get_participants($surveyid) { +//Returns the users with data in one survey +//(users with records in survey_analysis and survey_answers, students) + + global $CFG; + + //Get students from survey_analysis + $st_analysis = get_records_sql("SELECT DISTINCT u.* + FROM {$CFG->prefix}user u, + {$CFG->prefix}survey_analysis a + WHERE a.survey = '$surveyid' and + u.id = a.userid"); + //Get students from survey_answers + $st_answers = get_records_sql("SELECT DISTINCT u.* + FROM {$CFG->prefix}user u, + {$CFG->prefix}survey_answers a + WHERE a.survey = '$surveyid' and + u.id = a.userid"); + + //Add st_answers to st_analysis + if ($st_answers) { + foreach ($st_answers as $st_answer) { + $st_analysis[$st_answer->id] = $st_answer; + } + } + //Return st_analysis array (it contains an array of unique users) + return ($st_analysis); +} // SQL FUNCTIONS //////////////////////////////////////////////////////// @@ -410,33 +438,4 @@ function survey_print_graph($url) { } } -function survey_get_participants($surveyid) { -//Returns the users with data in one survey -//(users with records in survey_analysis and survey_answers, students) - - global $CFG; - - //Get students from survey_analysis - $st_analysis = get_records_sql("SELECT DISTINCT u.* - FROM {$CFG->prefix}user u, - {$CFG->prefix}survey_analysis a - WHERE a.survey = '$surveyid' and - u.id = a.userid"); - //Get students from survey_answers - $st_answers = get_records_sql("SELECT DISTINCT u.* - FROM {$CFG->prefix}user u, - {$CFG->prefix}survey_answers a - WHERE a.survey = '$surveyid' and - u.id = a.userid"); - - //Add st_answers to st_analysis - if ($st_answers) { - foreach ($st_answers as $st_answer) { - $st_analysis[$st_answer->id] = $st_answer; - } - } - //Return st_analysis array (it contains an array of unique users) - return ($st_analysis); -} - ?> diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php index 71d3e98a8a..7f87835896 100644 --- a/mod/workshop/lib.php +++ b/mod/workshop/lib.php @@ -702,6 +702,48 @@ function workshop_user_outline($course, $user, $mod, $workshop) { return NULL; } +////////////////////////////////////////////////////////////////////////////////////// +function workshop_get_participants($workshopid) { +//Returns the users with data in one workshop +//(users with records in workshop_submissions, workshop_assessments and workshop_comments, students) + + global $CFG; + + //Get students from workshop_submissions + $st_submissions = get_records_sql("SELECT DISTINCT u.* + FROM {$CFG->prefix}user u, + {$CFG->prefix}workshop_submissions s + WHERE s.workshopid = '$workshopid' and + u.id = s.userid"); + //Get students from workshop_assessments + $st_assessments = get_records_sql("SELECT DISTINCT u.* + FROM {$CFG->prefix}user u, + {$CFG->prefix}workshop_assessments a + WHERE a.workshopid = '$workshopid' and + u.id = a.userid"); + + //Get students from workshop_comments + $st_comments = get_records_sql("SELECT DISTINCT u.* + FROM {$CFG->prefix}user u, + {$CFG->prefix}workshop_comments c + WHERE c.workshopid = '$workshopid' and + u.id = c.userid"); + + //Add st_assessments to st_submissions + if ($st_assessments) { + foreach ($st_assessments as $st_assessment) { + $st_submissions[$st_assessment->id] = $st_assessment; + } + } + //Add st_comments to st_submissions + if ($st_comments) { + foreach ($st_comments as $st_comment) { + $st_submissions[$st_comment->id] = $st_comment; + } + } + //Return st_submissions array (it contains an array of unique users) + return ($st_submissions); +} ////////////////////////////////////////////////////////////////////////////////////// @@ -1244,51 +1286,6 @@ function workshop_get_grade_logs($course, $timestart) { AND u.id = s.userid AND e.id = a.workshopid"); } - -////////////////////////////////////////////////////////////////////////////////////// -function workshop_get_participants($workshopid) { -//Returns the users with data in one workshop -//(users with records in workshop_submissions, workshop_assessments and workshop_comments, students) - - global $CFG; - - //Get students from workshop_submissions - $st_submissions = get_records_sql("SELECT DISTINCT u.* - FROM {$CFG->prefix}user u, - {$CFG->prefix}workshop_submissions s - WHERE s.workshopid = '$workshopid' and - u.id = s.userid"); - //Get students from workshop_assessments - $st_assessments = get_records_sql("SELECT DISTINCT u.* - FROM {$CFG->prefix}user u, - {$CFG->prefix}workshop_assessments a - WHERE a.workshopid = '$workshopid' and - u.id = a.userid"); - - //Get students from workshop_comments - $st_comments = get_records_sql("SELECT DISTINCT u.* - FROM {$CFG->prefix}user u, - {$CFG->prefix}workshop_comments c - WHERE c.workshopid = '$workshopid' and - u.id = c.userid"); - - //Add st_assessments to st_submissions - if ($st_assessments) { - foreach ($st_assessments as $st_assessment) { - $st_submissions[$st_assessment->id] = $st_assessment; - } - } - //Add st_comments to st_submissions - if ($st_comments) { - foreach ($st_comments as $st_comment) { - $st_submissions[$st_comment->id] = $st_comment; - } - } - //Return st_submissions array (it contains an array of unique users) - return ($st_submissions); -} - - ////////////////////////////////////////////////////////////////////////////////////// function workshop_get_student_assessments($workshop, $user) { // Return all assessments on the student submissions by a user, order by youngest first, oldest last