/**
  * Add a column with an ID that uniquely identifies this user in this setaskment.
  *
  * @param stdClass $row
  * @return string
  */
 public function col_recordid(stdClass $row)
 {
     return get_string('hiddenuser', 'setask') . $this->setaskment->get_uniqueid_for_user($row->userid);
 }
Beispiel #2
0
/**
 * Callback called by comment::get_comments() and comment::add(). Gives an opportunity to enforce blind-marking.
 *
 * @param array $comments
 * @param stdClass $options
 * @return array
 * @throws comment_exception
 */
function setasksubmission_comments_comment_display($comments, $options)
{
    global $CFG, $DB, $USER;
    if ($options->commentarea != 'submission_comments' && $options->commentarea != 'submission_comments_upgrade') {
        throw new comment_exception('invalidcommentarea');
    }
    if (!($submission = $DB->get_record('setask_submission', array('id' => $options->itemid)))) {
        throw new comment_exception('invalidcommentitemid');
    }
    $context = $options->context;
    $cm = $options->cm;
    $course = $options->courseid;
    require_once $CFG->dirroot . '/mod/setask/locallib.php';
    $setaskment = new setask($context, $cm, $course);
    if ($setaskment->get_instance()->id != $submission->setaskment) {
        throw new comment_exception('invalidcontext');
    }
    if ($setaskment->is_blind_marking() && !empty($comments)) {
        // Blind marking is being used, may need to map unique anonymous ids to the comments.
        $usermappings = array();
        $hiddenuserstr = trim(get_string('hiddenuser', 'setask'));
        $guestuser = guest_user();
        foreach ($comments as $comment) {
            // Anonymize the comments.
            if (empty($usermappings[$comment->userid])) {
                // The blind-marking information for this commenter has not been generated; do so now.
                $anonid = $setaskment->get_uniqueid_for_user($comment->userid);
                $commenter = new stdClass();
                $commenter->firstname = $hiddenuserstr;
                $commenter->lastname = $anonid;
                $commenter->picture = 0;
                $commenter->id = $guestuser->id;
                $commenter->email = $guestuser->email;
                $commenter->imagealt = $guestuser->imagealt;
                // Temporarily store blind-marking information for use in later comments if necessary.
                $usermappings[$comment->userid]->fullname = fullname($commenter);
                $usermappings[$comment->userid]->avatar = $setaskment->get_renderer()->user_picture($commenter, array('size' => 18, 'link' => false));
            }
            // Set blind-marking information for this comment.
            $comment->fullname = $usermappings[$comment->userid]->fullname;
            $comment->avatar = $usermappings[$comment->userid]->avatar;
            $comment->profileurl = null;
        }
    }
    return $comments;
}
Beispiel #3
0
/**
 * Print recent activity from all setaskments in a given course
 *
 * This is used by the recent activity block
 * @param mixed $course the course to print activity for
 * @param bool $viewfullnames boolean to determine whether to show full names or not
 * @param int $timestart the time the rendering started
 * @return bool true if activity was printed, false otherwise.
 */
