first commit
This commit is contained in:
81
testcase/add.php
Normal file
81
testcase/add.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
require_once('../../../config.php');
|
||||
require_once($CFG->libdir . '/weblib.php');
|
||||
require_once('../lib.php');
|
||||
require_once('form.php');
|
||||
|
||||
$id = required_param('id', PARAM_INT); // programming ID
|
||||
$params = array('id' => $id);
|
||||
$PAGE->set_url('/mod/programming/testcase/add.php', $params);
|
||||
|
||||
if (!$cm = get_coursemodule_from_id('programming', $id,0,false,MUST_EXIST)) {
|
||||
print_error('invalidcoursemodule');
|
||||
}
|
||||
|
||||
if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
|
||||
print_error('coursemisconf');
|
||||
}
|
||||
|
||||
if (!$programming = $DB->get_record('programming', array('id' => $cm->instance))) {
|
||||
print_error('invalidprogrammingid', 'programming');
|
||||
}
|
||||
|
||||
require_login($course->id, true, $cm);
|
||||
$context = context_module::instance($cm->id);
|
||||
require_capability('mod/programming:edittestcase', $context);
|
||||
|
||||
$mform = new testcase_form();
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect(new moodle_url('list.php', array('id' => $cm->id)));
|
||||
} else if ($data = $mform->get_data()) {
|
||||
unset($data->id);
|
||||
$data->programmingid = $programming->id;
|
||||
$data->seq = $DB->count_records('programming_tests', array('programmingid' => $programming->id), 'MAX(seq)') + 1;
|
||||
$infile = $mform->get_file_content('inputfile');
|
||||
if (empty($infile)) {
|
||||
$data->input = stripcslashes($data->input);
|
||||
} else {
|
||||
$data->input = $infile;
|
||||
}
|
||||
$outfile = $mform->get_file_content('outputfile');
|
||||
if (empty($outfile)) {
|
||||
$data->output = stripcslashes($data->output);
|
||||
} else {
|
||||
$data->output = $outfile;
|
||||
}
|
||||
// $data->input = str_replace("\r\n\r\n", "", $data->input);
|
||||
// $data->output = str_replace("\r\n\r\n", "", $data->output);
|
||||
// $data->input = str_replace("\r\n\n", "", $data->input);
|
||||
// $data->output = str_replace("\r\n\n", "", $data->output);
|
||||
// $data->input = str_replace(chr(13), "", $data->input);
|
||||
// $data->output = str_replace(chr(13), "", $data->output);
|
||||
// $data->input = str_replace("\n\n", "\n", $data->input);
|
||||
// $data->output = str_replace("\n\n", "\n", $data->output);
|
||||
$data->input = rtrim($data->input);
|
||||
$data->output = rtrim($data->output);
|
||||
// $data->input .= "\n";
|
||||
// $data->output .= "\n";
|
||||
programming_test_add_instance($data);
|
||||
|
||||
redirect(new moodle_url('list.php', array('id' => $cm->id)), get_string('testcasemodified', 'programming'), 0);
|
||||
} else {
|
||||
/// Print the page header
|
||||
$PAGE->set_title(format_string($course->shortname) . ': ' . $programming->name) . ': ' . get_string('addtestcase', 'programming');
|
||||
$PAGE->set_heading(format_string($course->fullname));
|
||||
echo $OUTPUT->header();
|
||||
|
||||
/// Print tabs
|
||||
$renderer = $PAGE->get_renderer('mod_programming');
|
||||
$tabs = programming_navtab('edittest', 'testcase', $course, $programming, $cm);
|
||||
echo $renderer->render_navtab($tabs);
|
||||
|
||||
echo html_writer::tag('h2', $programming->name);
|
||||
echo html_writer::tag('h3', get_string('addtestcase', 'programming'));
|
||||
|
||||
/// Print page content
|
||||
$mform->display();
|
||||
|
||||
/// Finish the page
|
||||
echo $OUTPUT->footer($course);
|
||||
}
|
||||
39
testcase/delete.php
Normal file
39
testcase/delete.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
require_once('../../../config.php');
|
||||
require_once('../lib.php');
|
||||
|
||||
$id = required_param('id', PARAM_INT); // programming ID
|
||||
$case_id = required_param('case', PARAM_INT); // testcase ID
|
||||
|
||||
$params = array();
|
||||
if ($id) {
|
||||
$params['id'] = $id;
|
||||
}
|
||||
if ($case_id) {
|
||||
$params['case'] = $case_id;
|
||||
}
|
||||
$PAGE->set_url('/mod/programming/view.php', $params);
|
||||
|
||||
if ($id) {
|
||||
if (! $cm = get_coursemodule_from_id('programming', $id)) {
|
||||
error('Course Module ID was incorrect');
|
||||
}
|
||||
|
||||
if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
|
||||
error('Course is misconfigured');
|
||||
}
|
||||
|
||||
if (! $programming = $DB->get_record('programming', array('id' => $cm->instance))) {
|
||||
error('Course module is incorrect');
|
||||
}
|
||||
}
|
||||
|
||||
require_login($course->id, true, $cm);
|
||||
$context = context_module::instance($cm->id);
|
||||
require_capability('mod/programming:edittestcase', $context);
|
||||
|
||||
$DB->delete_records('programming_test_results', array('testid' => $case_id));
|
||||
$DB->delete_records('programming_tests', array('id' => $case_id));
|
||||
programming_testcase_adjust_sequence($programming->id);
|
||||
redirect(new moodle_url('list.php', array('id' => $cm->id)), get_string('testcasedeleted', 'programming'), 0);
|
||||
89
testcase/download_io.php
Normal file
89
testcase/download_io.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
require_once('../../../config.php');
|
||||
require_once('../lib.php');
|
||||
|
||||
$id = required_param('id', PARAM_INT); // programming ID
|
||||
$testid = required_param('test', PARAM_INT);
|
||||
$submitid = optional_param('submit', -1, PARAM_INT);
|
||||
$type = required_param('type', PARAM_CLEAN);
|
||||
$download = optional_param('download', 1, PARAM_INT);
|
||||
|
||||
$params = array();
|
||||
if ($id) {
|
||||
$params['id'] = $id;
|
||||
}
|
||||
if ($testid) {
|
||||
$params['test'] = $testid;
|
||||
}
|
||||
if ($submitid) {
|
||||
$params['submit'] = $submitid;
|
||||
}
|
||||
if ($type) {
|
||||
$params['type'] = $type;
|
||||
}
|
||||
if ($download) {
|
||||
$params['download'] = $download;
|
||||
}
|
||||
$PAGE->set_url('/mod/programming/download_io.php', $params);
|
||||
|
||||
if ($id) {
|
||||
if (! $cm = get_coursemodule_from_id('programming', $id)) {
|
||||
error('Course Module ID was incorrect');
|
||||
}
|
||||
|
||||
if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
|
||||
error('Course is misconfigured');
|
||||
}
|
||||
|
||||
if (! $programming = $DB->get_record('programming', array('id' => $cm->instance))) {
|
||||
error('Course module is incorrect');
|
||||
}
|
||||
}
|
||||
|
||||
require_login($course->id, true, $cm);
|
||||
$context = context_module::instance($cm->id);
|
||||
|
||||
// Download input and output of testcase
|
||||
if ($type == 'in' or ($type == 'out' and $submitid == -1)) {
|
||||
if (! $test = $DB->get_record('programming_tests', array('id' => $testid))) {
|
||||
error('Test ID was incorrect');
|
||||
}
|
||||
programming_testcase_require_view_capability($context, $test);
|
||||
$filename = sprintf('test-%d.%s', $testid, $type);
|
||||
if ($type == 'in') {
|
||||
$content = !empty($test->gzinput) ? bzdecompress($test->gzinput) : $test->input;
|
||||
} else {
|
||||
$content = !empty($test->gzoutput) ? bzdecompress($test->gzoutput) : $test->output;
|
||||
}
|
||||
}
|
||||
// Download output and error message of user program
|
||||
else if ($type == 'out' or $type == 'err') {
|
||||
require_capability('mod/programming:viewdetailresult', $context);
|
||||
if (! $result = $DB->get_record('programming_test_results', array('submitid' => $submitid, 'testid' => $testid))) {
|
||||
error('Test ID or submit ID was incorrect.');
|
||||
}
|
||||
$test = $DB->get_record('programming_tests', array('id' => $testid));
|
||||
if ($test->pub >= 0) {
|
||||
require_capability('mod/programming:viewpubtestcase', $context);
|
||||
} else {
|
||||
require_capability('mod/programming:viewhiddentestcase', $context);
|
||||
}
|
||||
$submit = $DB->get_record('programming_submits', array('id' => $submitid));
|
||||
if ($submit->userid != $USER->id) {
|
||||
require_capability('mod/programming:viewotherresult', $context);
|
||||
}
|
||||
if ($result->judgeresult == 'AC' && strlen($result->output) == 0) {
|
||||
$result->output = $test->output;
|
||||
}
|
||||
$filename = sprintf('test-%d-%d.%s', $testid, $submitid, $type);
|
||||
$content = $type == 'out' ? $result->output : $result->stderr;
|
||||
}
|
||||
|
||||
if ($filename && $download) {
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename="'.$filename.'"');
|
||||
} else {
|
||||
header('Content-Type: text/plain');
|
||||
}
|
||||
echo $content;
|
||||
85
testcase/edit.php
Normal file
85
testcase/edit.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
require_once('../../../config.php');
|
||||
require_once($CFG->libdir . '/weblib.php');
|
||||
require_once('../lib.php');
|
||||
require_once('form.php');
|
||||
|
||||
$id = required_param('id', PARAM_INT); // programming ID
|
||||
$case_id = required_param('case', PARAM_INT); // testcase ID
|
||||
$params = array('id' => $id, 'case' => $case_id);
|
||||
$PAGE->set_url('/mod/programming/testcase/edit.php', $params);
|
||||
|
||||
if (!$cm = get_coursemodule_from_id('programming', $id)) {
|
||||
print_error('invalidcoursemodule');
|
||||
}
|
||||
|
||||
if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
|
||||
print_error('coursemisconf');
|
||||
}
|
||||
|
||||
if (!$programming = $DB->get_record('programming', array('id' => $cm->instance))) {
|
||||
print_error('invalidprogrammingid', 'programming');
|
||||
}
|
||||
|
||||
require_login($course->id, true, $cm);
|
||||
$context = context_module::instance($cm->id);
|
||||
require_capability('mod/programming:edittestcase', $context);
|
||||
|
||||
$mform = new testcase_form();
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect(new moodle_url('list.php', array('id' => $cm->id)));
|
||||
} else if ($data = $mform->get_data()) {
|
||||
$data->id = $data->case;
|
||||
$data->programmingid = $programming->id;
|
||||
unset($data->case);
|
||||
$infile = $mform->get_file_content('inputfile');
|
||||
if (empty($infile)) {
|
||||
$data->input = stripcslashes($data->input);
|
||||
} else {
|
||||
$data->input = $infile;
|
||||
}
|
||||
$outfile = $mform->get_file_content('outputfile');
|
||||
if (empty($outfile)) {
|
||||
$data->output = stripcslashes($data->output);
|
||||
} else {
|
||||
$data->output = $outfile;
|
||||
}
|
||||
// $data->input = str_replace("\r\n\r\n", "", $data->input);
|
||||
// $data->output = str_replace("\r\n\r\n", "", $data->output);
|
||||
// $data->input = str_replace("\r\n\n", "", $data->input);
|
||||
// $data->output = str_replace("\r\n\n", "", $data->output);
|
||||
// $data->input = str_replace(chr(13), "", $data->input);
|
||||
// $data->output = str_replace(chr(13), "", $data->output);
|
||||
// $data->input = str_replace("\n\n", "\n", $data->input);
|
||||
// $data->output = str_replace("\n\n", "\n", $data->output);
|
||||
$data->input = rtrim($data->input);
|
||||
$data->output = rtrim($data->output);
|
||||
// $data->input .= "\n";
|
||||
// $data->output .= "\n";
|
||||
programming_test_update_instance($data);
|
||||
|
||||
redirect(new moodle_url('list.php', array('id' => $cm->id)), get_string('testcasemodified', 'programming'), 0);
|
||||
} else {
|
||||
$data = $DB->get_record('programming_tests', array('id' => $case_id));
|
||||
$mform->set_data($data);
|
||||
|
||||
/// Print the page header
|
||||
$PAGE->set_title(format_string($course->shortname) . ': ' . $programming->name) . ': ' . get_string('edittestcase', 'programming');
|
||||
$PAGE->set_heading(format_string($course->fullname));
|
||||
$PAGE->requires->css('/mod/programming/programming.css');
|
||||
echo $OUTPUT->header();
|
||||
|
||||
/// Print tabs
|
||||
$renderer = $PAGE->get_renderer('mod_programming');
|
||||
$tabs = programming_navtab('edittest', 'testcase', $course, $programming, $cm);
|
||||
echo $renderer->render_navtab($tabs);
|
||||
|
||||
/// Print page content
|
||||
echo html_writer::tag('h2', $programming->name);
|
||||
echo html_writer::tag('h3', get_string('edittestcase', 'programming'));
|
||||
$mform->display();
|
||||
|
||||
/// Finish the page
|
||||
echo $OUTPUT->footer($course);
|
||||
}
|
||||
65
testcase/form.php
Normal file
65
testcase/form.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
require_once ($CFG->libdir.'/formslib.php');
|
||||
|
||||
class testcase_form extends moodleform {
|
||||
|
||||
function definition() {
|
||||
global $CFG, $COURSE, $OUTPUT, $cm, $programming;
|
||||
$mform =& $this->_form;
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
$mform->addElement('hidden', 'id', $cm->id);
|
||||
$mform->setType('id', PARAM_INT);
|
||||
$mform->addElement('hidden', 'case');
|
||||
$mform->setType('case', PARAM_INT);
|
||||
|
||||
// $mform->addElement('textarea', 'input', get_string('input', 'programming').$OUTPUT->help_icon('input', 'programming'), 'rows="2" cols="50"');
|
||||
$mform->addElement('filepicker', 'inputfile', get_string('usefile', 'programming'));
|
||||
// $mform->addElement('textarea', 'output', get_string('output', 'programming').$OUTPUT->help_icon('output', 'programming'), 'rows="2" cols="50"');
|
||||
$mform->addElement('filepicker', 'outputfile', get_string('usefile', 'programming'));
|
||||
|
||||
$mform->addElement('select', 'timelimit', get_string('timelimit', 'programming').$OUTPUT->help_icon('timelimit', 'programming'), programming_get_timelimit_options());
|
||||
$mform->setDefault('timelimit', $programming->timelimit);
|
||||
|
||||
$mform->addElement('select', 'memlimit', get_string('memlimit', 'programming').$OUTPUT->help_icon('memlimit', 'programming'), programming_get_memlimit_options());
|
||||
$mform->setDefault('memlimit', $programming->memlimit);
|
||||
|
||||
$mform->addElement('select', 'nproc', get_string('extraproc', 'programming').$OUTPUT->help_icon('nproc', 'programming'), programming_get_nproc_options());
|
||||
$mform->setDefault('nproc', $programming->nproc);
|
||||
|
||||
$mform->addElement('select', 'weight', get_string('weight', 'programming').$OUTPUT->help_icon('weight', 'programming'), programming_get_weight_options());
|
||||
$mform->setDefault('weight', 1);
|
||||
|
||||
$mform->addElement('select', 'pub', get_string('testcasepub', 'programming').$OUTPUT->help_icon('testcasepub', 'programming'), programming_testcase_pub_options());
|
||||
$mform->setDefault('pub',-1);
|
||||
|
||||
// $mform->addElement('textarea', 'memo', get_string('memo', 'programming'), 'rows="2" cols="50"');
|
||||
|
||||
// buttons
|
||||
$this->add_action_buttons();
|
||||
}
|
||||
|
||||
function set_data($data) {
|
||||
$data->case = $data->id;
|
||||
unset($data->id);
|
||||
if (strlen($data->input) > 1023) {
|
||||
$data->input = '';
|
||||
}
|
||||
if (strlen($data->output) > 1023) {
|
||||
$data->output = '';
|
||||
}
|
||||
parent::set_data($data);
|
||||
}
|
||||
|
||||
/*
|
||||
function validation($data, $files) {
|
||||
$errors = array();
|
||||
|
||||
if (empty($data['output']) or trim($data['output']) == '')
|
||||
if (empty($files['outputfile']))
|
||||
$errors['output'] = get_string('required');
|
||||
|
||||
return $errors;
|
||||
}*/
|
||||
|
||||
}
|
||||
150
testcase/list.php
Normal file
150
testcase/list.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
require_once('../../../config.php');
|
||||
require_once($CFG->libdir.'/tablelib.php');
|
||||
require_once('../lib.php');
|
||||
|
||||
$id = required_param('id', PARAM_INT); // programming ID
|
||||
$params = array('id' => $id);
|
||||
$PAGE->set_url('/mod/programming/testcase/list.php', $params);
|
||||
|
||||
if (! $cm = get_coursemodule_from_id('programming', $id)) {
|
||||
print_error('invalidcoursemodule');
|
||||
}
|
||||
|
||||
if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
|
||||
print_error('coursemisconf');
|
||||
}
|
||||
|
||||
if (! $programming = $DB->get_record('programming', array('id' => $cm->instance))) {
|
||||
print_error('invalidprogrammingid', 'programming');
|
||||
}
|
||||
|
||||
require_login($course->id, true, $cm);
|
||||
$context = context_module::instance($cm->id);
|
||||
|
||||
require_capability('mod/programming:viewhiddentestcase', $context);
|
||||
|
||||
/// Print the page header
|
||||
$PAGE->set_title(format_string($course->shortname).': '.$programming->name).': '.get_string('testcase', 'programming');
|
||||
$PAGE->set_heading(format_string($course->fullname));
|
||||
echo $OUTPUT->header();
|
||||
|
||||
/// Print tabs
|
||||
$renderer = $PAGE->get_renderer('mod_programming');
|
||||
$tabs = programming_navtab('edittest', 'testcase', $course, $programming, $cm);
|
||||
echo $renderer->render_navtab($tabs);
|
||||
|
||||
/// Print page content
|
||||
echo html_writer::tag('h2', $programming->name);
|
||||
echo html_writer::tag('h3', get_string('testcase', 'programming').$OUTPUT->help_icon('testcase', 'programming'));
|
||||
print_testcase_table();
|
||||
|
||||
/// Finish the page
|
||||
echo $OUTPUT->footer($course);
|
||||
|
||||
function print_testcase_table() {
|
||||
global $CFG, $OUTPUT, $DB, $cm, $params, $programming, $course, $language, $groupid;
|
||||
|
||||
$table = new html_table();
|
||||
$table->head = array(
|
||||
get_string('sequence', 'programming'),
|
||||
get_string('testcasepub', 'programming').$OUTPUT->help_icon('testcasepub', 'programming'),
|
||||
get_string('input', 'programming').$OUTPUT->help_icon('input', 'programming'),
|
||||
get_string('output', 'programming').$OUTPUT->help_icon('output', 'programming'),
|
||||
get_string('timelimit', 'programming').$OUTPUT->help_icon('timelimit', 'programming'),
|
||||
get_string('memlimit', 'programming').$OUTPUT->help_icon('memlimit', 'programming'),
|
||||
get_string('extraproc', 'programming').$OUTPUT->help_icon('nproc', 'programming'),
|
||||
get_string('weight', 'programming').$OUTPUT->help_icon('weight', 'programming'),
|
||||
get_string('action'),
|
||||
);
|
||||
|
||||
//$table->set_attribute('id', 'presetcode-table');
|
||||
//$table->set_attribute('class', 'generaltable generalbox');
|
||||
$table->tablealign = 'center';
|
||||
$table->cellpadding = 3;
|
||||
$table->cellspacing = 1;
|
||||
$table->colclasses[2] = 'programming-io';
|
||||
$table->colclasses[3] = 'programming-io';
|
||||
//$table->no_sorting('code');
|
||||
$table->data = array();
|
||||
|
||||
$strshowasplaintext = get_string('showasplaintext', 'programming');
|
||||
$strdownload = get_string('download', 'programming');
|
||||
$stredit = get_string('edit');
|
||||
$strdelete = get_string('delete');
|
||||
$strmoveup = get_string('moveup');
|
||||
$strmovedown = get_string('movedown');
|
||||
$fields = 'id,programmingid,seq,input,output,cmdargs,timelimit,memlimit,nproc,pub,weight,memo,timemodified';
|
||||
$tests = $DB->get_records('programming_tests', array('programmingid' => $programming->id), 'seq',$fields);
|
||||
|
||||
if (is_array($tests)) {
|
||||
$tests_count = count($tests)-1;
|
||||
$i = 0;
|
||||
foreach ($tests as $case) {
|
||||
$data = array();
|
||||
$data[] = $case->seq;
|
||||
$data[] = programming_testcase_pub_getstring($case->pub);
|
||||
|
||||
// stdin
|
||||
$url = new moodle_url('/mod/programming/testcase/download_io.php', array('id' => $cm->id, 'test' => $case->id, 'type'=> 'in', 'download' => 0));
|
||||
$html = $OUTPUT->action_link($url, $strshowasplaintext, new popup_action('click', $url), array('class' => 'showasplaintext small'));
|
||||
$html .= ' ';
|
||||
$url->param('download', 1);
|
||||
$html .= $OUTPUT->action_link($url, $strdownload, null, array('class' => 'download small'));
|
||||
$html .= programming_format_io($case->input, false);
|
||||
$data[] = $html;
|
||||
|
||||
// stdout
|
||||
$url->params(array('type' => 'out', 'download' => 0));
|
||||
$html = $OUTPUT->action_link($url, $strshowasplaintext, new popup_action('click', $url), array('class' => 'showasplaintext small'));
|
||||
$html .= ' ';
|
||||
$url->param('download', 1);
|
||||
$html .= $OUTPUT->action_link($url, $strdownload, null, array('class' => 'download small'));
|
||||
$html .= programming_format_io($case->output, false);
|
||||
$data[] = $html;
|
||||
|
||||
// limits
|
||||
$data[] = get_string('nseconds', 'programming', $case->timelimit);
|
||||
$data[] = get_string('nkb', 'programming', $case->memlimit);
|
||||
$data[] = $case->nproc;
|
||||
|
||||
$data[] = get_string('nweight', 'programming', $case->weight);
|
||||
|
||||
// actions
|
||||
$actions = array();
|
||||
$actions[] = $OUTPUT->action_link(
|
||||
new moodle_url('edit.php', array('id' => $cm->id, 'case' => $case->id)),
|
||||
html_writer::empty_tag('img', array('title' => $stredit, 'src' => $OUTPUT->image_url('t/edit'))),
|
||||
null,
|
||||
array('class' => 'icon edit'));
|
||||
$url = new moodle_url('/mod/programming/testcase/delete.php', array('id' => $cm->id, 'case' => $case->id));
|
||||
$txt = html_writer::empty_tag('img', array('title' => $strdelete, 'src' => $OUTPUT->image_url('t/delete')));
|
||||
$act = new confirm_action(get_string('deletetestcaseconfirm', 'programming'));
|
||||
$actions[] = $OUTPUT->action_link($url, $txt, $act, array('class' => 'icon delete'));
|
||||
if ($i > 0) {
|
||||
$actions[] = $OUTPUT->action_link(
|
||||
new moodle_url('move.php', array('id' => $cm->id, 'case' => $case->id, 'direction' => 1)),
|
||||
html_writer::empty_tag('img', array('title' => $strmoveup, 'src' => $OUTPUT->image_url('t/up'))),
|
||||
null,
|
||||
array('class' => 'icon up'));
|
||||
}
|
||||
if ($i < $tests_count) {
|
||||
$actions[] = $OUTPUT->action_link(
|
||||
new moodle_url('move.php', array('id' => $cm->id, 'case' => $case->id, 'direction' => 2)),
|
||||
html_writer::empty_tag('img', array('title' => $strmovedown, 'src' => $OUTPUT->image_url('t/down'))),
|
||||
null,
|
||||
array('class' => 'icon down'));
|
||||
}
|
||||
$data[] = implode("\n",$actions);
|
||||
|
||||
$table->data[] = $data;
|
||||
$i++;
|
||||
}
|
||||
|
||||
echo html_writer::table($table);
|
||||
} else {
|
||||
echo html_writer::tag('p'.get_string('notestcase', 'programming'));
|
||||
}
|
||||
echo html_writer::tag('p', $OUTPUT->action_link(new moodle_url('add.php', array('id' => $cm->id)), get_string('addtestcase', 'programming')));
|
||||
}
|
||||
29
testcase/move.php
Normal file
29
testcase/move.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
require_once('../../../config.php');
|
||||
require_once('../lib.php');
|
||||
|
||||
$id = required_param('id', PARAM_INT);
|
||||
$case = required_param('case', PARAM_INT);
|
||||
$direction = required_param('direction', PARAM_INT);
|
||||
|
||||
if ($id) {
|
||||
if (! $cm = get_coursemodule_from_id('programming', $id)) {
|
||||
error('Course Module ID was incorrect');
|
||||
}
|
||||
|
||||
if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
|
||||
error('Course is misconfigured');
|
||||
}
|
||||
|
||||
if (! $programming = $DB->get_record('programming', array('id' => $cm->instance))) {
|
||||
error('Course module is incorrect');
|
||||
}
|
||||
}
|
||||
|
||||
require_login($course->id, true, $cm);
|
||||
$context = context_module::instance($cm->id);
|
||||
require_capability('mod/programming:edittestcase', $context);
|
||||
|
||||
programming_testcase_adjust_sequence($programming->id, $case, $direction);
|
||||
redirect(new moodle_url('/mod/programming/testcase/list.php', array('id' => $cm->id)), get_string('testcasemoved', 'programming'), 0);
|
||||
Reference in New Issue
Block a user