コード例 #1
0
ファイル: lib.php プロジェクト: krzpassrl/SRL_Moodle_Baseline
/**
 * Serves seplment submissions and other files.
 *
 * @param mixed $course course or id of the course
 * @param mixed $cm course module or id of the course module
 * @param context $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - just send the file
 */
function seplsubmission_onlinetext_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload)
{
    global $DB, $CFG;
    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }
    require_login($course, false, $cm);
    $itemid = (int) array_shift($args);
    $record = $DB->get_record('sepl_submission', array('id' => $itemid), 'userid, seplment, groupid', MUST_EXIST);
    $userid = $record->userid;
    $groupid = $record->groupid;
    require_once $CFG->dirroot . '/mod/sepl/locallib.php';
    $sepl = new sepl($context, $cm, $course);
    if ($sepl->get_instance()->id != $record->seplment) {
        return false;
    }
    if ($sepl->get_instance()->teamsubmission && !$sepl->can_view_group_submission($groupid)) {
        return false;
    }
    if (!$sepl->get_instance()->teamsubmission && !$sepl->can_view_submission($userid)) {
        return false;
    }
    $relativepath = implode('/', $args);
    $fullpath = "/{$context->id}/seplsubmission_onlinetext/{$filearea}/{$itemid}/{$relativepath}";
    $fs = get_file_storage();
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) || $file->is_directory()) {
        return false;
    }
    // Download MUST be forced - security!
    send_stored_file($file, 0, 0, true);
}
コード例 #2
0
 /**
  * Default implementation of file_get_info for plugins.
  * This is used by the filebrowser to browse a plugins file areas.
  *
  * This implementation should work for most plugins but can be overridden if required.
  * @param file_browser $browser
  * @param string $filearea
  * @param int $itemid
  * @param string $filepath
  * @param string $filename
  * @return file_info_stored
  */
 public function get_file_info($browser, $filearea, $itemid, $filepath, $filename)
 {
     global $CFG, $DB, $USER;
     $urlbase = $CFG->wwwroot . '/pluginfile.php';
     // Permission check on the itemid.
     if ($this->get_subtype() == 'seplsubmission') {
         if ($itemid) {
             $record = $DB->get_record('sepl_submission', array('id' => $itemid), 'userid', IGNORE_MISSING);
             if (!$record) {
                 return null;
             }
             if (!$this->seplment->can_view_submission($record->userid)) {
                 return null;
             }
         }
     } else {
         // Not supported for feedback plugins.
         return null;
     }
     $fs = get_file_storage();
     $filepath = is_null($filepath) ? '/' : $filepath;
     $filename = is_null($filename) ? '.' : $filename;
     if (!($storedfile = $fs->get_file($this->seplment->get_context()->id, $this->get_subtype() . '_' . $this->get_type(), $filearea, $itemid, $filepath, $filename))) {
         return null;
     }
     $client = (new SphereEngine\Api("dadeea82cdd4b840cbde18858d9f17d6fb11a957", "v3", "endpoint"))->getProblemsClient();
     $r = rand(1000, 9999);
     # $testClient = $client->problems->create('TEST', 'Test');
     //$aaa = 'test123';
     //var_dump($aaa);
     $testClient = $client->submissions->create('SEPLTEST_123', 'int main() {};', 11);
     #create('int main() {}', 11, 'Robsontest');/
     return new file_info_stored($browser, $this->seplment->get_context(), $storedfile, $urlbase, $filearea, $itemid, true, true, false);
 }
コード例 #3
0
ファイル: lib.php プロジェクト: krzpassrl/SRL_Moodle_Baseline
/**
 * Permission control method for submission plugin ---- required method for AJAXmoodle based comment API
 *
 * @param stdClass $options
 * @return array
 */
function seplsubmission_comments_comment_permissions(stdClass $options)
{
    global $USER, $CFG, $DB;
    if ($options->commentarea != 'submission_comments' && $options->commentarea != 'submission_comments_upgrade') {
        throw new comment_exception('invalidcommentarea');
    }
    if (!($submission = $DB->get_record('sepl_submission', array('id' => $options->itemid)))) {
        throw new comment_exception('invalidcommentitemid');
    }
    $context = $options->context;
    require_once $CFG->dirroot . '/mod/sepl/locallib.php';
    $seplment = new sepl($context, null, null);
    if ($seplment->get_instance()->id != $submission->seplment) {
        throw new comment_exception('invalidcontext');
    }
    if ($seplment->get_instance()->teamsubmission && !$seplment->can_view_group_submission($submission->groupid)) {
        return array('post' => false, 'view' => false);
    }
    if (!$seplment->get_instance()->teamsubmission && !$seplment->can_view_submission($submission->userid)) {
        return array('post' => false, 'view' => false);
    }
    return array('post' => true, 'view' => true);
}
コード例 #4
0
use seplfeedback_editpdf\page_editor;
use seplfeedback_editpdf\comments_quick_list;
define('AJAX_SCRIPT', true);
require '../../../../config.php';
require_once $CFG->dirroot . '/mod/sepl/locallib.php';
require_sesskey();
$action = optional_param('action', '', PARAM_ALPHANUM);
$seplmentid = required_param('seplmentid', PARAM_INT);
$userid = required_param('userid', PARAM_INT);
$attemptnumber = required_param('attemptnumber', PARAM_INT);
$readonly = optional_param('readonly', false, PARAM_BOOL);
$cm = \get_coursemodule_from_instance('sepl', $seplmentid, 0, false, MUST_EXIST);
$context = \context_module::instance($cm->id);
$seplment = new \sepl($context, null, null);
require_login($seplment->get_course(), false, $cm);
if (!$seplment->can_view_submission($userid)) {
    print_error('nopermission');
}
if ($action == 'loadallpages') {
    $draft = true;
    if (!has_capability('mod/sepl:grade', $context)) {
        $draft = false;
        $readonly = true;
        // A student always sees the readonly version.
        require_capability('mod/sepl:submit', $context);
    }
    // Whoever is viewing the readonly version should not use the drafts, but the actual annotations.
    if ($readonly) {
        $draft = false;
    }
    $pages = document_services::get_page_images_for_attempt($seplment, $userid, $attemptnumber, $readonly);