[system] / branches / gage_dev / webwork2 / lib / WeBWorK / Utils / CourseManagement.pm Repository:
ViewVC logotype

Diff of /branches/gage_dev/webwork2/lib/WeBWorK/Utils/CourseManagement.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2124 Revision 2148
1################################################################################ 1################################################################################
2# WeBWorK Online Homework Delivery System 2# WeBWorK Online Homework Delivery System
3# Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ 3# Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/
4# $CVSHeader: webwork-modperl/lib/WeBWorK/Utils/CourseManagement.pm,v 1.8 2004/05/13 21:14:56 sh002i Exp $ 4# $CVSHeader: webwork-modperl/lib/WeBWorK/Utils/CourseManagement.pm,v 1.9 2004/05/17 16:41:07 jj Exp $
5# 5#
6# This program is free software; you can redistribute it and/or modify it under 6# This program is free software; you can redistribute it and/or modify it under
7# the terms of either: (a) the GNU General Public License as published by the 7# the terms of either: (a) the GNU General Public License as published by the
8# Free Software Foundation; either version 2, or (at your option) any later 8# Free Software Foundation; either version 2, or (at your option) any later
9# version, or (b) the "Artistic License" which comes with this package. 9# version, or (b) the "Artistic License" which comes with this package.
26use strict; 26use strict;
27use warnings; 27use warnings;
28use Carp; 28use Carp;
29use DBI; 29use DBI;
30use File::Path qw(rmtree); 30use File::Path qw(rmtree);
31use WeBWorK::CourseEnvironment;
31use WeBWorK::Utils qw(dequote runtime_use undefstr readDirectory); 32use WeBWorK::Utils qw(dequote runtime_use undefstr readDirectory);
32 33
33our @EXPORT = (); 34our @EXPORT = ();
34our @EXPORT_OK = qw( 35our @EXPORT_OK = qw(
35 addCourse 36 addCourse
55 56
56=over 57=over
57 58
58=item addCourse(%options) 59=item addCourse(%options)
59 60
60Options must contain: 61%options must contain:
61 62
62 courseID => $courseID, 63 courseID => $courseID,
63 ce => $ce, 64 ce => $ce,
64 courseOptions => $courseOptions, 65 courseOptions => $courseOptions,
65 dbOptions => $dbOptions, 66 dbOptions => $dbOptions,
66 users => $users 67 users => $users
68
69%options may contain:
70
71 templatesFrom => $templatesCourseID,
67 72
68Create a new course named $courseID. 73Create a new course named $courseID.
69 74
70$ce is a WeBWorK::CourseEnvironment object that describes the new course's 75$ce is a WeBWorK::CourseEnvironment object that describes the new course's
71environment. 76environment.
106 111
107 $users = [ $User, $Password, $PermissionLevel ] 112 $users = [ $User, $Password, $PermissionLevel ]
108 113
109These users are added to the course. 114These users are added to the course.
110 115
116$templatesCourseID indicates the ID of a course from which the contents of the
117templates directory will be copied to the new course.
118
111=cut 119=cut
112 120
113sub addCourse { 121sub addCourse {
114 my (%options) = @_; 122 my (%options) = @_;
115 123
190 my $courseEnvFile = $ce->{courseFiles}->{environment}; 198 my $courseEnvFile = $ce->{courseFiles}->{environment};
191 open my $fh, ">", $courseEnvFile 199 open my $fh, ">", $courseEnvFile
192 or die "failed to open $courseEnvFile for writing.\n"; 200 or die "failed to open $courseEnvFile for writing.\n";
193 writeCourseConf($fh, $ce, %courseOptions); 201 writeCourseConf($fh, $ce, %courseOptions);
194 close $fh; 202 close $fh;
203
204 ##### step 5: copy templates #####
205
206 if (exists $options{templatesFrom}) {
207 my $sourceCourse = $options{templatesFrom};
208 my $sourceCE = new WeBWorK::CourseEnvironment(
209 $ce->{webworkDirs}->{root},
210 $ce->{webworkURLs}->{root},
211 $ce->{pg}->{directories}->{root},
212 $sourceCourse,
213 );
214 my $sourceDir = $sourceCE->{courseDirs}->{templates};
215
216 if (-d $sourceDir) {
217 my $destDir = $ce->{courseDirs}->{templates};
218 my $errno = system "/bin/cp -r $sourceDir/* $destDir";
219 if ($errno) {
220 warn "Failed to copy templates from course '$sourceCourse' (errno=$errno): $!\n";
221 }
222 } else {
223 warn "Failed to copy templates from course '$sourceCourse': templates directory '$sourceDir' does not exist.\n";
224 }
225 }
226
195} 227}
196 228
197=item renameCourse($webworkRoot, $oldCourseID, $newCourseID) 229=item renameCourse($webworkRoot, $oldCourseID, $newCourseID)
198 230
199Rename the course named $oldCourseID to $newCourseID. 231Rename the course named $oldCourseID to $newCourseID.

Legend:
Removed from v.2124  
changed lines
  Added in v.2148

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9