/**
  * 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;
 }
Esempio n. 2
0
 /**
  * Get deadlines string.
  * @return string
  */
 public static function deadlines()
 {
     global $USER, $PAGE;
     $events = self::upcoming_deadlines($USER->id);
     if (empty($events)) {
         return '<p>' . get_string('nodeadlines', 'theme_snap') . '</p>';
     }
     $output = $PAGE->get_renderer('theme_snap', 'core', RENDERER_TARGET_GENERAL);
     $o = '';
     foreach ($events as $event) {
         if (!empty($event->modulename)) {
             $modinfo = get_fast_modinfo($event->courseid);
             $cm = $modinfo->instances[$event->modulename][$event->instance];
             $eventtitle = $event->name . '<small><br>' . $event->coursefullname . '</small>';
             $modimageurl = $output->pix_url('icon', $event->modulename);
             $modname = get_string('modulename', $event->modulename);
             $modimage = \html_writer::img($modimageurl, $modname);
             $meta = $output->friendly_datetime($event->timestart + $event->timeduration);
             // Add completion meta data for students (exclude anyone who can grade them).
             if (!has_capability('mod/assign:grade', $cm->context)) {
                 /** @var \theme_snap_core_course_renderer $courserenderer */
                 $courserenderer = $PAGE->get_renderer('core', 'course', RENDERER_TARGET_GENERAL);
                 $activitymeta = activity::module_meta($cm);
                 $meta .= '<div class="snap-completion-meta">' . $courserenderer->submission_cta($cm, $activitymeta) . '</div>';
             }
             $o .= $output->snap_media_object($cm->url, $modimage, $eventtitle, $meta, '');
         }
     }
     return $o;
 }