예제 #1
0
/**
 * Print a detailed representation of what a user has done with
 * a given particular instance of this module, for user activity reports.
 *
 * @param stdClass $course The course record.
 * @param stdClass $user The user record.
 * @param cm_info|stdClass $mod The course module info object or record.
 * @param stdClass $teamwork The teamwork instance record.
 * @return string HTML
 */
function teamwork_user_complete($course, $user, $mod, $teamwork)
{
    global $CFG, $DB, $OUTPUT;
    require_once dirname(__FILE__) . '/locallib.php';
    require_once $CFG->libdir . '/gradelib.php';
    $teamwork = new teamwork($teamwork, $mod, $course);
    $grades = grade_get_grades($course->id, 'mod', 'teamwork', $teamwork->id, $user->id);
    if (!empty($grades->items[0]->grades)) {
        $submissiongrade = reset($grades->items[0]->grades);
        $info = get_string('submissiongrade', 'teamwork') . ': ' . $submissiongrade->str_long_grade;
        echo html_writer::tag('li', $info, array('class' => 'submissiongrade'));
    }
    if (!empty($grades->items[1]->grades)) {
        $assessmentgrade = reset($grades->items[1]->grades);
        $info = get_string('gradinggrade', 'teamwork') . ': ' . $assessmentgrade->str_long_grade;
        echo html_writer::tag('li', $info, array('class' => 'gradinggrade'));
    }
    if (has_capability('mod/teamwork:viewallsubmissions', $teamwork->context)) {
        $canviewsubmission = true;
        if (groups_get_activity_groupmode($teamwork->cm) == SEPARATEGROUPS) {
            // user must have accessallgroups or share at least one group with the submission author
            if (!has_capability('moodle/site:accessallgroups', $teamwork->context)) {
                $usersgroups = groups_get_activity_allowed_groups($teamwork->cm);
                $authorsgroups = groups_get_all_groups($teamwork->course->id, $user->id, $teamwork->cm->groupingid, 'g.id');
                $sharedgroups = array_intersect_key($usersgroups, $authorsgroups);
                if (empty($sharedgroups)) {
                    $canviewsubmission = false;
                }
            }
        }
        if ($canviewsubmission and $submission = $teamwork->get_submission_by_author($user->id)) {
            $title = format_string($submission->title);
            $url = $teamwork->submission_url($submission->id);
            $link = html_writer::link($url, $title);
            $info = get_string('submission', 'teamwork') . ': ' . $link;
            echo html_writer::tag('li', $info, array('class' => 'submission'));
        }
    }
    if (has_capability('mod/teamwork:viewallassessments', $teamwork->context)) {
        if ($assessments = $teamwork->get_assessments_by_reviewer($user->id)) {
            foreach ($assessments as $assessment) {
                $a = new stdclass();
                $a->submissionurl = $teamwork->submission_url($assessment->submissionid)->out();
                $a->assessmenturl = $teamwork->assess_url($assessment->id)->out();
                $a->submissiontitle = s($assessment->submissiontitle);
                echo html_writer::tag('li', get_string('assessmentofsubmission', 'teamwork', $a));
            }
        }
    }
}