Implement RFE "Non Required Fields on User Registration". Associated upgrade.
Minor streamlining of profile field listing methods. WebGUI::Operation::Profile::getRequiredProfileFields is now deprecated, because it's specific enough to be not significantly more useful than WebGUI::ProfileField::getRequiredFields, and because with this change nothing in core uses it anymore.
This commit is contained in:
parent
2843dd195b
commit
ca9d90c577
7 changed files with 106 additions and 43 deletions
|
|
@ -15,6 +15,7 @@
|
|||
- fix: A minor bug in the default viewPurchaseHistory template
|
||||
- fix: Thread determination of "current" Post, and shortcuts to non-Thread Posts
|
||||
- fix: make handling of profile field possible values slightly more robust
|
||||
- RFE: non-required fields shown on user registration
|
||||
|
||||
7.2.1
|
||||
- Made a change to version tag commits to deal with unusually long commit
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ my $quiet; # this line required
|
|||
my $session = start(); # this line required
|
||||
|
||||
# upgrade functions go here
|
||||
addProfileFieldsOnRegistration($session);
|
||||
|
||||
finish($session); # this line required
|
||||
|
||||
|
|
@ -53,6 +54,21 @@ sub start {
|
|||
return $session;
|
||||
}
|
||||
|
||||
#-------------------------------------------------
|
||||
sub addProfileFieldsOnRegistration {
|
||||
my $session = shift;
|
||||
print "\tAdding showAtRegistration to userProfileField rows.\n" unless $quiet;
|
||||
|
||||
$session->db->write($_) for(<<'EOT',
|
||||
ALTER TABLE userProfileField
|
||||
ADD COLUMN showAtRegistration int(11) NOT NULL default '0'
|
||||
EOT
|
||||
<<'EOT',
|
||||
UPDATE userProfileField SET showAtRegistration = required
|
||||
EOT
|
||||
);
|
||||
}
|
||||
|
||||
#-------------------------------------------------
|
||||
sub finish {
|
||||
my $session = shift;
|
||||
|
|
|
|||
|
|
@ -175,10 +175,26 @@ sub createAccount {
|
|||
|
||||
$vars->{'create.form.header'} = WebGUI::Form::formHeader($self->session,{});
|
||||
$vars->{'create.form.header'} .= WebGUI::Form::hidden($self->session,{"name"=>"op","value"=>"auth"});
|
||||
$vars->{'create.form.header'} .= WebGUI::Form::hidden($self->session,{"name"=>"method","value"=>$method});
|
||||
$vars->{'create.form.header'} .= WebGUI::Form::hidden($self->session,{"name"=>"method","value"=>$method});
|
||||
|
||||
#User Defined Options
|
||||
$vars->{'create.form.profile'} = WebGUI::Operation::Profile::getRequiredProfileFields($self->session);
|
||||
$vars->{'create.form.profile'} = [];
|
||||
foreach my $field (@{WebGUI::ProfileField->getRegistrationFields($self->session)}) {
|
||||
my ($id, $formField, $label) = ($field->getId, $field->formField, $field->getLabel);
|
||||
my $required = $field->isRequired;
|
||||
|
||||
# Old-style field loop.
|
||||
push @{$vars->{'create.form.profile'}},
|
||||
+{ 'profile.formElement' => $formField,
|
||||
'profile.formElement.label' => $label,
|
||||
'profile.required' => $required };
|
||||
|
||||
# Individual field template vars.
|
||||
my $prefix = 'create.form.profile.'.$field->getId.'.';
|
||||
$vars->{$prefix.'formElement'} = $id;
|
||||
$vars->{$prefix.'formElement.label'} = $label;
|
||||
$vars->{$prefix.'required'} = $required;
|
||||
}
|
||||
|
||||
$vars->{'create.form.submit'} = WebGUI::Form::submit($self->session,{});
|
||||
$vars->{'create.form.footer'} = WebGUI::Form::formFooter($self->session,);
|
||||
|
|
|
|||
|
|
@ -45,6 +45,10 @@ These methods are available from this package:
|
|||
Returns an array of hashes for required profile fields. This array is ready
|
||||
to be used as template variables in the WebGUI template system.
|
||||
|
||||
This method is deprecated, and should not be used in new code. Use
|
||||
the getRequiredFields method from WebGUI::ProfileField and specify the
|
||||
translation to template variables directly instead.
|
||||
|
||||
=head3 session
|
||||
|
||||
The current WebGUI session object.
|
||||
|
|
|
|||
|
|
@ -266,6 +266,12 @@ sub www_editProfileField {
|
|||
-hoverHelp=>$i18n->get('474 description'),
|
||||
-value=>$data->{required}
|
||||
);
|
||||
$f->yesNo(
|
||||
-name => 'showAtRegistration',
|
||||
-label => $i18n->get('showAtRegistration label'),
|
||||
-hoverHelp => $i18n->get('showAtRegistration hoverHelp'),
|
||||
-value => $data->{showAtRegistration}
|
||||
);
|
||||
if ($data->{fieldType} eq "Image") {
|
||||
$f->yesNo(
|
||||
-name=>"forceImageOnly",
|
||||
|
|
@ -336,6 +342,7 @@ sub www_editProfileFieldSave {
|
|||
editable=>$session->form->yesNo("editable"),
|
||||
visible=>$session->form->yesNo("visible"),
|
||||
required=>$session->form->yesNo("required"),
|
||||
showAtRegistration=>$session->form->yesNo("showAtRegistration"),
|
||||
possibleValues=>$session->form->textarea("possibleValues"),
|
||||
dataDefault=>$session->form->textarea("dataDefault"),
|
||||
fieldType=>$session->form->fieldType("fieldType"),
|
||||
|
|
|
|||
|
|
@ -252,42 +252,6 @@ sub getCategory {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getEditableFields ( session )
|
||||
|
||||
Returns an array reference of WebGUI::ProfileField objects that are marked "editable" or "required". This is a class method.
|
||||
|
||||
=cut
|
||||
|
||||
sub getEditableFields {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my @fields = ();
|
||||
foreach my $fieldName ($session->db->buildArray("select fieldName from userProfileField where required=1 or editable=1 order by sequenceNumber")) {
|
||||
push(@fields,WebGUI::ProfileField->new($session,$fieldName));
|
||||
}
|
||||
return \@fields;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getFields ( session )
|
||||
|
||||
Returns an array reference of WebGUI::ProfileField objects. This is a class method.
|
||||
|
||||
=cut
|
||||
|
||||
sub getFields {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my @fields = ();
|
||||
foreach my $fieldName ($session->db->buildArray("select fieldName from userProfileField order by profileCategoryId, sequenceNumber")) {
|
||||
push(@fields,WebGUI::ProfileField->new($session,$fieldName));
|
||||
}
|
||||
return \@fields;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getId ( )
|
||||
|
|
@ -318,6 +282,43 @@ sub getLabel {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
sub _listFieldsWhere {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $whereClause = shift;
|
||||
return [map{$class->new($session, $_)} $session->db->buildArray(<<"SQL")];
|
||||
SELECT f.fieldName
|
||||
FROM userProfileField AS f
|
||||
LEFT JOIN userProfileCategory AS c ON f.profileCategoryId = c.profileCategoryId
|
||||
WHERE $whereClause
|
||||
ORDER BY c.sequenceNumber, f.sequenceNumber
|
||||
SQL
|
||||
}
|
||||
|
||||
=head2 getEditableFields ( session )
|
||||
|
||||
Returns an array reference of WebGUI::ProfileField objects that are marked "editable" or "required". This is a class method.
|
||||
|
||||
=cut
|
||||
|
||||
sub getEditableFields {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
return $class->_listFieldsWhere($session, "f.required = 1 OR f.editable = 1");
|
||||
}
|
||||
|
||||
=head2 getFields ( session )
|
||||
|
||||
Returns an array reference of WebGUI::ProfileField objects. This is a class method.
|
||||
|
||||
=cut
|
||||
|
||||
sub getFields {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
return $class->_listFieldsWhere($session, "1");
|
||||
}
|
||||
|
||||
=head2 getRequiredFields ( session )
|
||||
|
||||
Returns an array reference of WebGUI::ProfileField objects that are marked "required". This is a class method.
|
||||
|
|
@ -327,11 +328,19 @@ Returns an array reference of WebGUI::ProfileField objects that are marked "requ
|
|||
sub getRequiredFields {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my @fields = ();
|
||||
foreach my $fieldName ($session->db->buildArray("select userProfileField.fieldName from userProfileField LEFT JOIN userProfileCategory ON userProfileField.profileCategoryId = userProfileCategory.profileCategoryId where userProfileField.required=1 order by userProfileCategory.sequenceNumber, userProfileField.sequenceNumber")) {
|
||||
push(@fields,WebGUI::ProfileField->new($session,$fieldName));
|
||||
}
|
||||
return \@fields;
|
||||
return $class->_listFieldsWhere($session, "f.required = 1");
|
||||
}
|
||||
|
||||
=head2 getRegistrationFields ( session )
|
||||
|
||||
Returns an array reference of profile field objects to use during anonymous registration. Class method.
|
||||
|
||||
=cut
|
||||
|
||||
sub getRegistrationFields {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
return $class->_listFieldsWhere($session, "f.showAtRegistration = 1");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -341,6 +341,16 @@ new categories of profile settings.
|
|||
message => "If set to yes, this form control will only allow image file types to be uploaded through it.",
|
||||
lastUpdated => 1162945563
|
||||
},
|
||||
|
||||
'showAtRegistration label' => {
|
||||
message => "Show at Registration?",
|
||||
lastUpdated => 1164237018
|
||||
},
|
||||
|
||||
'showAtRegistration hoverHelp' => {
|
||||
message => "Show an entry for this field at the registration screen for newly-registering users. The field will not actually be required unless Required is also set.",
|
||||
lastUpdated => 1164237018
|
||||
},
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue