File:  [LON-CAPA] / modules / gci / londocsgci.pm
Revision 1.3: download - view: text, annotated - select for diffs
Fri Nov 27 23:48:25 2009 UTC (14 years, 5 months ago) by gci
Branches: MAIN
CVS tags: HEAD
Mandatory problems cannot be deselected
Categories -> Bins
Different work flow

    1: # The LearningOnline Network
    2: # Custom Edit Course Routines for Assembly of Valid Concept Tests from
    3: # Geoscience Concept Inventory. 
    4: #
    5: # $Id: londocsgci.pm,v 1.3 2009/11/27 23:48:25 gci Exp $
    6: #
    7: # Copyright Michigan State University Board of Trustees
    8: #
    9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
   10: #
   11: # LON-CAPA is free software; you can redistribute it and/or modify
   12: # it under the terms of the GNU General Public License as published by
   13: # the Free Software Foundation; either version 2 of the License, or
   14: # (at your option) any later version.
   15: #
   16: # LON-CAPA is distributed in the hope that it will be useful,
   17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19: # GNU General Public License for more details.
   20: #
   21: # You should have received a copy of the GNU General Public License
   22: # along with LON-CAPA; if not, write to the Free Software
   23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   24: #
   25: # /home/httpd/html/adm/gpl.txt
   26: #
   27: # http://www.lon-capa.org/
   28: #
   29: 
   30: 
   31: package Apache::londocsgci;
   32: 
   33: use strict;
   34: 
   35: use Apache::lonnet;
   36: use Apache::loncommon;
   37: use LONCAPA::map();
   38: use Apache::lonindexer;
   39: use Apache::lonlocal;
   40: use LONCAPA qw(:DEFAULT :match);
   41: 
   42: {  #scope variables 
   43:  
   44: my $path;
   45: my $version;
   46: my $reqnum;
   47: my @categories;
   48: my @allprobs;
   49: my %probcat;
   50: my %prereqs;
   51: my @defchosen;
   52: my @chosen;
   53: my %mandatory;
   54: 
   55: sub setdefaults {
   56:    $path='/res/gci/gci';
   57:    $version='GCIv2-1-1';
   58:    $reqnum=15;
   59:    @allprobs=('01','02','03','04','05','06','07',
   60:               '08','10',
   61:               '09',
   62:               '11','12','13','14','15','16','17',
   63:               '18','69',
   64:               '19','20',
   65:               '21','22','23','24','25','26','27','28','29','30',
   66:               '31','32','33','34','35','36','37','38',
   67:               '39A','39B',
   68:               '40',
   69:               '41','42','43','44','45','46','47','48','49','50',
   70:               '51',
   71:               '52','57',
   72:               '53','54','55','56','58',
   73:               '60',
   74:               '61','62','63','64','65','66','67','68','70',
   75:               '71',
   76:               '2004_73');
   77: 
   78:    @categories=('M1','M2','M3','M4',
   79:                 'A','B','C','D','E','F','G','H','I','J','K');
   80:    %probcat =('01' => 'M1','02' => 'M2','03' => 'A' ,'04' => 'A' ,'05' => ''  ,'06' => 'A' ,'07' => 'B' ,'08' => 'B' ,'09' => 'B' ,'10' => 'C' ,
   81:               '11' => ''  ,'12' => 'C' ,'13' => 'C' ,'14' => 'C' ,'15' => 'C' ,'16' => 'C' ,'17' => 'C' ,'18' => 'D' ,'19' => 'D' ,'20' => 'D' ,
   82:               '21' => 'D' ,'22' => 'D' ,'23' => 'D' ,'24' => 'D' ,'25' => 'D' ,'26' => 'E' ,'27' => 'E' ,'28' => 'E' ,'29' => ''  ,'30' => 'E' ,
   83:               '31' => ''  ,'32' => 'F' ,'33' => 'F' ,'34' => 'F' ,'35' => 'F' ,'36' => 'F' ,'37' => 'M3','38' => 'G' ,
   84:               '39A'=> 'G' ,'39B'=> 'G' ,
   85:               '40' => 'G' ,
   86:               '41' => 'G' ,'42' => 'G' ,'43' => 'G' ,'44' => 'G' ,'45' => 'G' ,'46' => 'G' ,'47' => 'H' ,'48' => 'H' ,'49' => 'H' ,'50' => 'H' ,
   87:               '51' => 'H' ,'52' => 'H' ,'53' => 'H' ,'54' => 'I' ,'55' => 'I' ,'56' => 'I' ,'57' => 'I' ,'58' => 'I' ,
   88:               '60' => 'I' ,
   89:               '61' => 'I' ,'62' => 'I' ,'63' => 'J' ,'64' => 'J' ,'65' => 'J' ,'66' => 'K' ,'67' => 'K' ,'68' => 'K' ,'69' => 'K' ,'70' => 'K' ,
   90:               '71' => 'K' ,
   91:               '2004_73' => 'M4');
   92:    %mandatory=('01' => 1 ,'02' => 1,'37' => 1,'2004_73' => 1);
   93:    %prereqs=('10' => '08', '57' => '52', '69' => '18');
   94:    @defchosen=('01','02','03','07','12','18','26','32','37','38','47','54','63','66','2004_73');
   95: }
   96: 
   97: sub checkvalid {
   98:    my %covered=();
   99:    my %chosenproblems=();
  100:    my @errors=();
  101:    my $num=$#chosen+1;
  102:    if ($num<$reqnum) {
  103:       push(@errors,&mt('Test requires at least [_1] items, but has only [_2].',$reqnum,$num)); 
  104:    }
  105:    foreach my $item (@chosen) {
  106:       $chosenproblems{$item}=1;
  107:       $covered{$probcat{$item}}=1;
  108:    }
  109:    foreach my $cat (@categories) {
  110:       unless ($covered{$cat}) {
  111:          push(@errors,&mt('Bin [_1] not covered.',$cat));
  112:       }
  113:    }
  114:    foreach my $item (@chosen) {
  115:        if ($prereqs{$item}) {
  116:           unless ($chosenproblems{$prereqs{$item}}) {
  117:              push(@errors,&mt('Problem [_1] requires problem [_2].',$item,$prereqs{$item}));
  118:           }
  119:        }
  120:    }
  121:    return @errors;
  122: }
  123: 
  124: sub fullurl {
  125:    my ($item)=@_;
  126:    unless ($item=~/\_/) { $item='_'.$item; }
  127:    return $path.'/'.$version.'/GCI'.$item.'.problem';
  128: }
  129: 
  130: sub validcheck {
  131:    my ($r)=@_;
  132:    my @errors=&checkvalid();
  133:    if ($#errors>-1) {
  134:       $r->print('<span class="LC_error">'.&mt('Your test is not yet valid.').'</span><p>'.&mt('The following issues must be addressed before you can use the test:').'<ul>');
  135:       foreach my $message (@errors) {
  136:          $r->print('<li>'.$message.'</li>');
  137:       }
  138:       $r->print('</ul></p>');
  139:       return 0;
  140:    }
  141:    return 1;
  142: }
  143: 
  144: sub listresources {
  145:    my ($r)=@_;
  146:    if ((!&validcheck($r)) || ($env{'form.editmyown'})) {
  147:       &editor($r);
  148:    } else {
  149:       $r->print('<p><form name="choices" method="post">');
  150:       $r->print('<input type="submit" name="editmyown" value="'.&mt('Create Your Own Test').'" />');
  151:       $r->print('</form></p><p><form name="defaulting" method="post">');
  152:       $r->print('<input type="hidden" name="phase" value="storemap" />');
  153:       foreach my $item (@defchosen) {
  154:          $r->print('<input type="hidden" name="item'.$item.'" value="checked"');
  155:       }
  156:       $r->print('<input type="submit" name="defchosen" value="'.&mt('Let WebCenter Create a Test for You').'" />');
  157:       $r->print('</form><p>');
  158:    }
  159: }
  160: 
  161: sub editor {
  162:    my ($r)=@_;
  163:    my %chosen=();
  164:    foreach my $item (@chosen) {
  165:       $chosen{$item}=1;
  166:    }
  167:    $r->print('<form name="selecteditems" method="post" action="/adm/coursedocs">');
  168:    $r->print('<p>'.&mt('You may select test items from the list below and then press "Store Problem Selection" at the bottom of the screen.').'</p>');
  169:    $r->print('<p>'.&mt('Tests should have at least one item from each bin and [_1] items total.',$reqnum).'</p>'); 
  170:    $r->print(&Apache::loncommon::start_data_table().
  171:              &Apache::loncommon::start_data_table_header_row().
  172:              '<th>'.&mt('Select').'</th><th>'.&mt('Problem').'</th><th>'.&mt('Bin').'</th><th>'.&mt('Preview').'</th>'.
  173:              &Apache::loncommon::end_data_table_header_row());
  174:    foreach my $item (@allprobs) {
  175:       $r->print(&Apache::loncommon::start_data_table_row());
  176:       $r->print('<td><font size="+3">');
  177:       if ($mandatory{$item}) {
  178:          $r->print('<input type="hidden" name="item'.$item.'" value="checked"');
  179:       } else {
  180:          $r->print('<input type="checkbox" name="item'.$item.'"');
  181:          if ($chosen{$item}) { $r->print(' checked="checked"'); }
  182:       }
  183:       $r->print(' /></font></td>');
  184:       $r->print('<td><font size="+3">'.$item.'</font></td><td><font size="+3">'.$probcat{$item}.'</font></td>');
  185:       my $output=&Apache::lonindexer::showpreview(&fullurl($item));
  186:       $r->print('<td> '.($output eq '' ? '&nbsp;':$output)." </td>\n");
  187: 
  188:       $r->print( &Apache::loncommon::end_data_table_row());
  189:    }
  190:    $r->print(&Apache::loncommon::end_data_table());
  191:    $r->print('<input type="hidden" name="phase" value="storemap" />');
  192:    $r->print('<input type="submit" value="'.&mt('Store Problem Selection').'" /></form>');
  193: }
  194: 
  195: sub evaluate {
  196:    if ($env{'form.phase'} eq 'storemap') {
  197:       @chosen=();
  198:       foreach my $item (@allprobs) {
  199:          if ($env{'form.item'.$item}) {
  200:             push(@chosen,$item);
  201:          }
  202:       }
  203:    }
  204: }
  205: 
  206: sub mapread_gci {
  207:     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
  208:     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
  209:     return
  210:       &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/default.sequence');
  211: }
  212: 
  213: sub storemap_gci {
  214:     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
  215:     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
  216:     my ($outtext,$errtext)=
  217:       &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/default.sequence',1);
  218:     if ($errtext) { return ($errtext,2); }
  219:     return ($errtext,0);
  220: }
  221: 
  222: sub chosen_to_map {
  223:    my %chosenproblems=();
  224:    foreach my $item (@chosen) {
  225:       $chosenproblems{$item}=1;
  226:    }
  227:    @LONCAPA::map::order=();
  228:    @LONCAPA::map::resources=();
  229:    for (my $idx=0;$idx<=$#allprobs;$idx++) {
  230:        my $residx=$idx+1;
  231:        if ($chosenproblems{$allprobs[$idx]}) {
  232:           push(@LONCAPA::map::order,$residx);
  233:           my $url  = &LONCAPA::map::qtunescape(&fullurl($allprobs[$idx]));
  234: 	  my $name = &LONCAPA::map::qtunescape('Problem '.$allprobs[$idx]);
  235: 	  $LONCAPA::map::resources[$residx]=join(':', ($name, $url, 'false', 'normal', 'res'));
  236:        }
  237:     }
  238: }
  239: 
  240: sub map_to_chosen {
  241:     @chosen=();
  242:     foreach my $idx (@LONCAPA::map::order) {
  243:        push(@chosen,$allprobs[$idx-1]);
  244:     }
  245: }
  246: 
  247: sub store {
  248:    my ($r)=@_;
  249:    my @errors=&checkvalid();
  250:    if ($#errors>1) { return; }
  251:    &chosen_to_map();
  252:    &storemap_gci();
  253:    if ($env{'form.phase'} eq 'storemap') {
  254:       unless ($#errors>-1) {
  255:          $r->print('<p>'.&mt('You have successfully assembled a valid test.').
  256:                 '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
  257:                 '<input type="hidden" name="orgurl" value="/adm/navmaps" /><input type="hidden" name="selectrole" value="1" />'.
  258:                 '<input type="hidden" name="'.$env{'request.role'}.'" value="1" /><input type="submit" value="'.
  259:                  &mt('Activate Current Test').'" /></form></p>');
  260:       }
  261:    }
  262: }
  263: 
  264: sub load {
  265:    &mapread_gci();
  266:    &map_to_chosen();
  267:    my @errors=&checkvalid();
  268:    if ($#errors>1) { @chosen=@defchosen; }
  269: }
  270: 
  271: } #end scope variables
  272: 
  273: 1;
  274: __END__
  275: 

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