コード例 #1
0
/**
 * Returns the HTML to display the file submitted by the student
 * (adapted from mod/assignment/lib.php)
 *
 * @param int $attemptid attempt id
 * @param int $questionid question id
 * @return string string to print to display file list
 */
function get_student_answer($attemptid, $questionid)
{
    global $CFG;
    $filearea = quiz_file_area_name($attemptid, $questionid);
    $output = '';
    if ($basedir = quiz_file_area($filearea)) {
        if ($files = get_directory_list($basedir)) {
            if (count($files) == 0) {
                return false;
            }
            foreach ($files as $key => $file) {
                require_once $CFG->libdir . '/filelib.php';
                $icon = mimeinfo('icon', $file);
                // remove "questionattempt", the first dir in the path, from the URL
                $filearealist = explode('/', $filearea);
                $fileareaurl = implode('/', array_slice($filearealist, 1));
                if ($CFG->slasharguments) {
                    $ffurl = "{$CFG->wwwroot}/question/file.php/{$fileareaurl}/{$file}";
                } else {
                    $ffurl = "{$CFG->wwwroot}/question/file.php?file=/{$fileareaurl}/{$file}";
                }
                $output .= '<img align="middle" src="' . $CFG->pixpath . '/f/' . $icon . '" class="icon" alt="' . $icon . '" />' . '<a href="' . $ffurl . '" >' . $file . '</a><br />';
            }
        }
    }
    // (Is this desired for theme reasons?)
    //$output = '<div class="files">'.$output.'</div>';
    return $output;
}
コード例 #2
0
ファイル: questiontype.php プロジェクト: nadavkav/MoodleTAO
 /**
  * Deletes files submitted in these states
  *
  * @param string $stateslist  Comma separated list of state ids to be deleted
  * @return boolean to indicate success or failure.
  */
 function delete_states($stateslist)
 {
     global $CFG;
     $states = explode(',', $stateslist);
     foreach ($states as $stateid) {
         $state = get_record("question_states", "id", "{$stateid}");
         $attemptid = $state->attempt;
         $questionid = $state->question;
         // delete any files submitted in this attempt
         $dir = quiz_file_area_name($attemptid, $questionid);
         if (file_exists($CFG->dataroot . '/' . $dir)) {
             fulldelete($CFG->dataroot . '/' . $dir);
             $dirparts = explode('/', $dir);
             // the directory is two levels deep, so delete the lower directory, too
             array_pop($dirparts);
             $dir = implode('/', $dirparts);
             fulldelete($CFG->dataroot . '/' . $dir);
         }
     }
     return true;
 }