[LON-CAPA-cvs] cvs: loncom /imspackages imsprocessor.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Mon, 13 Dec 2004 23:11:09 -0000


This is a MIME encoded message

--raeburn1102979469
Content-Type: text/plain

raeburn		Mon Dec 13 18:11:09 2004 EDT

  Modified files:              
    /loncom/imspackages	imsprocessor.pm 
  Log:
  Import assessment questions from quizzes or surveys into DOCS as simple problems.  
  
  
--raeburn1102979469
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20041213181109.txt"

Index: loncom/imspackages/imsprocessor.pm
diff -u loncom/imspackages/imsprocessor.pm:1.11 loncom/imspackages/imsprocessor.pm:1.12
--- loncom/imspackages/imsprocessor.pm:1.11	Mon Dec 13 15:01:09 2004
+++ loncom/imspackages/imsprocessor.pm	Mon Dec 13 18:11:09 2004
@@ -491,7 +491,6 @@
         }
         if (@{$surveys}) {
             $$items{'Top'}{'contentscount'} ++;
-        
         }
     }
 
@@ -680,7 +679,6 @@
         if (@{$surveys} > 0)  {
             &process_specials($context,'surveys',$surveys,\$topnum,$$items{'Top'}{contentscount},$destdir,$udom,$uname,$cdom,$crs,$timenow,$newdir,$timestamp,$resinfo,\$seqtext{'Top'},$pagesfiles,$seqfiles,$topurls,$topnames);
         }
-
         $seqtext{'Top'} .= "</map>\n";
         open(TOPFILE,">$destdir/sequences/Top.sequence");
         print TOPFILE $seqtext{'Top'};
@@ -1692,7 +1690,15 @@
     }
     print $fh qq|<map>
 |;
-    my $probsrc="/res/$udom/$uname/$resdir/problems/$dirtitle/$allids[0].problem";
+    my $probsrc = "/res/lib/templates/simpleproblem.problem";
+    my ($cid,$cdom,$cnum);
+    if ($context eq 'DOCS') {
+        $cid = $ENV{'request.course.id'};
+        ($cdom,$cnum) = split/_/,$cid;
+    }
+    if ($context eq 'CSTR') {
+        $probsrc="/res/$udom/$uname/$resdir/problems/$dirtitle/$allids[0].problem";
+    }
     print $fh qq|<resource id="1" src="$probsrc" type="start" title="question_0001"></resource>|;
     if (@allids == 1) {
         print $fh qq|
@@ -1721,8 +1727,22 @@
     }
     print $fh qq|</map>|;
     close($fh);
