[system] / trunk / wwmoodle / wwquestion / edit_webwork_form.php Repository:
ViewVC logotype

Diff of /trunk/wwmoodle/wwquestion/edit_webwork_form.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 5476 Revision 5477
6 * @author mleventi@gmail.com 6 * @author mleventi@gmail.com
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License 7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package webwork_qtype 8 * @package webwork_qtype
9 *//** */ 9 *//** */
10 10
11require_once($CFG->dirroot.'/question/type/edit_question_form.php'); 11require_once("$CFG->dirroot/question/type/edit_question_form.php");
12require_once("$CFG->dirroot/question/type/webwork/locallib.php");
12require_once($CFG->dirroot.'/question/type/webwork/questiontype.php'); 13require_once("$CFG->dirroot/question/type/webwork/questiontype.php");
14require_once("$CFG->dirroot/backup/lib.php");
13 15
14/** 16/**
15 * webwork editing form definition. 17 * webwork editing form definition.
16 * 18 *
17 * See http://docs.moodle.org/en/Development:lib/formslib.php for information 19 * See http://docs.moodle.org/en/Development:lib/formslib.php for information
18 * about the Moodle forms library, which is based on the HTML Quickform PEAR library. 20 * about the Moodle forms library, which is based on the HTML Quickform PEAR library.
19 */ 21 */
20class question_edit_webwork_form extends question_edit_form { 22class question_edit_webwork_form extends question_edit_form {
23
21 function definition_inner(&$mform) { 24 function definition_inner(&$mform) {
22 25
23 //HEADER 26 //CODE HEADER
24 $mform->addElement('header', 'generalheader', get_string("edit_header", 'qtype_webwork')); 27 $mform->addElement('header', 'codeheader', get_string("edit_codeheader", 'qtype_webwork'));
28 $mform->setHelpButton('codeheader',array('codeheader', get_string('edit_codeheader','qtype_webwork'),'webwork'));
29
30 //CODE
31 $mform->addElement('textarea', 'code', get_string('edit_code', 'qtype_webwork'),
32 array('rows' => 10,'cols' => 60));
33 $mform->setType('code', PARAM_RAW);
34 $mform->setHelpButton('code', array('code', get_string('edit_code', 'qtype_webwork'), 'webwork'));
35
36 //FILES HEADER
37 $mform->addElement('header', 'fileheader', get_string("edit_fileheader", 'qtype_webwork'));
38 $mform->setHelpButton('fileheader',array('fileheader', get_string('edit_fileheader','qtype_webwork'),'webwork'));
39
40 //FILES
41 if(!isset($this->question->webworkid)) {
42 $tempid = -1;
43 } else {
44 $tempid = $this->question->webworkid;
45 }
46 $src = webwork_get_filemanager_url($tempid);
47 $html = "<iframe src='".$src."' width='100%' height='300px' style='border:0px;'></iframe>";
48 $mform->addElement('html',$html);
49
50 //OPTIONS HEADER
51 $mform->addElement('header', 'optionheader', get_string("edit_optionheader","qtype_webwork"));
25 52
26 //CODECHECK 53 //CODECHECK
27 $codecheckoptions = array( 54 $codecheckoptions = array(
28 0 => get_string('edit_codecheck0','qtype_webwork'), 55 0 => get_string('edit_codecheck0','qtype_webwork'),
29 1 => get_string('edit_codecheck1','qtype_webwork'), 56 1 => get_string('edit_codecheck1','qtype_webwork'),
30 2 => get_string('edit_codecheck2','qtype_webwork')); 57 2 => get_string('edit_codecheck2','qtype_webwork'));
31 $mform->addElement('select','codecheck', get_string('edit_codecheck', 'qtype_webwork'),$codecheckoptions); 58 $mform->addElement('select','codecheck', get_string('edit_codecheck', 'qtype_webwork'),$codecheckoptions);
32 $mform->setType('codecheck',PARAM_INT); 59 $mform->setType('codecheck',PARAM_INT);
33 $mform->setHelpButton('codecheck', array('webwork', get_string('edit_codecheck', 'qtype_webwork'), 'webwork')); 60 $mform->setHelpButton('codecheck', array('codecheck', get_string('edit_codecheck', 'qtype_webwork'), 'webwork'));
34 $mform->setDefault('codecheck',2); 61 $mform->setDefault('codecheck',2);
35
36 //CODE
37 $mform->addElement('textarea', 'code', get_string('edit_code', 'qtype_webwork'),
38 array('rows' => 10,'cols' => 60));
39 $mform->setType('code', PARAM_RAW);
40 $mform->setHelpButton('code', array('webwork', get_string('edit_code', 'qtype_webwork'), 'webwork'));
41 $mform->addRule('code', null, 'required', null, 'client');
42 62
43 //SEED 63 //SEED
44 $mform->addElement('text', 'seed', get_string('edit_seed','qtype_webwork'), 64 $mform->addElement('text', 'seed', get_string('edit_seed','qtype_webwork'),
45 array('size' => 3)); 65 array('size' => 3));
46 $mform->setType('seed', PARAM_INT); 66 $mform->setType('seed', PARAM_INT);
53 array('size' => 3)); 73 array('size' => 3));
54 $mform->setType('trials', PARAM_INT); 74 $mform->setType('trials', PARAM_INT);
55 $mform->setHelpButton('trials', array('webwork', get_string('edit_trials', 'qtype_webwork'), 'webwork')); 75 $mform->setHelpButton('trials', array('webwork', get_string('edit_trials', 'qtype_webwork'), 'webwork'));
56 $mform->setDefault('trials', 10); 76 $mform->setDefault('trials', 10);
57 $mform->addRule('trials', null, 'required', null, 'client'); 77 $mform->addRule('trials', null, 'required', null, 'client');
58 } 78 }
59 79
60 function set_data($question) { 80 function set_data($question) {
61 parent::set_data($question); 81 parent::set_data($question);
62 } 82 }
63 83
64 function validation($data) { 84 function validation($data) {
85 global $CFG;
65 //check that the code is valid 86 //check that the code is valid
66 $err = $this->codecheck($data); 87 $err = $this->codecheck($data);
67 if($err != false) { 88 if($err != false) {
68 return $err; 89 return $err;
69 } 90 }
91 return true;
70 } 92 }
71 93
72 function codecheck($data) { 94 function codecheck($data) {
95
73 //codechecklevel 96 //codechecklevel
74 $codechecklevel = $data['codecheck']; 97 $codechecklevel = $data['codecheck'];
75 //here we construct a temp question object 98 //here we construct a temp question object
76 $question = new stdClass; 99 $question = new stdClass;
77 $question->code = base64_encode(stripslashes($data['code'])); 100 $question->code = base64_encode(stripslashes($data['code']));
78 $question->seed = $data['seed']; 101 $question->seed = $data['seed'];
79 $question->trials = $data['trials']; 102 $question->trials = $data['trials'];
80 103
104 //temporary solution
105 if(!isset($this->question->webworkid)) {
106 $path = webwork_get_tmp_path_full();
107 $urlpath = webwork_get_filehandler_path() . '/' . webwork_get_tmp_path() . '/';
108 } else {
109 $path = webwork_get_wwquestion_path_full($this->question->webworkid);
110 $urlpath = webwork_get_filehandler_path() . '/' . webwork_get_wwquestion_path($this->question->webworkid) . '/';
111 }
112 $filelist = list_directories_and_files($path);
113 $filearray = array();
114
115 foreach($filelist as $file) {
116 if(!is_dir($path . '/' . $file)) {
117 $encode = base64_encode($urlpath . '/' . $file);
118 array_push($filearray,$encode);
119 }
120
121 }
122 $question->files = $filearray;
123
81 //one call to the server will return response for this code and keep it static in the function 124 //one call to the server will return response for this code and keep it static in the function
82 $results = webwork_qtype::get_derived_questions($question); 125 $results = webwork_get_derivations($question);
126 //127.0.0.1
83 //no code check 127 //no code check
84 if($codechecklevel == 0) { 128 if($codechecklevel == 0) {
85 webwork_qtype::_derivedquestions($results); 129 webwork_qtype::_derivations($results);
86 return false; 130 return false;
87 } 131 }
88 132
89 //init error array 133 //init error array
90 $errorresults = array(); 134 $errorresults = array();
91 $goodresults = array(); 135 $noerrorresults = array();
92 136
93 //see if we got errors (split) 137 //see if we got errors (split)
94 foreach($results as $record) { 138 foreach($results as $record) {
95 if((isset($record['errors'])) && ($record['errors'] != '') && ($record['errors'] != null)) { 139 if((isset($record['errors'])) && ($record['errors'] != '') && ($record['errors'] != null)) {
96 array_push($errorresults,$record); 140 array_push($errorresults,$record);
97 } else { 141 } else {
142 array_push($noerrorresults,$record);
143 }
144 }
145
146 $goodresults = array();
147 $warningresults = array();
148
149 foreach($noerrorresults as $record) {
150 if((isset($record['warnings'])) && ($record['warnings'] != '') && ($record['warnings'] != null)) {
151 array_push($warningresults,$record);
152 } else {
98 array_push($goodresults,$record); 153 array_push($goodresults,$record);
99 } 154 }
155
156 }
100 } 157
101 158
102 //if there are good seeds we use those 159 //if there are good seeds we use those
103 if((count($goodresults) > 0) && ($codechecklevel == 1)) { 160 if((count($goodresults) > 0) && ($codechecklevel == 1)) {
104 webwork_qtype::_derivedquestions($goodresults); 161 webwork_qtype::_derivations($goodresults);
105 return false; 162 return false;
106 } 163 }
107 164
108 //if code check is strict 165 //if code check is strict
109 if(count($goodresults) == count($results)) { 166 if(count($goodresults) == count($results)) {
110 webwork_qtype::_derivedquestions($results); 167 webwork_qtype::_derivations($results);
111 return false; 168 return false;
112 } 169 }
113 170
114 $errormsgs = array(); 171 $errormsgs = array();
172 $warningmsgs = array();
115 //at this point we are going to be invalid 173 //at this point we are going to be invalid
116
117 //this correlates seeds with certain error messages for better output 174 //this correlates seeds with certain error messages for better output
118 175 //ERRORS
119 foreach($errorresults as $record) { 176 foreach($errorresults as $record) {
120 $found = 0; 177 $found = 0;
121 $candidate = $record['errors']; 178 $candidate = $record['errors'] . "<br>";
122 $candidateseed = $record['seed']; 179 $candidateseed = $record['seed'];
123 for($i=0;$i<count($errormsgs);$i++) { 180 for($i=0;$i<count($errormsgs);$i++) {
124 if($candidate == $errormsgs[$i]['errors']) { 181 if($candidate == $errormsgs[$i]['errors']) {
125 $found = 1; 182 $found = 1;
126 $errormsgs[$i]['seeds'][] = $candidateseed; 183 $errormsgs[$i]['seeds'][] = $candidateseed;
132 $msg['errors'] = $candidate; 189 $msg['errors'] = $candidate;
133 $msg['seeds'] = array(); 190 $msg['seeds'] = array();
134 $msg['seeds'][] = $candidateseed; 191 $msg['seeds'][] = $candidateseed;
135 $errormsgs[] = $msg; 192 $errormsgs[] = $msg;
136 } 193 }
194 }
195 //WARNINGS
196 foreach($warningresults as $record) {
197 $found = 0;
198 $candidate = $record['warnings'] . "<br>";
199 $candidateseed = $record['seed'];
200 for($i=0;$i<count($warningmsgs);$i++) {
201 if($candidate == $warningmsgs[$i]['errors']) {
202 $found = 1;
203 $warningmsgs[$i]['seeds'][] = $candidateseed;
204 }
205 }
206 if($found == 0) {
207 //new error message
208 $msg = array();
209 $msg['warnings'] = $candidate;
210 $msg['seeds'] = array();
211 $msg['seeds'][] = $candidateseed;
212 $warningmsgs[] = $msg;
213 }
214
137 } 215 }
138 $output = "Errors in PG Code on: " . count($errorresults) . " out of " . count($results) . " seeds tried:<br>"; 216 $output = "Errors in PG Code on: " . count($errorresults) . " out of " . count($results) . " seeds tried:<br>";
139 //construct error statement 217 //construct error statement
140 $counter = 1; 218 $counter = 1;
141 foreach($errormsgs as $msg) { 219 foreach($errormsgs as $msg) {
142 $output .= "$counter) "; 220 $output .= "$counter) ";
143 $output .= "Seeds ("; 221 $output .= "Seeds (";
144 foreach ($msg['seeds'] as $seed) { 222 foreach ($msg['seeds'] as $seed) {
145 $output .= $seed . " "; 223 $output .= $seed . " ";
146 } 224 }
147 $output .= ") gave Error:" . $msg['errors'] . "<br><br>"; 225 $output .= ") gave Errors:" . $msg['errors'] . "<br><br>";
226 $counter++;
227 }
228 $output .= "Warnings in PG Code on: " . count($warningresults) . " out of " . count($results) . " seeds tried:<br>";
229 $counter = 1;
230 foreach($warningmsgs as $msg) {
231 $output .= "$counter) ";
232 $output .= "Seeds (";
233 foreach ($msg['seeds'] as $seed) {
234 $output .= $seed . " ";
235 }
236 $output .= ") gave Warnings:" . $msg['warnings'] . "<br><br>";
148 $counter++; 237 $counter++;
149 } 238 }
150 $returner =array(); 239 $returner =array();
151 $returner['code'] = $output; 240 $returner['code'] = $output;
152 return $returner; 241 return $returner;

Legend:
Removed from v.5476  
changed lines
  Added in v.5477

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9