function setask_print_recent_activity($course, $viewfullnames, $timestart)
{
    global $CFG, $USER, $DB, $OUTPUT;
    require_once $CFG->dirroot . '/mod/setask/locallib.php';
    // Do not use log table if possible, it may be huge.
    $dbparams = array($timestart, $course->id, 'setask', ASSIGN_SUBMISSION_STATUS_SUBMITTED);
    $namefields = user_picture::fields('u', null, 'userid');
    if (!($submissions = $DB->get_records_sql("SELECT asb.id, asb.timemodified, cm.id AS cmid,\n                                                     {$namefields}\n                                                FROM {setask_submission} asb\n                                                     JOIN {setask} a      ON a.id = asb.setaskment\n                                                     JOIN {course_modules} cm ON cm.instance = a.id\n                                                     JOIN {modules} md        ON md.id = cm.module\n                                                     JOIN {user} u            ON u.id = asb.userid\n                                               WHERE asb.timemodified > ? AND\n                                                     asb.latest = 1 AND\n                                                     a.course = ? AND\n                                                     md.name = ? AND\n                                                     asb.status = ?\n                                            ORDER BY asb.timemodified ASC", $dbparams))) {
        return false;
    }
    $modinfo = get_fast_modinfo($course);
    $show = array();
    $grader = array();
    $showrecentsubmissions = get_config('setask', 'showrecentsubmissions');
    foreach ($submissions as $submission) {
        if (!array_key_exists($submission->cmid, $modinfo->get_cms())) {
            continue;
        }
        $cm = $modinfo->get_cm($submission->cmid);
        if (!$cm->uservisible) {
            continue;
        }
        if ($submission->userid == $USER->id) {
            $show[] = $submission;
            continue;
        }
        $context = context_module::instance($submission->cmid);
        // The act of submitting of setaskment may be considered private -
        // only graders will see it if specified.
        if (empty($showrecentsubmissions)) {
            if (!array_key_exists($cm->id, $grader)) {
                $grader[$cm->id] = has_capability('moodle/grade:viewall', $context);
            }
            if (!$grader[$cm->id]) {
                continue;
            }
        }
        $groupmode = groups_get_activity_groupmode($cm, $course);
        if ($groupmode == SEPARATEGROUPS && !has_capability('moodle/site:accessallgroups', $context)) {
            if (isguestuser()) {
                // Shortcut - guest user does not belong into any group.
                continue;
            }
            // This will be slow - show only users that share group with me in this cm.
            if (!$modinfo->get_groups($cm->groupingid)) {
                continue;
            }
            $usersgroups = groups_get_all_groups($course->id, $submission->userid, $cm->groupingid);
            if (is_array($usersgroups)) {
                $usersgroups = array_keys($usersgroups);
                $intersect = array_intersect($usersgroups, $modinfo->get_groups($cm->groupingid));
                if (empty($intersect)) {
                    continue;
                }
            }
        }
        $show[] = $submission;
    }
    if (empty($show)) {
        return false;
    }
    echo $OUTPUT->heading(get_string('newsubmissions', 'setask') . ':', 3);
    foreach ($show as $submission) {
        $cm = $modinfo->get_cm($submission->cmid);
        $context = context_module::instance($submission->cmid);
        $setask = new setask($context, $cm, $cm->course);
        $link = $CFG->wwwroot . '/mod/setask/view.php?id=' . $cm->id;
        // Obscure first and last name if blind marking enabled.
        if ($setask->is_blind_marking()) {
            $submission->firstname = get_string('participant', 'mod_setask');
            $submission->lastname = $setask->get_uniqueid_for_user($submission->userid);
        }
        print_recent_activity_note($submission->timemodified, $submission, $cm->name, $link, false, $viewfullnames);
    }
    return true;
}
 /**
  * Process an uploaded zip file
  *
  * @param setask $setaskment - The setaskment instance
  * @param setask_feedback_file $fileplugin - The file feedback plugin
  * @return string - The html response
  */
 public function import_zip_files($setaskment, $fileplugin)
 {
     global $CFG, $PAGE, $DB;
     core_php_time_limit::raise(ASSIGNFEEDBACK_FILE_MAXFILEUNZIPTIME);
     $packer = get_file_packer('application/zip');
     $feedbackfilesupdated = 0;
     $feedbackfilesadded = 0;
     $userswithnewfeedback = array();
     $contextid = $setaskment->get_context()->id;
     $fs = get_file_storage();
     $files = $this->get_import_files($contextid);
     $currentgroup = groups_get_activity_group($setaskment->get_course_module(), true);
     $allusers = $setaskment->list_participants($currentgroup, false);
     $participants = array();
     foreach ($allusers as $user) {
         $participants[$setaskment->get_uniqueid_for_user($user->id)] = $user;
     }
     foreach ($files as $unzippedfile) {
         // Set the timeout for unzipping each file.
         $user = null;
         $plugin = null;
         $filename = '';
         if ($this->is_valid_filename_for_import($setaskment, $unzippedfile, $participants, $user, $plugin, $filename)) {
             if ($this->is_file_modified($setaskment, $user, $plugin, $filename, $unzippedfile)) {
                 $grade = $setaskment->get_user_grade($user->id, true);
                 if ($oldfile = $fs->get_file($contextid, 'setaskfeedback_file', ASSIGNFEEDBACK_FILE_FILEAREA, $grade->id, '/', $filename)) {
                     // Update existing feedback file.
                     $oldfile->replace_file_with($unzippedfile);
                     $feedbackfilesupdated++;
                 } else {
                     // Create a new feedback file.
                     $newfilerecord = new stdClass();
                     $newfilerecord->contextid = $contextid;
                     $newfilerecord->component = 'setaskfeedback_file';
                     $newfilerecord->filearea = ASSIGNFEEDBACK_FILE_FILEAREA;
                     $newfilerecord->filename = $filename;
                     $newfilerecord->filepath = '/';
                     $newfilerecord->itemid = $grade->id;
                     $fs->create_file_from_storedfile($newfilerecord, $unzippedfile);
                     $feedbackfilesadded++;
                 }
                 $userswithnewfeedback[$user->id] = 1;
                 // Update the number of feedback files for this user.
                 $fileplugin->update_file_count($grade);
                 // Update the last modified time on the grade which will trigger student notifications.
                 $setaskment->notify_grade_modified($grade);
             }
         }
     }
     require_once $CFG->dirroot . '/mod/setask/feedback/file/renderable.php';
     $importsummary = new setaskfeedback_file_import_summary($setaskment->get_course_module()->id, count($userswithnewfeedback), $feedbackfilesadded, $feedbackfilesupdated);
     $setaskrenderer = $setaskment->get_renderer();
     $renderer = $PAGE->get_renderer('setaskfeedback_file');
     $o = '';
     $o .= $setaskrenderer->render(new setask_header($setaskment->get_instance(), $setaskment->get_context(), false, $setaskment->get_course_module()->id, get_string('uploadzipsummary', 'setaskfeedback_file')));
     $o .= $renderer->render($importsummary);
     $o .= $setaskrenderer->render_footer();
     return $o;
 }