[LON-CAPA-cvs] cvs: loncom(BZ4492) /homework radiobuttonresponse.pm

foxr foxr at source.lon-capa.org
Fri Jan 20 06:41:31 EST 2012


foxr		Fri Jan 20 11:41:31 2012 EDT

  Modified files:              (Branch: BZ4492)
    /loncom/homework	radiobuttonresponse.pm 
  Log:
  BZ 4492 Start refactorying the rendition code so that it's tractable 
  for modification
  
  
  
Index: loncom/homework/radiobuttonresponse.pm
diff -u loncom/homework/radiobuttonresponse.pm:1.153 loncom/homework/radiobuttonresponse.pm:1.153.6.1
--- loncom/homework/radiobuttonresponse.pm:1.153	Thu Jan  5 11:56:34 2012
+++ loncom/homework/radiobuttonresponse.pm	Fri Jan 20 11:41:31 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # mutliple choice style responses
 #
-# $Id: radiobuttonresponse.pm,v 1.153 2012/01/05 11:56:34 foxr Exp $
+# $Id: radiobuttonresponse.pm,v 1.153.6.1 2012/01/20 11:41:31 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -387,6 +387,7 @@
 
 }
 
+##
 sub displayallfoils {
     my ( $direction, $target ) = @_;
     my $result;
@@ -767,6 +768,87 @@
     &Apache::lonxml::debug("Answer is $answer");
     return ( $answer, @whichfalse );
 }
+##
+# Display foils in html rendition:
+#
+# @param $whichfoils - Set of foils to display.
+# @param $target     - Rendition target...there are several html targets.
+# @param $direction  - 'horizontal' if layout is horizontal.
+# @param $part       - Part of the problem that's being displayed.
+# @param $solved     - Solution state of the problem.
+# @param $show_answer- True if answers should be shown.
+#
+# @return string
+# @retval generated html.
+#
+sub display_foils_html {
+    my ($whichfoils, $target, $direction, $part, $solved, $show_answer) = @_;
+    my $result;
+
+    # if the answers get shown, we need to label each item as correct or
+    # incorrect.
+
+    if ($show_answer) {
+	my $item_pretext     = '<br />'; # html prior to each item
+	my $item_posttext    = '';	 # html after each item.
+	my $finalclose       = '';	 # html to close off the whole shebang
+
+
+	# Horizontal layout is a table with each foil in a cell
+
+	if ($direction eq 'horizontal') {
+	    $result        = '<table><tr>';
+	    $item_pretext  = '<td>' . $item_pretext;
+	    $item_posttext = '</td>';
+	    $finalclose    = '</tr></table>';
+	} 
+
+	foreach my $name (@{$whichfoils}) {
+
+	    # If the item gets further surrounded by tags, this 
+	    # holds the closures for those tages.
+
+	    my $item_closetag = '';
+
+	    $result .= $item_pretext;
+
+	    # Label each foil as correct or incorrect:
+
+	    if ($Apache::response::foilgroup{$name . '.value'} eq 'true') {
+		$result .= &mt('Correct:') . '<b>';
+		$item_closetag .= '</b>';
+		
+	    } else {
+		$result .= &mt('Incorrect');
+	    }
+
+	    # Web rendition encloses the 
+	    # item text in a label tag as well:
+
+	    if ($target eq 'web') {
+		$result .= '<label>';
+		$item_closetag = '</label>' . $item_closetag;
+	    }
+	    $result .= $Apache::response::foilgroup{$name . '.text'};
+	    $result .= $item_closetag;
+	    $result .= $item_posttext;
+	    $result .= "\n";	# make the html a bit more readable.
+	}
+
+	$result .= $finalclose;
+
+    } else {
+	#  Not showing the answers, we need to generate the HTML appropriate
+	#  to allowing the student to respond.
+	
+
+    }
+
+    return $result;
+}
+
+
+##
 
 sub displayfoils {
     my ( $target, $answer, $whichfoils, $direction, $bubbles_per_line ) = @_;
@@ -777,48 +859,52 @@
     if ( ( $target ne 'tex' )
         && &Apache::response::show_answer() )
     {
-        if ( $direction eq 'horizontal' ) {
-            if ( $target ne 'tex' ) {
-                $result .= '<table><tr>';
-            }
-        }
-        foreach my $name ( @{$whichfoils} ) {
-            if ( $direction eq 'horizontal' ) {
-                if ( $target ne 'tex' ) { $result .= '<td>'; }
-            }
-            if ( $target ne 'tex' ) {
-                $result .= "<br />";
-            }
-            else {
-                $result .= '\item \vskip -2 mm  ';
-            }
-            if ( $Apache::response::foilgroup{ $name . '.value' } eq 'true' ) {
-                if ( $target ne 'tex' ) {
-                    $result .= &mt('Correct:') . '<b>';
-                }
-                else {
-                    $result .= &mt('Correct:') . ' \textbf{';
-                }
-            }
-            else {
-                $result .= &mt('Incorrect:');
-            }
-            if ( $target eq 'web' ) { $result .= "<label>"; }
-            $result .= $Apache::response::foilgroup{ $name . '.text' };
-            if ( $target eq 'web' ) { $result .= "</label>"; }
-            if ( $Apache::response::foilgroup{ $name . '.value' } eq 'true' ) {
-                if   ( $target ne 'tex' ) { $result .= '</b>'; }
-                else                      { $result .= '}'; }
-            }
-            if ( $direction eq 'horizontal' ) {
-                if ( $target ne 'tex' ) { $result .= '</td>'; }
-            }
-        }
-        if ( $direction eq 'horizontal' ) {
-            if ( $target ne 'tex' ) {
-                $result .= '</tr></table>';
-            }
-        }
+
+	$result = &display_foils_html(
+	    $whichfoils, $target, $direction, $part, $solved, 1);
+
+#        if ( $direction eq 'horizontal' ) {
+#            if ( $target ne 'tex' ) {
+#                $result .= '<table><tr>';
+#            }
+#        }
+#        foreach my $name ( @{$whichfoils} ) {
+#            if ( $direction eq 'horizontal' ) {
+#                if ( $target ne 'tex' ) { $result .= '<td>'; }
+#            }
+#            if ( $target ne 'tex' ) {
+#                $result .= "<br />";
+#            }
+#            else {
+#                $result .= '\item \vskip -2 mm  ';
+#            }
+#            if ( $Apache::response::foilgroup{ $name . '.value' } eq 'true' ) {
+#                if ( $target ne 'tex' ) {
+#                    $result .= &mt('Correct:') . '<b>';
+#                }
+#                else {
+#                    $result .= &mt('Correct:') . ' \textbf{';
+#                }
+#            }
+#            else {
+#                $result .= &mt('Incorrect:');
+#            }
+#            if ( $target eq 'web' ) { $result .= "<label>"; }
+#            $result .= $Apache::response::foilgroup{ $name . '.text' };
+#            if ( $target eq 'web' ) { $result .= "</label>"; }
+#            if ( $Apache::response::foilgroup{ $name . '.value' } eq 'true' ) {
+#                if   ( $target ne 'tex' ) { $result .= '</b>'; }
+#                else                      { $result .= '}'; }
+#            }
+#            if ( $direction eq 'horizontal' ) {
+#                if ( $target ne 'tex' ) { $result .= '</td>'; }
+#            }
+#        }
+#        if ( $direction eq 'horizontal' ) {
+#            if ( $target ne 'tex' ) {
+#                $result .= '</tr></table>';
+#            }
+#        }
     }
     else {
         my @alphabet      = ( 'A' .. 'Z' );




More information about the LON-CAPA-cvs mailing list