コード例 #1
0
/**
 * Submit task to judge
 *
 * @param int $cmid ID of coursemodule
 * @param int $userid ID of user
 * @param string $language ID of the language
 * @param array $files array of stored_file of source code or array of filename => filecontent
 * @param object $options include input, output and etc.
 * @return id of the task or throw exception
 */
function onlinejudge_submit_task($cmid, $userid, $language, $files, $component, $options)
{
    global $DB;
    $task->cmid = $cmid;
    $task->userid = $userid;
    $task->status = ONLINEJUDGE_STATUS_PENDING;
    $task->submittime = time();
    if (!array_key_exists($language, onlinejudge_get_languages())) {
        throw new onlinejudge_exception('invalidlanguage', $language);
    }
    $task->language = $language;
    $task->component = $component;
    $judgeclass = 'judge_' . onlinejudge_judge_name($language);
    $judgeclasses = onlinejudge_get_judge_classes();
    if (!in_array($judgeclass, $judgeclasses)) {
        throw new onlinejudge_exception('invalidjudgeclass', $judgeclass);
    }
    $judgeclass::parse_options($options, $task);
    $task->id = $DB->insert_record('onlinejudge_tasks', $task);
    $fs = get_file_storage();
    $file_record->contextid = get_context_instance(CONTEXT_SYSTEM)->id;
    $file_record->component = 'local_onlinejudge';
    $file_record->filearea = 'tasks';
    $file_record->itemid = $task->id;
    foreach ($files as $key => $value) {
        if ($value instanceof stored_file) {
            $fs->create_file_from_storedfile($file_record, $value);
        } else {
            $file_record->filepath = dirname($key);
            if (strpos($file_record->filepath, '/') !== 0) {
                $file_record->filepath = '/' . $file_record->filepath;
            }
            if (strrpos($file_record->filepath, '/') !== strlen($file_record->filepath) - 1) {
                $file_record->filepath .= '/';
            }
            $file_record->filename = basename($key);
            $fs->create_file_from_string($file_record, $value);
        }
    }
    return $task->id;
}
コード例 #2
0
//                                                                       //
// Online Judge 2 is distributed in the hope that it will be useful,     //
// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
// GNU General Public License for more details.                          //
//                                                                       //
// You should have received a copy of the GNU General Public License     //
// along with Online Judge 2. If not, see <http://www.gnu.org/licenses/>.//
//                                                                       //
///////////////////////////////////////////////////////////////////////////
/**
 * Administration forms of the online judge
 * 
 * @package   local_onlinejudge
 * @copyright 2011 Sun Zhigang (http://sunner.cn)
 * @author    Sun Zhigang
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
defined('MOODLE_INTERNAL') || die;
if ($hassiteconfig) {
    // needs this condition or there is error on login page
    require_once $CFG->dirroot . '/local/onlinejudge/judgelib.php';
    $temp = new admin_settingpage('onlinejudge', get_string('pluginname', 'local_onlinejudge'));
    $temp->add(new admin_setting_configtext('local_onlinejudge/maxmemlimit', get_string('maxmemlimit', 'local_onlinejudge'), get_string('maxmemlimit_help', 'local_onlinejudge'), 64, PARAM_INT));
    $temp->add(new admin_setting_configtext('local_onlinejudge/maxcpulimit', get_string('maxcpulimit', 'local_onlinejudge'), get_string('maxcpulimit_help', 'local_onlinejudge'), 10, PARAM_INT));
    $temp->add(new admin_setting_configtext('local_onlinejudge/ideonedelay', get_string('ideonedelay', 'local_onlinejudge'), get_string('ideonedelay_help', 'local_onlinejudge'), 10, PARAM_INT));
    $choices = onlinejudge_get_languages();
    $temp->add(new admin_setting_configselect('local_onlinejudge/defaultlanguage', get_string('defaultlanguage', 'local_onlinejudge'), get_string('defaultlanguage_help', 'local_onlinejudge'), '', $choices));
    $temp->add(new admin_setting_users_with_capability('local_onlinejudge/judgedcrashnotify', get_string('judgedcrashnotify', 'local_onlinejudge'), get_string('judgedcrashnotify_help', 'local_onlinejudge'), array(), 'moodle/site:config'));
    $ADMIN->add('localplugins', $temp);
}
コード例 #3
0
 /**
  * Print the form for this assignment type
  *
  * @param $mform object Allready existant form
  */
 function setup_elements(&$mform)
 {
     global $CFG, $COURSE, $DB;
     // Some code are copied from parent::setup_elements(). Keep sync please.
     $ynoptions = array(0 => get_string('no'), 1 => get_string('yes'));
     $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes);
     $choices[0] = get_string('courseuploadlimit') . ' (' . display_size($COURSE->maxbytes) . ')';
     $mform->addElement('select', 'maxbytes', get_string('maximumfilesize', 'assignment_onlinejudge'), $choices);
     $mform->setDefault('maxbytes', $CFG->assignment_maxbytes);
     $mform->addElement('select', 'resubmit', get_string('allowdeleting', 'assignment'), $ynoptions);
     $mform->addHelpButton('resubmit', 'allowdeleting', 'assignment');
     $mform->setDefault('resubmit', 1);
     $options = array();
     for ($i = 1; $i <= 20; $i++) {
         $options[$i] = $i;
     }
     $mform->addElement('select', 'var1', get_string('allowmaxfiles', 'assignment'), $options);
     $mform->addHelpButton('var1', 'allowmaxfiles', 'assignment');
     $mform->setDefault('var1', 1);
     $mform->addElement('select', 'var2', get_string('allownotes', 'assignment'), $ynoptions);
     $mform->addHelpButton('var2', 'allownotes', 'assignment');
     $mform->setDefault('var2', 0);
     $mform->addElement('select', 'var3', get_string('hideintro', 'assignment'), $ynoptions);
     $mform->addHelpButton('var3', 'hideintro', 'assignment');
     $mform->setDefault('var3', 0);
     $mform->addElement('select', 'emailteachers', get_string('emailteachers', 'assignment'), $ynoptions);
     $mform->addHelpButton('emailteachers', 'emailteachers', 'assignment');
     $mform->setDefault('emailteachers', 0);
     // Get existing onlinejudge settings
     $update = optional_param('update', 0, PARAM_INT);
     if (!empty($update)) {
         $cm = $DB->get_record('course_modules', array('id' => $update), '*', MUST_EXIST);
         $onlinejudge = $DB->get_record('assignment_oj', array('assignment' => $cm->instance));
     }
     // Programming languages
     unset($choices);
     $choices = onlinejudge_get_languages();
     $mform->addElement('select', 'language', get_string('assignmentlangs', 'assignment_onlinejudge'), $choices);
     $mform->setDefault('language', isset($onlinejudge) ? $onlinejudge->language : get_config('local_onlinejudge', 'defaultlanguage'));
     // Presentation error grade ratio
     unset($choices);
     $choices = get_grade_options()->gradeoptions;
     // Steal from question lib
     $mform->addElement('select', 'ratiope', get_string('ratiope', 'assignment_onlinejudge'), $choices);
     $mform->addHelpButton('ratiope', 'ratiope', 'assignment_onlinejudge');
     $mform->setDefault('ratiope', isset($onlinejudge) ? $onlinejudge->ratiope : 0);
     $mform->setAdvanced('ratiope');
     // Max. CPU time
     unset($choices);
     $choices = $this->get_max_cpu_times();
     $mform->addElement('select', 'cpulimit', get_string('cpulimit', 'assignment_onlinejudge'), $choices);
     $mform->setDefault('cpulimit', isset($onlinejudge) ? $onlinejudge->cpulimit : 1);
     // Max. memory usage
     unset($choices);
     $choices = $this->get_max_memory_usages();
     $mform->addElement('select', 'memlimit', get_string('memlimit', 'assignment_onlinejudge'), $choices);
     $mform->setDefault('memlimit', isset($onlinejudge) ? $onlinejudge->memlimit : 1048576);
     // Compile only?
     $mform->addElement('select', 'compileonly', get_string('compileonly', 'assignment_onlinejudge'), $ynoptions);
     $mform->addHelpButton('compileonly', 'compileonly', 'assignment_onlinejudge');
     $mform->setDefault('compileonly', isset($onlinejudge) ? $onlinejudge->compileonly : 0);
     $mform->setAdvanced('compileonly');
     //ideone.com
     $mform->addElement('text', 'ideoneuser', get_string('ideoneuser', 'assignment_onlinejudge'), array('size' => 20));
     $mform->addHelpButton('ideoneuser', 'ideoneuser', 'assignment_onlinejudge');
     $mform->setType('ideoneuser', PARAM_ALPHANUMEXT);
     $mform->setDefault('ideoneuser', isset($onlinejudge) ? $onlinejudge->ideoneuser : '');
     $mform->addElement('password', 'ideonepass', get_string('ideonepass', 'assignment_onlinejudge'), array('size' => 20));
     $mform->addHelpButton('ideonepass', 'ideonepass', 'assignment_onlinejudge');
     $mform->setDefault('ideonepass', isset($onlinejudge) ? $onlinejudge->ideonepass : '');
     $course_context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
     plagiarism_get_form_elements_module($mform, $course_context);
 }