Annotation of modules/gci/londocsgci.pm, revision 1.2
1.1 gci 1: # The LearningOnline Network
2: # Custom Edit Course Routines for Assembly of Valid Concept Tests from
3: # Geoscience Concept Inventory.
4: #
1.2 ! gci 5: # $Id: londocsgci.pm,v 1.1 2009/09/24 22:18:52 gci Exp $
1.1 gci 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:
54: sub setdefaults {
55: $path='/res/gci/gci';
56: $version='GCIv2-1-1';
57: $reqnum=15;
58: @allprobs=('01','02','03','04','05','06','07',
59: '08','10',
60: '09',
61: '11','12','13','14','15','16','17',
62: '18','69',
63: '19','20',
64: '21','22','23','24','25','26','27','28','29','30',
65: '31','32','33','34','35','36','37','38',
66: '39A','39B',
67: '40',
68: '41','42','43','44','45','46','47','48','49','50',
69: '51',
70: '52','57',
71: '53','54','55','56','58',
72: '60',
73: '61','62','63','64','65','66','67','68','70',
74: '71',
75: '2004_73');
76:
77: @categories=('M1','M2','M3','M4',
78: 'A','B','C','D','E','F','G','H','I','J','K');
79: %probcat =('01' => 'M1','02' => 'M2','03' => 'A' ,'04' => 'A' ,'05' => '' ,'06' => 'A' ,'07' => 'B' ,'08' => 'B' ,'09' => 'B' ,'10' => 'C' ,
80: '11' => '' ,'12' => 'C' ,'13' => 'C' ,'14' => 'C' ,'15' => 'C' ,'16' => 'C' ,'17' => 'C' ,'18' => 'D' ,'19' => 'D' ,'20' => 'D' ,
81: '21' => 'D' ,'22' => 'D' ,'23' => 'D' ,'24' => 'D' ,'25' => 'D' ,'26' => 'E' ,'27' => 'E' ,'28' => 'E' ,'29' => '' ,'30' => 'E' ,
82: '31' => '' ,'32' => 'F' ,'33' => 'F' ,'34' => 'F' ,'35' => 'F' ,'36' => 'F' ,'37' => 'M3','38' => 'G' ,
83: '39A'=> 'G' ,'39B'=> 'G' ,
84: '40' => 'G' ,
85: '41' => 'G' ,'42' => 'G' ,'43' => 'G' ,'44' => 'G' ,'45' => 'G' ,'46' => 'G' ,'47' => 'H' ,'48' => 'H' ,'49' => 'H' ,'50' => 'H' ,
86: '51' => 'H' ,'52' => 'H' ,'53' => 'H' ,'54' => 'I' ,'55' => 'I' ,'56' => 'I' ,'57' => 'I' ,'58' => 'I' ,
87: '60' => 'I' ,
88: '61' => 'I' ,'62' => 'I' ,'63' => 'J' ,'64' => 'J' ,'65' => 'J' ,'66' => 'K' ,'67' => 'K' ,'68' => 'K' ,'69' => 'K' ,'70' => 'K' ,
89: '71' => 'K' ,
90: '2004_73' => 'M4');
91: %prereqs=('10' => '08', '57' => '52', '69' => '18');
92: @defchosen=('01','02','03','07','12','18','26','32','37','38','47','54','63','66','2004_73');
93: }
94:
95: sub checkvalid {
96: my %covered=();
97: my %chosenproblems=();
98: my @errors=();
99: my $num=$#chosen+1;
100: if ($num<$reqnum) {
101: push(@errors,&mt('Test requires at least [_1] items, but has only [_2].',$reqnum,$num));
102: }
103: foreach my $item (@chosen) {
104: $chosenproblems{$item}=1;
105: $covered{$probcat{$item}}=1;
106: }
107: foreach my $cat (@categories) {
108: unless ($covered{$cat}) {
109: push(@errors,&mt('Category [_1] not covered.',$cat));
110: }
111: }
112: foreach my $item (@chosen) {
113: if ($prereqs{$item}) {
114: unless ($chosenproblems{$prereqs{$item}}) {
115: push(@errors,&mt('Problem [_1] requires problem [_2].',$item,$prereqs{$item}));
116: }
117: }
118: }
119: return @errors;
120: }
121:
122: sub fullurl {
123: my ($item)=@_;
124: unless ($item=~/\_/) { $item='_'.$item; }
125: return $path.'/'.$version.'/GCI'.$item.'.problem';
126: }
127:
128: sub listresources {
129: my ($r)=@_;
130: my @errors=&checkvalid();
131: if ($#errors>-1) {
132: $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>');
133: foreach my $message (@errors) {
134: $r->print('<li>'.$message.'</li>');
135: }
136: $r->print('</ul></p>');
137: }
138: my %chosen=();
139: foreach my $item (@chosen) {
140: $chosen{$item}=1;
141: }
1.2 ! gci 142: $r->print('<form name="selecteditems" method="post" action="/adm/coursedocs">');
1.1 gci 143: $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>');
144: $r->print(&Apache::loncommon::start_data_table().
145: &Apache::loncommon::start_data_table_header_row().
146: '<th>'.&mt('Select').'</th><th>'.&mt('Problem').'</th><th>'.&mt('Category').'</th><th>'.&mt('Preview').'</th>'.
147: &Apache::loncommon::end_data_table_header_row());
148: foreach my $item (@allprobs) {
149: $r->print(&Apache::loncommon::start_data_table_row());
150: $r->print('<td><font size="+3">');
151: $r->print('<input type="checkbox" name="item'.$item.'"');
152: if ($chosen{$item}) { $r->print(' checked="checked"'); }
153: $r->print(' /></font></td>');
154: $r->print('<td><font size="+3">'.$item.'</font></td><td><font size="+3">'.$probcat{$item}.'</font></td>');
155: my $output=&Apache::lonindexer::showpreview(&fullurl($item));
156: $r->print('<td> '.($output eq '' ? ' ':$output)." </td>\n");
157:
158: $r->print( &Apache::loncommon::end_data_table_row());
159: }
160: $r->print(&Apache::loncommon::end_data_table());
161: $r->print('<input type="hidden" name="phase" value="storemap" />');
162: $r->print('<input type="submit" value="'.&mt('Store Problem Selection').'" /></form>');
163: }
164:
165: sub evaluate {
166: if ($env{'form.phase'} eq 'storemap') {
167: @chosen=();
168: foreach my $item (@allprobs) {
169: if ($env{'form.item'.$item}) {
170: push(@chosen,$item);
171: }
172: }
173: }
174: }
175:
176: sub mapread_gci {
177: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
178: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
179: return
180: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/default.sequence');
181: }
182:
183: sub storemap_gci {
184: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
185: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
186: my ($outtext,$errtext)=
187: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/default.sequence',1);
188: if ($errtext) { return ($errtext,2); }
189: return ($errtext,0);
190: }
191:
192: sub chosen_to_map {
193: my %chosenproblems=();
194: foreach my $item (@chosen) {
195: $chosenproblems{$item}=1;
196: }
197: @LONCAPA::map::order=();
198: @LONCAPA::map::resources=();
199: for (my $idx=0;$idx<=$#allprobs;$idx++) {
200: my $residx=$idx+1;
201: if ($chosenproblems{$allprobs[$idx]}) {
202: push(@LONCAPA::map::order,$residx);
203: my $url = &LONCAPA::map::qtunescape(&fullurl($allprobs[$idx]));
204: my $name = &LONCAPA::map::qtunescape('Problem '.$allprobs[$idx]);
205: $LONCAPA::map::resources[$residx]=join(':', ($name, $url, 'false', 'normal', 'res'));
206: }
207: }
208: }
209:
210: sub map_to_chosen {
211: @chosen=();
212: foreach my $idx (@LONCAPA::map::order) {
213: push(@chosen,$allprobs[$idx-1]);
214: }
215: }
216:
217: sub store {
218: my ($r)=@_;
219: my @errors=&checkvalid();
220: if ($#errors>1) { return; }
221: &chosen_to_map();
222: &storemap_gci();
223: unless ($#errors>-1) {
224: $r->print('<p>'.&mt('You have successfully assembled a valid test.').
225: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
226: '<input type="hidden" name="orgurl" value="/adm/navmaps" /><input type="hidden" name="selectrole" value="1" />'.
227: '<input type="hidden" name="'.$env{'request.role'}.'" value="1" /><input type="submit" value="'.
228: &mt('Activate Current Test').'" /></form></p>');
229: }
230: }
231:
232: sub load {
233: &mapread_gci();
234: &map_to_chosen();
235: my @errors=&checkvalid();
236: if ($#errors>1) { @chosen=@defchosen; }
237: }
238:
239: } #end scope variables
240:
241: 1;
242: __END__
243:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>