+    my $qnum = 0;
     foreach my $id (@allids) {
+        $qnum ++;
         my $output;
+        my $permcontainer = $containerdir;
+        $permcontainer =~ s#/home/httpd/html/userfiles#uploaded#;
+        my $symb = $cid.'.'.$permcontainer.'___'.$qnum.'___lib/templates/simpleproblem.problem.0.';
+        my %resourcedata = ();
+        for (my $i=0; $i<10; $i++) {
+            my $iter = $i+1;
+            $resourcedata{$symb.'text'.$iter} = "";
+            $resourcedata{$symb.'value'.$iter} = "unused";
+            $resourcedata{$symb.'position'.$iter} = "random";
+        }  
+        $resourcedata{$symb.'randomize'} = 'yes';
+        $resourcedata{$symb.'maxfoils'} = 10;
         if ($context eq 'CSTR') {
             $output = qq|<problem>
 |;
@@ -1738,10 +1758,16 @@
  $$settings{$id}{feedbackcorr}
  </postanswerdate>
 |;
+             } else {
+		 $resourcedata{$symb.'questiontext'} = $$settings{$id}{text};
+                 $resourcedata{$symb.'hiddenparts'} = '!essay';
+                 $resourcedata{$symb.'questiontype'} = 'essay';
              }
         } else {
             if ($context eq 'CSTR') {
                 $output .= qq|<startouttext />$$settings{$id}{text}\n|;
+            } else {
+                $resourcedata{$symb.'questiontext'} = $$settings{$id}{text};
             }
             my ($image,$imglink,$url);
             if ( defined($$settings{$id}{image}) ) {
@@ -1757,6 +1783,8 @@
             if ($context eq 'CSTR') {
                 $output .= $image.$imglink.$url.'
 <endouttext />';
+            } else {
+                $resourcedata{$symb.'questiontext'} .= $image.$imglink.$url;
             }
             if ($$settings{$id}{class} eq 'QUESTION_MULTIPLECHOICE') {
                 my $numfoils = @{$allanswers{$id}};
@@ -1765,20 +1793,29 @@
  <radiobuttonresponse max="$numfoils" randomize="yes">
   <foilgroup>
 |;
+                } else {
+                    $resourcedata{$symb.'hiddenparts'} = '!radio';
+                    $resourcedata{$symb.'questiontype'} = 'radio';
+                    $resourcedata{$symb.'maxfoils'} = $numfoils;
                 }
                 for (my $k=0; $k<@{$allanswers{$id}}; $k++) {
+                    my $iter = $k+1;
                     $output .= "   <foil name=\"foil".$k."\" value=\"";
                     if (grep/^$allanswers{$id}[$k]$/,@{$$settings{$id}{correctanswer}}) {
                         $output .= "true\" location=\"";
+                        $resourcedata{$symb.'value'.$iter} = "true";
                     } else {
                         $output .= "false\" location=\"";
+                        $resourcedata{$symb.'value'.$iter} = "false";
                     }
                     if (lc ($allanswers{$id}[$k]) =~ m/^\s?([Aa]ll)|([Nn]one)\sof\sthe\sabove\.?/) {
                         $output .= "bottom\"";
+                        $resourcedata{$symb.'position'.$iter} = "bottom";
                     } else {
                         $output .= "random\"";
                     }
                     $output .= "\><startouttext />".$$settings{$id}{$allanswers{$id}[$k]}{text};
+                    $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$allanswers{$id}[$k]}{text};
                     my ($ans_image,$ans_link);
                     if ( defined($$settings{$id}{$allanswers{$id}[$k]}{image}) ) {
                         if ( $$settings{$id}{$allanswers{$id}[$k]}{style} eq 'embed' ) {
@@ -1788,6 +1825,7 @@
                         }
                     }
                     $output .= $ans_image.$ans_link.'<endouttext /></foil>'."\n";
+                    $resourcedata{$symb.'text'.$iter} .= $ans_image.$ans_link;
                 }
                 if ($context eq 'CSTR') {
                     chomp($output);
@@ -1803,15 +1841,23 @@
    <radiobuttonresponse max="$numfoils" randomize="yes">
     <foilgroup>
 |;
+                } else {
+                    $resourcedata{$symb.'maxfoils'} = $numfoils;
+                    $resourcedata{$symb.'hiddenparts'} = '!radio';
+                    $resourcedata{$symb.'questiontype'} = 'radio';
                 }
                 for (my $k=0; $k<@{$allanswers{$id}}; $k++) {
+                    my $iter = $k+1;
                     $output .= "   <foil name=\"foil".$k."\" value=\"";
                     if (grep/^$allanswers{$id}[$k]$/,@{$$settings{$id}{correctanswer}}) {
                         $output .= "true\" location=\"random\"";
+                        $resourcedata{$symb.'value'.$iter} = "true";
                     } else {
                         $output .= "false\" location=\"random\"";
+                        $resourcedata{$symb.'value'.$iter} = "false";
                     }
                     $output .= "\><startouttext />".$$settings{$id}{$allanswers{$id}[$k]}{text}."<endouttext /></foil>\n";
+                    $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$allanswers{$id}[$k]}{text};
                 }
                 if ($context eq 'CSTR') {
                     chomp($output);
@@ -1827,15 +1873,26 @@
    <optionresponse max="$numfoils" randomize="yes">
     <foilgroup options="('True','False')">
 |;
+                } else {
+                    $resourcedata{$symb.'newopt'} = '';
+                    $resourcedata{$symb.'delopt'} = '';
+                    $resourcedata{$symb.'options'} = "('True','False')";
+                    $resourcedata{$symb.'hiddenparts'} = '!option';
+                    $resourcedata{$symb.'questiontype'} = 'option';
+                    $resourcedata{$symb.'maxfoils'} = $numfoils;
                 }
                 for (my $k=0; $k<@{$allanswers{$id}}; $k++) {
+                    my $iter = $k+1;
                     $output .= "   <foil name=\"foil".$k."\" value=\"";
                     if (grep/^$allanswers{$id}[$k]$/,@{$$settings{$id}{correctanswer}}) {
                         $output .= "True\"";
+                        $resourcedata{$symb.'value'.$iter} = "True";
                     } else {
                         $output .= "False\"";
+                        $resourcedata{$symb.'value'.$iter} = "False";
                     }
                     $output .= "\><startouttext />".$$settings{$id}{$allanswers{$id}[$k]}{text}."<endouttext /></foil>\n";
+                    $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$allanswers{$id}[$k]}{text};
                 }
                 if ($context eq 'CSTR') {  
                     chomp($output);
@@ -1846,15 +1903,28 @@
                 }
             } elsif ($$settings{$id}{class} eq 'QUESTION_ORDER') {
                 my $numfoils = @{$allanswers{$id}};
+                my @allorder = ();
                 if ($context eq 'CSTR') {
                     $output .= qq|
    <rankresponse max="$numfoils" randomize="yes">
     <foilgroup>
 |;
+                } else {
+                    $resourcedata{$symb.'newopt'} = '';
+                    $resourcedata{$symb.'delopt'} = '';
+                    $resourcedata{$symb.'hiddenparts'} = '!option';
+                    $resourcedata{$symb.'questiontype'} = 'option';
+                    $resourcedata{$symb.'maxfoils'} = $numfoils;
                 }
                 for (my $k=0; $k<@{$allanswers{$id}}; $k++) {
                     if ($context eq 'CSTR') {
                         $output .= "   <foil location=\"random\" name=\"foil".$k."\" value=\"".$$settings{$id}{$allanswers{$id}[$k]}{order}."\"><startouttext />".$$settings{$id}{$allanswers{$id}[$k]}{text}."<endouttext /></foil>\n";
+                    } else {
+                        my $iter = $k+1;
+                        $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$allanswers{$id}[$k]}{text};
+                        if (!grep/^$$settings{$id}{$allanswers{$id}[$k]}{order}$/,@allorder) {
+                            push @allorder, $$settings{$id}{$allanswers{$id}[$k]}{order};
+                        }
                     }
                 }
                 if ($context eq 'CSTR') {
@@ -1863,6 +1933,11 @@
     </foilgroup>
    </rankresponse>
 |;
+                } else {
+                    print STDERR "order before is ".join(',',@allorder)."\n";
+                    @allorder = sort {$a <=> $b} @allorder;
+                    print STDERR "order after is ".join(',',@allorder)."\n"; 
+                    $resourcedata{$symb.'options'} = "('".join("','",@allorder)."')";
                 }
             } elsif ($$settings{$id}{class} eq 'QUESTION_FILLINBLANK') {
                 my $numerical = 1;
@@ -1906,7 +1981,14 @@
 |;
                     }
                 } else {
-                    if ($context eq 'CSTR') {
+                    if ($context eq 'DOCS') {
+                        $resourcedata{$symb.'hiddenparts'} = '!string';
+                        $resourcedata{$symb.'questiontype'} = 'string';
+                        $resourcedata{$symb.'maxfoils'} = @{$allanswers{$id}};
+                        $resourcedata{$symb.'hiddenparts'} = '!string';
+                        $resourcedata{$symb.'stringtype'} = 'ci';
+                        $resourcedata{$symb.'stringanswer'} = $$settings{$id}{$allanswers{$id}[0]}{text};
+                    } else {
                         if (@{$allanswers{$id}} == 1) {
                             $output .= qq|
 <stringresponse answer="$$settings{$id}{$allanswers{$id}[0]}{text}" type="ci">
@@ -1932,12 +2014,20 @@
                     } 
                 }
             } elsif ($$settings{$id}{class} eq "QUESTION_MATCH") {
+                my @allmatchers = ();
+                my %matchtext = ();
                 if ($context eq 'CSTR') {
                     $output .= qq|
 <matchresponse max="10" randomize="yes">
     <foilgroup>
         <itemgroup>
 |;
+                } else {
+                    $resourcedata{$symb.'newopt'} = '';
+                    $resourcedata{$symb.'delopt'} = '';
+                    $resourcedata{$symb.'hiddenparts'} = '!option';
+                    $resourcedata{$symb.'questiontype'} = 'option';
+                    $resourcedata{$symb.'maxfoils'} =  @{$allanswers{$id}};
                 }
                 for (my $k=0; $k<@{$allchoices{$id}}; $k++) {
                     if ($context eq 'CSTR') {
@@ -1946,6 +2036,11 @@
 <startouttext />$$settings{$id}{$allchoices{$id}[$k]}{text}<endouttext />
 </item>
                     |;
+                    } else {
+                        if (!grep/^$$settings{$id}{$allchoices{$id}[$k]}{text}$/,@allmatchers) {
+                            push @allmatchers, $$settings{$id}{$allchoices{$id}[$k]}{text};
+                            $matchtext{$allchoices{$id}[$k]} = $$settings{$id}{$allchoices{$id}[$k]}{text};
+                        }
                     }
                 }
                 if ($context eq 'CSTR') {
@@ -1960,6 +2055,10 @@
          <startouttext />$$settings{$id}{$allanswers{$id}[$k]}{text}<endouttext />
         </foil>
 |;
+                    } else {
+                        my $iter = $k+1;
+                        $resourcedata{$symb.'value'.$iter} = $matchtext{$$settings{$id}{$allanswers{$id}[$k]}{choice_id}};
+                        $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$allanswers{$id}[$k]}{text};
                     }
                 }
                 if ($context eq 'CSTR') {
@@ -1967,6 +2066,8 @@
     </foilgroup>
 </matchresponse>
 |;
+                } else {
+                    $resourcedata{$symb.'options'} = "('".join("','",@allmatchers)."')";
                 }
             }
         }
@@ -1976,6 +2077,10 @@
             open(PROB,">$newdir/$id.problem");
             print PROB $output;
             close PROB;
+        } else {
+# put %resourcedata;
+            my $reply=&Apache::lonnet::cput
+                ('resourcedata',\%resourcedata,$cdom,$cnum);
         }
     }
 }

--raeburn1102979469--