Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package WebGUI::Form::AlumniCountry;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2006 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use base 'WebGUI::Form::SelectBox';
use Tie::IxHash;
use WebGUI::International;
=head1 NAME
Package WebGUI::Form::AlumniCountry
=head1 DESCRIPTION
Creates a country chooser control, specific to the Alumni site. Based on the Country form field type.
=head1 SEE ALSO
This is a subclass of WebGUI::Form::SelectBox.
=head1 METHODS
The following methods are specifically available from this class. Check the superclass for additional methods.
=cut
#-------------------------------------------------------------------
=head2 definition ( [ additionalTerms ] )
See the super class for additional details.
=head3 additionalTerms
The following additional parameters have been added via this sub class.
=head4 name
The identifier for this field. Defaults to "country".
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift || [];
my $i18n = WebGUI::International->new($session, 'Form_AlumniCountry');
push(@{$definition}, {
formName=>{
defaultValue=>$i18n->get('formName')
},
defaultValue=>{
defaultValue=>undef
},
defaultText=>{
defaultValue=>$i18n->echo("Please Select")
},
dbDataType => {
defaultValue => "VARCHAR(22) BINARY",
},
});
return $class->SUPER::definition($session, $definition);
}
#----------------------------------------------------------------------------
=head2 getName
Get the name of this form control
=cut
sub getName {
my $self = shift;
my $session = shift;
my $i18n = WebGUI::International->new($session, 'Form_AlumniCountry');
return $i18n->get( "formName" );
}
#-------------------------------------------------------------------
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
my $session = $self->session;
my $tie_obj = tie my %countries, "Tie::IxHash";
%countries = (
"" => $self->get("defaultText"),
%{$session->db->buildHashRef(qq{
select code, name
from AlumniCountries
JOIN Alumni_RegionCountries
ON code=countryCode
WHERE regionId IS NOT NULL
order by name
})},
);
my $us =$countries{'US'};
$tie_obj->Delete('US');
$tie_obj->Splice(1, 0, 'US',$us);
$self->set('options', \%countries);
return $self;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.