#!/usr/bin/perl # assign_resources2classes.pl use constant CLASSES => ( 'ARCH-10311', 'ARCH-20511', 'ARHI-34416', 'BIOS-21202', 'BIOS-28498', 'EE-20242', 'EE-30342', 'MATH-30530', 'MATH-60360', 'MGTE-40590', 'PHYS-83700', 'PHYS-98700', 'POLS-22100', 'POLS-30001', 'THEO-30220', 'THEO-33970' ); use strict; use MyLibrary::Core; MyLibrary::Config->instance( 'your_page' ); # check for input my $class = $ARGV[0]; if ( ! $class ) { print "Usage: $0 [ARCH-10311 ARCH-20511 ARHI-34416 BIOS-21202 BIOS-28498 EE-20242 EE-30342 MATH-30530 MATH-60360 MGTE-40590 PHYS-83700 PHYS-98700 POLS-22100 POLS-30001 THEO-30220 THEO-33970]\n"; exit; } # sanity check my $found = 0; foreach ( CLASSES ) { if ( $class eq $_ ) { $found = 1; last; } } # bad input if ( ! $found ) { print "Usage: $0 [ARCH-10311 ARHI-34416 BIOS-21202 BIOS-28498 EE-20242 EE-30342 MATH-30530 MATH-60360 MGTE-40590 PHYS-83700 PHYS-98700 POLS-22100 POLS-30001 THEO-30220 THEO-33970]\n"; exit; } # get the class and its id my $term = MyLibrary::Term->new( name => $class ); $class = $term->term_name; my $class_id = $term->term_id; # get the ids to associate with the class my $resource_ids; print "Enter a list of resource ID's to associate with $class: "; chop ( $resource_ids = ); while ( $resource_ids =~ / / ) { $resource_ids =~ s/ / /g; } my @resource_ids = split / /, $resource_ids; # process each id foreach my $resource_id ( @resource_ids ) { if ( MyLibrary::Resource->new( id => $resource_id )) { my $resource = MyLibrary::Resource->new( id => $resource_id ); my $title = $resource->name; $resource->related_terms( new => [ $class_id ]); $resource->commit; print "$title has been added as a resource for $class.\n"; } else { print "$resource_id does not point to an existing information resource\n"; } }