File:  [LON-CAPA] / loncom / imspackages / imsexport.pm
Revision 1.1: download - view: text, annotated - select for diffs
Thu Dec 23 14:00:58 2004 UTC (19 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Export to IMS now exports discussion content - uses lonfeedback::listdiscussion().  Modification to export of templated documents (syllabus, aboutme, simplepage etc.) to IMS. Simple problems now converted to standard LON-CAPA problem format before export to IMS. Same routines could be used to dump simple problems to CSTR.

    1: # Copyright Michigan State University Board of Trustees
    2: #
    3: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    4: #
    5: # LON-CAPA is free software; you can redistribute it and/or modify
    6: # it under the terms of the GNU General Public License as published by
    7: # the Free Software Foundation; either version 2 of the License, or
    8: # (at your option) any later version.
    9: #
   10: # LON-CAPA is distributed in the hope that it will be useful,
   11: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   12: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13: # GNU General Public License for more details.
   14: #
   15: # You should have received a copy of the GNU General Public License
   16: # along with LON-CAPA; if not, write to the Free Software
   17: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   18: #
   19: # /home/httpd/html/adm/gpl.txt
   20: #
   21: # http://www.lon-capa.org/
   22: #
   23: 
   24: package Apache::imsexport;
   25: 
   26: use strict;
   27: use Apache::lonnet;
   28: 
   29: sub simpleproblem  {
   30:     my ($symb,$output) = @_;
   31:     my %qparms = &Apache::lonnet::dump('resourcedata',
   32:                   $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
   33:                   $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
   34:                   $ENV{'request.course.id'}.'.'.$symb);
   35:     if ($symb) {
   36:         my $prefix=$ENV{'request.course.id'}.'.'.$symb.'.0.';
   37:         my $qtype=$qparms{$prefix.'questiontype'};
   38:         my $qtext=$qparms{$prefix.'questiontext'};
   39:         my $hint=$qparms{$prefix.'hinttext'};
   40:         my %values = ();
   41:         my %foils = ();
   42:         if (($qtype eq 'radio') || ($qtype eq 'option')) {
   43:             my $maxfoils=$qparms{$prefix.'maxfoils'};
   44:             my $randomize=$qparms{$prefix.'randomize'};
   45:             if ($qtype eq 'option') {
   46:                 my $options=$qparms{$prefix.'options'};
   47:                 %values = &evaloptionhash($options);
   48:                 $$output .= qq|
   49: <problem>
   50:   <optionresponse max="$maxfoils" randomize="$randomize">
   51:     <foilgroup options="$options">
   52: |;
   53:                 for (my $k=0; $k<10; $k++) {
   54:                     my $iter = $k+1;
   55:                     $$output .= '   <foil name="foil'.$k.'" value="'.$qparms{$prefix.'.value.'.$iter}.'"';
   56:                     $$output .= 'location="'.$qparms{$prefix.'.position.'.$iter}.'" ';
   57:                     $$output .= '><startouttext />'.$qparms{$prefix.'.text.'.$iter}.'<endouttext /></foil>'."\n";
   58:                 }
   59:                 chomp($$output);
   60:                 $$output .= qq|
   61:     </foilgroup>
   62: |;
   63:                 if ($hint) {
   64:                     $$output .= '
   65:     <hintgroup>
   66:      <hintpart on="default">
   67:       <startouttext />'.$hint.'<endouttext/>
   68:      </hintpart>
   69:     </hintgroup>';
   70:                 }
   71:                 $$output .= qq|
   72:   </optionresponse>
   73: </problem>
   74: |;
   75:             } else {
   76:                 $$output .= qq|
   77: <problem>
   78:   <radiobuttonresponse max="$maxfoils" randomize="$randomize">
   79:    <foilgroup>
   80: |;
   81:                 for (my $k=0; $k<10; $k++) {
   82:                     my $iter = $k+1;
   83:                     $$output .= '   <foil name="foil'.$k.'" value="'.$qparms{$prefix.'.value.'.$iter}.'"';
   84:                     $$output .= 'location="'.$qparms{$prefix.'.position.'.$iter}.'" ';
   85:                     $$output .= '><startouttext />'.$qparms{$prefix.'.text.'.$iter}.'<endouttext /></foil>'."\n";
   86:                 }
   87:                 chomp($$output);
   88:                 $$output .= qq|
   89:    </foilgroup>
   90: |;
   91:                 if ($hint) {
   92:                     $$output .= '
   93:    <hintgroup>
   94:     <hintpart on="default">
   95:      <startouttext />'.$hint.'<endouttext/>
   96:     </hintpart>
   97:    </hintgroup>';
   98:                 }
   99:                 $$output .= qq|
  100:   </radiobuttonresponse>
  101: </problem>
  102: |;
  103:             }
  104:         } elsif ($qtype eq 'stringanswer') {
  105:             my $stringanswer = $qparms{$prefix.'stringanswer'};
  106:             my $stringtype=$qparms{$prefix.'stringtype'};
  107:             $$output .= qq|
  108: <problem>
  109:   <stringresponse answer="$stringanswer" type="$stringtype">
  110:     <textline>
  111:     </textline>
  112:             |;
  113:             if ($hint) {
  114:                 $$output .= '
  115:    <hintgroup>
  116:     <hintpart on="default">
  117:      <startouttext />'.$hint.'<endouttext/>
  118:     </hintpart>
  119:    </hintgroup>';
  120:             }
  121:             $$output .= qq|
  122:   </stringresponse>
  123: </problem>
  124: |;
  125:         } else {
  126:             $$output .= qq|
  127: <problem>
  128:   <startouttext />$qtext<endouttext />
  129:   <essayresponse>
  130:   <textfield></textfield>
  131:   </essayresponse>
  132: </problem>
  133: |;
  134:         }
  135:     }
  136:     return;
  137: }
  138: 
  139: sub evaloptionhash {
  140:     my $options=shift;
  141:     $options=~s/^\(\'//;
  142:     $options=~s/\'\)$//;
  143:     my %returnhash=();
  144:     foreach (split(/\'\,\'/,$options)) {
  145:         $returnhash{$_}=$_;
  146:     }
  147:     return %returnhash;
  148: }
  149: 
  150: sub external {
  151:     my ($symb,$title) = @_;
  152:     my $output;
  153:     if ($symb =~  m-\.sequence___\d+___ext$-) {
  154:         my $exturl = &Apache::lonnet::escape($1);
  155:         $output = qq|
  156: <html>
  157: <head><title>$title</title>
  158: </head>
  159: <frameset rows="0,*" border="0">
  160: <frame src=''>
  161: <frame src="$exturl" name="external">
  162: </frameset>
  163: </html>
  164:         |;
  165:     }
  166:     return $output;
  167: }
  168: 
  169: sub templatedpage {
  170:     my ($content_type,$timestamp,$count,$uploads,$udom,$uname) = @_;
  171:     my $cdom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
  172:     my $cnum = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};  
  173:     my $output = '
  174: <'.$content_type.'>';
  175:     my %syllabusdata=();
  176:     my %syllabusfields=();
  177:     if ($content_type eq 'syllabus') {
  178:         %syllabusfields=&Apache::lonlocal::texthash(
  179:            'aaa_instructorinfo' => 'Instructor Information',
  180:            'bbb_description'    => 'Course Description',
  181:            'ccc_prereq'         => 'Prerequisites',
  182:            'cdc_classhours'     => 'Class Hours',
  183:            'ddd_officehours'    => 'Office Hours',
  184:            'eee_helproom'       => 'Helproom Hours',
  185:            'efe_projectinfo'    => 'Project Information',
  186:            'fff_examinfo'       => 'Exam Information',
  187:            'fgf_deadlines'      => 'Deadlines',
  188:            'ggg_grading'        => 'Grading Information',
  189:            'hhh_readings'       => 'Readings',
  190:            'iii_coursepack'     => 'Coursepack',
  191:            'jjj_weblinks'       => 'Web Links',
  192:            'kkk_textbook'       => 'Textbook',
  193:            'lll_includeurl'     => 'URLs To Include in Syllabus'
  194:         );
  195:         %syllabusdata = &Apache::lonnet::dump('syllabus',$cdom,$cnum);
  196: 
  197:     } elsif ($content_type eq 'simplepage') {
  198:         %syllabusfields=&Apache::lonlocal::texthash(
  199:            'aaa_title'         => 'Page Title',
  200:            'bbb_content'       => 'Content',
  201:            'ccc_webreferences' => 'Web References'
  202:         );
  203:         %syllabusdata = &Apache::lonnet::dump('smppage_'.$timestamp,$cdom,$cnum);
  204:     } elsif ($content_type eq 'bulletinboard') {
  205:         %syllabusfields=&Apache::lonlocal::texthash(
  206:            'aaa_title'         => 'Topic',
  207:            'bbb_content'       => 'Task',
  208:            'ccc_webreferences' => 'Web References'
  209:         );
  210:         %syllabusdata = &Apache::lonnet::dump('bulletinpage_'.$timestamp,$cdom,$cnum);
  211:     } elsif ($content_type eq 'aboutme') {
  212:         %syllabusdata=&Apache::lonnet::dump('aboutme',$udom,$uname);
  213:         %syllabusfields=&Apache::lonlocal::texthash(
  214:            'aaa_contactinfo'   => 'Contact Information',
  215:            'bbb_aboutme'       => 'About Me',
  216:            'ccc_webreferences' => 'Web References'
  217:         );
  218:         $output .= qq|
  219:   <username>$uname</username>
  220:   <domain>$udom</domain>
  221: |;
  222:     }
  223:     foreach (sort keys %syllabusfields) {
  224:         $output .= qq|
  225: <$_>
  226:  <name>$syllabusfields{$_}</name>
  227:  <value>$syllabusdata{$_}</value>
  228: </$_>|;
  229:     }
  230:     if (defined($syllabusdata{'uploaded.photourl'})) {
  231:         if ($syllabusdata{'uploaded.photourl'} =~  m-^/uploaded/$cdom/$cnum/$content_type/(.+)$-) {
  232:             push @{$$uploads}, $syllabusdata{'uploaded.photourl'};
  233:         }
  234:         $output .= '
  235: <photo>
  236:  <filename>'.$count.'/'.$1.'</filename>
  237: </photo>';
  238:     }
  239:     $output .= '
  240: </'.$content_type.'>';
  241:     return $output;
  242: }
  243: 
  244: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>