/** * Output the Tests section of the form * @param type $mform */ private function testsSection() { global $DB, $CFG, $PAGE; //var_dump($PAGE->context->id); //echo '<pre>'.print_r($PAGE, true).'</pre>'; $this->_form->addElement('header', 'tests', 'Tests'); $this->_form->addElement('html', '<div id="ca-tests">'); // Get existing tests $tests = $DB->get_records('codeactivity_tests', array('activity_id' => $this->current->id)); //echo '<pre>'.print_r($this, true).'</pre>'; if (!empty($tests)) { foreach ($tests as $test) { //echo '<pre>'.print_r($test, true).'</pre>'; $this->_form->addElement('html', codeactivity::testHTML($test->id)); } } $this->_form->addElement('html', '</div>'); // #ca-tests $this->_form->addElement('html', '<div id="ca-add-test" style="display:none;">'); //get_string('codeactivityname', 'codeactivity'), array('size'=>'64')); $this->_form->addElement('text', 'testname', get_string('test_name', 'codeactivity'), array('size' => '64')); $this->_form->setType('testname', PARAM_RAW); $this->_form->addElement('select', 'testtype', get_string('test_type', 'codeactivity'), array('unittest' => get_string('unittest', 'codeactivity'), 'output' => get_string('outputmatch', 'codeactivity'))); $this->_form->addElement('html', '<div id="ca-unittestcode" style="display:none;">'); $this->_form->addElement('textarea', 'unittestcode', get_string('unittest_code', 'codeactivity')); $this->_form->addElement('html', '</div>'); $this->_form->addElement('html', '<div id="ca-outputmatching" style="display:none;">'); $this->_form->addElement('select', 'runfile', get_string('runfile', 'codeactivity'), array()); $this->_form->addElement('textarea', 'expectedoutput', get_string('expected_output', 'codeactivity')); $this->_form->addElement('selectyesno', 'convertnulls', get_string('convert_nulls', 'codeactivity')); $this->_form->addElement('selectyesno', 'ignorewhitespace', get_string('ignore_whitespace', 'codeactivity')); $this->_form->addElement('html', '</div>'); $this->_form->addElement('html', '</div>'); // #ca-add-test $buttonarray = array(); $buttonarray[] = $this->_form->createElement('button', 'add_test', 'Add Test'); $buttonarray[] = $this->_form->createElement('button', 'add_save', 'Save'); $buttonarray[] = $this->_form->createElement('button', 'add_cancel', 'Cancel'); $this->_form->addGroup($buttonarray, 'add_buttons', '', array(''), false); $this->_form->addElement('hidden', 'ca_temp_code', uniqid()); $this->_form->setType('ca_temp_code', PARAM_RAW); //echo '<pre>'.print_r($PAGE->context, true).'</pre>'; $this->_form->addElement('hidden', 'ca_context', $PAGE->context->instanceid); $this->_form->setType('ca_context', PARAM_RAW); }
* The main codeactivity configuration form * * It uses the standard core Moodle formslib. For more info about them, please * visit: http://docs.moodle.org/en/Development:lib/formslib.php * * @package mod_codeactivity * @copyright 2014 Ryan Nutt http://www.nutt.net * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ if (!defined('AJAX_SCRIPT')) { define('AJAX_SCRIPT', true); } require_once dirname(__FILE__) . '/../../config.php'; require_once $CFG->dirroot . '/repository/lib.php'; require_once dirname(__FILE__) . '/inc/classes/codeactivity.php'; // For unit tests to work. global $CFG, $PAGE; require_login(); if ($_POST['action'] == 'listFiles') { codeactivity::ajaxListFiles(); } else { if ($_POST['action'] == 'addTest') { codeactivity::ajaxAddTest(); } else { if ($_POST['action'] == 'deleteTest') { codeactivity::ajaxDeleteTest(); } else { die('Invalid action parameter: ' . $_POST['action']); } } }