--- modules/gci/londocsgci.pm 2009/11/27 23:48:25 1.3 +++ modules/gci/londocsgci.pm 2010/11/09 01:19:04 1.14 @@ -2,7 +2,7 @@ # Custom Edit Course Routines for Assembly of Valid Concept Tests from # Geoscience Concept Inventory. # -# $Id: londocsgci.pm,v 1.3 2009/11/27 23:48:25 gci Exp $ +# $Id: londocsgci.pm,v 1.14 2010/11/09 01:19:04 gci Exp $ # # Copyright Michigan State University Board of Trustees # @@ -44,26 +44,33 @@ use LONCAPA qw(:DEFAULT :match); my $path; my $version; my $reqnum; +my @mandcats; +my @bincats; my @categories; my @allprobs; my %probcat; my %prereqs; +my %revreqs; my @defchosen; my @chosen; +my @mandprobs; +my @bins; +my @optional; my %mandatory; +my @development; sub setdefaults { $path='/res/gci/gci'; $version='GCIv2-1-1'; $reqnum=15; - @allprobs=('01','02','03','04','05','06','07', + @allprobs=('01','02','37','2004_73','03','04','05','06','07', '08','10', '09', '11','12','13','14','15','16','17', '18','69', '19','20', '21','22','23','24','25','26','27','28','29','30', - '31','32','33','34','35','36','37','38', + '31','32','33','34','35','36','38', '39A','39B', '40', '41','42','43','44','45','46','47','48','49','50', @@ -72,26 +79,43 @@ sub setdefaults { '53','54','55','56','58', '60', '61','62','63','64','65','66','67','68','70', - '71', - '2004_73'); - - @categories=('M1','M2','M3','M4', - 'A','B','C','D','E','F','G','H','I','J','K'); - %probcat =('01' => 'M1','02' => 'M2','03' => 'A' ,'04' => 'A' ,'05' => '' ,'06' => 'A' ,'07' => 'B' ,'08' => 'B' ,'09' => 'B' ,'10' => 'C' , - '11' => '' ,'12' => 'C' ,'13' => 'C' ,'14' => 'C' ,'15' => 'C' ,'16' => 'C' ,'17' => 'C' ,'18' => 'D' ,'19' => 'D' ,'20' => 'D' , + '71'); + @bins = ( ['03','04','06'], + ['07','08','09'], + ['10','12','13','14','15','16','17'], + ['18','19','20','21','22','23','24','25'], + ['26','27','28','30'], + ['32','33','34','35','36'], + ['38','39A','39B','40','41','42','43','44','45','46'], + ['47','48','49','50','51','52','53'], + ['54','55','56','57','58','60','61','62'], + ['63','64','65'], + ['66','67','68','69','70','71']); + @optional = ('05','11','29','31'); + @mandcats = ('M1','M2','M3','M4'); + @bincats = ('A','B','C','D','E','F','G','H','I','J','K'); + @categories=(@mandcats,@bincats); + %probcat =('01' => 'M1' ,'02' => 'M2' ,'37' => 'M3' ,'2004_73' => 'M4' , + '03' => 'A' ,'04' => 'A','05' => '' ,'06' => 'A' ,'07' => 'B' , + '08' => 'B' ,'09' => 'B' ,'10' => 'C' ,'11' => '' ,'12' => 'C' , + '13' => 'C' ,'14' => 'C' ,'15' => 'C' ,'16' => 'C' ,'17' => 'C' ,'18' => 'D' ,'19' => 'D' ,'20' => 'D' , '21' => 'D' ,'22' => 'D' ,'23' => 'D' ,'24' => 'D' ,'25' => 'D' ,'26' => 'E' ,'27' => 'E' ,'28' => 'E' ,'29' => '' ,'30' => 'E' , - '31' => '' ,'32' => 'F' ,'33' => 'F' ,'34' => 'F' ,'35' => 'F' ,'36' => 'F' ,'37' => 'M3','38' => 'G' , + '31' => '' ,'32' => 'F' ,'33' => 'F' ,'34' => 'F' ,'35' => 'F' ,'36' => 'F' ,'38' => 'G' , '39A'=> 'G' ,'39B'=> 'G' , '40' => 'G' , '41' => 'G' ,'42' => 'G' ,'43' => 'G' ,'44' => 'G' ,'45' => 'G' ,'46' => 'G' ,'47' => 'H' ,'48' => 'H' ,'49' => 'H' ,'50' => 'H' , '51' => 'H' ,'52' => 'H' ,'53' => 'H' ,'54' => 'I' ,'55' => 'I' ,'56' => 'I' ,'57' => 'I' ,'58' => 'I' , '60' => 'I' , '61' => 'I' ,'62' => 'I' ,'63' => 'J' ,'64' => 'J' ,'65' => 'J' ,'66' => 'K' ,'67' => 'K' ,'68' => 'K' ,'69' => 'K' ,'70' => 'K' , - '71' => 'K' , - '2004_73' => 'M4'); - %mandatory=('01' => 1 ,'02' => 1,'37' => 1,'2004_73' => 1); - %prereqs=('10' => '08', '57' => '52', '69' => '18'); - @defchosen=('01','02','03','07','12','18','26','32','37','38','47','54','63','66','2004_73'); + '71' => 'K'); + %mandatory=('01' => 1 ,'02' => 1,'37' => 1, '2004_73' => 1); + @mandprobs = ('01','02','37','2004_73'); + %prereqs=('10' => '08', '57' => '52', '69' => '18'); + foreach my $item (keys(%prereqs)) { + $revreqs{$prereqs{$item}} = $item; + } + @defchosen=('01','02','03','07','12','18','26','32','37','38','47','54','63','66','2004_73'); + @development = ('001','002','003','004','005','006','007','008','009','010','011','012','013','014','015','016','017','018','019','020','021','022'); } sub checkvalid { @@ -114,7 +138,11 @@ sub checkvalid { foreach my $item (@chosen) { if ($prereqs{$item}) { unless ($chosenproblems{$prereqs{$item}}) { - push(@errors,&mt('Problem [_1] requires problem [_2].',$item,$prereqs{$item})); + my $url = &fullurl($item); + my $title = &Apache::lonnet::metadata($url,'title'); + my $prerequrl = &fullurl($prereqs{$item}); + my $prereqtitle = &Apache::lonnet::metadata($prerequrl,'title'); + push(@errors,&mt('[_1] requires [_2].',"'$title'","'$prereqtitle'")); } } } @@ -122,11 +150,21 @@ sub checkvalid { } sub fullurl { - my ($item)=@_; + my ($item,$catname)=@_; unless ($item=~/\_/) { $item='_'.$item; } + if ($catname eq 'development') { + return $path.'/pilot/pilot'.$item.'.problem'; + } return $path.'/'.$version.'/GCI'.$item.'.problem'; } +sub item_from_url { + my ($url)=@_; + if ($url =~ m{\Q$path\E/\Q$version\E/GCI_?([^.]+)\.problem$}) { + return $1; + } +} + sub validcheck { my ($r)=@_; my @errors=&checkvalid(); @@ -142,54 +180,210 @@ sub validcheck { } sub listresources { - my ($r)=@_; - if ((!&validcheck($r)) || ($env{'form.editmyown'})) { - &editor($r); + my ($r,$context,$cdom,$cnum)=@_; + my $numchosen = scalar(@chosen); + my $multipart = 0; + my $composites; + if ($numchosen > 0) { + foreach my $key (keys(%prereqs)) { + if (grep(/^\Q$key\E/,@chosen)) { + $multipart ++; + $numchosen --; + } + } + if ($multipart) { + $composites = &mt(' (of which [quant,_1,is a combination question,are combination questions] in which students select both an answer, and the reasoning used).',$multipart).'
'; + } else { + $composites = '. '; + } + } + unless ($numchosen > 0) { + $r->print('

