diff --git a/classes/ext_db/db_connect.php b/classes/ext_db/db_connect.php new file mode 100644 index 0000000..f044446 --- /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; + } + + /* 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; + } + +} diff --git a/course_overview.php b/course_overview.php index 8f71044..ccd72e5 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(); @@ -217,10 +222,14 @@ ''; // 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(); if ($configcategory = get_config('block_fn_mentor', 'category')) { @@ -303,6 +312,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 +449,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 +461,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 +497,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 +532,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 +584,15 @@ class="" > } echo '
'; + $progressbar = block_fn_mentor_print_activity_progress ($course , $menteeuser->id); + echo $progressbar; + echo '
'; - echo ''; // Grade. echo ''; diff --git a/course_overview_single.php b/course_overview_single.php index cf9fccb..fd7e45a 100644 --- a/course_overview_single.php +++ b/course_overview_single.php @@ -33,20 +33,20 @@ $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'); 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'); } @@ -100,7 +100,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 +112,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 +142,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 +192,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 +202,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 +359,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 +387,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 +446,9 @@ get_string('teacher', 'block_fn_mentor').': "; } -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) { @@ -2488,7 +3145,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', @@ -2496,7 +3153,47 @@ function block_fn_mentor_embed ($text, $id) { 'value' => $text, 'type' => 'button', 'id' => $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 +3253,287 @@ 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_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': + 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 == '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); + // 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 +3607,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 +3620,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 +3637,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 +3802,16 @@ 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. + require_once($libfile); + $gradefunction = $mod->modname . "_get_user_grades"; + if(!function_exists($gradefunction)) { + $gradefunction = "grade_get_grades"; + } + } + 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 +3824,365 @@ 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_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': + 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; diff --git a/listactivities.php b/listactivities.php index 4083e26..06d1143 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,288 @@ 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_forum_status($activity, $menteeid, true)) { + // Check for forum posts for waiting grade count. + 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 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 == '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); + // 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': @@ -232,54 +433,140 @@ } 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"; - echo "\n"; - } + $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') { + 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. + $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); + 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"; + echo "\n"; + } + // Add journal waiting for grades. + } else if ($activity->modname == 'journal') { + if (($activitystate == 1 || $activitystate == 2 || $shownogradejournal) && $journalmodstatus !== 'waitinggrade') { + echo "\n"; + echo "\n"; + } + } else if ($activitystate == 1 || $activitystate == 2 || $shownogradeassignment || $shownogradequiz || $shownogradelesson || $shownogradejournal) { + echo "\n"; + echo "\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 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); + $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 && $usergrade->grade != NULL) { + if (($activity->module == 1) && ($activity->modname == 'assignment' || $activity->modname == 'assign') && ($activity->completion == 2) @@ -297,6 +584,86 @@ $CFG->wwwroot . "/mod/$modtype/view.php?id=$data->coursemoduleid' style=\"padding-left:4px\">" . $activity->name . "\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; + } + // Check quiz status. + } else if (($activity->modname == 'quiz') + && ($activity->completion == 2) + && $quizstatus) { + + if ($quizstatus == 'submitted') { + echo "\n"; + echo "\n"; + + } else { + continue; + } + // Check lesson status. + } else if (($activity->modname == 'lesson') + && ($activity->completion == 2) + && $lessonstatus) { + + if ($lessonstatus == 'submitted') { + echo "\n"; + echo "\n"; + + } else { + continue; + } + // Check journal status. + } else if (($activity->modname == 'journal') + && ($activity->completion == 2) + && $journalstatus) { + + if ($journalstatus == 'submitted') { + echo "\n"; + echo "\n"; + } else { continue; } @@ -312,6 +679,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"; + echo "\n"; + + } + } + } + } } } } @@ -324,12 +713,42 @@ $data = $completion->get_data($activity, true, $menteeid, null); $activitystate = $data->completionstate; $assignmentstatus = block_fn_mentor_assignment_status($activity, $menteeid); - if ($activitystate == 0) { + // 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); + // 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 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) { + continue; + } + if (($activity->modname == 'lesson') + && ($activity->completion == 2) + && $lessonstatus) { + continue; + } + if (($activity->modname == 'journal') + && ($activity->completion == 2) + && $journalstatus) { + continue; } echo "\n"; - echo "\n"; - } - } - } + // 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); + // 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"; + echo "\n"; + } + } + // 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) { + if (isset($quizstatus)) { + if ($quizstatus == 'waitinggrade') { + echo "\n"; + echo "\n"; + } + } + } else if (($activity->modname == 'lesson') + && ($activity->completion == 2) + && $lessonstatus) { + if (isset($lessonstatus)) { + if ($lessonstatus == 'waitinggrade') { + echo "\n"; + echo "\n"; + } + } + } else if (($activity->modname == 'journal') + && ($activity->completion == 2) + && $journalstatus) { + if (isset($journalstatus)) { + if ($journalstatus == 'waitinggrade') { + echo "\n"; + echo "\n"; + } + } + } + } } } } @@ -385,7 +884,15 @@ $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 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); + // 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 +912,79 @@ } } } + // 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) { + if (isset($quizstatus)) { + if ($quizstatus == 'saved') { + echo "\n"; + echo "\n"; + } + } + } + if (($activity->modname == 'lesson') + && ($activity->completion == 2) + && $lessonstatus) { + if (isset($lessonstatus)) { + if ($lessonstatus == 'saved') { + echo "\n"; + echo "\n"; + } + } + } + if (($activity->modname == 'journal') + && ($activity->completion == 2) + && $journalstatus) { + if (isset($journalstatus)) { + if ($journalstatus == 'saved') { + echo "\n"; + echo "\n"; + } + } + } } } } 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',
'; 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 +559,6 @@ ); echo '
'; $gradebook = reset($simplegradebook); - if (isset($gradebook['grade'])) { // TABLE. echo ""; @@ -546,15 +599,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 ''; } diff --git a/lang/en/block_fn_mentor.php b/lang/en/block_fn_mentor.php index 602c460..81511d0 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.'; @@ -152,7 +154,9 @@
  • 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'; $string['incompleted2'] = 'Completed - unsuccessful'; $string['info_about_selected_people'] = 'Info about selected people'; @@ -209,7 +213,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 +227,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 +251,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'; diff --git a/lib.php b/lib.php index d31086d..ee68910 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,13 +867,39 @@ 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; if (isset($SESSION->completioncache)) { unset($SESSION->completioncache); } - if ($mod->modname == 'assignment') { if (!($assignment = $DB->get_record('assignment', array('id' => $mod->instance)))) { return false; @@ -1025,6 +1053,254 @@ 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) { + //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) { + $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 journal. + $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 +1331,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); @@ -1099,12 +1370,49 @@ 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($lesson = $DB->get_record('lesson', array('id' => $mod->instance))) { + 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 (!$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))) { @@ -1128,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 { @@ -1145,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, @@ -1155,9 +1465,17 @@ 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))) { - $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++; @@ -1184,6 +1502,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 ($data->all == 0) { + $data->courseaverage = 'N/A'; + } } $sqlactivity = "SELECT gi.id, @@ -1204,10 +1526,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 +1543,240 @@ 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, 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 gi.id = gg.itemid + 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) { + // 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; + } 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; + // If no course grade then don't show a percentage. + if ($data->all == 0) { + $data->courseaverage = 'N/A'; + } + } + } + + 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 Quality 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,10 +1789,15 @@ 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 .= ''; + // 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 = ' '; @@ -1244,7 +1805,25 @@ 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 = ''; + } + // If no course grade then don't show a percentage. + if (is_numeric($qualitysummary->courseaverage)){ + $qualitysummary->courseaverage = $qualitysummary->courseaverage . '%'; + } + $html .= ''; + $html .= ''; + $html .= '
    '.$gradesummary->courseaverage.'%'.$gradesummary->courseaverage.'
    '.$warningimg.get_string('nocoursetotal', 'block_fn_mentor').'
    '.get_string('qualitygrade', 'block_fn_mentor').':'.$qualitysummary->courseaverage.'
    '; + return $html; } @@ -1792,12 +2371,18 @@ 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; + $lasthsupost = null; + $llastattempt = null; + $jlastentry = null; + $sclastattempt = null; + $ltilastsubmission = null; // Assign. $sqlassign = "SELECT s.id, @@ -1824,6 +2409,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->modified) / (24 * 60 * 60)), 0); + } // Forum. $sqlforum = "SELECT f.id, @@ -1836,8 +2445,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"; + + 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"; - return min($lastsubmission, $lastattempt, $lastpost); + 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 +2515,89 @@ function block_fn_mentor_report_outline_print_row($mod, $instance, $result) { 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 "$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 == 'assign') ? 'assignment' : $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 == 'assign') ? 'assignment' : $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 == 'assign') ? 'assignment' : $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 . "
    \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 == 'assign') ? 'assignment' : $modtype; + echo "$modicon" . + $activity->name . "
    \n"; $modtype = $DB->get_field('modules', 'name', array('id' => $activity->module)); @@ -350,29 +769,109 @@ 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); - 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 "$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 == 'assign') ? 'assignment' : $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 . "
    \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 . "
    \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 . "