コード例 #1
0
ファイル: lib.php プロジェクト: rimacher/moodle-mod_grouptool
/**
 * prepare text for mymoodle-Page to be displayed
 *
 * @param stdClass[] $courses
 * @param string[] $htmlarray
 */
function grouptool_print_overview($courses, &$htmlarray)
{
    global $USER, $CFG, $DB, $OUTPUT;
    require_once $CFG->dirroot . '/mod/grouptool/locallib.php';
    if (empty($courses) || !is_array($courses) || count($courses) == 0) {
        return;
    }
    if (!($grouptools = get_all_instances_in_courses('grouptool', $courses))) {
        return;
    }
    foreach ($grouptools as $grouptool) {
        $context = context_module::instance($grouptool->coursemodule, MUST_EXIST);
        $strgrouptool = get_string('grouptool', 'grouptool');
        $strduedate = get_string('duedate', 'grouptool');
        $strduedateno = get_string('duedateno', 'grouptool');
        $str = "";
        if (has_capability('mod/grouptool:register', $context) || has_capability('mod/grouptool:view_regs_group_view', $context) || has_capability('mod/grouptool:view_regs_course_view', $context)) {
            $attrib = array('title' => $strgrouptool, 'href' => $CFG->wwwroot . '/mod/grouptool/view.php?id=' . $grouptool->coursemodule);
            if (!$grouptool->visible || $grouptool->timedue != 0 && $grouptool->timedue <= time()) {
                $attrib['class'] = 'dimmed';
            }
            list($cc, $nused) = grouptool_display_lateness(time(), $grouptool->timedue);
            $str .= html_writer::tag('div', $strgrouptool . ': ' . html_writer::tag('a', $grouptool->name, $attrib), array('class' => 'name'));
            $attr = array('class' => 'info');
            if ($grouptool->timeavailable > time()) {
                $ta = $grouptool->timeavailable;
                $str .= html_writer::tag('div', get_string('availabledate', 'grouptool') . ': ' . html_writer::tag('span', userdate($ta)), $attr);
            }
            if ($grouptool->timedue) {
                $str .= html_writer::tag('div', $strduedate . ': ' . html_writer::tag('span', userdate($grouptool->timedue), array('class' => $cc == 'late' ? ' late' : '')), $attr);
            } else {
                $str .= html_writer::tag('div', $strduedateno, $attr);
            }
        }
        $details = '';
        if (has_capability('mod/grouptool:register', $context) || has_capability('mod/grouptool:view_regs_group_view', $context) || has_capability('mod/grouptool:view_regs_course_view', $context)) {
            $instance = new mod_grouptool($grouptool->coursemodule, $grouptool);
            $userstats = $instance->get_registration_stats($USER->id);
        }
        if (has_capability('mod/grouptool:register', $context) && $grouptool->allow_reg) {
            if (count($userstats->registered)) {
                $tempstr = "";
                foreach ($userstats->registered as $registration) {
                    $ts = $registration->timestamp;
                    list($colorclass, $text) = grouptool_display_lateness($ts, $grouptool->timedue);
                    if ($tempstr != "") {
                        $tempstr .= '; ';
                    }
                    $tempstr .= html_writer::tag('span', $registration->grpname);
                }
                if ($grouptool->allow_multiple && count($userstats->registered) < $grouptool->choose_min || !$grouptool->allow_multiple && !count($userstats->registered)) {
                    if ($grouptool->allow_multiple) {
                        $missing = $grouptool->choose_min - count($userstats->registered);
                        $stringlabel = $missing > 1 ? 'registrations_missing' : 'registration_missing';
                    } else {
                        $missing = 1;
                        $stringlabel = 'registration_missing';
                    }
                    $details .= html_writer::tag('div', html_writer::tag('div', get_string($stringlabel, 'grouptool', $missing)) . ' ' . get_string('registrations', 'grouptool') . ': ' . $tempstr, array('class' => 'registered'));
                } else {
                    $details .= html_writer::tag('div', get_string('registrations', 'grouptool') . ': ' . $tempstr, array('class' => 'registered'));
                }
            } else {
                if ($grouptool->allow_multiple) {
                    $missing = $grouptool->choose_min;
                    $stringlabel = $missing > 1 ? 'registrations_missing' : 'registration_missing';
                } else {
                    $missing = 1;
                    $stringlabel = 'registration_missing';
                }
                $details .= html_writer::tag('div', html_writer::tag('div', get_string($stringlabel, 'grouptool', $missing)) . get_string('registrations', 'grouptool') . ': ' . get_string('not_registered', 'grouptool'), array('class' => 'registered'));
            }
            if (count($userstats->queued)) {
                $tempstr = "";
                foreach ($userstats->queued as $queue) {
                    list($colorclass, $text) = grouptool_display_lateness($queue->timestamp, $grouptool->timedue);
                    if ($tempstr != "") {
                        $tempstr .= ", ";
                    }
                    $tempstr .= html_writer::tag('span', $queue->grpname . ' (' . $queue->rank . ')', array('class' => $colorclass));
                }
                $details .= html_writer::tag('div', get_string('queues', 'grouptool') . ': ' . $tempstr, array('class' => 'queued'));
            }
        }
        if ($grouptool->allow_reg && (has_capability('mod/grouptool:view_regs_group_view', $context) || has_capability('mod/grouptool:view_regs_course_view', $context))) {
            $details .= html_writer::tag('div', get_string('global_userstats', 'grouptool', $userstats), array('class' => 'userstats'));
        }
        if (has_capability('mod/grouptool:view_regs_group_view', $context) || has_capability('mod/grouptool:view_regs_course_view', $context) || has_capability('mod/grouptool:register', $context)) {
            if ($grouptool->allow_reg) {
                $str .= html_writer::tag('div', $details, array('class' => 'details'));
            }
            $str = html_writer::tag('div', $str, array('class' => 'grouptool overview'));
            if (empty($htmlarray[$grouptool->course]['grouptool'])) {
                $htmlarray[$grouptool->course]['grouptool'] = $str;
            } else {
                $htmlarray[$grouptool->course]['grouptool'] .= $str;
            }
        }
    }
}
コード例 #2
0
     list($colorclass, $unused) = grouptool_display_lateness(time(), $grouptool->timedue);
     $attr = array('class' => 'info');
     if ($grouptool->timeavailable > time()) {
         $str .= html_writer::tag('div', get_string('availabledate', 'grouptool') . ': ' . html_writer::tag('span', userdate($grouptool->timeavailable)), $attr);
     }
     if ($grouptool->timedue) {
         $str .= html_writer::tag('div', $strduedate . ': ' . html_writer::tag('span', userdate($grouptool->timedue), array('class' => $colorclass == 'late' ? ' late' : '')), $attr);
     } else {
         $str .= html_writer::tag('div', $strduedateno, $attr);
     }
 }
 $details = '';
 if (has_capability('mod/grouptool:register', $context) || has_capability('mod/grouptool:view_regs_course_view', $context) || has_capability('mod/grouptool:view_regs_group_view', $context)) {
     // It's similar to the student mymoodle output!
     $instance = new mod_grouptool($grouptool->coursemodule, $grouptool);
     $userstats = $instance->get_registration_stats($USER->id);
 }
 if (has_capability('mod/grouptool:register', $context)) {
     if ($grouptool->allow_reg) {
         if (count($userstats->registered)) {
             $tempstr = "";
             foreach ($userstats->registered as $registration) {
                 if ($tempstr != "") {
                     $tempstr .= '; ';
                 }
                 $tempstr .= html_writer::tag('span', $registration->grpname);
             }
             if ($grouptool->allow_multiple && count($userstats->registered) < $grouptool->choose_min || !$grouptool->allow_multiple && !count($userstats->registered)) {
                 if ($grouptool->allow_multiple) {
                     $missing = $grouptool->choose_min - count($userstats->registered);
                     $stringlabel = $missing > 1 ? 'registrations_missing' : 'registration_missing';