From 4b5e448e3c610616f7faacef04506b1f25f7913b Mon Sep 17 00:00:00 2001 From: cmERDC Digital Learning Date: Wed, 22 Nov 2017 10:02:53 -0600 Subject: [PATCH 01/22] new lang strings for extra features --- lang/en/block_fn_mentor.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lang/en/block_fn_mentor.php b/lang/en/block_fn_mentor.php index 602c460..2754c26 100644 --- a/lang/en/block_fn_mentor.php +++ b/lang/en/block_fn_mentor.php @@ -94,6 +94,8 @@ $string['email'] = 'Email'; $string['emailerror'] = '..........Email[ERROR]'; $string['emailsent'] = '..........Email[SENT]'; +$string['enroldates'] = 'Dates'; +$string['enroldatesnone'] = 'No enrollment dates'; $string['export'] = 'Export'; $string['export_mentorsandmanagers'] = 'Include all users that currently mentors and managers. This option will preserve the mentor-mentee relations as well as group memberships.'; @@ -153,6 +155,7 @@ '; $string['importusers'] = 'Import users'; $string['includeextranedcolumns'] = 'Experimental: Include extra NED columns in Export page'; +$string['includewaitinggrade'] = 'Include waiting for grade in progress calculations'; $string['incompleted'] = 'Incompleted'; $string['incompleted2'] = 'Completed - unsuccessful'; $string['info_about_selected_people'] = 'Info about selected people'; @@ -209,7 +212,7 @@ $string['notifications'] = 'Notifications'; $string['notification_rules'] = 'Notification Rules'; $string['notingroup'] = 'Not in group'; -$string['numofcomplete'] = 'Number of complete activities'; +$string['numofcomplete'] = 'Number of graded activities'; $string['open'] = 'Open'; $string['open_progress_reports'] = 'Open Progress Reports'; $string['othersettings'] = 'Other settings'; @@ -223,7 +226,11 @@ $string['pluginname'] = 'NED Mentor Manager'; $string['profile'] = 'Profile'; $string['progress'] = 'Progress'; +$string['progressnoactivities'] = 'There are no graded activities in this course.'; +$string['progressnoactivitiescomp'] = 'No activities completed.'; $string['progressreportfrom'] = 'Message from {$a}'; +$string['progressstudentpace'] = 'Student Pace'; +$string['progresssuggestedpace'] = 'Suggested Pace'; $string['potentialusers'] = 'Potential users'; $string['remove_all'] = 'Remove All'; $string['remove_button'] = 'Remove'; @@ -243,6 +250,8 @@ $string['sendall'] = 'Notification criteria + Appended Message'; $string['sendappended'] = 'Only send Appended Message'; $string['sendusernotification'] = 'Send user notification'; +$string['sessions'] = 'Meeting Times'; +$string['sessionsnone'] = 'There is no meeting time for this course.'; $string['setgroupleader'] = 'Set Group Leader'; $string['settings'] = 'Settings'; $string['show'] = 'Show'; From 3c6034f274945217c167cbb214422063496eaf0b Mon Sep 17 00:00:00 2001 From: cmERDC Digital Learning Date: Wed, 22 Nov 2017 10:07:04 -0600 Subject: [PATCH 02/22] new graded mods Added new mod capabilities and checks. Progress bar for suggested pace. Reworked some logic. --- lib.php | 1527 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 1287 insertions(+), 240 deletions(-) diff --git a/lib.php b/lib.php index d31086d..98ebfee 100644 --- a/lib.php +++ b/lib.php @@ -1,5 +1,5 @@ dirroot.'/mod/assignment/lib.php'); require_once($CFG->dirroot.'/lib/completionlib.php'); +// Connect to an external DB for log files. +require_once($CFG->dirroot.'/blocks/fn_mentor/classes/ext_db/db_connect.php'); define('BLOCK_FN_MENTOR_MESSAGE_SEND_ALL', 0); define('BLOCK_FN_MENTOR_MESSAGE_SEND_APPENDED', 1); @@ -865,6 +867,33 @@ function block_fn_mentor_render_mentees_by_student($menteeid) { return $html; } +/* Add modules to check for course_overview.php, + * course_overview_single.php, simple_gradebook.php, + * listactivities.php, lib functions to make it easier + * to add extra mods. + * @author Sheilla Rindahl + * @return array modlist + */ +function get_graded_mods() { + $modlist = array( + 'assign' => 'assign.submissions.fn.php', + 'quiz' => 'quiz.submissions.fn.php', + 'assignment' => 'assignment.submissions.fn.php', + 'forum' => 'forum.submissions.fn.php', + // Add extra Moodle mods + 'lesson' => 'lesson.submissions.fn.php', + 'scorm' => 'scorm.submissions.fn.php', + 'lti' => 'lti.submissions.fn.php', + // Add extra Moodle plugins graded... + // The below functions are used fn_marking and need to be developed if using fn_marking plugin. + 'hsuforum' => 'hsuforum.submissions.fn.php', + 'journal' => 'journal.submissions.fn.php', + 'hvp' => 'hvp.submissions.fn.php', + 'collaborate' => 'collaborate.submissions.fn.php', + ); + return $modlist; +} + function block_fn_mentor_assignment_status($mod, $userid) { global $CFG, $DB, $SESSION; @@ -1025,6 +1054,224 @@ function block_fn_mentor_assign_plugin_config($assignmentid, $subtype = 'assigns return false; } +function block_fn_mentor_quiz_status($mod, $userid) { + //SRINDHL Add manually graded quizzes in the waiting for grade counts. + global $DB, $SESSION; + if (isset($SESSION->completioncache)) { + unset($SESSION->completioncache); + } + if ($mod->modname == 'quiz') { + + if (!($quiz = $DB->get_record('quiz', array('id' => $mod->instance)))) { + return false; + } + $attempts = $DB->get_records('quiz_attempts', array( + 'quiz' => $quiz->id, 'userid' => $userid), 'attempt DESC', '*', 0, 1); + if ($attempts) { + foreach($attempts as $id=>$attempt) { + + if ($attemptisgraded = $DB->get_records('quiz_grades', array( + 'quiz' => $quiz->id, 'userid' => $userid))) { + + $attemptisgraded = reset($attemptisgraded); + if ($attemptisgraded->grade > -1) { + if (($attempt->timemodified > $attemptisgraded->timemodified)) { + $graded = false; + } else { + $graded = true; + } + } else { + $graded = false; + } + } else { + $graded = false; + } + + // No grade assignments. + if (($quiz->grade == 0) && ($attempt->state == 'finished')) { + return 'submitted'; + } + + if ($attempt->sumgrades === NULL) { + if ($attempt->state == 'abandoned') { + return false; + } elseif ($attempt->state == 'overdue') { + return false; + } elseif ($attempt->state == 'inprogress') { + return 'saved'; + } elseif ($attempt->state == 'finished') { + return 'waitinggrade'; + } + } else { + if ($attempt->state == 'inprogress') { + if ($graded) { + return 'submitted'; + } else { + return 'saved'; + } + } elseif ($attempt->state == 'finished') { + if ($graded) { + return 'submitted'; + } + } + } + } + } else { + return false; + } + } else { + return false; + } +} + + +function block_fn_mentor_lesson_status($mod, $userid, $course) { + //SRINDHL Add manually graded essays in the waiting for grade counts. + global $CFG, $DB, $SESSION; + require_once("$CFG->libdir/gradelib.php"); + if (isset($SESSION->completioncache)) { + unset($SESSION->completioncache); + } + if ($mod->modname == 'lesson') { + if (!($lesson = $DB->get_record('lesson', array('id' => $mod->instance)))) { + return false; + } + // Check to see if it an incomplete attempt. + $sql = "SELECT * + FROM {lesson_timer} + WHERE lessonid = :lessonid + AND userid = :userid + ORDER by starttime desc"; + $params = array('lessonid' => $lesson->id, 'userid' => $userid); + $timer = $DB->get_record_sql($sql, $params, IGNORE_MULTIPLE); + // Get any grades for the lesson. + $grades = grade_get_grades($course->id, 'mod', 'lesson', $lesson->id, $userid); + if (((empty($grades->items[0]->grades)) && (!$timer)) || ($lesson->practice == 1)) { + return false; + } else if ((empty($grades->items[0]->grades)) && (!empty($timer))) { + return 'saved'; + } else { + // Detrmine the status. + if ($timer) { + + $grade = reset($grades->items[0]->grades); + // No grade lessons. + if (($lesson->grade == 0) || ($lesson->practice == 1)) { + if($timer->completed == 1) { + return 'submitted'; + } else { + return 'saved'; + } + } + if($timer->completed == 1) { + if ($grade->grade) { + //var_dump($grade); + $attempts = $DB->get_records('lesson_attempts', array( + 'lessonid' => $lesson->id, 'userid' => $userid), 'answerid DESC'); + if($attempts) { + $i = 0; + $count = count($attempts); + $attempt = array_values($attempts); + for($i = 0; $i < $count; ++$i) { + + // check for ungraded lesson essay answers. + $useranswer = $attempt[$i]->useranswer; + if((strpos($useranswer, 'stdClass') !== false) && (strpos($useranswer, 'graded') !== false)) + if($answer = unserialize($useranswer)) { + if($answer->graded == 0) { + return 'waitinggrade'; + } + } + continue; + } + + } + return 'submitted'; + } + } else { + return 'saved'; + } + } else { + return false; + } + } + return false; + } + return false; + +} + +function block_fn_mentor_journal_status($mod, $userid, $course) { + //SRINDHL Add journal entries in the waiting for grade counts. + global $CFG, $DB, $SESSION; + if (isset($SESSION->completioncache)) { + unset($SESSION->completioncache); + } + if ($mod->modname == 'journal') { + + if (!($journal = $DB->get_record('journal', array('id' => $mod->instance)))) { + return false; + } + $entries = $DB->get_records('journal_entries', array( + 'journal' => $journal->id, 'userid' => $userid), 'id DESC', '*', 0, 1); + // Get any grades for the lesson. + $grades = grade_get_grades($course->id, 'mod', 'journal', $journal->id, $userid); + if ($entries) { + $grade = reset($grades->items[0]->grades); + foreach($entries as $id=>$attempt) { + if ($grade->grade) { + if ($grade->grade > -1) { + if (($attempt->modified > $grade->dategraded)) { + $graded = false; + } else { + $graded = true; + } + } else { + $graded = false; + } + } else { + $graded = false; + } + + // No grade journals. + if ($journal->grade == 0) { + return 'submitted'; + } + + if ($attempt->rating === NULL || $grade->grade === NULL) { + return 'waitinggrade'; + } else { + if ($graded) { + return 'submitted'; + } + } + } + } else { + return false; + } + } else { + return false; + } +} + + +/* Add functionality for getting Scorm data +*/ +function get_scorm_activity($course, $userid, $mod) { + global $CFG; + require_once($CFG->dirroot.'/mod/scorm/lib.php'); + $scorm = new stdClass; + $scorm->id = $mod->instance; + $user = new stdClass; + $user->id = $userid; + $scormgrade = scorm_get_user_grades($scorm, $userid); + $scormoutline = scorm_user_outline($course, $user, $mod, $scorm); + $scormactivity = array(); + $scormactivity['grade'] = $scormgrade; + $scormactivity['outline'] = $scormoutline; + return $scormactivity; +} + function block_fn_mentor_grade_summary($studentid, $courseid=0) { global $DB; @@ -1055,12 +1302,7 @@ function block_fn_mentor_grade_summary($studentid, $courseid=0) { $course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST); // Available modules for grading. - $modavailable = array( - 'assign' => '1', - 'quiz' => '1', - 'assignment' => '1', - 'forum' => '1', - ); + $modavailable = get_graded_mods(); $context = context_course::instance($course->id); @@ -1157,7 +1399,13 @@ function block_fn_mentor_grade_summary($studentid, $courseid=0) { AND gi.courseid = ? AND gg.userid = ?"; if ($courseaverage = $DB->get_record_sql($sqlcourseaverage, array('course', $id, $studentid))) { - $coursegrades[$id] = ($courseaverage->finalgrade / $courseaverage->rawgrademax) * 100; + //Prevent division by zero. + if($courseaverage->rawgrademax > 0) { + $coursegrades[$id] = ($courseaverage->finalgrade / $courseaverage->rawgrademax) * 100; + } else { + //Prevent division by zero. + $coursegrades[$id] = 0; + } if ($coursegrades[$id] >= $passinggrade) { $data->passed++; @@ -1204,10 +1452,16 @@ function block_fn_mentor_grade_summary($studentid, $courseid=0) { } } $totalnumofgraded = $nogradeassignments + $numofgraded; + //added to separate completed vs total. + $data->numofgraded = $totalnumofgraded; + $data->numofactivities = $numofactivities; $data->numofcompleted = "$totalnumofgraded/$numofactivities"; $data->percentageofcompleted = round(($numofgraded / $numofactivities) * 100); } else { - $data->numofcompleted = "N/A"; + //added to separate completed vs total. + $data->numofgraded = "N/A"; + $data->numofactivities = 0; + $data->numofcompleted = "N/A"; $data->percentageofcompleted = 0; } } @@ -1215,12 +1469,197 @@ function block_fn_mentor_grade_summary($studentid, $courseid=0) { return $data; } +function block_fn_mentor_quality_grade ($studentid, $courseid=0) { + //Add BlueSky's quality grade calculation to Grade window. + global $DB; + + $data = new stdClass(); + $courses = array(); + $coursegrades = array(); + $nogradeassignments = 0; + $qualitygrades = array(); + + if (! $passinggrade = get_config('block_fn_mentor', 'passinggrade')) { + $passinggrade = 50; + } + + $gradetotal = array( + 'attempted_grade' => 0, + 'attempted_max' => 0, + 'all_max' => 0 + ); + + if ($courseid) { + $courses[$courseid] = $courseid; + } else { + $courses = block_fn_mentor_get_student_courses($studentid); + } + + if ($courses) { + foreach ($courses as $id => $value) { + + $course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST); + + // Available modules for grading. + $modavailable = get_graded_mods(); + + $context = context_course::instance($course->id); + + // Collect modules data. + $mods = get_course_mods($course->id); + + // Skip some mods. + foreach ($mods as $mod) { + if (!isset($modavailable[$mod->modname])) { + continue; + } + // Skip non tracked activities. + if ($mod->completion == COMPLETION_TRACKING_NONE) { + continue; + } + if ($mod->groupingid) { + $sqlgrouiping = "SELECT 1 + FROM {groupings_groups} gg + INNER JOIN {groups_members} gm + ON gg.groupid = gm.groupid + WHERE gg.groupingid = ? + AND gm.userid = ?"; + if (!$DB->record_exists_sql($sqlgrouiping, array($mod->groupingid, $studentid))) { + continue; + } + } + // Check no grade assignments. + if ($mod->modname == 'assign') { + if ($assignment = $DB->get_record('assign', array('id' => $mod->instance))) { + if ($assignment->grade == 0) { + if ($submission = $DB->get_records('assign_submission', array( + 'assignment' => $assignment->id, 'userid' => $studentid), 'attemptnumber DESC', '*', 0, 1) + ) { + ++$nogradeassignments; + } + } + } + } + + if (!$gradeitem = $DB->get_record('grade_items', + array('itemtype' => 'mod', 'itemmodule' => $mod->modname, 'iteminstance' => $mod->instance))) { + continue; + } + + $gradetotal['all_max'] += $gradeitem->grademax; + + if ($gradegrade = $DB->get_record('grade_grades', array('itemid' => $gradeitem->id, 'userid' => $studentid))) { + + if ($mod->modname == 'assign') { + if ($assigngrades = $DB->get_records('assign_grades', array( + 'assignment' => $mod->instance, 'userid' => $studentid), 'attemptnumber DESC')) { + $assigngrade = reset($assigngrades); + if ($assigngrade->grade >= 0) { + // Graded. + $gradetotal['attempted_grade'] += $gradegrade->finalgrade; + $gradetotal['attempted_max'] += $gradeitem->grademax; + } + } + } else { + // Graded. + $gradetotal['attempted_grade'] += $gradegrade->finalgrade; + $gradetotal['attempted_max'] += $gradeitem->grademax; + } + } + } + } + } + if ($gradetotal['attempted_max']) { + $attempted = round(($gradetotal['attempted_grade'] / $gradetotal['attempted_max']) * 100); + } else { + $attempted = 0; + } + if ($gradetotal['all_max']) { + $all = round(($gradetotal['attempted_grade'] / $gradetotal['all_max']) * 100); + } else { + $all = 0; + } + + $data->attempted = $attempted; + $data->all = $all; + $data->passed = 0; + $data->failed = 0; + $data->timecompleted = 0; + + if ($courses) { + foreach ($courses as $id => $value) { + $sqlcourseaverage = "SELECT gg.id, round(gg.finalgrade,2) as finalgrade, round(gg.rawgrademax,2) as rawgrademax + FROM {grade_grades} gg + JOIN {grade_items} gi + ON gg.itemid = gi.id + WHERE gi.itemtype = ? + AND gi.courseid = ? + AND gg.userid = ? + AND gi.gradetype <> '0' + AND gi.aggregationcoef <> '1%' + AND gg.finalgrade IS NOT NULL"; + + if ($records = $DB->get_records_sql($sqlcourseaverage, array('mod', $id, $studentid))) { + $quality = new stdClass; + $quality->finalgrade = 0; + $quality->rawgrademax = 0; + foreach ($records as $record) { + foreach ($record as $key => $value) { + if($key != 'id') { + $quality->$key += $value; + } + } + }; + if ($quality->rawgrademax == 0) { + $qualitygrades[$id] = 0; + } else { + $qualitygrades[$id] = ($quality->finalgrade / $quality->rawgrademax) * 100; + } + + if ($qualitygrades[$id] >= $passinggrade) { + $data->passed++; + } else { + $data->failed++; + } + } + $info = new completion_info($cor = $DB->get_record('course', array('id' => $id))); + if ($iscomplete = $info->is_course_complete($studentid)) { + $ccompletion = $DB->get_record('course_completions', array('userid' => $studentid, 'course' => $id)); + $data->timecompleted = $ccompletion->timecompleted; + } + } + } + if (count($qualitygrades)) { + $data->allcourseaverge = round(array_sum($qualitygrades) / count($qualitygrades)); + } else { + $data->allcourseaverge = 0; + } + + if ($courseid) { + + if (isset($qualitygrades[$courseid])) { + $data->courseaverage = round($qualitygrades[$courseid]); + } else { + $data->courseaverage = 0; + } + } + + return $data; + +} + function block_fn_mentor_print_grade_summary ($courseid , $studentid) { global $OUTPUT; $html = ''; $courseaverage = block_fn_mentor_get_user_course_average($studentid, $courseid); $gradesummary = block_fn_mentor_grade_summary($studentid, $courseid); + //Add Quzlity Grade to print results. + $qualitysummary = block_fn_mentor_quality_grade ($studentid, $courseid); + // Use the configured passing grade. + if (! $passinggrade = get_config('block_fn_mentor', 'passinggrade')) { + $passinggrade = 50; + } $html .= ''; $html .= ''; @@ -1233,7 +1672,8 @@ function block_fn_mentor_print_grade_summary ($courseid , $studentid) { $class = 'red'; $nocoursetotalmsg = get_string('nocoursetotal', 'block_fn_mentor'); } else { - $class = ($gradesummary->courseaverage >= 50) ? 'green' : 'red'; + // Use the configured passing grade. + $class = ($gradesummary->courseaverage >= $passinggrade) ? 'green' : 'red'; $nocoursetotalmsg = ''; } $html .= ''; @@ -1244,7 +1684,21 @@ function block_fn_mentor_print_grade_summary ($courseid , $studentid) { $html .= ''; $html .= ''; } + // add Quality grade to grade window. + $html .= ''; + $html .= ''; + if ($courseaverage == false) { + $class = 'red'; + $nocoursetotalmsg = get_string('nocoursetotal', 'block_fn_mentor'); + } else { + $class = ($qualitysummary->courseaverage >= $passinggrade) ? 'green' : 'red'; + $nocoursetotalmsg = ''; + } + $html .= ''; + $html .= ''; + $html .= '
'.$gradesummary->courseaverage.'%'.$warningimg.get_string('nocoursetotal', 'block_fn_mentor').'
'.get_string('qualitygrade', 'block_fn_mentor').':'.$qualitysummary->courseaverage.'%
'; + return $html; } @@ -1792,9 +2246,10 @@ function block_fn_mentor_render_notification_rule_table($notification, $number) return $html; } + function block_fn_mentor_last_activity ($studentid) { global $DB; - + // added extra activity types, lesson, journal, scorm, LTI, HSU forum. $lastsubmission = null; $lastattempt = null; $lastpost = null; @@ -1824,6 +2279,30 @@ function block_fn_mentor_last_activity ($studentid) { $attempt = reset($attempts); $lastattempt = round(((time() - $attempt->timefinish) / (24 * 60 * 60)), 0); } + + // Lessons. + $sqllesson = "SELECT l.id, + l.completed + FROM {lesson_grades} l + WHERE l.userid = ? + ORDER BY l.completed DESC"; + + if ($lattempts = $DB->get_records_sql($sqllesson, array($studentid))) { + $lattempt = reset($lattempts); + $llastattempt = round(((time() - $lattempt->completed) / (24 * 60 * 60)), 0); + } + + // Journals. + $sqljournal = "SELECT j.id, + j.modified + FROM {journal_entries} j + WHERE j.userid = ? + ORDER BY j.modified DESC"; + + if ($entries = $DB->get_records_sql($sqljournal, array($studentid))) { + $entry = reset($entries); + $jlastentry = round(((time() - $entry->completed) / (24 * 60 * 60)), 0); + } // Forum. $sqlforum = "SELECT f.id, @@ -1836,8 +2315,44 @@ function block_fn_mentor_last_activity ($studentid) { $post = reset($posts); $lastpost = round(((time() - $post->modified) / (24 * 60 * 60)), 0); } + + // HSUForum. + $sqlhforum = "SELECT f.id, + f.modified + FROM {hsuforum_posts} f + WHERE f.userid = ? + ORDER BY f.modified DESC"; - return min($lastsubmission, $lastattempt, $lastpost); + if ($hposts = $DB->get_records_sql($sqlhforum, array($studentid))) { + $hpost = reset($hposts); + $lasthsupost = round(((time() - $hpost->modified) / (24 * 60 * 60)), 0); + } + + //Scorm. + $sqlscorm = "SELECT sc.id, + sc.timemodified + FROM {scorm_scoes_track} sc + WHERE sc.userid = ? + ORDER BY sc.timemodified DESC"; + + if ($scattempts = $DB->get_records_sql($sqlscorm, array($studentid))) { + $scattempt = reset($scattempts); + $sclastattempt = round(((time() - $scattempt->timemodified) / (24 * 60 * 60)), 0); + } + + // LTI. + $sqllti = "SELECT lti.id, + lti.datesubmitted + FROM {lti_submission} lti + WHERE lti.userid = ? + ORDER BY lti.datesubmitted DESC"; + + if ($ltisubmissions = $DB->get_records_sql($sqllti, array($studentid))) { + $ltisubmission = reset($ltisubmissions); + $ltilastsubmission = round(((time() - $ltisubmission->datesubmitted) / (24 * 60 * 60)), 0); + } + + return min($lastsubmission, $lastattempt, $llastattempt, $lastpost, $lasthsupost, $jlastentry, $sclastattempt, $ltilastsubmission); } function block_fn_mentor_report_outline_print_row($mod, $instance, $result) { @@ -1870,77 +2385,89 @@ function block_fn_mentor_report_outline_print_row($mod, $instance, $result) { echo ""; } -function block_fn_mentor_format_time($totalsecs, $str=null) { - - $totalsecs = abs($totalsecs); - - if (!$str) { // Create the str structure the slow way. - $str = new stdClass(); - $str->day = get_string('day'); - $str->days = get_string('days'); - $str->hour = get_string('hour'); - $str->hours = get_string('hours'); - $str->min = get_string('min'); - $str->mins = get_string('mins'); - $str->sec = get_string('sec'); - $str->secs = get_string('secs'); - $str->year = get_string('year'); - $str->years = get_string('years'); - } - - $years = floor($totalsecs / YEARSECS); - $remainder = $totalsecs - ($years * YEARSECS); - $days = floor($remainder / DAYSECS); - $remainder = $totalsecs - ($days * DAYSECS); - $hours = floor($remainder / HOURSECS); - $remainder = $remainder - ($hours * HOURSECS); - $mins = floor($remainder / MINSECS); - $secs = $remainder - ($mins * MINSECS); - - $ss = ($secs == 1) ? $str->sec : $str->secs; - $sm = ($mins == 1) ? $str->min : $str->mins; - $sh = ($hours == 1) ? $str->hour : $str->hours; - $sd = ($days == 1) ? $str->day : $str->days; - $sy = ($years == 1) ? $str->year : $str->years; - - $oyears = ''; - $odays = ''; - $ohours = ''; - $omins = ''; - $osecs = ''; - - if ($years) { - $oyears = $years .' '. $sy; - } - if ($days) { - $odays = $days .' '. $sd; - } - if ($hours) { - $ohours = $hours .' '. $sh; - } - if ($mins) { - $omins = $mins .' '. $sm; - } - if ($secs) { - $osecs = $secs .' '. $ss; - } - - if ($years) { - return trim($oyears); - } - if ($days) { - return trim($odays); - } - if ($hours) { - return trim($ohours); - } - if ($mins) { - return trim($omins); - } - if ($secs) { - return $osecs; - } - return get_string('now'); +function block_fn_mentor_format_time($time, $lastaccess, $str=null) { + /* adjusted the function to include never access, + * make sure to change all instances of function to three + * params in course_overview.php and + * course_overview_single.php */ + + if($lastaccess == 0) { + $never = true; + return 'Never'; + // No calulations necessary. + } else { + // Go ahead and calculate the last access + $totalsecs = abs($time - $lastaccess); + + if (!$str) { // Create the str structure the slow way. + $str = new stdClass(); + $str->day = get_string('day'); + $str->days = get_string('days'); + $str->hour = get_string('hour'); + $str->hours = get_string('hours'); + $str->min = get_string('min'); + $str->mins = get_string('mins'); + $str->sec = get_string('sec'); + $str->secs = get_string('secs'); + $str->year = get_string('year'); + $str->years = get_string('years'); + } + + $years = floor($totalsecs / YEARSECS); + $remainder = $totalsecs - ($years * YEARSECS); + $days = floor($remainder / DAYSECS); + $remainder = $totalsecs - ($days * DAYSECS); + $hours = floor($remainder / HOURSECS); + $remainder = $remainder - ($hours * HOURSECS); + $mins = floor($remainder / MINSECS); + $secs = $remainder - ($mins * MINSECS); + + $ss = ($secs == 1) ? $str->sec : $str->secs; + $sm = ($mins == 1) ? $str->min : $str->mins; + $sh = ($hours == 1) ? $str->hour : $str->hours; + $sd = ($days == 1) ? $str->day : $str->days; + $sy = ($years == 1) ? $str->year : $str->years; + + $oyears = ''; + $odays = ''; + $ohours = ''; + $omins = ''; + $osecs = ''; + + + if ($years) { + $oyears = $years .' '. $sy; + } + if ($days) { + $odays = $days .' '. $sd; + } + if ($hours) { + $ohours = $hours .' '. $sh; + } + if ($mins) { + $omins = $mins .' '. $sm; + } + if ($secs) { + $osecs = $secs .' '. $ss; + } + + if ($years) { + return trim($oyears); + } + if ($days) { + return trim($odays); + } + if ($hours) { + return trim($ohours); + } + if ($mins) { + return trim($omins); + } + if ($secs) { + return $osecs; + } + return get_string('now'); + } } function block_fn_mentor_note_print($note, $detail = NOTES_SHOW_FULL) { @@ -2498,6 +3025,46 @@ function block_fn_mentor_embed ($text, $id) { ); }; +function get_enrollment_dates($menteeid, $enrolledcourse) { + // Add for enrollment period dates. + global $DB; + $data = new stdClass; + $sql = "SELECT ue.timestart, ue.timeend + FROM {user_enrolments} ue + JOIN {enrol} e + ON e.id = ue.enrolid + WHERE ue.userid = ? + AND e.courseid = ?"; + if ($enrolinfo = $DB->get_records_sql($sql, array($menteeid, $enrolledcourse))) { + // If there are more than one enrollment record remove any records without a start or end date. + if (count($enrolinfo) > 1) { + foreach($enrolinfo as $key => $value) { + if($value->timestart == 0 || $value->timeend == 0) { + unset($enrolinfo[$key]); + } + } + } + + foreach ($enrolinfo as $enrol) { + $data->enrolstart = $enrol->timestart; + $data->enrolend = $enrol->timeend; + } + } else { + $data->enrolstart = 0; + $data->enrolend = 0; + } + + return $data; +} + + +function get_session_times($enrolledcourse) { + // Connect to external database logs to get session times for each course. Compare course id number to get times. Returns string. + $extdb = new Database(); + $sessiondata = $extdb->get_extdb_sessions($enrolledcourse); + return $sessiondata; +} + function block_fn_mentor_activity_progress($course, $menteeid, $modgradesarray) { global $CFG, $DB, $SESSION; @@ -2556,80 +3123,244 @@ function block_fn_mentor_activity_progress($course, $menteeid, $modgradesarray) continue; } $instance = $DB->get_record($activity->modname, array("id" => $activity->instance)); - $item = $DB->get_record('grade_items', - array("itemtype" => 'mod', "itemmodule" => $activity->modname, "iteminstance" => $activity->instance) - ); - + // Only count if it is a graded item. + if (!$item = $DB->get_record('grade_items', + array("itemtype" => 'mod', "itemmodule" => $activity->modname, "iteminstance" => $activity->instance))) { + continue; + } + $libfile = $CFG->dirroot . '/mod/' . $activity->modname . '/lib.php'; - - if (file_exists($libfile)) { - require_once($libfile); - $gradefunction = $activity->modname . "_get_user_grades"; - - if ((($activity->modname != 'forum') || ($instance->assessed > 0)) - && isset($modgradesarray[$activity->modname])) { - - if (function_exists($gradefunction)) { - - if (($activity->modname == 'quiz') || ($activity->modname == 'forum')) { - - if ($grade = $gradefunction($instance, $menteeid)) { - if ($item->gradepass > 0) { - if ($grade[$menteeid]->rawgrade >= $item->gradepass) { - // Passed - ++$completedactivities; - } else { - // Failed - ++$incompletedactivities; - } - } else { - // Graded - ++$completedactivities; - } - } else { - // Ungraded - ++$notattemptedactivities; - } - } else if ($modstatus = block_fn_mentor_assignment_status($activity, $menteeid, true)) { - switch ($modstatus) { - case 'submitted': - if ($instance->grade == 0) { - // Graded - ++$completedactivities; - } elseif ($grade = $gradefunction($instance, $menteeid)) { - if ($item->gradepass > 0) { - if ($grade[$menteeid]->rawgrade >= $item->gradepass) { - // Passed - ++$completedactivities; - } else { - // Fail. - ++$incompletedactivities; - } - } else { - // Graded - ++$completedactivities; - } - } - break; - - case 'saved': - // Saved - ++$savedactivities; - break; - - case 'waitinggrade': - // Waiting for grade - ++$waitingforgradeactivities; - break; - } - } else { - // Ungraded - ++$notattemptedactivities; - } - } - } - } - } + // Check to see if the mod has an internal grade function, if not use Moodle get grades function. (For extra modules). + if (file_exists($libfile)) { + $gradefunction = $activity->modname . "_get_user_grades"; + if(!function_exists($gradefunction)) { + $gradefunction = "grade_get_grades"; + } else { + require_once($libfile); + } + } + // Add the advanced forums to check. + if ((($activity->modname != 'forum') || ($activity->modname != 'hsuforum') || ($instance->assessed > 0)) + && isset($modgradesarray[$activity->modname])) { + + if (function_exists($gradefunction)) { + // Check to see if this module is using their own get grades method or switch to the standard Moodle get grades function. + if (strpos($gradefunction, $activity->modname) !== false) { + + if ($grade = $gradefunction($instance, $menteeid)) { + // Reordered loop to pass through special cases first before using the standard method. + if ($modstatus = block_fn_mentor_assignment_status($activity, $menteeid, true)) { + switch ($modstatus) { + case 'submitted': + if ($instance->grade == 0) { + // Graded + ++$completedactivities; + } else if ($grade = $gradefunction($instance, $menteeid)) { + if ($item->gradepass > 0) { + if ($grade[$menteeid]->rawgrade >= $item->gradepass) { + // Passed + ++$completedactivities; + } else { + // Fail. + ++$incompletedactivities; + } + } else { + // Graded + ++$completedactivities; + } + } + break; + + case 'saved': + // Saved + ++$savedactivities; + break; + + case 'waitinggrade': + // Waiting for grade + ++$waitingforgradeactivities; + break; + } + } else if ($modstatus = block_fn_mentor_quiz_status($activity, $menteeid, true)) { + // Check for special quiz statuses. + switch ($modstatus) { + case 'submitted': + if ($instance->grade == 0) { + // Graded + ++$completedactivities; + } else if ($grade = $gradefunction($instance, $menteeid)) { + if ($item->gradepass > 0) { + if ($grade[$menteeid]->rawgrade >= $item->gradepass) { + // Passed + ++$completedactivities; + } else { + // Fail. + ++$incompletedactivities; + } + } else { + // Graded + ++$completedactivities; + } + } + break; + + case 'saved': + // Saved + ++$savedactivities; + break; + + case 'waitinggrade': + // Waiting for grade + ++$waitingforgradeactivities; + break; + } + } else if ($modstatus = block_fn_mentor_lesson_status($activity, $menteeid, $course, true)) { + // Check for special lesson statuses. + switch ($modstatus) { + case 'submitted': + if ($instance->grade == 0) { + // Graded + ++$completedactivities; + } else if ($grade = $gradefunction($instance, $menteeid)) { + if ($item->gradepass > 0) { + if ($grade[$menteeid]->rawgrade >= $item->gradepass) { + // Passed + ++$completedactivities; + } else { + // Fail. + ++$incompletedactivities; + } + } else { + // Graded + ++$completedactivities; + } + } + break; + + case 'saved': + // Saved + ++$savedactivities; + break; + + case 'waitinggrade': + // Waiting for grade + ++$waitingforgradeactivities; + break; + } + } else if ($modstatus = block_fn_mentor_journal_status($activity, $menteeid, $course, true)) { + // Check for special journal statuses. + switch ($modstatus) { + case 'submitted': + if ($instance->grade == 0) { + // Graded + ++$completedactivities; + } else if ($grade = $gradefunction($instance, $menteeid)) { + if ($item->gradepass > 0) { + if ($grade[$menteeid]->rawgrade >= $item->gradepass) { + // Passed + ++$completedactivities; + } else { + // Fail. + ++$incompletedactivities; + } + } else { + // Graded + ++$completedactivities; + } + } + break; + + case 'saved': + // Saved + ++$savedactivities; + break; + + case 'waitinggrade': + // Waiting for grade + ++$waitingforgradeactivities; + break; + } + } else if ($grade) { + if ($item->gradepass > 0) { + if ($grade[$menteeid]->rawgrade >= $item->gradepass) { + // Passed + ++$completedactivities; + } else { + // Failed + ++$incompletedactivities; + } + } else { + // Graded + ++$completedactivities; + } + + } else { + // Ungraded + ++$notattemptedactivities; + } + + } else if ($activity->modname == 'quiz') { + // Count waiting for grade quizzes without a grade from grade function. + $modstatus = block_fn_mentor_quiz_status($activity, $menteeid, true); + // Waiting for grade + if($modstatus == 'waitinggrade') { + ++$waitingforgradeactivities; + } else { + // Ungraded + ++$notattemptedactivities; + } + + } else if ($activity->modname == 'lesson') { + // Count saved lessons that don't yet have a grade + + $modstatus = block_fn_mentor_lesson_status($activity, $menteeid, $course, true); + // Saved + if($modstatus == 'saved') { + ++$savedactivities; + } else { + // Ungraded + ++$notattemptedactivities; + } + } else if ($activity->modname == 'journal') { + $modstatus = block_fn_mentor_journal_status($activity, $menteeid, $course, true); + // Saved + if($modstatus == 'waitinggrade') { + ++$waitingforgradeactivities; + } else { + // Ungraded + ++$notattemptedactivities; + } + } else { + // Ungraded + ++$notattemptedactivities; + } + + } else { + // Add other graded module types. + if ($grade = $gradefunction($course->id, 'mod', $activity->modname, $activity->instance, $menteeid)) { + $usergrade = $grade->items[0]->grades[$menteeid]; + if ($usergrade->grade !== null && $usergrade->dategraded !== null) { + if ($item->gradepass > 0) { + if ($usergrade->grade >= $item->gradepass) { + // Passed + ++$completedactivities; + } else { + // Failed + ++$incompletedactivities; + } + } else { + // Graded + ++$completedactivities; + } + } else { + // Ungraded + ++$notattemptedactivities; + } + } + } + } // end check for grade function + } // end check for graded modules + } // end foreach activity if ($incompletedactivities == 0) { $completed = get_string('completed', 'block_fn_mentor'); @@ -2703,6 +3434,8 @@ function block_fn_mentor_activity_progress($course, $menteeid, $modgradesarray) $progressdata->completed = $completedactivities + $incompletedactivities; $progressdata->total = $completedactivities + $incompletedactivities + $savedactivities + $notattemptedactivities + $waitingforgradeactivities; + //SRINDHAL. Added to include waiting for grade activities in progress calculations with configuration. + $progressdata->completewaiting = $completedactivities + $incompletedactivities + $waitingforgradeactivities; $sql = "SELECT gg.id, gg.rawgrademax, @@ -2714,7 +3447,12 @@ function block_fn_mentor_activity_progress($course, $menteeid, $modgradesarray) AND gi.courseid = ? AND gg.userid = ?"; if ($courseaverage = $DB->get_record_sql($sql, array('course', $course->id, $menteeid))) { - $progressdata->percentage = ($courseaverage->finalgrade / $courseaverage->rawgrademax) * 100; + // Prevent division by zero. + if ($courseaverage->rawgrademax > 0) { + $progressdata->percentage = ($courseaverage->finalgrade / $courseaverage->rawgrademax) * 100; + } else { + $progressdata->percentage = 100; + } } } else { @@ -2726,6 +3464,88 @@ function block_fn_mentor_activity_progress($course, $menteeid, $modgradesarray) return $progressdata; } +function block_fn_mentor_calculate_activity_progress ($course, $menteeid) { + // Calculate the progress in course using dates for progress bar. + global $DB; + + $data = new stdClass; + $modgradesarray = get_graded_mods(); + $usewaiting = get_config('block_fn_mentor', 'includewaitinggrade'); + + $progressdata = block_fn_mentor_activity_progress($course, $menteeid, $modgradesarray); + + if ($usewaiting) { + $data->activitycomplete = $progressdata->completewaiting; + } else { + $data->activitycomplete = $progressdata->completed; + } + $data->activitytotal = $progressdata->total; + if ($data->activitytotal > 0 ) { + $data->activpercentcomplete = round(($data->activitycomplete / $data->activitytotal) * 100, 0); + } else { + $data->activpercentcomplete = 100; + } + $data->timecompleted = $progressdata->timecompleted; + $time = time(); + $weekofseconds = 604800; + $sql = "SELECT ue.timestart, ue.timeend + FROM {user_enrolments} ue + JOIN {enrol} e + ON e.id = ue.enrolid + WHERE ue.userid = ? + AND e.courseid = ?"; + if ($enrolinfo = $DB->get_records_sql($sql, array($menteeid, $course->id))) { + if (count($enrolinfo) > 1) { + foreach($enrolinfo as $key => $value) { + if($value->timestart == 0 || $value->timeend == 0) { + unset($enrolinfo[$key]); + } + } + } + foreach ($enrolinfo as $enrol) { + $data->enrolstart = $enrol->timestart; + $data->enrolend = $enrol->timeend; + } + + if ($data->enrolstart == 0 || $data->enrolend == 0){ + // FIND CURRENT WEEK. + $courseformat = course_get_format($course); + $courseformatoptions = $courseformat->get_format_options(); + $coursenumsections = $courseformatoptions['numsections']; + + + $weekdate = $course->startdate; + $weekdate += 7200; + $courseenddate = $course->startdate + ($weekofseconds * $coursenumsections); + // Calculate the current week based on today's date and the starting date of the course. + $currentweek = ($time > $course->startdate) ? (int) ((($time - $course->startdate) / $weekofseconds) + 1) : 0; + $currentweek = min($currentweek, $coursenumsections); + $data->totalweeks = (int)(($courseenddate - $course->startdate) / $weekofseconds); + $data->currentweek = $currentweek; + if ($data->activitytotal == 0) { + $data->activitiesperweek = 0; + } else { + $data->activitiesperweek = round(($data->activitytotal / $data->totalweeks), 1, PHP_ROUND_HALF_UP); + } + } else { + $data->totalweeks = (int)(($data->enrolend - $data->enrolstart) / $weekofseconds); + $data->currentweek = ($time > $data->enrolstart) ? (int) ((($time - $data->enrolstart) / $weekofseconds) + 1) : 0; + if ($data->activitytotal == 0) { + $data->activitiesperweek = 0; + } else if ($data->currentweek > $data->totalweeks) { + $data->activitiesperweek = $data->activitytotal; + } else { + $data->activitiesperweek = round(($data->activitytotal / $data->totalweeks), 1, PHP_ROUND_HALF_UP); + } + } + + } + $data->currenttimepercentage = (($data->currentweek / $data->totalweeks) < 1) ? (int) (round(($data->currentweek / $data->totalweeks) * 100)) : 100; + + return $data; +} + + function block_fn_mentor_simplegradebook($course, $menteeuser, $modgradesarray) { global $CFG, $DB; @@ -2809,10 +3629,17 @@ function block_fn_mentor_simplegradebook($course, $menteeuser, $modgradesarray) $libfile = $CFG->dirroot . '/mod/' . $mod->modname . '/lib.php'; if (file_exists($libfile)) { - require_once($libfile); - $gradefunction = $mod->modname . "_get_user_grades"; - - if ((($mod->modname != 'forum') || ($instance->assessed > 0)) + // Check to see if this module is using their own get grades method or switch to the standard Moodle get grades function. + $gradefunction = $mod->modname . "_get_user_grades"; + if(!function_exists($gradefunction)) { + $gradefunction = "grade_get_grades"; + } else { + require_once($libfile); + } + } + if($item) { + // Added advanced forum check. + if (((($mod->modname != 'forum') || ($mod->modname != 'hsuforum')) || ($instance->assessed > 0)) && isset($modgradesarray[$mod->modname])) { if (function_exists($gradefunction)) { @@ -2825,108 +3652,328 @@ function block_fn_mentor_simplegradebook($course, $menteeuser, $modgradesarray) $weekactivitycount[$i]['mod'][] = $image; $weekactivitycount[$i]['modname'][] = $instance->name; + foreach ($simplegradebook as $key => $value) { - - if (($mod->modname == 'quiz')||($mod->modname == 'forum')) { - - if ($grade = $gradefunction($instance, $key)) { - if ($item->gradepass > 0) { - if ($grade[$key]->rawgrade >= $item->gradepass) { - $simplegradebook[$key]['grade'][$i][$mod->id] = 'marked.gif'; // Passed. - $simplegradebook[$key]['avg'][] = array( - 'grade' => $grade[$key]->rawgrade, - 'grademax' => $item->grademax - ); - } else { - $simplegradebook[$key]['grade'][$i][$mod->id] = 'incomplete.gif'; // Fail. - $simplegradebook[$key]['avg'][] = array( - 'grade' => $grade[$key]->rawgrade, - 'grademax' => $item->grademax - ); - } - } else { - // Graded (grade-to-pass is not set). - $simplegradebook[$key]['grade'][$i][$mod->id] = 'graded_.gif'; - $simplegradebook[$key]['avg'][] = array( - 'grade' => $grade[$key]->rawgrade, - 'grademax' => $item->grademax - ); - } - } else { + + if (strpos($gradefunction, $mod->modname) !== false) { + // Run through special cases first before applying standard grade checks. + $grade = $gradefunction($instance, $key); + + if ($modstatus = block_fn_mentor_assignment_status($mod, $key, true)) { + + switch ($modstatus) { + case 'submitted': + if ($instance->grade == 0) { + $simplegradebook[$key]['grade'][$i][$mod->id] = 'graded_.gif'; + } else if ($grade) { + if ($item->gradepass > 0) { + if ($grade[$key]->rawgrade >= $item->gradepass) { + $simplegradebook[$key]['grade'][$i][$mod->id] = 'marked.gif';// Passed. + $simplegradebook[$key]['avg'][] = array( + 'grade' => $grade[$key]->rawgrade, 'grademax' => $item->grademax + ); + } else { + // Fail. + $simplegradebook[$key]['grade'][$i][$mod->id] = 'incomplete.gif'; + $simplegradebook[$key]['avg'][] = array( + 'grade' => $grade[$key]->rawgrade, 'grademax' => $item->grademax + ); + } + } else { + // Graded (grade-to-pass is not set). + $simplegradebook[$key]['grade'][$i][$mod->id] = 'graded_.gif'; + $simplegradebook[$key]['avg'][] = array( + 'grade' => $grade[$key]->rawgrade, 'grademax' => $item->grademax + ); + } + } + break; + + case 'saved': + $simplegradebook[$key]['grade'][$i][$mod->id] = 'saved.gif'; + break; + + case 'waitinggrade': + $simplegradebook[$key]['grade'][$i][$mod->id] = 'unmarked.gif'; + break; + } + } else if($modstatus = block_fn_mentor_quiz_status($mod, $key, true)) { + // Check for manually graded quizzes. + switch ($modstatus) { + case 'submitted': + if ($instance->grade == 0) { + $simplegradebook[$key]['grade'][$i][$mod->id] = 'graded_.gif'; + } else if ($grade) { + if ($item->gradepass > 0) { + if ($grade[$key]->rawgrade >= $item->gradepass) { + $simplegradebook[$key]['grade'][$i][$mod->id] = 'marked.gif';// Passed. + $simplegradebook[$key]['avg'][] = array( + 'grade' => $grade[$key]->rawgrade, 'grademax' => $item->grademax + ); + } else { + // Fail. + $simplegradebook[$key]['grade'][$i][$mod->id] = 'incomplete.gif'; + $simplegradebook[$key]['avg'][] = array( + 'grade' => $grade[$key]->rawgrade, 'grademax' => $item->grademax + ); + } + } else { + // Graded (grade-to-pass is not set). + $simplegradebook[$key]['grade'][$i][$mod->id] = 'graded_.gif'; + $simplegradebook[$key]['avg'][] = array( + 'grade' => $grade[$key]->rawgrade, 'grademax' => $item->grademax + ); + } + } + break; + + case 'saved': + $simplegradebook[$key]['grade'][$i][$mod->id] = 'saved.gif'; + break; + + case 'waitinggrade': + $simplegradebook[$key]['grade'][$i][$mod->id] = 'unmarked.gif'; + break; + } + } else if ($modstatus = block_fn_mentor_lesson_status($mod, $key, $course, true)) { + // Check for manually graded lesson essays. + switch ($modstatus) { + case 'submitted': + if ($instance->grade == 0) { + $simplegradebook[$key]['grade'][$i][$mod->id] = 'graded_.gif'; + } else if ($grade) { + if ($item->gradepass > 0) { + if ($grade[$key]->rawgrade >= $item->gradepass) { + $simplegradebook[$key]['grade'][$i][$mod->id] = 'marked.gif';// Passed. + $simplegradebook[$key]['avg'][] = array( + 'grade' => $grade[$key]->rawgrade, 'grademax' => $item->grademax + ); + } else { + // Fail. + $simplegradebook[$key]['grade'][$i][$mod->id] = 'incomplete.gif'; + $simplegradebook[$key]['avg'][] = array( + 'grade' => $grade[$key]->rawgrade, 'grademax' => $item->grademax + ); + } + } else { + // Graded (grade-to-pass is not set). + $simplegradebook[$key]['grade'][$i][$mod->id] = 'graded_.gif'; + $simplegradebook[$key]['avg'][] = array( + 'grade' => $grade[$key]->rawgrade, 'grademax' => $item->grademax + ); + } + } + break; + + case 'saved': + $simplegradebook[$key]['grade'][$i][$mod->id] = 'saved.gif'; + break; + + case 'waitinggrade': + $simplegradebook[$key]['grade'][$i][$mod->id] = 'unmarked.gif'; + break; + } + + } else if ($modstatus = block_fn_mentor_journal_status($mod, $key, $course, true)) { + // Check ungraded submitted journal entries. + switch ($modstatus) { + case 'submitted': + if ($instance->grade == 0) { + $simplegradebook[$key]['grade'][$i][$mod->id] = 'graded_.gif'; + } else if ($grade) { + if ($item->gradepass > 0) { + if ($grade[$key]->rawgrade >= $item->gradepass) { + $simplegradebook[$key]['grade'][$i][$mod->id] = 'marked.gif';// Passed. + $simplegradebook[$key]['avg'][] = array( + 'grade' => $grade[$key]->rawgrade, 'grademax' => $item->grademax + ); + } else { + // Fail. + $simplegradebook[$key]['grade'][$i][$mod->id] = 'incomplete.gif'; + $simplegradebook[$key]['avg'][] = array( + 'grade' => $grade[$key]->rawgrade, 'grademax' => $item->grademax + ); + } + } else { + // Graded (grade-to-pass is not set). + $simplegradebook[$key]['grade'][$i][$mod->id] = 'graded_.gif'; + $simplegradebook[$key]['avg'][] = array( + 'grade' => $grade[$key]->rawgrade, 'grademax' => $item->grademax + ); + } + } + break; + + case 'saved': + $simplegradebook[$key]['grade'][$i][$mod->id] = 'saved.gif'; + break; + + case 'waitinggrade': + $simplegradebook[$key]['grade'][$i][$mod->id] = 'unmarked.gif'; + break; + } + } else if ($grade) { + if ($item) { + + if ($item->gradepass > 0) { + if ($grade[$key]->rawgrade >= $item->gradepass) { + $simplegradebook[$key]['grade'][$i][$mod->id] = 'marked.gif'; // Passed. + $simplegradebook[$key]['avg'][] = array( + 'grade' => $grade[$key]->rawgrade, + 'grademax' => $item->grademax + ); + } else { + $simplegradebook[$key]['grade'][$i][$mod->id] = 'incomplete.gif'; // Fail. + $simplegradebook[$key]['avg'][] = array( + 'grade' => $grade[$key]->rawgrade, + 'grademax' => $item->grademax + ); + } + } else { + // Graded (grade-to-pass is not set). + $simplegradebook[$key]['grade'][$i][$mod->id] = 'graded_.gif'; + $simplegradebook[$key]['avg'][] = array( + 'grade' => $grade[$key]->rawgrade, + 'grademax' => $item->grademax + ); + } + + } + } else { + $simplegradebook[$key]['grade'][$i][$mod->id] = 'ungraded.gif'; if ($unsubmitted) { $simplegradebook[$key]['avg'][] = array( 'grade' => 0, 'grademax' => $item->grademax ); } - } - } else if ($modstatus = block_fn_mentor_assignment_status($mod, $key, true)) { - switch ($modstatus) { - case 'submitted': - if ($instance->grade == 0) { - $simplegradebook[$key]['grade'][$i][$mod->id] = 'graded_.gif'; - } elseif ($grade = $gradefunction($instance, $key)) { - if ($item->gradepass > 0) { - if ($grade[$key]->rawgrade >= $item->gradepass) { - $simplegradebook[$key]['grade'][$i][$mod->id] = 'marked.gif';// Passed. - $simplegradebook[$key]['avg'][] = array( - 'grade' => $grade[$key]->rawgrade, 'grademax' => $item->grademax - ); - } else { - // Fail. - $simplegradebook[$key]['grade'][$i][$mod->id] = 'incomplete.gif'; - $simplegradebook[$key]['avg'][] = array( - 'grade' => $grade[$key]->rawgrade, 'grademax' => $item->grademax - ); - } - } else { - // Graded (grade-to-pass is not set). - $simplegradebook[$key]['grade'][$i][$mod->id] = 'graded_.gif'; - $simplegradebook[$key]['avg'][] = array( - 'grade' => $grade[$key]->rawgrade, 'grademax' => $item->grademax - ); - } - } - break; - - case 'saved': - $simplegradebook[$key]['grade'][$i][$mod->id] = 'saved.gif'; - break; - - case 'waitinggrade': - $simplegradebook[$key]['grade'][$i][$mod->id] = 'unmarked.gif'; - break; - } + } } else { - $simplegradebook[$key]['grade'][$i][$mod->id] = 'ungraded.gif'; - if ($unsubmitted) { - $simplegradebook[$key]['avg'][] = array('grade' => 0, 'grademax' => $item->grademax); - } - } - } - } + + if($grade = grade_get_grades($course->id, 'mod', $mod->modname, $mod->instance, $key)) { + $usergrade = $grade->items[0]->grades[$menteeuser->id]; + if ($usergrade->grade) { + if ($item->gradepass > 0) { + if ($usergrade->grade >= $item->gradepass) { + $simplegradebook[$key]['grade'][$i][$mod->id] = 'marked.gif'; // Passed. + $simplegradebook[$key]['avg'][] = array( + 'grade' => $usergrade->grade, + 'grademax' => $item->grademax + ); + } else { + $simplegradebook[$key]['grade'][$i][$mod->id] = 'incomplete.gif'; // Fail. + $simplegradebook[$key]['avg'][] = array( + 'grade' => $usergrade->grade, + 'grademax' => $item->grademax + ); + } + + } else { + // Graded (grade-to-pass is not set). + $simplegradebook[$key]['grade'][$i][$mod->id] = 'graded_.gif'; + $simplegradebook[$key]['avg'][] = array( + 'grade' => $usergrade->grade, + 'grademax' => $item->grademax + ); + } + } else { + $simplegradebook[$key]['grade'][$i][$mod->id] = 'ungraded.gif'; + if ($unsubmitted) { + $simplegradebook[$key]['avg'][] = array( + 'grade' => 0, 'grademax' => $item->grademax + ); + } + + } + } + + } + + } //END. foreach + } //END. gradefunction exists } - } + } //END. if grade book item } } } + $weekactivitycount[$i]['numofweek'] = $numberofitem; } return array($simplegradebook, $weekactivitycount, $courseformat); } +function block_fn_mentor_print_activity_progress ($course , $studentid) { + // Print a Course Progress Bar to the page. + global $OUTPUT; + + $html = ''; + $progressbardata = block_fn_mentor_calculate_activity_progress ($course, $studentid); + + if ($progressbardata->currentweek > $progressbardata->totalweeks) { + // account for past course dates that are a long time in the past. + $suggestedpacenum = $progressbardata->activitytotal; + } else { + $suggestedpacenum = round($progressbardata->activitiesperweek * $progressbardata->currentweek, 1); + } + $studentcompletednum = $progressbardata->activitycomplete; + + if ($progressbardata->activpercentcomplete < $progressbardata->currenttimepercentage) { + $color = 'bar-danger'; + } else { + $color = 'bar-success'; + } + $html .= '
'; + //$html .= '

Track Progress

'; + $html .= '

'; + if($progressbardata->timecompleted > 0) { + // Course completed + $html .= '
Course Complete
'; + $html .= '
'; + $html .= '
'; + $html .= '100%'; + $html .= '
'; // end progress bar div + $html .= '
'; // end progress div + } else if ($progressbardata->activitytotal == 0) { + // No activities to complete + $html .= '

'.get_string('progressnoactivities', 'block_fn_mentor').'

'; + + } else if ($progressbardata->activitytotal > 0 && $progressbardata->activpercentcomplete == 0) { + // Has not completed any activities yet. + $html .= '
'.get_string('progresssuggestedpace', 'block_fn_mentor').' (activities)
'; + $html .= '
'; + $html .= '
'; + $html .= $suggestedpacenum; + $html .= '
'; // end progress bar div + $html .= '
'; // end progress div + $html .= '
'.get_string('progressstudentpace', 'block_fn_mentor').' (activities)
'; + $html .= '

'.get_string('progressnoactivitiescomp', 'block_fn_mentor').'

'; + } else { + $html .= '
'.get_string('progresssuggestedpace', 'block_fn_mentor').' (activities)
'; + $html .= '
'; + $html .= '
'; + $html .= $suggestedpacenum; + $html .= '
'; // end progress bar div + $html .= '
'; // end progress div + $html .= '
'.get_string('progressstudentpace', 'block_fn_mentor').' (activities)
'; + $html .= '
'; + $html .= '
'; + $html .= $studentcompletednum; + $html .= '
'; // end progress bar div + $html .= '
'; // end progress div + } + $html .= '
'; //end row + $html .= '
'; // end container + + return $html; +} + function block_fn_mentor_generate_report(progress_bar $progressbar = null) { global $DB; $inprogress = get_config('block_fn_mentor', 'inprogress'); $reportdate = get_config('block_fn_mentor', 'reportdate'); - $modgradesarray = array( - 'assign' => 'assign.submissions.fn.php', - 'quiz' => 'quiz.submissions.fn.php', - 'assignment' => 'assignment.submissions.fn.php', - 'forum' => 'forum.submissions.fn.php', - ); + $modgradesarray = get_graded_mods(); if ($inprogress && ((time() - $reportdate) < 10 * 60)) { return; From 9e5931f39de0e0169682d0597b653baad022147b Mon Sep 17 00:00:00 2001 From: cmERDC Digital Learning Date: Wed, 22 Nov 2017 10:08:26 -0600 Subject: [PATCH 03/22] new graded mods Added new graded mod types. Mades some logic changes. --- listactivities.php | 737 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 605 insertions(+), 132 deletions(-) diff --git a/listactivities.php b/listactivities.php index 4083e26..dd7e087 100644 --- a/listactivities.php +++ b/listactivities.php @@ -24,6 +24,8 @@ require_once($CFG->dirroot . '/course/lib.php'); require_once($CFG->dirroot . '/blocks/fn_mentor/lib.php'); require_once($CFG->libdir . '/completionlib.php'); +// Get the grade lib file for grade checks. +require_once($CFG->libdir . '/gradelib.php'); $usinghtmleditor = false; @@ -51,12 +53,7 @@ } // Array of functions to call for grading purposes for modules. -$modgradesarray = array( - 'assign' => 'assign.submissions.fn.php', - 'quiz' => 'quiz.submissions.fn.php', - 'assignment' => 'assignment.submissions.fn.php', - 'forum' => 'forum.submissions.fn.php', -); +$modgradesarray = get_graded_mods(); $completedactivities = 0; $incompletedactivities = 0; @@ -87,84 +84,245 @@ continue; } $instance = $DB->get_record($activity->modname, array("id" => $activity->instance)); - $item = $DB->get_record('grade_items', - array("itemtype" => 'mod', "itemmodule" => $activity->modname, "iteminstance" => $activity->instance) - ); - - $libfile = $CFG->dirroot . '/mod/' . $activity->modname . '/lib.php'; - - if (file_exists($libfile)) { - require_once($libfile); - $gradefunction = $activity->modname . "_get_user_grades"; - - if ((($activity->modname != 'forum') || ($instance->assessed > 0)) - && isset($modgradesarray[$activity->modname])) { - - if (function_exists($gradefunction)) { - - if (($activity->modname == 'quiz') || ($activity->modname == 'forum')) { - - if ($grade = $gradefunction($instance, $menteeid)) { - if ($item->gradepass > 0) { - if ($grade[$menteeid]->rawgrade >= $item->gradepass) { - // Passed - ++$completedactivities; - } else { - // Failed - ++$incompletedactivities; - } - } else { - // Graded - ++$completedactivities; - } - } else { - // Ungraded - ++$notattemptedactivities; - } - } else if ($modstatus = block_fn_mentor_assignment_status($activity, $menteeid, true)) { - switch ($modstatus) { - case 'submitted': - if ($instance->grade == 0) { - // Graded - ++$completedactivities; - } elseif ($grade = $gradefunction($instance, $menteeid)) { - if ($item->gradepass > 0) { - if ($grade[$menteeid]->rawgrade >= $item->gradepass) { - // Passed - ++$completedactivities; - } else { - // Fail. - ++$incompletedactivities; - } - } else { - // Graded - ++$completedactivities; - } - } - break; - - case 'saved': - // Saved - ++$savedactivities; - break; - - case 'waitinggrade': - // Waiting for grade - ++$waitingforgradeactivities; - break; - } - } else { - // Ungraded - ++$notattemptedactivities; - } - } - } + // Make sure we are only passing graded items. + if (!$item = $DB->get_record('grade_items', + array("itemtype" => 'mod', "itemmodule" => $activity->modname, "iteminstance" => $activity->instance))) { + continue; } + + $libfile = $CFG->dirroot . '/mod/' . $activity->modname . '/lib.php'; + if (file_exists($libfile)) { + // Check to see if this module is using their own get grades method or switch to the standard Moodle get grades function. + $gradefunction = $activity->modname . "_get_user_grades"; + if(!function_exists($gradefunction)) { + $gradefunction = "grade_get_grades"; + } else { + require_once($libfile); + } + } + + if (function_exists($gradefunction)) { + // Loop through special cases first. + if (strpos($gradefunction, $activity->modname) !== false) { + if ($grade = $gradefunction($instance, $menteeid)) { + if ($modstatus = block_fn_mentor_assignment_status($activity, $menteeid, true)) { + switch ($modstatus) { + case 'submitted': + if ($instance->grade == 0) { + // Graded + ++$completedactivities; + } elseif ($grade = $gradefunction($instance, $menteeid)) { + if ($item->gradepass > 0) { + if ($grade[$menteeid]->rawgrade >= $item->gradepass) { + // Passed + ++$completedactivities; + } else { + // Fail. + ++$incompletedactivities; + } + } else { + // Graded + ++$completedactivities; + } + } + break; + + case 'saved': + // Saved + ++$savedactivities; + break; + + case 'waitinggrade': + // Waiting for grade + ++$waitingforgradeactivities; + break; + } + + } else if ($modstatus = block_fn_mentor_quiz_status($activity, $menteeid, true)) { + // Check for manually graded quizzes. + switch ($modstatus) { + case 'submitted': + if ($instance->grade == 0) { + // Graded + ++$completedactivities; + } else if ($grade = $gradefunction($instance, $menteeid)) { + if ($item->gradepass > 0) { + if ($grade[$menteeid]->rawgrade >= $item->gradepass) { + // Passed + ++$completedactivities; + } else { + // Fail. + ++$incompletedactivities; + } + } else { + // Graded + ++$completedactivities; + } + } + break; + + case 'saved': + // Saved + ++$savedactivities; + break; + + case 'waitinggrade': + // Waiting for grade + ++$waitingforgradeactivities; + break; + } + + } else if ($modstatus = block_fn_mentor_lesson_status($activity, $menteeid, $course, true)) { + // Check for manually graded lessons. + switch ($modstatus) { + case 'submitted': + if ($instance->grade == 0) { + // Graded + ++$completedactivities; + } else if ($grade = $gradefunction($instance, $menteeid)) { + if ($item->gradepass > 0) { + if ($grade[$menteeid]->rawgrade >= $item->gradepass) { + // Passed + ++$completedactivities; + } else { + // Fail. + ++$incompletedactivities; + } + } else { + // Graded + ++$completedactivities; + } + } + break; + + case 'saved': + // Saved + ++$savedactivities; + break; + + case 'waitinggrade': + // Waiting for grade + ++$waitingforgradeactivities; + break; + } + + } else if ($modstatus = block_fn_mentor_journal_status($activity, $menteeid, $course, true)) { + // Check for journals waiting to be graded. + switch ($modstatus) { + case 'submitted': + if ($instance->grade == 0) { + // Graded + ++$completedactivities; + } else if ($grade = $gradefunction($instance, $menteeid)) { + if ($item->gradepass > 0) { + if ($grade[$menteeid]->rawgrade >= $item->gradepass) { + // Passed + ++$completedactivities; + } else { + // Fail. + ++$incompletedactivities; + } + } else { + // Graded + ++$completedactivities; + } + } + break; + + case 'saved': + // Saved + ++$savedactivities; + break; + + case 'waitinggrade': + // Waiting for grade + ++$waitingforgradeactivities; + break; + } + } else if ($grade) { + if ($item->gradepass > 0) { + if ($grade[$menteeid]->rawgrade >= $item->gradepass) { + // Passed + ++$completedactivities; + } else { + // Failed + ++$incompletedactivities; + } + } else { + // Graded + ++$completedactivities; + } + } else { + // Ungraded + ++$notattemptedactivities; + } + } else if ($activity->modname == 'quiz') { + // Count waiting for grade quizzes without a grade from grade function. + $modstatus = block_fn_mentor_quiz_status($activity, $menteeid, true); + // Waiting for grade + if($modstatus == 'waitinggrade') { + ++$waitingforgradeactivities; + } else { + // Ungraded + ++$notattemptedactivities; + } + + } else if ($activity->modname == 'lesson') { + // Count saved lessons that don't yet have a grade + $modstatus = block_fn_mentor_lesson_status($activity, $menteeid, $course, true); + // Saved + if($modstatus == 'saved') { + ++$savedactivities; + } else { + // Ungraded + ++$notattemptedactivities; + } + } else if ($activity->modname == 'journal') { + // Count waiting for grade journals that don't yet have a grade + $modstatus = block_fn_mentor_journal_status($activity, $menteeid, $course, true); + // Waiting for grade + if($modstatus == 'waitinggrade') { + ++$waitingforgradeactivities; + } else { + // Ungraded + ++$notattemptedactivities; + } + } else { + // Ungraded + ++$notattemptedactivities; + } + } else { + // Add other graded modules. + if ($grade[$menteeid] = grade_get_grades($course->id, 'mod', $activity->modname, $activity->instance, $menteeid)) { + $usergrade = $grade[$menteeid]->items[0]->grades[$menteeid]; + if ($usergrade->grade && $usergrade->dategraded !== null){ + if ($item->gradepass > 0) { + if ($usergrade->grade >= $item->gradepass) { + // Passed + ++$completedactivities; + } else { + // Failed + ++$incompletedactivities; + } + } else { + // Graded + ++$completedactivities; + } + + } else { + // Ungraded + ++$notattemptedactivities; + } + } else { + // Ungraded + ++$notattemptedactivities; + } + } // End other graded modules + } // End check for grade function. } } - -// Switch to show soecific assignment. +// Switch to show specific assignment. switch ($show) { case 'completed': @@ -231,55 +389,141 @@ echo ""; } + if ($show == 'completed') { - if ($activities) { + if ($activities) { foreach ($activities as $activity) { if (!$activity->visible) { continue; } $data = $completion->get_data($activity, false, $menteeid, null); - $activitystate = $data->completionstate; - // Check no grade assignments. - $shownogradeassignment = false; - if ($activity->modname == 'assign') { - if ($assignment = $DB->get_record('assign', array('id' => $activity->instance))) { - if ($assignment->grade == 0) { - if ($submission = $DB->get_records('assign_submission', array( - 'assignment' => $assignment->id, 'userid' => $menteeid), 'attemptnumber DESC', '*', 0, 1) - ) { - $shownogradeassignment = true; - } - } - } - } - - - if ($activitystate == 1 || $activitystate == 2 || $shownogradeassignment) { - echo "\n"; - $modtype = $DB->get_field('modules', 'name', array('id' => $activity->module)); - $modicon = "wwwroot/mod/$modtype/pix/icon.png\" ". - "HEIGHT=\"16\" WIDTH=\"16\" >"; - echo ($modtype == 'assign') ? 'assignment' : $modtype; - echo "\n"; - echo "$modicon" . - $activity->name . "\n"; - } + $activitystate = $data->completionstate; + // Make sure this is an actual graded item by getting the gradebook entries. + $grade[$menteeid] = grade_get_grades($course->id, 'mod', $activity->modname, $activity->instance, $menteeid); + if (!empty($grade[$menteeid]->items)) { + // Check no grade assignments. + $shownogradeassignment = false; + if ($activity->modname == 'assign') { + if ($assignment = $DB->get_record('assign', array('id' => $activity->instance))) { + if ($assignment->grade == 0) { + if ($submission = $DB->get_records('assign_submission', array( + 'assignment' => $assignment->id, 'userid' => $menteeid), 'attemptnumber DESC', '*', 0, 1) + ) { + $shownogradeassignment = true; + } + } + } + } + + // Check no grade quiz. + $shownogradequiz = false; + if ($activity->modname == 'quiz') { + if ($quiz = $DB->get_record('quiz', array('id' => $activity->instance))) { + if ($quiz->grade == 0) { + if ($attempts = $DB->get_records('quiz_attempts', array( + 'quiz' => $quiz->id, 'userid' => $menteeid), 'attempt DESC', '*', 0, 1) + ) { + $shownogradequiz = true; + } + } + } + } + + // Check no grade lesson. + $shownogradelesson = false; + if ($activity->modname == 'lesson') { + if ($lesson = $DB->get_record('lesson', array('id' => $activity->instance))) { + $lessonmodstatus = block_fn_mentor_lesson_status($activity, $menteeid, $course, true); + if ($lesson->grade == 0) { + if (($attempts = $DB->get_records('lesson_timer', array( + 'lessonid' => $lesson->id, 'userid' => $menteeid), 'attempt DESC', '*', 0, 1)) + ) { + $shownogradelesson = true; + } + } + } + } + // Check no grade journal. + $shownogradelesson = false; + if ($activity->modname == 'journal') { + if ($journal = $DB->get_record('lesson', array('id' => $activity->instance))) { + $journalmodstatus = block_fn_mentor_journal_status($activity, $menteeid, $course, true); + if ($journal->grade == 0) { + if (($attempts = $DB->get_records('journal_entries', array( + 'journal' => $journal->id, 'userid' => $menteeid), 'id DESC', '*', 0, 1)) + ) { + $shownogradejournal = true; + } + } + } + } + + // Add lessons waiting for grades. + if ($activity->modname == 'lesson') { + if (($activitystate == 1 || $activitystate == 2 || $shownogradelesson) && $lessonmodstatus !== 'waitinggrade') { + echo "\n"; + $modtype = $DB->get_field('modules', 'name', array('id' => $activity->module)); + $modicon = "wwwroot/mod/$modtype/pix/icon.png\" ". + "HEIGHT=\"16\" WIDTH=\"16\" >"; + echo ($modtype == 'assign') ? 'assignment' : $modtype; + echo "\n"; + echo "$modicon" . + $activity->name . "\n"; + } + // Add lessons waiting for grades. + } else if ($activity->modname == 'journal') { + if (($activitystate == 1 || $activitystate == 2 || $shownogradejournal) && $journalmodstatus !== 'waitinggrade') { + echo "\n"; + $modtype = $DB->get_field('modules', 'name', array('id' => $activity->module)); + $modicon = "wwwroot/mod/$modtype/pix/icon.png\" ". + "HEIGHT=\"16\" WIDTH=\"16\" >"; + echo ($modtype == 'assign') ? 'assignment' : $modtype; + echo "\n"; + echo "$modicon" . + $activity->name . "\n"; + } + } else if ($activitystate == 1 || $activitystate == 2 || $shownogradeassignment || $shownogradequiz || $shownogradelesson || $shownogradejournal) { + echo "\n"; + $modtype = $DB->get_field('modules', 'name', array('id' => $activity->module)); + $modicon = "wwwroot/mod/$modtype/pix/icon.png\" ". + "HEIGHT=\"16\" WIDTH=\"16\" >"; + echo ($modtype == 'assign') ? 'assignment' : $modtype; + echo "\n"; + echo "$modicon" . + $activity->name . "\n"; + } + } } } } else if ($show == 'incompleted') { if ($activities) { + foreach ($activities as $activity) { + if (!$activity->visible) { continue; } $data = $completion->get_data($activity, true, $menteeid, null); $activitystate = $data->completionstate; $assignmentstatus = block_fn_mentor_assignment_status($activity, $menteeid); - if ($activitystate == 3) { + // Get the quizzes, lessons, and journals statuses. + $quizstatus = block_fn_mentor_quiz_status($activity, $menteeid); + $lessonstatus = block_fn_mentor_lesson_status($activity, $menteeid, $course); + $journalstatus = block_fn_mentor_journal_status($activity, $menteeid, $course); + $item = $DB->get_record('grade_items', + array("itemtype" => 'mod', "itemmodule" => $activity->modname, "iteminstance" => $activity->instance)); + $grade[$menteeid] = grade_get_grades($course->id, 'mod', $activity->modname, $activity->instance, $menteeid); + // Make sure these are graded items. + if ($activitystate == 3 && (!empty($grade[$menteeid]->items))) { + if (($activity->module == 1) && ($activity->modname == 'assignment' || $activity->modname == 'assign') && ($activity->completion == 2) @@ -297,6 +541,66 @@ $CFG->wwwroot . "/mod/$modtype/view.php?id=$data->coursemoduleid' style=\"padding-left:4px\">" . $activity->name . "\n"; + } else { + continue; + } + // Check quiz status. + } else if (($activity->modname == 'quiz') + && ($activity->completion == 2) + && $quizstatus) { + + if ($quizstatus == 'submitted') { + echo "\n"; + $modtype = $DB->get_field('modules', 'name', array('id' => $activity->module)); + $modicon = "wwwroot/mod/$modtype/pix/icon.png\" ". + "HEIGHT=\"16\" WIDTH=\"16\" >"; + echo $modtype; + echo "\n"; + echo "$modicon" . + $activity->name . "\n"; + + } else { + continue; + } + // Check lesson status. + } else if (($activity->modname == 'lesson') + && ($activity->completion == 2) + && $lessonstatus) { + + if ($lessonstatus == 'submitted') { + echo "\n"; + $modtype = $DB->get_field('modules', 'name', array('id' => $activity->module)); + $modicon = "wwwroot/mod/$modtype/pix/icon.png\" ". + "HEIGHT=\"16\" WIDTH=\"16\" >"; + echo $modtype; + echo "\n"; + echo "$modicon" . + $activity->name . "\n"; + + } else { + continue; + } + // Check journal status. + } else if (($activity->modname == 'journal') + && ($activity->completion == 2) + && $journalstatus) { + + if ($journalstatus == 'submitted') { + echo "\n"; + $modtype = $DB->get_field('modules', 'name', array('id' => $activity->module)); + $modicon = "wwwroot/mod/$modtype/pix/icon.png\" ". + "HEIGHT=\"16\" WIDTH=\"16\" >"; + echo $modtype; + echo "\n"; + echo "$modicon" . + $activity->name . "\n"; + } else { continue; } @@ -312,6 +616,28 @@ $CFG->wwwroot . "/mod/$modtype/view.php?id=$data->coursemoduleid' style=\"padding-left:4px\">" . $activity->name . "\n"; } + } else { + // Get other graded modules. + if ($grade[$menteeid] = grade_get_grades($course->id, 'mod', $activity->modname, $activity->instance, $menteeid)) { + $usergrade = $grade[$menteeid]->items[0]->grades[$menteeid]; + if ($usergrade->grade && ($usergrade->dategraded !== null)) { + if($item->gradepass > 0) { + if (($usergrade->grade) && ($usergrade->grade < $item->gradepass)) { + echo "\n"; + $modtype = $DB->get_field('modules', 'name', array('id' => $activity->module)); + $modicon = "wwwroot/mod/$modtype/pix/icon.png\" ". + "HEIGHT=\"16\" WIDTH=\"16\" >"; + echo ($modtype == 'assign') ? 'assignment' : $modtype; + echo "\n"; + echo "$modicon" . + $activity->name . "\n"; + + } + } + } + } } } } @@ -324,12 +650,36 @@ $data = $completion->get_data($activity, true, $menteeid, null); $activitystate = $data->completionstate; $assignmentstatus = block_fn_mentor_assignment_status($activity, $menteeid); - if ($activitystate == 0) { + // Add quizzes, lesson, and journal statuses. + $quizstatus = block_fn_mentor_quiz_status($activity, $menteeid); + $lessonstatus = block_fn_mentor_lesson_status($activity, $menteeid, $course); + $journalstatus = block_fn_mentor_journal_status($activity, $menteeid, $course); + // Make sure these are graded items. + $grade[$menteeid] = grade_get_grades($course->id, 'mod', $activity->modname, $activity->instance, $menteeid); + $usergrade = $grade[$menteeid]->items[0]->grades[$menteeid]; + // Make sure these are graded items. + if (($activitystate == 0) && (!empty($grade[$menteeid]->items)) && ($usergrade->dategraded == null)) { if (($activity->module == 1) && ($activity->modname == 'assignment' || $activity->modname == 'assign') && ($activity->completion == 2) && $assignmentstatus) { continue; + } + // Check quiz, lesson, and journal statuses. + if (($activity->modname == 'quiz') + && ($activity->completion == 2) + && $quizstatus) { + continue; + } + if (($activity->modname == 'lesson') + && ($activity->completion == 2) + && $lessonstatus) { + continue; + } + if (($activity->modname == 'journal') + && ($activity->completion == 2) + && $journalstatus) { + continue; } echo "\n"; $modtype = $DB->get_field('modules', 'name', array('id' => $activity->module)); @@ -353,26 +703,87 @@ $data = $completion->get_data($activity, true, $menteeid, null); $activitystate = $data->completionstate; $assignmentstatus = block_fn_mentor_assignment_status($activity, $menteeid); - if (($activitystate == 0)||($activitystate == 1)||($activitystate == 2)||($activitystate == 3)) { - if (($activity->module == 1) - && ($activity->modname == 'assignment' || $activity->modname == 'assign') - && ($activity->completion == 2) - && $assignmentstatus) { - if (isset($assignmentstatus)) { - if ($assignmentstatus == 'waitinggrade') { - echo "\n"; - $modtype = $DB->get_field('modules', 'name', array('id' => $activity->module)); - $modicon = "wwwroot/mod/$modtype/pix/icon.png\" ". - "HEIGHT=\"16\" WIDTH=\"16\" >"; - echo ($modtype == 'assign') ? 'assignment' : $modtype; - echo "\n"; - echo "$modicon" . - $activity->name . "\n"; - } - } - } + // Get quizzes, lessons, and journals statuses. + $quizstatus = block_fn_mentor_quiz_status($activity, $menteeid); + $lessonstatus = block_fn_mentor_lesson_status($activity, $menteeid, $course); + $journalstatus = block_fn_mentor_journal_status($activity, $menteeid, $course); + // Make sure these are graded items. + $grade[$menteeid] = grade_get_grades($course->id, 'mod', $activity->modname, $activity->instance, $menteeid); + // Make sure these are graded items. + if (!empty($grade[$menteeid]->items)) { + if (($activitystate == 0)||($activitystate == 1)||($activitystate == 2)||($activitystate == 3)) { + if (($activity->module == 1) + && ($activity->modname == 'assignment' || $activity->modname == 'assign') + && ($activity->completion == 2) + && $assignmentstatus) { + if (isset($assignmentstatus)) { + if ($assignmentstatus == 'waitinggrade') { + echo "\n"; + $modtype = $DB->get_field('modules', 'name', array('id' => $activity->module)); + $modicon = "wwwroot/mod/$modtype/pix/icon.png\" ". + "HEIGHT=\"16\" WIDTH=\"16\" >"; + echo ($modtype == 'assign') ? 'assignment' : $modtype; + echo "\n"; + echo "$modicon" . + $activity->name . "\n"; + } + } + // Check status of quiz, lessons, and journals. + } else if (($activity->modname == 'quiz') + && ($activity->completion == 2) + && $quizstatus) { + if (isset($quizstatus)) { + if ($quizstatus == 'waitinggrade') { + echo "\n"; + $modtype = $DB->get_field('modules', 'name', array('id' => $activity->module)); + $modicon = "wwwroot/mod/$modtype/pix/icon.png\" ". + "HEIGHT=\"16\" WIDTH=\"16\" >"; + echo $modtype; + echo "\n"; + echo "$modicon" . + $activity->name . "\n"; + } + } + } else if (($activity->modname == 'lesson') + && ($activity->completion == 2) + && $lessonstatus) { + if (isset($lessonstatus)) { + if ($lessonstatus == 'waitinggrade') { + echo "\n"; + $modtype = $DB->get_field('modules', 'name', array('id' => $activity->module)); + $modicon = "wwwroot/mod/$modtype/pix/icon.png\" ". + "HEIGHT=\"16\" WIDTH=\"16\" >"; + echo $modtype; + echo "\n"; + echo "$modicon" . + $activity->name . "\n"; + } + } + } else if (($activity->modname == 'journal') + && ($activity->completion == 2) + && $journalstatus) { + if (isset($journalstatus)) { + if ($journalstatus == 'waitinggrade') { + echo "\n"; + $modtype = $DB->get_field('modules', 'name', array('id' => $activity->module)); + $modicon = "wwwroot/mod/$modtype/pix/icon.png\" ". + "HEIGHT=\"16\" WIDTH=\"16\" >"; + echo $modtype; + echo "\n"; + echo "$modicon" . + $activity->name . "\n"; + } + } + } + } } } } @@ -385,7 +796,14 @@ $data = $completion->get_data($activity, true, $menteeid, null); $activitystate = $data->completionstate; $assignmentstatus = block_fn_mentor_assignment_status($activity, $menteeid); - if (($activitystate == 0) || ($activitystate == 1) || ($activitystate == 2) || ($activitystate == 3)) { + // Get quiz, lesson, and journal status. + $quizstatus = block_fn_mentor_quiz_status($activity, $menteeid); + $lessonstatus = block_fn_mentor_lesson_status($activity, $menteeid, $course); + $journalstatus = block_fn_mentor_journal_status($activity, $menteeid, $course); + // Make sure these are graded items. + $grade[$menteeid] = grade_get_grades($course->id, 'mod', $activity->modname, $activity->instance, $menteeid); + if ((($activitystate == 0) || ($activitystate == 1) || ($activitystate == 2) || ($activitystate == 3)) && (!empty($grade[$menteeid]->items))) { + // Make sure these are graded items. if (($activity->module == 1) && ($activity->modname == 'assignment' || $activity->modname == 'assign') && ($activity->completion == 2) @@ -405,6 +823,61 @@ } } } + // Get quiz, lesson, and journal statuses. + if (($activity->modname == 'quiz') + && ($activity->completion == 2) + && $quizstatus) { + if (isset($quizstatus)) { + if ($quizstatus == 'saved') { + echo "\n"; + $modtype = $DB->get_field('modules', 'name', array('id' => $activity->module)); + $modicon = "wwwroot/mod/$modtype/pix/icon.png\" ". + "HEIGHT=\"16\" WIDTH=\"16\" >"; + echo $modtype; + echo "\n"; + echo "$modicon" . + $activity->name . "\n"; + } + } + } + if (($activity->modname == 'lesson') + && ($activity->completion == 2) + && $lessonstatus) { + if (isset($lessonstatus)) { + if ($lessonstatus == 'saved') { + echo "\n"; + $modtype = $DB->get_field('modules', 'name', array('id' => $activity->module)); + $modicon = "wwwroot/mod/$modtype/pix/icon.png\" ". + "HEIGHT=\"16\" WIDTH=\"16\" >"; + echo $modtype; + echo "\n"; + echo "$modicon" . + $activity->name . "\n"; + } + } + } + if (($activity->modname == 'journal') + && ($activity->completion == 2) + && $journalstatus) { + if (isset($journalstatus)) { + if ($journalstatus == 'saved') { + echo "\n"; + $modtype = $DB->get_field('modules', 'name', array('id' => $activity->module)); + $modicon = "wwwroot/mod/$modtype/pix/icon.png\" ". + "HEIGHT=\"16\" WIDTH=\"16\" >"; + echo $modtype; + echo "\n"; + echo "$modicon" . + $activity->name . "\n"; + } + } + } } } } From 8ae445accf3948c5702a37ac291c91b15a983334 Mon Sep 17 00:00:00 2001 From: cmERDC Digital Learning Date: Wed, 22 Nov 2017 10:10:00 -0600 Subject: [PATCH 04/22] student view and added features Added student views, and new views... Learning Plans, progress bar, enrollment and session time info. --- course_overview.php | 107 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 93 insertions(+), 14 deletions(-) diff --git a/course_overview.php b/course_overview.php index 8f71044..c2ecb49 100644 --- a/course_overview.php +++ b/course_overview.php @@ -31,13 +31,8 @@ $courseid = optional_param('courseid', 0, PARAM_INT); $groupid = optional_param('groupid', 0, PARAM_INT); -// Array of functions to call for grading purposes for modules. -$modgradesarray = array( - 'assign' => 'assign.submissions.fn.php', - 'quiz' => 'quiz.submissions.fn.php', - 'assignment' => 'assignment.submissions.fn.php', - 'forum' => 'forum.submissions.fn.php', -); +// Array of functions to call for grading purposes for modules. (- new function to add additional). +$modgradesarray = get_graded_mods(); require_login(null, false); @@ -46,6 +41,7 @@ $ismentor = block_fn_mentor_has_system_role($USER->id, get_config('block_fn_mentor', 'mentor_role_system')); $isteacher = block_fn_mentor_isteacherinanycourse($USER->id); $isstudent = block_fn_mentor_isstudentinanycourse($USER->id); +$menteecanview = get_config('block_fn_mentor', 'menteecanview'); // Use the setting students can view for student views. $allownotes = get_config('block_fn_mentor', 'allownotes'); @@ -77,8 +73,13 @@ } // Pick a mentee if not selected. if ((!$menteeid && $mentees) || (!in_array($menteeid, array_keys($mentees)))) { + // Account for student views + if($isstudent && $menteecanview) { + $menteeid = $USER->id; + } else { $var = reset($mentees); $menteeid = $var->studentid; + } } if (($USER->id <> $menteeid) && !$isadmin && !in_array($menteeid, array_keys($mentees))) { @@ -119,8 +120,9 @@ $lastaccess = ''; if ($menteeuser->lastaccess) { + // Extra param for last access. $lastaccess .= get_string('lastaccess').get_string('labelsep', 'langconfig'). - block_fn_mentor_format_time(time() - $menteeuser->lastaccess); + block_fn_mentor_format_time(time(), $menteeuser->lastaccess); } else { $lastaccess .= get_string('lastaccess').get_string('labelsep', 'langconfig').get_string('never'); } @@ -137,6 +139,9 @@ AND gm.userid = ? ORDER BY g.name ASC"; $groups = $DB->get_records_sql($sql, array('M', $USER->id)); +} else if ($isstudent) { + // Account for student views. + $groups = ''; } $groupmenu = array(); @@ -220,7 +225,6 @@ if (!$enrolledcourses = enrol_get_all_users_courses($menteeid, false, 'id,fullname,shortname', 'fullname ASC')) { $enrolledcourses = array(); } - $filtercourses = array(); if ($configcategory = get_config('block_fn_mentor', 'category')) { @@ -303,6 +307,57 @@ '; +// Add LEARNING PLANS. + // Requires mentor to have moodle/competency:planview set to allow in role. +if(get_config('core_competency', 'enabled')) { + $userid = optional_param('userid', $menteeuser->id, PARAM_INT); + $view = \core_competency\plan::can_read_user($userid); + $lp_url = new moodle_url('/admin/tool/lp/plans.php', array('userid' => $userid)); + $plans = \core_competency\api::list_user_plans($userid); + $tooltip = 'View complete report for all learning plans.'; + $reports = core_component::get_plugin_list('report'); + $lpmonitoring= false; + if ($reports['lpmonitoring']) { + $lp_url = new moodle_url('/report/lpmonitoring/userreport.php', array('userid' => $menteeuser->id)); + + } + if ($view) { + echo '
+
+ Learning Plans +
+
+ +
+
'; + + // Learning plan. + $lp_count = count($plans); + foreach($plans as $plan) { + $exporter = new \core_competency\external\plan_exporter($plan, array('template' => $plan->get_template())); + $record = $exporter->export($OUTPUT); + $plan_record = '
' . $record->name . ''; + if($record->duedate) { + $due_date = $record->duedateformatted; + $plan_record .= ' (Due: '.$due_date.')'; + } + if($record->iscompleted) { + $plan_record .= ' - Completed '; + } + $plan_record .= '
'; + + echo $plan_record; + + } + + echo '
+
'; + } +} // NOTES. if ($view = has_capability('block/fn_mentor:viewcoursenotes', context_system::instance()) && $allownotes) { echo '
@@ -389,6 +444,8 @@ class="" > $progresshtml .= '
' . $progressdata->content->icons[$key] . $progressdata->content->items[$key] . '
'; } + // Add enrollment dates. + $enroldata = get_enrollment_dates($menteeid, $enrolledcourse->id); echo ''; echo ''; @@ -399,7 +456,21 @@ class="" > $enrolledcourse->id . '\', \'\', \'width=800,height=600,toolbar=no,location=no,menubar=no,'. 'copyhistory=no,status=no,directories=no,scrollbars=yes,resizable=yes\'); return false;" class="" >' . $course_fullname . ''; - + // Enrollment dates. + if ($enroldata->enrolstart && $enroldata->enrolend){ + echo '
'.get_string('enroldates', 'block_fn_mentor').':
'.date('n/j/Y', $enroldata->enrolstart).' - '.date('n/j/Y', $enroldata->enrolend).'
'; + } else { + echo '
'.get_string('enroldates', 'block_fn_mentor').':
'.get_string('enroldatesnone', 'block_fn_mentor').'
'; + } + // Add Session times. + + $session = get_session_times($enrolledcourse->id); + + if ($session){ + echo '
'.get_string('sessions', 'block_fn_mentor').':
'.$session['meeting'].'
'; + } else { + echo '
'.get_string('sessions', 'block_fn_mentor').':
'.get_string('sessionsnone', 'block_fn_mentor').'
'; + } echo '
'; echo '
'; // Course teachers. @@ -421,8 +492,9 @@ class="" > $teacherlist = ''; $teacherlabel = get_string('teacher', 'block_fn_mentor'); foreach ($teachers as $teacher) { + // Extra param for last access. $lastaccess = get_string('lastaccess') . get_string('labelsep', 'langconfig') . - block_fn_mentor_format_time(time() - $teacher->lastaccess); + block_fn_mentor_format_time(time(), $teacher->lastaccess); $teacherlist .= block_fn_mentor_teacher_link ($teacher->id, $lastaccess); } if ($numofteachers > 1) { @@ -455,8 +527,9 @@ class="" > 'blockname') : get_string('mentor', 'block_fn_mentor'); foreach ($mentors as $mentor) { + // Extra param for last access. $lastaccess = get_string('lastaccess') . get_string('labelsep', 'langconfig') . - block_fn_mentor_format_time(time() - $mentor->lastaccess); + block_fn_mentor_format_time(time(), $mentor->lastaccess); $mentorlist .= block_fn_mentor_teacher_link($mentor->mentorid, $lastaccess); } echo ''; echo ''; - + // Add Progress bar. + echo ''; + echo ''; + echo ''; + // End echo '
'; @@ -506,9 +579,15 @@ class="" > } echo '
'; + $progressbar = block_fn_mentor_print_activity_progress ($course , $menteeuser->id); + echo $progressbar; + echo '
'; - echo ''; // Grade. echo ''; From 9c79aee81c9783bb2178bd72aae3682e73d8e6d6 Mon Sep 17 00:00:00 2001 From: cmERDC Digital Learning Date: Wed, 22 Nov 2017 10:10:53 -0600 Subject: [PATCH 05/22] student view and extra features Added student views, and new views... Learning Plans, progress bar, enrollment and session time info. --- course_overview_single.php | 91 +++++++++++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 20 deletions(-) diff --git a/course_overview_single.php b/course_overview_single.php index cf9fccb..cd649f8 100644 --- a/course_overview_single.php +++ b/course_overview_single.php @@ -33,13 +33,8 @@ $groupid = optional_param('groupid', 0, PARAM_INT); $navpage = optional_param('page', 'overview', PARAM_TEXT); -// Array of functions to call for grading purposes for modules. -$modgradesarray = array( - 'assign' => 'assign.submissions.fn.php', - 'quiz' => 'quiz.submissions.fn.php', - 'assignment' => 'assignment.submissions.fn.php', - 'forum' => 'forum.submissions.fn.php', -); +// Array of functions to call for grading purposes for modules. New mod array function for extra mods. +$modgradesarray = get_graded_mods(); $allownotes = get_config('block_fn_mentor', 'allownotes'); @@ -100,7 +95,9 @@ $courseid = $ecourse->id; } if ($courseid) { - $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); + //$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); + // Need course object, use Moodle standard function for proper format. + $course = get_course($courseid); } else { print_error('unspecifycourseid', 'error'); } @@ -110,6 +107,7 @@ $ismentor = block_fn_mentor_has_system_role($USER->id, get_config('block_fn_mentor', 'mentor_role_system')); $isteacher = block_fn_mentor_isteacherinanycourse($USER->id); $isstudent = block_fn_mentor_isstudentinanycourse($USER->id); +$menteecanview = get_config('block_fn_mentor', 'menteecanview'); // Use the setting students can view if ($allownotes && $ismentor) { $allownotes = true; @@ -139,8 +137,13 @@ // Pick a mentee if not selected. if ((!$menteeid && $mentees) || (!in_array($menteeid, array_keys($mentees)))) { + // Account for student views + if($isstudent && $menteecanview) { + $menteeid = $USER->id; + } else { $var = reset($mentees); $menteeid = $var->studentid; + } } $menteeuser = $DB->get_record('user', array('id' => $menteeid), '*', MUST_EXIST); @@ -184,8 +187,9 @@ $lastaccess = ''; if ($menteeuser->lastaccess) { + // Extra param for last access. $lastaccess .= get_string('lastaccess').get_string('labelsep', 'langconfig'). - block_fn_mentor_format_time(time() - $menteeuser->lastaccess); + block_fn_mentor_format_time(time(), $menteeuser->lastaccess); } else { $lastaccess .= get_string('lastaccess').get_string('labelsep', 'langconfig').get_string('never'); } @@ -193,7 +197,7 @@ // Groups menu. if ($isadmin) { $groups = $DB->get_records('block_fn_mentor_group', null, 'name ASC'); -} else if ($ismentor) { +} else if ($ismentor || $isstudent) { // Added $isstudent for student views $sql = "SELECT g.id, g.name FROM {block_fn_mentor_group} g JOIN {block_fn_mentor_group_mem} gm @@ -350,12 +354,12 @@ '.get_string('overview', 'block_fn_mentor').' + $menteeid.'&groupid=' . $groupid.'&courseid='.$courseid.'">Overview '.get_string('grades', 'block_fn_mentor').' + $menteeid.'&groupid=' . $groupid.'&courseid='.$courseid.'">Grades '.get_string('activity', 'block_fn_mentor').''; + $menteeid.'&groupid=' . $groupid.'&courseid='.$courseid.'">Activity'; echo '
@@ -378,11 +382,44 @@ $progress .= '
'.$progressdata->content->icons[$key] . $progressdata->content->items[$key] . '
'; } + // Get enrollment dates. + $enroldata = get_enrollment_dates($menteeid, $enrolledcourse->id); echo ''; echo ''; echo '
'; + // Enrollment dates. + if ($enroldata->enrolstart && $enroldata->enrolend){ + echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
'.get_string('enroldates', 'block_fn_mentor').':'.date('n/j/Y', $enroldata->enrolstart).' - '.date('n/j/Y', $enroldata->enrolend).'
'; + echo '
'; + } + // Session times. (External DB). + + $session = get_session_times($enrolledcourse->id); + + if ($session){ + echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
'.get_string('sessions', 'block_fn_mentor').':'.$session['meeting'].'
'; + echo '
'; + } else { + echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
'.get_string('sessions', 'block_fn_mentor').':'.get_string('sessionsnone', 'block_fn_mentor').'
'; + echo '
'; + } echo '
'; echo ''; // Course teachers. @@ -404,8 +441,9 @@ get_string('teacher', 'block_fn_mentor').':
'; foreach ($teachers as $teacher) { + // Extra param for last access. $lastaccess = get_string('lastaccess').get_string('labelsep', 'langconfig'). - block_fn_mentor_format_time(time() - $teacher->lastaccess); + block_fn_mentor_format_time(time(), $teacher->lastaccess); echo '
'; foreach ($mentors as $mentor) { + // Extra param for last access. $lastaccess = get_string('lastaccess').get_string('labelsep', - 'langconfig'). block_fn_mentor_format_time(time() - $mentor->lastaccess); + 'langconfig'). block_fn_mentor_format_time(time(), $mentor->lastaccess); echo '
'; @@ -505,7 +554,6 @@ ); echo '
'; $gradebook = reset($simplegradebook); - if (isset($gradebook['grade'])) { // TABLE. echo ""; @@ -546,15 +594,18 @@ $grademaxtot = 0; $avg = 0; - if (!isset($studentreport['avg'])) { + // Moved to align table view. + /*if (!isset($studentreport['avg'])) { echo ''; - } - + }*/ foreach ($studentreport['grade'] as $sgrades) { foreach ($sgrades as $sgrade) { echo ''; } + } + if (!isset($studentreport['avg'])) { + echo ''; } echo ''; } From 7e4e8944e3ff9d3dbfc88758d49c9127cfe064dc Mon Sep 17 00:00:00 2001 From: cmERDC Digital Learning Date: Wed, 22 Nov 2017 10:13:26 -0600 Subject: [PATCH 06/22] add external log db connection Added ability to connect to external data for session times. --- classes/ext_db/db_connect.php | 181 ++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 classes/ext_db/db_connect.php diff --git a/classes/ext_db/db_connect.php b/classes/ext_db/db_connect.php new file mode 100644 index 0000000..1ffb709 --- /dev/null +++ b/classes/ext_db/db_connect.php @@ -0,0 +1,181 @@ +. + +/** + * DB connect class of the external database of logs. + * + * Defines the db connection used by fn_mentor + * + * @package block_fn_mentor + * @author Sheilla Rindahl + * @copyright 2016 cmERDC + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +defined('MOODLE_INTERNAL') || die; + + +class Database { +/** + * Here is the Moodle external database connection functions + * using the built in tools in Moodle. + */ + + private $dbtype = "mysqli"; + private $dbhost = "localhost"; + private $dbname = "DB_NAME"; + private $dbuser = "DB_USER"; + private $dbpass = "DB_PASSWORD"; + private $tablesession = "TABLE_NAME"; + private $dbencoding = "utf-8"; + private $dbsetupsql = "SET NAMES 'utf8'"; + private $dbdebug = false; + private $dbsybasequoting = false; + public $conn; + + /** + * Tries to make connection to the external database. + * + * @return null|ADONewConnection + */ + protected function db_init() { + global $CFG; + + require_once($CFG->libdir.'/adodb/adodb.inc.php'); + + // Connect to the external database (forcing new connection). + $extdb = ADONewConnection($this->dbtype); + if ($this->dbdebug) { + $extdb->debug = true; + ob_start(); // Start output buffer to allow later use of the page headers. + } + + // The dbtype my contain the new connection URL, so make sure we are not connected yet. + if (!$extdb->IsConnected()) { + $result = $extdb->Connect($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname, true); + if (!$result) { + return null; + } + } + + $extdb->SetFetchMode(ADODB_FETCH_ASSOC); + if ($this->dbsetupsql) { + $extdb->Execute($this->dbsetupsql); + } + return $extdb; + } + + protected function db_addslashes($text) { + // Use custom made function for now - it is better to not rely on adodb or php defaults. + if ($this->dbsybasequoting) { + $text = str_replace('\\', '\\\\', $text); + $text = str_replace(array('\'', '"', "\0"), array('\\\'', '\\"', '\\0'), $text); + } else { + $text = str_replace("'", "''", $text); + } + return $text; + } + + protected function db_encode($text) { + $dbenc = $this->dbencoding; + if (empty($dbenc) or $dbenc == 'utf-8') { + return $text; + } + if (is_array($text)) { + foreach($text as $k=>$value) { + $text[$k] = $this->db_encode($value); + } + return $text; + } else { + return core_text::convert($text, 'utf-8', $dbenc); + } + } + + protected function db_decode($text) { + $dbenc = $this->dbencoding; + if (empty($dbenc) or $dbenc == 'utf-8') { + return $text; + } + if (is_array($text)) { + foreach($text as $k=>$value) { + $text[$k] = $this->db_decode($value); + } + return $text; + } else { + return core_text::convert($text, $dbenc, 'utf-8'); + } + } + + function db_get_sql($table, array $conditions, array $fields, $distinct = false, $sort = "") { + $fields = $fields ? implode(',', $fields) : "*"; + $where = array(); + if ($conditions) { + foreach ($conditions as $key=>$value) { + $value = $this->db_encode($this->db_addslashes($value)); + + $where[] = "$key = '$value'"; + } + } + $where = $where ? "WHERE ".implode(" AND ", $where) : ""; + $sort = $sort ? "ORDER BY $sort" : ""; + $distinct = $distinct ? "DISTINCT" : ""; + $sql = "SELECT $distinct $fields + FROM $table + $where + $sort"; + + return $sql; + } + + /*SRINDAHL add external database connection for + * displaying the session times for courses. + */ + function get_extdb_sessions($enrolledcourse) { + global $CFG, $OUTPUT; + // /classes/ext_db/db_connect.php needed. + $table = "session_times"; + $conditions = array("course" => $enrolledcourse,); + $fields = array("meeting"); + $adodb = $this->db_init(); + if (!$adodb or !$adodb->IsConnected()) { + $this->config->debugdb = $olddebugdb; + $CFG->debug = $olddebug; + ini_set('display_errors', $olddisplay); + error_reporting($CFG->debug); + ob_end_flush(); + + echo $OUTPUT->notification('Cannot connect the database.', 'notifyproblem'); + return; + } + $sql = $this->db_get_sql($table, $conditions, $fields); + if (!empty($enrolledcourse)) { + $rs = $adodb->Execute($sql); + if (!$rs) { + echo $OUTPUT->notification('Can not read external enrol table.', 'notifyproblem'); + + } else if ($rs->EOF) { + $session = false; + $rs->Close(); + + } else { + $session = $rs->FetchRow(); + $rs->Close(); + } + } + $adodb->Close(); + return $session; + } + +} \ No newline at end of file From 2b8c488cebee62678bc0ef9c22a3e0825e4012b7 Mon Sep 17 00:00:00 2001 From: cmERDC Digital Learning Date: Wed, 22 Nov 2017 10:16:40 -0600 Subject: [PATCH 07/22] dcoumentation changes --- classes/ext_db/db_connect.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/classes/ext_db/db_connect.php b/classes/ext_db/db_connect.php index 1ffb709..f044446 100644 --- a/classes/ext_db/db_connect.php +++ b/classes/ext_db/db_connect.php @@ -20,7 +20,7 @@ * Defines the db connection used by fn_mentor * * @package block_fn_mentor - * @author Sheilla Rindahl + * @author Sheilla Rindahl * @copyright 2016 cmERDC * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -139,7 +139,7 @@ function db_get_sql($table, array $conditions, array $fields, $distinct = false, return $sql; } - /*SRINDAHL add external database connection for + /* Add external database connection for * displaying the session times for courses. */ function get_extdb_sessions($enrolledcourse) { @@ -178,4 +178,4 @@ function get_extdb_sessions($enrolledcourse) { return $session; } -} \ No newline at end of file +} From d737e617bd6874417e7087159aa14bd5779521d7 Mon Sep 17 00:00:00 2001 From: cmERDC Digital Learning Date: Wed, 22 Nov 2017 14:17:31 -0600 Subject: [PATCH 08/22] add only active enrollment courses --- settings.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/settings.php b/settings.php index be0e8b8..7280c21 100644 --- a/settings.php +++ b/settings.php @@ -226,6 +226,16 @@ ) ); +// Include only current active enrolled courses? +$settings->add( + new admin_setting_configcheckbox( + 'block_fn_mentor/includecurrentenrollments', + get_string('includecurrentenrollments', 'block_fn_mentor'), + '', + '0' + ) +); + $settings->add( new admin_setting_configtext( 'block_fn_mentor/passinggrade', From a3e6d35ff56bb547bee932730e52bb2838cb5c20 Mon Sep 17 00:00:00 2001 From: cmERDC Digital Learning Date: Wed, 22 Nov 2017 14:18:49 -0600 Subject: [PATCH 09/22] lang string for new setting active enrollments --- lang/en/block_fn_mentor.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lang/en/block_fn_mentor.php b/lang/en/block_fn_mentor.php index 2754c26..81511d0 100644 --- a/lang/en/block_fn_mentor.php +++ b/lang/en/block_fn_mentor.php @@ -154,6 +154,7 @@
  • Import the file by clicking on the Import Users button below.
  • '; $string['importusers'] = 'Import users'; +$string['includecurrentenrollments'] = 'Include only current active enrollments'; $string['includeextranedcolumns'] = 'Experimental: Include extra NED columns in Export page'; $string['includewaitinggrade'] = 'Include waiting for grade in progress calculations'; $string['incompleted'] = 'Incompleted'; From 922de74572cdfb5e1a3aed7c7739528608e3ce57 Mon Sep 17 00:00:00 2001 From: cmERDC Digital Learning Date: Wed, 22 Nov 2017 14:20:00 -0600 Subject: [PATCH 10/22] new active only enrollment setting --- course_overview.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/course_overview.php b/course_overview.php index c2ecb49..ccd72e5 100644 --- a/course_overview.php +++ b/course_overview.php @@ -222,7 +222,12 @@ ''; // COURSES. -if (!$enrolledcourses = enrol_get_all_users_courses($menteeid, false, 'id,fullname,shortname', 'fullname ASC')) { +if($enrollmenttypeconfig = get_config('block_fn_mentor', 'includecurrentenrollments')) { + $enrollmenttype = true; +} else { + $enrollmenttype = false; +} +if (!$enrolledcourses = enrol_get_all_users_courses($menteeid, $enrollmenttype, 'id,fullname,shortname', 'fullname ASC')) { $enrolledcourses = array(); } $filtercourses = array(); From a94ad0eaf2e93af962031bf2df2edff13bce4c7b Mon Sep 17 00:00:00 2001 From: cmERDC Digital Learning Date: Wed, 22 Nov 2017 14:20:42 -0600 Subject: [PATCH 11/22] new active only enrollment setting --- course_overview_single.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/course_overview_single.php b/course_overview_single.php index cd649f8..fd7e45a 100644 --- a/course_overview_single.php +++ b/course_overview_single.php @@ -41,7 +41,12 @@ require_login(null, false); // COURSES. -if (!$enrolledcourses = enrol_get_all_users_courses($menteeid, 'id,fullname,shortname', null, 'fullname ASC')) { +if($enrollmenttypeconfig = get_config('block_fn_mentor', 'includecurrentenrollments')) { + $enrollmenttype = true; +} else { + $enrollmenttype = false; +} +if (!$enrolledcourses = enrol_get_all_users_courses($menteeid, $enrollmenttype, 'id,fullname,shortname', null, 'fullname ASC')) { print_error('error_enrolled_course', 'block_fn_mentor'); } From 4e4e2c7a588ec1cbc5bcaae97c2ff3d22820ba38 Mon Sep 17 00:00:00 2001 From: cmERDC Digital Learning Date: Wed, 22 Nov 2017 14:22:51 -0600 Subject: [PATCH 12/22] add forum waiting for grade --- lib.php | 155 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 134 insertions(+), 21 deletions(-) diff --git a/lib.php b/lib.php index 98ebfee..8272171 100644 --- a/lib.php +++ b/lib.php @@ -1054,8 +1054,39 @@ function block_fn_mentor_assign_plugin_config($assignmentid, $subtype = 'assigns return false; } +function block_fn_mentor_forum_status($mod, $userid) { + // Add forum/hsuforum post that have not been graded to waiting for grade counts. + global $CFG, $DB, $SESSION; + require_once("$CFG->libdir/gradelib.php"); + require_once($CFG->dirroot . '/mod/' . $mod->modname . '/lib.php'); + if (isset($SESSION->completioncache)) { + unset($SESSION->completioncache); + } + if($mod->modname == 'forum' || $mod->modname == 'hsuforum') { + if (!($forum = $DB->get_record($mod->modname, array('id' => $mod->instance)))) { + return false; + } + $postfunction = $mod->modname.'_discussions_user_has_posted_in'; + if (!$posts = $postfunction($forum->id, $userid)) { + return false; + } else { + $gradefunction = $mod->modname.'_get_user_grades'; + $grade = $gradefunction($forum, $userid); + if(!empty($grade)) { + return 'submitted'; + } else if ($posts) { + return 'waitinggrade'; + } else { + return false; + } + } + } else { + return false; + } +} + function block_fn_mentor_quiz_status($mod, $userid) { - //SRINDHL Add manually graded quizzes in the waiting for grade counts. + //Add manually graded quizzes in the waiting for grade counts. global $DB, $SESSION; if (isset($SESSION->completioncache)) { unset($SESSION->completioncache); @@ -3015,7 +3046,7 @@ function block_fn_mentor_get_selected_courses($category, &$filtercourses) { block_fn_mentor_get_selected_courses($subcat, $course); } } -}; +} function block_fn_mentor_embed ($text, $id) { return html_writer::tag('p', @@ -3023,7 +3054,7 @@ function block_fn_mentor_embed ($text, $id) { 'value' => $text, 'type' => 'button', 'id' => $id )) ); -}; +} function get_enrollment_dates($menteeid, $enrolledcourse) { // Add for enrollment period dates. @@ -3181,7 +3212,40 @@ function block_fn_mentor_activity_progress($course, $menteeid, $modgradesarray) ++$waitingforgradeactivities; break; } - } else if ($modstatus = block_fn_mentor_quiz_status($activity, $menteeid, true)) { + } else if ($modstatus = block_fn_mentor_forum_status($activity, $menteeid, true)) { + // Check for special forum statuses. + switch ($modstatus) { + case 'submitted': + if ($instance->assessed == 0) { + // Graded + ++$completedactivities; + } else if ($grade = $gradefunction($instance, $menteeid)) { + if ($item->gradepass > 0) { + if ($grade[$menteeid]->rawgrade >= $item->gradepass) { + // Passed + ++$completedactivities; + } else { + // Fail. + ++$incompletedactivities; + } + } else { + // Graded + ++$completedactivities; + } + } + break; + + case 'saved': + // Saved + ++$savedactivities; + break; + + case 'waitinggrade': + // Waiting for grade + ++$waitingforgradeactivities; + break; + } + } else if ($modstatus = block_fn_mentor_quiz_status($activity, $menteeid, true)) { // Check for special quiz statuses. switch ($modstatus) { case 'submitted': @@ -3281,6 +3345,7 @@ function block_fn_mentor_activity_progress($course, $menteeid, $modgradesarray) break; } } else if ($grade) { + if($activity->modname == 'forum' || $activity->modname == 'hsuforum') {var_dump($grade);} if ($item->gradepass > 0) { if ($grade[$menteeid]->rawgrade >= $item->gradepass) { // Passed @@ -3299,6 +3364,16 @@ function block_fn_mentor_activity_progress($course, $menteeid, $modgradesarray) ++$notattemptedactivities; } + } else if ($activity->modname == 'forum' || $activity->modname == 'hsuforum') { + // Count waiting for grade forums without a grade from grade function. + $modstatus = block_fn_mentor_forum_status($activity, $menteeid, true); + // Waiting for grade + if($modstatus == 'waitinggrade') { + ++$waitingforgradeactivities; + } else { + // Ungraded + ++$notattemptedactivities; + } } else if ($activity->modname == 'quiz') { // Count waiting for grade quizzes without a grade from grade function. $modstatus = block_fn_mentor_quiz_status($activity, $menteeid, true); @@ -3697,7 +3772,45 @@ function block_fn_mentor_simplegradebook($course, $menteeuser, $modgradesarray) $simplegradebook[$key]['grade'][$i][$mod->id] = 'unmarked.gif'; break; } - } else if($modstatus = block_fn_mentor_quiz_status($mod, $key, true)) { + } else if($modstatus = block_fn_mentor_forum_status($mod, $key, true)) { + // Check for forum status. + switch ($modstatus) { + case 'submitted': + if ($instance->assessed == 0) { + $simplegradebook[$key]['grade'][$i][$mod->id] = 'graded_.gif'; + } else if ($grade) { + if ($item->gradepass > 0) { + if ($grade[$key]->rawgrade >= $item->gradepass) { + $simplegradebook[$key]['grade'][$i][$mod->id] = 'marked.gif';// Passed. + $simplegradebook[$key]['avg'][] = array( + 'grade' => $grade[$key]->rawgrade, 'grademax' => $item->grademax + ); + } else { + // Fail. + $simplegradebook[$key]['grade'][$i][$mod->id] = 'incomplete.gif'; + $simplegradebook[$key]['avg'][] = array( + 'grade' => $grade[$key]->rawgrade, 'grademax' => $item->grademax + ); + } + } else { + // Graded (grade-to-pass is not set). + $simplegradebook[$key]['grade'][$i][$mod->id] = 'graded_.gif'; + $simplegradebook[$key]['avg'][] = array( + 'grade' => $grade[$key]->rawgrade, 'grademax' => $item->grademax + ); + } + } + break; + + case 'saved': + $simplegradebook[$key]['grade'][$i][$mod->id] = 'saved.gif'; + break; + + case 'waitinggrade': + $simplegradebook[$key]['grade'][$i][$mod->id] = 'unmarked.gif'; + break; + } + } else if($modstatus = block_fn_mentor_quiz_status($mod, $key, true)) { // Check for manually graded quizzes. switch ($modstatus) { case 'submitted': @@ -3815,28 +3928,28 @@ function block_fn_mentor_simplegradebook($course, $menteeuser, $modgradesarray) } else if ($grade) { if ($item) { - if ($item->gradepass > 0) { - if ($grade[$key]->rawgrade >= $item->gradepass) { - $simplegradebook[$key]['grade'][$i][$mod->id] = 'marked.gif'; // Passed. - $simplegradebook[$key]['avg'][] = array( - 'grade' => $grade[$key]->rawgrade, - 'grademax' => $item->grademax - ); - } else { - $simplegradebook[$key]['grade'][$i][$mod->id] = 'incomplete.gif'; // Fail. - $simplegradebook[$key]['avg'][] = array( - 'grade' => $grade[$key]->rawgrade, - 'grademax' => $item->grademax - ); - } + if ($item->gradepass > 0) { + if ($grade[$key]->rawgrade >= $item->gradepass) { + $simplegradebook[$key]['grade'][$i][$mod->id] = 'marked.gif'; // Passed. + $simplegradebook[$key]['avg'][] = array( + 'grade' => $grade[$key]->rawgrade, + 'grademax' => $item->grademax + ); } else { - // Graded (grade-to-pass is not set). - $simplegradebook[$key]['grade'][$i][$mod->id] = 'graded_.gif'; + $simplegradebook[$key]['grade'][$i][$mod->id] = 'incomplete.gif'; // Fail. $simplegradebook[$key]['avg'][] = array( 'grade' => $grade[$key]->rawgrade, 'grademax' => $item->grademax ); } + } else { + // Graded (grade-to-pass is not set). + $simplegradebook[$key]['grade'][$i][$mod->id] = 'graded_.gif'; + $simplegradebook[$key]['avg'][] = array( + 'grade' => $grade[$key]->rawgrade, + 'grademax' => $item->grademax + ); + } } } else { From 3aa7b4aa0ba8d7e9a4c45bb9409a3f0b67c1bc50 Mon Sep 17 00:00:00 2001 From: cmERDC Digital Learning Date: Wed, 22 Nov 2017 14:24:05 -0600 Subject: [PATCH 13/22] add new forum waiting for grade --- listactivities.php | 123 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 115 insertions(+), 8 deletions(-) diff --git a/listactivities.php b/listactivities.php index dd7e087..0c3f51d 100644 --- a/listactivities.php +++ b/listactivities.php @@ -138,6 +138,39 @@ break; } + } else if ($modstatus = block_fn_mentor_forum_status($activity, $userid, true)) { + // Check for forum posts for waiting grade count. + switch ($modstatus) { + case 'submitted': + if ($instance->grade == 0) { + // Graded + ++$completedactivities; + } else if ($grade = $gradefunction($instance, $menteeid)) { + if ($item->gradepass > 0) { + if ($grade[$menteeid]->rawgrade >= $item->gradepass) { + // Passed + ++$completedactivities; + } else { + // Fail. + ++$incompletedactivities; + } + } else { + // Graded + ++$completedactivities; + } + } + break; + + case 'saved': + // Saved + ++$savedactivities; + break; + + case 'waitinggrade': + // Waiting for grade + ++$waitingforgradeactivities; + break; + } } else if ($modstatus = block_fn_mentor_quiz_status($activity, $menteeid, true)) { // Check for manually graded quizzes. switch ($modstatus) { @@ -256,6 +289,16 @@ // Ungraded ++$notattemptedactivities; } + } else if ($activity->modname == 'forum' || $activity->modname == 'hsuforum') { + // Count waiting for grade forums without a grade from grade function. + $modstatus = block_fn_mentor_forum_status($activity, $menteeid, true); + // Waiting for grade + if($modstatus == 'waitinggrade') { + ++$waitingforgradeactivities; + } else { + // Ungraded + ++$notattemptedactivities; + } } else if ($activity->modname == 'quiz') { // Count waiting for grade quizzes without a grade from grade function. $modstatus = block_fn_mentor_quiz_status($activity, $menteeid, true); @@ -448,7 +491,7 @@ // Check no grade journal. $shownogradelesson = false; if ($activity->modname == 'journal') { - if ($journal = $DB->get_record('lesson', array('id' => $activity->instance))) { + if ($journal = $DB->get_record('journal', array('id' => $activity->instance))) { $journalmodstatus = block_fn_mentor_journal_status($activity, $menteeid, $course, true); if ($journal->grade == 0) { if (($attempts = $DB->get_records('journal_entries', array( @@ -474,7 +517,7 @@ $CFG->wwwroot . "/mod/$modtype/view.php?id=$data->coursemoduleid' style=\"padding-left:4px\">" . $activity->name . "\n"; } - // Add lessons waiting for grades. + // Add journal waiting for grades. } else if ($activity->modname == 'journal') { if (($activitystate == 1 || $activitystate == 2 || $shownogradejournal) && $journalmodstatus !== 'waitinggrade') { echo "
    \n"; + } else { + continue; + } + // Check forum status. + } else if (($activity->modname == 'forum' || $activity->modname == 'hsuforum') + && ($activity->completion == 2) + && $forumstatus) { + + if ($forumstatus == 'submitted') { + echo "\n"; + echo "\n"; + } else { continue; } @@ -650,7 +714,8 @@ $data = $completion->get_data($activity, true, $menteeid, null); $activitystate = $data->completionstate; $assignmentstatus = block_fn_mentor_assignment_status($activity, $menteeid); - // Add quizzes, lesson, and journal statuses. + // Add forum, quizzes, lesson, and journal statuses. + $forumstatus = block_fn_mentor_forum_status($activity, $menteeid); $quizstatus = block_fn_mentor_quiz_status($activity, $menteeid); $lessonstatus = block_fn_mentor_lesson_status($activity, $menteeid, $course); $journalstatus = block_fn_mentor_journal_status($activity, $menteeid, $course); @@ -665,7 +730,12 @@ && $assignmentstatus) { continue; } - // Check quiz, lesson, and journal statuses. + // Check forum, quiz, lesson, and journal statuses. + if (($activity->modname == 'forum' || $activity->modname == 'hsuforum') + && ($activity->completion == 2) + && $forumstatus) { + continue; + } if (($activity->modname == 'quiz') && ($activity->completion == 2) && $quizstatus) { @@ -704,6 +774,7 @@ $activitystate = $data->completionstate; $assignmentstatus = block_fn_mentor_assignment_status($activity, $menteeid); // Get quizzes, lessons, and journals statuses. + $forumstatus = block_fn_mentor_forum_status($activity, $menteeid); $quizstatus = block_fn_mentor_quiz_status($activity, $menteeid); $lessonstatus = block_fn_mentor_lesson_status($activity, $menteeid, $course); $journalstatus = block_fn_mentor_journal_status($activity, $menteeid, $course); @@ -730,7 +801,24 @@ $activity->name . "\n"; } } - // Check status of quiz, lessons, and journals. + // Check status of forum, quiz, lessons, and journals. + } else if (($activity->modname == 'forum' || $activity->modname == 'hsuforum') + && ($activity->completion == 2) + && $forumstatus) { + if (isset($forumstatus)) { + if ($forumstatus == 'waitinggrade') { + echo "\n"; + echo "\n"; + } + } } else if (($activity->modname == 'quiz') && ($activity->completion == 2) && $quizstatus) { @@ -796,7 +884,8 @@ $data = $completion->get_data($activity, true, $menteeid, null); $activitystate = $data->completionstate; $assignmentstatus = block_fn_mentor_assignment_status($activity, $menteeid); - // Get quiz, lesson, and journal status. + // Get forum, quiz, lesson, and journal status. + $forumstatus = block_fn_mentor_forum_status($activity, $menteeid); $quizstatus = block_fn_mentor_quiz_status($activity, $menteeid); $lessonstatus = block_fn_mentor_lesson_status($activity, $menteeid, $course); $journalstatus = block_fn_mentor_journal_status($activity, $menteeid, $course); @@ -823,7 +912,25 @@ } } } - // Get quiz, lesson, and journal statuses. + // Get forum, quiz, lesson, and journal statuses. + if (($activity->modname == 'forum' || $activity->modname == 'hsuforum') + && ($activity->completion == 2) + && $forumstatus) { + if (isset($forumstatus)) { + if ($forumstatus == 'saved') { + echo "\n"; + echo "\n"; + } + } + } if (($activity->modname == 'quiz') && ($activity->completion == 2) && $quizstatus) { From 75e351654b31aefddbe79f40c99aa9604b91a810 Mon Sep 17 00:00:00 2001 From: cmERDC Digital Learning Date: Mon, 27 Nov 2017 10:32:18 -0600 Subject: [PATCH 14/22] fixed lesson counts and quality grade --- lib.php | 107 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 92 insertions(+), 15 deletions(-) diff --git a/lib.php b/lib.php index 8272171..7488732 100644 --- a/lib.php +++ b/lib.php @@ -1245,7 +1245,7 @@ function block_fn_mentor_journal_status($mod, $userid, $course) { } $entries = $DB->get_records('journal_entries', array( 'journal' => $journal->id, 'userid' => $userid), 'id DESC', '*', 0, 1); - // Get any grades for the lesson. + // Get any grades for the journal. $grades = grade_get_grades($course->id, 'mod', 'journal', $journal->id, $userid); if ($entries) { $grade = reset($grades->items[0]->grades); @@ -1372,12 +1372,47 @@ function block_fn_mentor_grade_summary($studentid, $courseid=0) { } } } - - if (!$gradeitem = $DB->get_record('grade_items', - array('itemtype' => 'mod', 'itemmodule' => $mod->modname, 'iteminstance' => $mod->instance))) { - continue; + + // Remove not fully graded lessons. + if ($mod->modname == 'lesson') { + + if ($lessongrades = $DB->get_record('lesson_grades', array('lessonid' => $mod->instance, 'userid' => $studentid))) { + if ($lessongrades->grade >= 0) { + //Graded. + if ($attempts = $DB->get_records('lesson_attempts', array( + 'lessonid' => $mod->instance, 'userid' => $studentid), 'id DESC', '*', 0, 1) + ) { + if($attempts) { + $i = 0; + $count = count($attempts); + $attempt = array_values($attempts); + $lessongrades->dontcount = false; + for($i = 0; $i < $count; ++$i) { + // check for ungraded lesson essay answers. + $useranswer = $attempt[$i]->useranswer; + if((strpos($useranswer, 'stdClass') !== false) && (strpos($useranswer, 'graded') !== false)) { + if($answer = unserialize($useranswer)) { + if($answer->graded == 0) { + $lessongrades->dontcount = true; + } + } + } + } + } + if ($lessongrades->dontcount == true) { + + --$nogradeassignments; + } + } + } + } } + if (!$gradeitem = $DB->get_record('grade_items', + array('itemtype' => 'mod', 'itemmodule' => $mod->modname, 'iteminstance' => $mod->instance))) { + continue; + } + $gradetotal['all_max'] += $gradeitem->grademax; if ($gradegrade = $DB->get_record('grade_grades', array('itemid' => $gradeitem->id, 'userid' => $studentid))) { @@ -1401,6 +1436,7 @@ function block_fn_mentor_grade_summary($studentid, $courseid=0) { } } } + if ($gradetotal['attempted_max']) { $attempted = round(($gradetotal['attempted_grade'] / $gradetotal['attempted_max']) * 100); } else { @@ -1418,6 +1454,7 @@ function block_fn_mentor_grade_summary($studentid, $courseid=0) { $data->failed = 0; $data->timecompleted = 0; + if ($courses) { foreach ($courses as $id => $value) { $sqlcourseaverage = "SELECT gg.id, @@ -1428,7 +1465,9 @@ function block_fn_mentor_grade_summary($studentid, $courseid=0) { ON gi.id = gg.itemid WHERE gi.itemtype = ? AND gi.courseid = ? - AND gg.userid = ?"; + AND gg.userid = ? + AND gi.gradetype <> '0' + AND gi.aggregationcoef <> '1%'"; if ($courseaverage = $DB->get_record_sql($sqlcourseaverage, array('course', $id, $studentid))) { //Prevent division by zero. if($courseaverage->rawgrademax > 0) { @@ -1571,6 +1610,7 @@ function block_fn_mentor_quality_grade ($studentid, $courseid=0) { } } } + if (!$gradeitem = $DB->get_record('grade_items', array('itemtype' => 'mod', 'itemmodule' => $mod->modname, 'iteminstance' => $mod->instance))) { @@ -1619,10 +1659,10 @@ function block_fn_mentor_quality_grade ($studentid, $courseid=0) { if ($courses) { foreach ($courses as $id => $value) { - $sqlcourseaverage = "SELECT gg.id, round(gg.finalgrade,2) as finalgrade, round(gg.rawgrademax,2) as rawgrademax + $sqlcourseaverage = "SELECT gg.id, gi.itemmodule as itemmodule, gi.iteminstance as iteminstance, round(gg.finalgrade,2) as finalgrade, round(gg.rawgrademax,2) as rawgrademax FROM {grade_grades} gg JOIN {grade_items} gi - ON gg.itemid = gi.id + ON gi.id = gg.itemid WHERE gi.itemtype = ? AND gi.courseid = ? AND gg.userid = ? @@ -1635,11 +1675,49 @@ function block_fn_mentor_quality_grade ($studentid, $courseid=0) { $quality->finalgrade = 0; $quality->rawgrademax = 0; foreach ($records as $record) { - foreach ($record as $key => $value) { - if($key != 'id') { - $quality->$key += $value; + // Don't count ungraded lessons in quality count. + if ($record->itemmodule == 'lesson') { + if ($lessongrades = $DB->get_records('lesson_grades', array( + 'lessonid' => $record->iteminstance, 'userid' => $studentid), 'id DESC')) { + $lessongrade = reset($lessongrades); + if ($lessongrade->grade >= 0) { + //Graded. + $attempts = $DB->get_records('lesson_attempts', array( + 'lessonid' => $record->iteminstance, 'userid' => $studentid), 'answerid DESC'); + if($attempts) { + $i = 0; + $count = count($attempts); + $attempt = array_values($attempts); + $lessongrade->dontcount = false; + for($i = 0; $i < $count; ++$i) { + // check for ungraded lesson essay answers. + $useranswer = $attempt[$i]->useranswer; + if((strpos($useranswer, 'stdClass') !== false) && (strpos($useranswer, 'graded') !== false)) { + if($answer = unserialize($useranswer)) { + if($answer->graded == 0) { + $lessongrade->dontcount = true; + } + } + } + } + } + if ($lessongrade->dontcount != true) { + // Graded. + $quality->finalgrade += $record->finalgrade; + $quality->rawgrademax += $record->rawgrademax; + } + + } } - } + } else { + $quality->finalgrade += $record->finalgrade; + $quality->rawgrademax += $record->rawgrademax; + } + /*foreach ($record as $key => $value) { + if($key != 'id') { + $quality->$key += $value; + } + } */ }; if ($quality->rawgrademax == 0) { $qualitygrades[$id] = 0; @@ -3704,12 +3782,11 @@ function block_fn_mentor_simplegradebook($course, $menteeuser, $modgradesarray) $libfile = $CFG->dirroot . '/mod/' . $mod->modname . '/lib.php'; if (file_exists($libfile)) { - // Check to see if this module is using their own get grades method or switch to the standard Moodle get grades function. + // Check to see if this module is using their own get grades method or switch to the standard Moodle get grades function. + require_once($libfile); $gradefunction = $mod->modname . "_get_user_grades"; if(!function_exists($gradefunction)) { $gradefunction = "grade_get_grades"; - } else { - require_once($libfile); } } if($item) { From 5ca85f00522fd5533e471af8f0a2b9600c4891ad Mon Sep 17 00:00:00 2001 From: cmERDC Digital Learning Date: Mon, 27 Nov 2017 14:47:41 -0600 Subject: [PATCH 15/22] added new mods to notification function --- lib.php | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/lib.php b/lib.php index 7488732..fa3cbd4 100644 --- a/lib.php +++ b/lib.php @@ -22,7 +22,7 @@ require_once($CFG->dirroot.'/mod/assignment/lib.php'); require_once($CFG->dirroot.'/lib/completionlib.php'); -// Connect to an external DB for log files. +// Connect to an external DB for log files. require_once($CFG->dirroot.'/blocks/fn_mentor/classes/ext_db/db_connect.php'); define('BLOCK_FN_MENTOR_MESSAGE_SEND_ALL', 0); @@ -1690,15 +1690,15 @@ function block_fn_mentor_quality_grade ($studentid, $courseid=0) { $attempt = array_values($attempts); $lessongrade->dontcount = false; for($i = 0; $i < $count; ++$i) { - // check for ungraded lesson essay answers. - $useranswer = $attempt[$i]->useranswer; - if((strpos($useranswer, 'stdClass') !== false) && (strpos($useranswer, 'graded') !== false)) { - if($answer = unserialize($useranswer)) { - if($answer->graded == 0) { - $lessongrade->dontcount = true; - } + // check for ungraded lesson essay answers. + $useranswer = $attempt[$i]->useranswer; + if((strpos($useranswer, 'stdClass') !== false) && (strpos($useranswer, 'graded') !== false)) { + if($answer = unserialize($useranswer)) { + if($answer->graded == 0) { + $lessongrade->dontcount = true; + } + } } - } } } if ($lessongrade->dontcount != true) { @@ -1719,11 +1719,11 @@ function block_fn_mentor_quality_grade ($studentid, $courseid=0) { } } */ }; - if ($quality->rawgrademax == 0) { - $qualitygrades[$id] = 0; - } else { - $qualitygrades[$id] = ($quality->finalgrade / $quality->rawgrademax) * 100; - } + if ($quality->rawgrademax == 0) { + $qualitygrades[$id] = 0; + } else { + $qualitygrades[$id] = ($quality->finalgrade / $quality->rawgrademax) * 100; + } if ($qualitygrades[$id] >= $passinggrade) { $data->passed++; @@ -1763,9 +1763,9 @@ function block_fn_mentor_print_grade_summary ($courseid , $studentid) { $html = ''; $courseaverage = block_fn_mentor_get_user_course_average($studentid, $courseid); $gradesummary = block_fn_mentor_grade_summary($studentid, $courseid); - //Add Quzlity Grade to print results. + // Add Quality Grade to print results. $qualitysummary = block_fn_mentor_quality_grade ($studentid, $courseid); - // Use the configured passing grade. + // Use the configured passing grade. if (! $passinggrade = get_config('block_fn_mentor', 'passinggrade')) { $passinggrade = 50; } @@ -1781,7 +1781,7 @@ function block_fn_mentor_print_grade_summary ($courseid , $studentid) { $class = 'red'; $nocoursetotalmsg = get_string('nocoursetotal', 'block_fn_mentor'); } else { - // Use the configured passing grade. + // Use the configured passing grade. $class = ($gradesummary->courseaverage >= $passinggrade) ? 'green' : 'red'; $nocoursetotalmsg = ''; } @@ -1793,7 +1793,7 @@ function block_fn_mentor_print_grade_summary ($courseid , $studentid) { $html .= ''; $html .= ''; } - // add Quality grade to grade window. + // add Quality grade to grade window. $html .= ''; $html .= ''; if ($courseaverage == false) { @@ -2362,6 +2362,11 @@ function block_fn_mentor_last_activity ($studentid) { $lastsubmission = null; $lastattempt = null; $lastpost = null; + $lasthsupost = null; + $llastattempt = null; + $jlastentry = null; + $sclastattempt = null; + $ltilastsubmission = null; // Assign. $sqlassign = "SELECT s.id, From c975c5e7e0b1c471d9dbf6c70e01f26b0958ed51 Mon Sep 17 00:00:00 2001 From: cmERDC Digital Learning Date: Mon, 27 Nov 2017 15:10:22 -0600 Subject: [PATCH 16/22] fixes for lesson grade --- lib.php | 58 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/lib.php b/lib.php index fa3cbd4..10f2652 100644 --- a/lib.php +++ b/lib.php @@ -1375,34 +1375,38 @@ function block_fn_mentor_grade_summary($studentid, $courseid=0) { // Remove not fully graded lessons. if ($mod->modname == 'lesson') { - - if ($lessongrades = $DB->get_record('lesson_grades', array('lessonid' => $mod->instance, 'userid' => $studentid))) { - if ($lessongrades->grade >= 0) { - //Graded. - if ($attempts = $DB->get_records('lesson_attempts', array( - 'lessonid' => $mod->instance, 'userid' => $studentid), 'id DESC', '*', 0, 1) - ) { - if($attempts) { - $i = 0; - $count = count($attempts); - $attempt = array_values($attempts); - $lessongrades->dontcount = false; - for($i = 0; $i < $count; ++$i) { - // check for ungraded lesson essay answers. - $useranswer = $attempt[$i]->useranswer; - if((strpos($useranswer, 'stdClass') !== false) && (strpos($useranswer, 'graded') !== false)) { - if($answer = unserialize($useranswer)) { - if($answer->graded == 0) { - $lessongrades->dontcount = true; - } - } - } - } - } - if ($lessongrades->dontcount == true) { - - --$nogradeassignments; + if($lesson = $DB->get_record('lesson', array('id' => $mod->instance))) { + if ($lessongrades = $DB->get_records('lesson_grades', array('lessonid' => $lesson->id, 'userid' => $studentid), 'id DESC')) { + foreach($lessongrades as $key =>$gradeobj) { + if ($gradeobj->grade >= 0) { + //Graded. + if ($attempts = $DB->get_records('lesson_attempts', array( + 'lessonid' => $lesson->id, 'userid' => $studentid), 'id DESC', '*', 0, 1) + ) { + if($attempts) { + $i = 0; + $count = count($attempts); + $attempt = array_values($attempts); + $lessongrade = new stdClass; + $lessongrade->dontcount = false; + for($i = 0; $i < $count; ++$i) { + // check for ungraded lesson essay answers. + $useranswer = $attempt[$i]->useranswer; + if((strpos($useranswer, 'stdClass') !== false) && (strpos($useranswer, 'graded') !== false)) { + if($answer = unserialize($useranswer)) { + if($answer->graded == 0) { + $lessongrade->dontcount = true; + } + } + } + } + } + if ($lessongrade->dontcount == true) { + + --$nogradeassignments; + } } + } } } } From 1b915d9218817965706b355df8c92cafdb85e9ea Mon Sep 17 00:00:00 2001 From: cmERDC Digital Learning Date: Mon, 27 Nov 2017 15:24:22 -0600 Subject: [PATCH 17/22] fixes --- lib.php | 56 +++++++++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/lib.php b/lib.php index 10f2652..5040781 100644 --- a/lib.php +++ b/lib.php @@ -1376,39 +1376,37 @@ function block_fn_mentor_grade_summary($studentid, $courseid=0) { // Remove not fully graded lessons. if ($mod->modname == 'lesson') { if($lesson = $DB->get_record('lesson', array('id' => $mod->instance))) { - if ($lessongrades = $DB->get_records('lesson_grades', array('lessonid' => $lesson->id, 'userid' => $studentid), 'id DESC')) { - foreach($lessongrades as $key =>$gradeobj) { - if ($gradeobj->grade >= 0) { - //Graded. - if ($attempts = $DB->get_records('lesson_attempts', array( - 'lessonid' => $lesson->id, 'userid' => $studentid), 'id DESC', '*', 0, 1) - ) { - if($attempts) { - $i = 0; - $count = count($attempts); - $attempt = array_values($attempts); - $lessongrade = new stdClass; - $lessongrade->dontcount = false; - for($i = 0; $i < $count; ++$i) { - // check for ungraded lesson essay answers. - $useranswer = $attempt[$i]->useranswer; - if((strpos($useranswer, 'stdClass') !== false) && (strpos($useranswer, 'graded') !== false)) { - if($answer = unserialize($useranswer)) { - if($answer->graded == 0) { - $lessongrade->dontcount = true; - } - } + if ($lesson->grade > 0 && $lesson->practice != 1) { + if ($lessongrades = $DB->get_records('lesson_grades', array('lessonid' => $lesson->id, 'userid' => $studentid), 'id DESC', '*', 0, 1)) { + //Graded. + if ($attempts = $DB->get_records('lesson_attempts', array( + 'lessonid' => $lesson->id, 'userid' => $studentid), 'id DESC', '*', 0, 1) + ) { + if($attempts) { + $i = 0; + $count = count($attempts); + $attempt = array_values($attempts); + $lessongrade = new stdClass; + $lessongrade->dontcount = false; + for($i = 0; $i < $count; ++$i) { + // check for ungraded lesson essay answers. + $useranswer = $attempt[$i]->useranswer; + if((strpos($useranswer, 'stdClass') !== false) && (strpos($useranswer, 'graded') !== false)) { + if($answer = unserialize($useranswer)) { + if($answer->graded == 0) { + $lessongrade->dontcount = true; + } } - } - } - if ($lessongrade->dontcount == true) { - - --$nogradeassignments; + } } - } + } + if ($lessongrade->dontcount == true) { + + --$nogradeassignments; + } } } - } + } } } From df159bc9f3eeabc5f607f315a3ff4b097e2f5d7f Mon Sep 17 00:00:00 2001 From: cmERDC Digital Learning Date: Mon, 27 Nov 2017 15:38:19 -0600 Subject: [PATCH 18/22] journal fix --- lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib.php b/lib.php index 5040781..27fff92 100644 --- a/lib.php +++ b/lib.php @@ -2417,7 +2417,7 @@ function block_fn_mentor_last_activity ($studentid) { if ($entries = $DB->get_records_sql($sqljournal, array($studentid))) { $entry = reset($entries); - $jlastentry = round(((time() - $entry->completed) / (24 * 60 * 60)), 0); + $jlastentry = round(((time() - $entry->modified) / (24 * 60 * 60)), 0); } // Forum. From 34744069fb07ddb7d593d643e315ada376c38bfc Mon Sep 17 00:00:00 2001 From: cmERDC Digital Learning Date: Tue, 28 Nov 2017 08:21:56 -0600 Subject: [PATCH 19/22] Adjust non-graded course percentages to N/A --- lib.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib.php b/lib.php index 27fff92..47ed64e 100644 --- a/lib.php +++ b/lib.php @@ -1504,6 +1504,10 @@ function block_fn_mentor_grade_summary($studentid, $courseid=0) { $data->courseaverage = round($coursegrades[$courseid]); } else { $data->courseaverage = 0; + // If no course grade then don't show a percentage. + if ($courseaverage->rawgrademax == 0) { + $data->courseaverage = 'N/A'; + } } $sqlactivity = "SELECT gi.id, @@ -1752,6 +1756,10 @@ function block_fn_mentor_quality_grade ($studentid, $courseid=0) { $data->courseaverage = round($qualitygrades[$courseid]); } else { $data->courseaverage = 0; + // If no course grade then don't show a percentage. + if ($quality->rawgrademax == 0) { + $data->courseaverage = 'N/A'; + } } } @@ -1787,7 +1795,11 @@ function block_fn_mentor_print_grade_summary ($courseid , $studentid) { $class = ($gradesummary->courseaverage >= $passinggrade) ? 'green' : 'red'; $nocoursetotalmsg = ''; } - $html .= ''; + // If no course grade then don't show a percentage. + if (is_numeric($gradesummary->courseaverage)){ + $gradesummary->courseaverage = $gradesummary->courseaverage . '%'; + } + $html .= ''; $html .= ''; if ($courseaverage == false) { $warningimg = ' '; @@ -1805,7 +1817,11 @@ function block_fn_mentor_print_grade_summary ($courseid , $studentid) { $class = ($qualitysummary->courseaverage >= $passinggrade) ? 'green' : 'red'; $nocoursetotalmsg = ''; } - $html .= ''; + // If no course grade then don't show a percentage. + if (is_numeric($qualitysummary->courseaverage)){ + $qualitysummary->courseaverage = $qualitysummary->courseaverage . '%'; + } + $html .= ''; $html .= ''; $html .= '
    - '.''.' -
    \n"; @@ -514,7 +557,8 @@ $data = $completion->get_data($activity, true, $menteeid, null); $activitystate = $data->completionstate; $assignmentstatus = block_fn_mentor_assignment_status($activity, $menteeid); - // Get the quizzes, lessons, and journals statuses. + // Get the forum, quizzes, lessons, and journals statuses. + $forumstatus = block_fn_mentor_forum_status($activity, $menteeid); $quizstatus = block_fn_mentor_quiz_status($activity, $menteeid); $lessonstatus = block_fn_mentor_lesson_status($activity, $menteeid, $course); $journalstatus = block_fn_mentor_journal_status($activity, $menteeid, $course); @@ -541,6 +585,26 @@ $CFG->wwwroot . "/mod/$modtype/view.php?id=$data->coursemoduleid' style=\"padding-left:4px\">" . $activity->name . "
    \n"; + $modtype = $DB->get_field('modules', 'name', array('id' => $activity->module)); + $modicon = "wwwroot/mod/$modtype/pix/icon.png\" ". + "HEIGHT=\"16\" WIDTH=\"16\" >"; + echo $modtype; + echo "$modicon" . + $activity->name . "
    \n"; + $modtype = $DB->get_field('modules', 'name', array('id' => $activity->module)); + $modicon = "wwwroot/mod/$modtype/pix/icon.png\" ". + "HEIGHT=\"16\" WIDTH=\"16\" >"; + echo $modtype; + echo "$modicon" . + $activity->name . "
    \n"; + $modtype = $DB->get_field('modules', 'name', array('id' => $activity->module)); + $modicon = "wwwroot/mod/$modtype/pix/icon.png\" ". + "HEIGHT=\"16\" WIDTH=\"16\" >"; + echo $modtype; + echo "$modicon" . + $activity->name . "'.$warningimg.get_string('nocoursetotal', 'block_fn_mentor').'
    '.get_string('qualitygrade', 'block_fn_mentor').':'.$gradesummary->courseaverage.'%'.$gradesummary->courseaverage.'
    '.$qualitysummary->courseaverage.'%'.$qualitysummary->courseaverage.'
    '; From 5210c2814934ba8ad5607a847c3eda74595b71bd Mon Sep 17 00:00:00 2001 From: cmERDC Digital Learning Date: Wed, 29 Nov 2017 08:44:19 -0600 Subject: [PATCH 20/22] fixes --- lib.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib.php b/lib.php index 47ed64e..e997805 100644 --- a/lib.php +++ b/lib.php @@ -1505,7 +1505,7 @@ function block_fn_mentor_grade_summary($studentid, $courseid=0) { } else { $data->courseaverage = 0; // If no course grade then don't show a percentage. - if ($courseaverage->rawgrademax == 0) { + if ($data->all == 0) { $data->courseaverage = 'N/A'; } } @@ -1757,7 +1757,7 @@ function block_fn_mentor_quality_grade ($studentid, $courseid=0) { } else { $data->courseaverage = 0; // If no course grade then don't show a percentage. - if ($quality->rawgrademax == 0) { + if ($data->all == 0) { $data->courseaverage = 'N/A'; } } @@ -1774,7 +1774,7 @@ function block_fn_mentor_print_grade_summary ($courseid , $studentid) { $courseaverage = block_fn_mentor_get_user_course_average($studentid, $courseid); $gradesummary = block_fn_mentor_grade_summary($studentid, $courseid); // Add Quality Grade to print results. - $qualitysummary = block_fn_mentor_quality_grade ($studentid, $courseid); + $qualitysummary = block_fn_mentor_quality_grade($studentid, $courseid); // Use the configured passing grade. if (! $passinggrade = get_config('block_fn_mentor', 'passinggrade')) { $passinggrade = 50; From 382ff57e485af0278324211c4ecc43a747e088c9 Mon Sep 17 00:00:00 2001 From: cmERDC Digital Learning Date: Mon, 4 Dec 2017 11:29:17 -0600 Subject: [PATCH 21/22] some fixes --- lib.php | 4 ---- listactivities.php | 6 +++--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lib.php b/lib.php index e997805..ee68910 100644 --- a/lib.php +++ b/lib.php @@ -900,7 +900,6 @@ function block_fn_mentor_assignment_status($mod, $userid) { if (isset($SESSION->completioncache)) { unset($SESSION->completioncache); } - if ($mod->modname == 'assignment') { if (!($assignment = $DB->get_record('assignment', array('id' => $mod->instance)))) { return false; @@ -1196,7 +1195,6 @@ function block_fn_mentor_lesson_status($mod, $userid, $course) { } if($timer->completed == 1) { if ($grade->grade) { - //var_dump($grade); $attempts = $DB->get_records('lesson_attempts', array( 'lessonid' => $lesson->id, 'userid' => $userid), 'answerid DESC'); if($attempts) { @@ -3446,7 +3444,6 @@ function block_fn_mentor_activity_progress($course, $menteeid, $modgradesarray) break; } } else if ($grade) { - if($activity->modname == 'forum' || $activity->modname == 'hsuforum') {var_dump($grade);} if ($item->gradepass > 0) { if ($grade[$menteeid]->rawgrade >= $item->gradepass) { // Passed @@ -3833,7 +3830,6 @@ function block_fn_mentor_simplegradebook($course, $menteeuser, $modgradesarray) if (strpos($gradefunction, $mod->modname) !== false) { // Run through special cases first before applying standard grade checks. $grade = $gradefunction($instance, $key); - if ($modstatus = block_fn_mentor_assignment_status($mod, $key, true)) { switch ($modstatus) { diff --git a/listactivities.php b/listactivities.php index 0c3f51d..324413c 100644 --- a/listactivities.php +++ b/listactivities.php @@ -138,11 +138,11 @@ break; } - } else if ($modstatus = block_fn_mentor_forum_status($activity, $userid, true)) { + } else if ($modstatus = block_fn_mentor_forum_status($activity, $$menteeid, true)) { // Check for forum posts for waiting grade count. switch ($modstatus) { case 'submitted': - if ($instance->grade == 0) { + if ($instance->assessed == 0) { // Graded ++$completedactivities; } else if ($grade = $gradefunction($instance, $menteeid)) { @@ -489,7 +489,7 @@ } } // Check no grade journal. - $shownogradelesson = false; + $shownogradejournal = false; if ($activity->modname == 'journal') { if ($journal = $DB->get_record('journal', array('id' => $activity->instance))) { $journalmodstatus = block_fn_mentor_journal_status($activity, $menteeid, $course, true); From 81ff66309476fbf4964922ae9e9e9090b5c175e3 Mon Sep 17 00:00:00 2001 From: cmERDC Digital Learning Date: Mon, 4 Dec 2017 12:54:31 -0600 Subject: [PATCH 22/22] recalculate completed list with grade accounted --- listactivities.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/listactivities.php b/listactivities.php index 324413c..06d1143 100644 --- a/listactivities.php +++ b/listactivities.php @@ -138,7 +138,7 @@ break; } - } else if ($modstatus = block_fn_mentor_forum_status($activity, $$menteeid, true)) { + } else if ($modstatus = block_fn_mentor_forum_status($activity, $menteeid, true)) { // Check for forum posts for waiting grade count. switch ($modstatus) { case 'submitted': @@ -432,20 +432,18 @@ echo "
    "; } - if ($show == 'completed') { if ($activities) { foreach ($activities as $activity) { if (!$activity->visible) { continue; } - $data = $completion->get_data($activity, false, $menteeid, null); - - $activitystate = $data->completionstate; - // Make sure this is an actual graded item by getting the gradebook entries. - $grade[$menteeid] = grade_get_grades($course->id, 'mod', $activity->modname, $activity->instance, $menteeid); - if (!empty($grade[$menteeid]->items)) { + $activitystate = $data->completionstate; + $grade[$menteeid] = grade_get_grades($course->id, 'mod', $activity->modname, $activity->instance, $menteeid); + $usergrade = $grade[$menteeid]->items[0]->grades[$menteeid]; + // Make sure these are graded items. + if (!empty($grade[$menteeid]->items) && $usergrade->grade != NULL) { // Check no grade assignments. $shownogradeassignment = false; if ($activity->modname == 'assign') { @@ -565,8 +563,9 @@ $item = $DB->get_record('grade_items', array("itemtype" => 'mod', "itemmodule" => $activity->modname, "iteminstance" => $activity->instance)); $grade[$menteeid] = grade_get_grades($course->id, 'mod', $activity->modname, $activity->instance, $menteeid); + $usergrade = $grade[$menteeid]->items[0]->grades[$menteeid]; // Make sure these are graded items. - if ($activitystate == 3 && (!empty($grade[$menteeid]->items))) { + if ($activitystate == 3 && $usergrade->grade != NULL) { if (($activity->module == 1) && ($activity->modname == 'assignment' || $activity->modname == 'assign') @@ -770,6 +769,7 @@ if (!$activity->visible) { continue; } + //var_dump($activity->id); $data = $completion->get_data($activity, true, $menteeid, null); $activitystate = $data->completionstate; $assignmentstatus = block_fn_mentor_assignment_status($activity, $menteeid);