public function test_participant_count_feedback() { $courseid = $this->course->id; $actual = local::course_participant_count($courseid, 'feedback'); $expected = count($this->students); $this->assertSame($expected, $actual); $this->create_extra_users(); $actual = local::course_participant_count($courseid, 'feedback'); $expected = count($this->students); $this->assertSame($expected, $actual); }
/** * Get the module meta data for a specific module. * * @param cm_info $mod * * @return string */ protected function module_meta_html(cm_info $mod) { global $COURSE, $CFG; $content = ''; if (is_guest(context_course::instance($COURSE->id))) { return ''; } // Do we have an activity function for this module for returning meta data? // @todo - check module lib.php for a meta function (won't work for core mods but will for ours if we wish). $methodname = $mod->modname . '_meta'; if (method_exists('theme_snap\\activity', $methodname)) { $meta = call_user_func('theme_snap\\activity::' . $methodname, $mod); } else { // Can't get meta data for this module. return ''; } $content .= '<div class="module-meta">'; if ($meta->isteacher) { // Teacher - useful teacher meta data. if (!empty($meta->timeclose)) { $dueinfo = get_string('due', 'theme_snap'); $dueclass = 'label-info'; $content .= '<span class="label ' . $dueclass . '">' . $dueinfo . ' ' . userdate($meta->timeclose, get_string('strftimedate', 'langconfig') . '</span>'); } $engagementmeta = array(); $gradedlabel = "info"; // Below, !== false means we get 0 out of x submissions. if (!$meta->submissionnotrequired && $meta->numsubmissions !== false) { $engagementmeta[] = get_string('xofy' . $meta->submitstrkey, 'theme_snap', (object) array('completed' => $meta->numsubmissions, 'participants' => \theme_snap\local::course_participant_count($COURSE->id))); } if ($meta->numrequiregrading) { $gradedlabel = "warning"; $engagementmeta[] = get_string('xungraded', 'theme_snap', $meta->numrequiregrading); } $link = $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?action=grading&id=' . $mod->id . '&tsort=timesubmitted&filter=require_grading'; $content .= '<a href="' . s($link) . '"><span class="label label-' . $gradedlabel . '">' . implode(', ', $engagementmeta) . '</span></a>'; } else { // Student - useful student meta data. if (!empty($meta->timeopen) && $meta->timeopen > time()) { // Todo - spit out a 'submissions allowed form' tag. $content .= '</div>'; return $content; } // Note, due date is rendered seperately for students as it has a warning class if overdue. if (!empty($meta->timeclose)) { if (empty($meta->submissionnotrequired) && empty($meta->timesubmitted) && time() > usertime($meta->timeclose)) { $dueinfo = get_string('overdue', 'theme_snap'); $dueclass = 'label-danger'; } else { $dueinfo = get_string('due', 'theme_snap'); $dueclass = 'label-info'; } $content .= '<span class="label ' . $dueclass . '">' . $dueinfo . ' ' . userdate($meta->timeclose, get_string('strftimedate', 'langconfig') . '</span>'); } // Feedback meta. if (!empty($meta->grade)) { // Note - the link that a module takes you to would be better off defined by a function in // theme/snap/activity - for now its just hard coded. $url = new \moodle_url('/grade/report/user/index.php', ['id' => $COURSE->id]); if (in_array($mod->modname, ['quiz', 'assign'])) { $url = new \moodle_url('/mod/' . $mod->modname . '/view.php?id=' . $mod->id); } $content .= '<a href="' . $url->out() . '"><span class="label label-info">' . get_string('feedbackavailable', 'theme_snap') . '</span></a>'; } // Submission CTA. if (empty($meta->submissionnotrequired)) { $content .= '<a class="assignment_stage" href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">'; if ($meta->submitted) { if (empty($meta->timesubmitted)) { $submittedonstr = ''; } else { $submittedonstr = ' ' . userdate($meta->timesubmitted, get_string('strftimedate', 'langconfig')); } $content .= '<span class="label label-success">' . $meta->submittedstr . $submittedonstr . '</span>'; } else { $warningstr = $meta->draft ? $meta->draftstr : $meta->notsubmittedstr; $warningstr = $meta->reopened ? $meta->reopenedstr : $warningstr; $content .= '<span class="label label-warning">' . $warningstr . '</span>'; } $content .= '</a>'; } } $content .= '</div>'; return $content; }
/** * Get the module meta data for a specific module. * * @param cm_info $mod * @return string */ protected function module_meta_html(cm_info $mod) { global $COURSE; $content = ''; if (is_guest(context_course::instance($COURSE->id))) { return ''; } // Do we have an activity function for this module for returning meta data? // @todo - check module lib.php for a meta function (won't work for core mods but will for ours if we wish). $meta = activity::module_meta($mod); if (!$meta->is_set(true)) { // Can't get meta data for this module. return ''; } $content .= ''; if ($meta->isteacher) { // Teacher - useful teacher meta data. if (!empty($meta->timeclose)) { $due = get_string('due', 'theme_snap'); $dateformat = get_string('strftimedate', 'langconfig'); $labeltext = $due . ' ' . userdate($meta->timeclose, $dateformat); $labelclass = 'label label-info'; $url = new \moodle_url("/mod/{$mod->modname}/view.php", ['id' => $mod->id]); $content .= html_writer::link($url, $labeltext, ['class' => $labelclass]); } $engagementmeta = array(); $gradedlabel = "info"; // Below, !== false means we get 0 out of x submissions. if (!$meta->submissionnotrequired && $meta->numsubmissions !== false) { $engagementmeta[] = get_string('xofy' . $meta->submitstrkey, 'theme_snap', (object) array('completed' => $meta->numsubmissions, 'participants' => \theme_snap\local::course_participant_count($COURSE->id, $mod->modname))); } if ($meta->numrequiregrading) { $gradedlabel = "warning"; $engagementmeta[] = get_string('xungraded', 'theme_snap', $meta->numrequiregrading); } if (!empty($engagementmeta)) { $engagementstr = implode(', ', $engagementmeta); $params = array('action' => 'grading', 'id' => $mod->id, 'tsort' => 'timesubmitted', 'filter' => 'require_grading'); $url = new moodle_url("/mod/{$mod->modname}/view.php", $params); $content .= html_writer::link($url, $engagementstr, ['class' => "label label-{$gradedlabel}"]); } } else { // Student - useful student meta data. if (!empty($meta->timeopen) && $meta->timeopen > time()) { // TODO - spit out a 'submissions allowed form' tag. return $content; } // Note, due date is rendered seperately for students as it has a warning class if overdue. if (!empty($meta->timeclose)) { if ($meta->overdue) { $dueinfo = $meta->overduestr; $status = 'danger'; } else { $dueinfo = $meta->duestr; $status = 'info'; } $url = new \moodle_url("/mod/{$mod->modname}/view.php", ['id' => $mod->id]); $dateformat = get_string('strftimedate', 'langconfig'); $labeltext = $dueinfo . ' ' . userdate($meta->timeclose, $dateformat); $labelclass = "label label-{$status}"; $content .= html_writer::link($url, $labeltext, ['class' => $labelclass]); } // Feedback meta. if (!empty($meta->grade)) { // Note - the link that a module takes you to would be better off defined by a function in // theme/snap/activity - for now its just hard coded. $url = new \moodle_url('/grade/report/user/index.php', ['id' => $COURSE->id]); if (in_array($mod->modname, ['quiz', 'assign'])) { $url = new \moodle_url('/mod/' . $mod->modname . '/view.php?id=' . $mod->id); } $feedbackavailable = get_string('feedbackavailable', 'theme_snap'); $content .= html_writer::link($url, $feedbackavailable, ['class' => 'label label-info']); } $content .= $this->submission_cta($mod, $meta); } return $content; }