'.&mt('Create a Concept Test').'

'. + '

'.&mt('Choose how the test should be built:').'
'. + '

'. + '
'. + '

'. + ''. + '

'); + return; + } + if ((!&validcheck($r)) || ($env{'form.concepttest'} eq 'editmyown')) { + &editor($r,$context,$cdom,$cnum); } else { - $r->print('

'); - $r->print(''); - $r->print('

'); - $r->print(''); - foreach my $item (@defchosen) { - $r->print('print('

'.&mt('This course contains a valid concept test which includes [quant,_1,question]',$numchosen).$composites.''.&mt('Display Contents').'
'); + } + if ($numsub > 0) { + $r->print(&mt('As there are existing student submissions, modification of the [_1]contents[_2] of the Concept Test will result in loss of student performance data, and is [_3]not[_4] permitted.','','','','').'
'.&mt('Modification of open and close dates [_1]is[_2] permitted.','','').'

'); + } else { + $r->print('
'.&mt('Modify Test').''. + &mt('Currently no student submissions have been recorded, so you may modify the contents of the Concept Test.'). + '
'. + ''. + '

'); } - $r->print(''); - $r->print('

'); + my ($crsparms,$ineffect,$parmlev) = ¤t_parms($cdom,$cnum); + my $formname = 'datesform'; + my $datebutton = &mt('Save'); + my $startform = + &Apache::lonhtmlcommon::date_setter($formname,'opendate', + $crsparms->{'opendate'}); + my $endform = + &Apache::lonhtmlcommon::date_setter($formname,'duedate', + $crsparms->{'duedate'}); + $r->print('

'.&mt('Test Availability').''. + &mt('Open and close dates for test items for the concept test are currently set as follows:'). + '
'. + '
'. + &Apache::lonhtmlcommon::start_pick_box(). + &Apache::lonhtmlcommon::row_title(&mt('Open date')). + $startform. + &Apache::lonhtmlcommon::row_closure(1). + &Apache::lonhtmlcommon::row_title(&mt('Close date')). + $endform. + &Apache::lonhtmlcommon::row_closure(1). + &Apache::lonhtmlcommon::end_pick_box().'
'. + ''. + ''. + '

'); } } sub editor { - my ($r)=@_; - my %chosen=(); - foreach my $item (@chosen) { - $chosen{$item}=1; - } - $r->print('
'); - $r->print('

'.&mt('You may select test items from the list below and then press "Store Problem Selection" at the bottom of the screen.').'

'); - $r->print('

'.&mt('Tests should have at least one item from each bin and [_1] items total.',$reqnum).'

'); - $r->print(&Apache::loncommon::start_data_table(). - &Apache::loncommon::start_data_table_header_row(). - ''.&mt('Select').''.&mt('Problem').''.&mt('Bin').''.&mt('Preview').''. - &Apache::loncommon::end_data_table_header_row()); - foreach my $item (@allprobs) { - $r->print(&Apache::loncommon::start_data_table_row()); - $r->print(''); - if ($mandatory{$item}) { - $r->print('print('print(' checked="checked"'); } - } - $r->print(' />'); - $r->print(''.$item.''.$probcat{$item}.''); - my $output=&Apache::lonindexer::showpreview(&fullurl($item)); - $r->print(' '.($output eq '' ? ' ':$output)." \n"); - - $r->print( &Apache::loncommon::end_data_table_row()); - } - $r->print(&Apache::loncommon::end_data_table()); - $r->print(''); - $r->print('
'); + my ($r,$context,$cdom,$cnum)=@_; + my %chosenitems=(); + my $havedev = 0; + foreach my $item (@chosen) { + $chosenitems{$item}=1; + } + my @devitems = &get_development_questions($cdom,$cnum); + &Apache::lonnet::appenv({'request.gcicontext' => 'buildtest'}); + $r->print('
'); + $r->print(&mt('Select test items from the numbered bins below and then press [_1]"Store Problem Selection"[_2] at the bottom of the page.','','').'
'); + $r->print(''); + my $mandleg = &mt('Mandatory Questions'); + $r->print(&display_questions(\@mandprobs,'mandatory',$mandleg,\%chosenitems)); + for (my $i=0; $i<@bins; $i++) { + my $num = $i+1; + my $legend = &mt('Bin [_1]',$num); + my $catname = 'bin'.$i; + $r->print(&display_questions($bins[$i],$catname,$legend,\%chosenitems)); + } + my $optleg = &mt('Optional Questions'); + $r->print(&display_questions(\@optional,'optional',$optleg,\%chosenitems)); + my $devleg = &mt('Development Questions'); + $r->print(&display_questions(\@devitems,'development',$devleg,\%chosenitems)); + $r->print(''. + ''. + ''. + ''. + '
'); + &Apache::lonnet::delenv('request.gcicontext'); +} + +sub display_questions { + my ($questions,$catname,$catlegend,$chosenitems) = @_; + return unless((ref($questions) eq 'ARRAY') && (ref($chosenitems) eq 'HASH')); + my $total = 0; + foreach my $item (@{$questions}) { + if ($chosenitems->{$item}) { + $total ++; + } + } + my $fieldid = 'GCI_'.$catname.'_q'; + my $titleid = 'GCI_'.$catname.'_t'; + my $countid = 'GCI_'.$catname.'_count'; + my $output = '
'; + my %fixed = ( + mandatory => 4, + development => 2, + ); + if (($catname eq 'mandatory') || ($catname eq 'development')) { + $output .= ''.&mt('[_1] [_2] selected automatically',$catlegend, + '').''; + } else { + $output .= ''.&mt('[_1]: currently [_2] selected',$catlegend, + '').''; + } + $output .= ''. + ''. + &mt('Show').' ...
'. + '