From: Chris S. <san...@us...> - 2008-12-19 16:03:10
|
Update of /cvsroot/stack/stack-dev/lib/ui In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv19573/lib/ui Modified Files: Tag: question-test GhostWriter.php AuthorDisplay.php Log Message: Index: GhostWriter.php =================================================================== RCS file: /cvsroot/stack/stack-dev/lib/ui/GhostWriter.php,v retrieving revision 1.36 retrieving revision 1.36.10.1 diff -C2 -d -r1.36 -r1.36.10.1 *** GhostWriter.php 30 Nov 2007 15:36:36 -0000 1.36 --- GhostWriter.php 19 Dec 2008 16:02:58 -0000 1.36.10.1 *************** *** 92,95 **** --- 92,96 ---- $this->updateMeta(); $this->updateOptions(); + $this->updateTests(); //PRTs should be updated last. *************** *** 481,485 **** $this->item->PRTrees[$name]->setFeedbackVariables($this->posted["$prefix-feedbackVariables"]); } ! //description if(array_key_exists("$prefix-description", $this->posted)) --- 482,486 ---- $this->item->PRTrees[$name]->setFeedbackVariables($this->posted["$prefix-feedbackVariables"]); } ! //description if(array_key_exists("$prefix-description", $this->posted)) *************** *** 681,706 **** if($exploded[0] == 'qp' && in_array($exploded[1], $qpNames) && $exploded[2] == 'inputTypeParam') { ! $qpName = $exploded[1]; $qpKey = $exploded[2]; $itKey = $exploded[3]; ! ! $count = count($exploded); ! switch($count) { case '4': $itOptions[$qpName][$itKey] = $post; break; ! case '5': $itOptions[$qpName][$itKey][$exploded[4]] = $post; break; ! case '6': $itOptions[$qpName][$itKey][$exploded[4]][$exploded[5]] = $post; break; ! case '7': $itOptions[$qpName][$itKey][$exploded[4]][$exploded[5]][$exploded[6]] = $post; break; ! case '8': $itOptions[$qpName][$itKey][$exploded[4]][$exploded[5]][$exploded[6]][$exploded[7]] = $post; break; --- 682,707 ---- if($exploded[0] == 'qp' && in_array($exploded[1], $qpNames) && $exploded[2] == 'inputTypeParam') { ! $qpName = $exploded[1]; $qpKey = $exploded[2]; $itKey = $exploded[3]; ! ! $count = count($exploded); ! switch($count) { case '4': $itOptions[$qpName][$itKey] = $post; break; ! case '5': $itOptions[$qpName][$itKey][$exploded[4]] = $post; break; ! case '6': $itOptions[$qpName][$itKey][$exploded[4]][$exploded[5]] = $post; break; ! case '7': $itOptions[$qpName][$itKey][$exploded[4]][$exploded[5]][$exploded[6]] = $post; break; ! case '8': $itOptions[$qpName][$itKey][$exploded[4]][$exploded[5]][$exploded[6]][$exploded[7]] = $post; break; *************** *** 708,712 **** } } ! if(!empty($toUpdate)) { --- 709,713 ---- } } ! if(!empty($toUpdate)) { *************** *** 773,777 **** return $result; } ! /** * Updates the meta information, including keywords & question description. --- 774,778 ---- return $result; } ! /** * Updates the meta information, including keywords & question description. *************** *** 784,791 **** $autoKeywords = $this->autoFindKeywords($this->posted['questionKeywords']); $this->item->questionKeywords->setSelection($autoKeywords); ! $this->item->questionName->setSelection($this->posted['questionName']); $this->item->questionDescription->setSelection($this->posted['questionDescription']); ! $this->item->language->setSelection($this->posted['language']); $this->item->questionLearningContext->setSelection($this->posted['questionLearningContext']); --- 785,792 ---- $autoKeywords = $this->autoFindKeywords($this->posted['questionKeywords']); $this->item->questionKeywords->setSelection($autoKeywords); ! $this->item->questionName->setSelection($this->posted['questionName']); $this->item->questionDescription->setSelection($this->posted['questionDescription']); ! $this->item->language->setSelection($this->posted['language']); $this->item->questionLearningContext->setSelection($this->posted['questionLearningContext']); *************** *** 850,853 **** --- 851,905 ---- } + /** + * Updates the item's questionTests + * + * @return void + * @access private + */ + private function updateTests() + { + // Ensure old questions have tests. + if (NULL===$this->item->itemTests) { + $this->itemTests = new ItemTests(); + } + // Add any new question tests. + if (0 != $this->posted['itemTests-add']) { + $this->item->itemTests->addTest($this->posted['itemTests-add']); + } + $QTs = $this->item->itemTests->getTests(); + $qpNames = array_keys($this->item->questionPart); + $PRTs = $this->item->getPRTs(); + if (!empty($QTs)) { + foreach($QTs as $key => $QT) { + + // Remove any question tests. + $field = 'itemTests_'.$key.'-remove'; + if (array_key_exists($field,$this->posted)) { + $this->item->itemTests->removeTest($key); + } else { + + // Insert new values in + foreach($qpNames as $name) { + $field = 'itemTests_'.$key.'_IE_'.$name; + if (array_key_exists($field,$this->posted)) { + $this->item->itemTests->setTest($key,'IE_'.$name,$this->posted[$field]); + } + } + + foreach($PRTs as $name => $PRT) { + $field = 'itemTests_'.$key.'_PRT_'.$name; + if (array_key_exists($field,$this->posted)) { + $this->item->itemTests->setTest($key,'PRT_'.$name,$this->posted[$field]); + } + } + + + } // else remove else. + } + } + + //echo "<pre>";print_r($this->item->itemTests);echo "</pre>"; + } + } Index: AuthorDisplay.php =================================================================== RCS file: /cvsroot/stack/stack-dev/lib/ui/AuthorDisplay.php,v retrieving revision 1.59 retrieving revision 1.59.2.1 diff -C2 -d -r1.59 -r1.59.2.1 *** AuthorDisplay.php 18 Dec 2008 14:39:28 -0000 1.59 --- AuthorDisplay.php 19 Dec 2008 16:02:58 -0000 1.59.2.1 *************** *** 147,150 **** --- 147,151 ---- } $display .= $this->displayOptions(); + $display .= $this->displayTests(); $display .= $this->displayMeta(); $display .= $this->displayMoodleAuthor($engineID); *************** *** 606,610 **** --- 607,695 ---- } + private function displayTests() + { + global $config; + $tests = '<div class="section"><h3><img src="'.$config->get('weburl').'/pix/triangleDown.gif" name="testsIcon" />'.get_string('stackAuthor_questionTests', 'stack','').'</a></h3>'; + $tests .= '<div id="tests">'; + if(!empty($this->item->questionPart)) { + $qpNames = array_keys($this->item->questionPart); + $PRTs = $this->item->getPRTs(); + + //echo "<pre>";print_r($PRTs);echo "</pre>"; + + $tests .="\n<table class='interactionElementsTable' border='1' cellpadding='2' cellspacing='0''>\n<tr><td></td>"; + foreach($qpNames as $name) { + $tests .= '<td class="tableTitle">'.$name.'</td>'; + } + if($PRTs != NULL) { + foreach($PRTs as $name => $PRT) { + // Generate header row for table. + $tests .= '<td class="tableTitle">'.$name.'</td>'; + } + } + $tests .= '<td class="tableTitle">'.get_string('stackAuthor_removeCheckbox','stack','').'</td>'; + $tests .="\n</tr>\n"; + + $QTs = $this->item->itemTests->getTests(); + // Fill in body of table. + if($QTs != NULL) { + if (!empty($QTs)) { + foreach($QTs as $key => $QT) { + $prefix = 'itemTests_'.$key; + $tests .="\n</tr>\n<td>$key</td>"; + foreach($qpNames as $name) { + $value = ''; + if (array_key_exists('IE_'.$name,$QT)) { + $value = $QT['IE_'.$name]; + } + $tests .= '<td><input type="text" size="15" name="'.$prefix.'_IE_'.$name.'" value="'.$value.'" /></td>'; + } + + foreach($PRTs as $name =>$PRT) { + $value = ''; + if (array_key_exists('PRT_'.$name,$QT)) { + $value = $QT['PRT_'.$name]; + } + $an = array_merge(array('NONE'),$PRT -> getAnswerNotes()); + $found_an = false; + $widget = ''; + foreach ($an as $note) { + if($note == $value) { + $widget .= '<option value="'.$note.'" selected="selected">'.$note.'</option>'; + $found_an = true; + } + else + { + $widget .= '<option value="'.$note.'">'.$note.'</option>'; + } + } + $widget = '<select name="'.$prefix.'_PRT_'.$name.'"> '.$widget.'</select>'; + //$tests .= '<td><input type="text" size="15" name="'.$prefx.'_PRT_'.$name.'" value="'.$value.'" /></td>'; + $tests .= '<td>'.$widget.'</td>'; + } + + $tests .='<td><input type="checkbox" name="'.$prefix.'-remove" value="true" /></td></tr>'; + } + } + } + + $tests .="\n</table>\n"; + //$tests .= + + } + + // Allow user to add tests. + $tests .= '<p>'.get_string('stackQuestion_PR_Add','stack','').' '; + $tests .= "<select name=\"itemTests-add\">"; + for($i = 0; $i <= 10; $i++) + { + $tests .= "<option value=\"$i\">$i</option>"; + } + $tests .= "</select></p>"; + + $tests .= '<div class="clearer"> </div></div></div>'; + return $tests; + } private function validateQuestion() |