Created
November 11, 2009 21:09
-
-
Save preaction/232298 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 [email protected] | |
------------------------------------------------------------------- | |
=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