Multiple changes:

- Shift ProfileField API so that new returns undef on invalid fields.
    This makes it possible for Shortcut::www_saveUserPrefs to execute.
    The class methods in ProfileField are now also actually class methods.

    + Also fix up other modules that created dummy ProfileFields so that
      they don't need to do that anymore, because it's now invalid.

  - Merge contradictory-looking code from Shortcut's view and www_view
    into a reasonable compromise in view, and then have www_view call
    $self->view in a manner similar to that of the default Asset::view.

    + The profile field overrides still don't work, because there's no
      obvious mechanism for "transclude asset in context".  This may
      require some fiddling to get right...
This commit is contained in:
Drake 2006-08-31 00:14:56 +00:00
parent 84e8d8f689
commit 565119fa1a
5 changed files with 57 additions and 36 deletions

View file

@ -21,6 +21,7 @@ use WebGUI::Form::DynamicField;
use WebGUI::Operation::Shared;
use WebGUI::HTML;
use WebGUI::User;
use WebGUI::Utility;
=head1 NAME
@ -54,6 +55,19 @@ sub _reorderFields {
$sth->finish;
}
#-------------------------------------------------------------------
=head2 isReservedFieldName ( fieldName )
Return true iff fieldName is reserved and therefore not usable as a profile field name.
=cut
sub isReservedFieldName {
my $class = shift;
my $fieldName = shift;
return isIn($fieldName, ('func', 'op'));
}
#-------------------------------------------------------------------
=head2 create ( session, fieldName [, properties, categoryId] )
@ -86,6 +100,8 @@ sub create {
my $categoryId = shift || "1";
my ($fieldNameExists) = $session->db->quickArray("select count(*) from userProfileField where fieldName=".$session->db->quote($fieldName));
return undef if ($fieldNameExists);
return undef if $class->isReservedFieldName($fieldName);
my $id = $session->db->setRow("userProfileField","fieldName",{fieldName=>"new"},$fieldName);
my $self = $class->new($session,$id);
$self->setCategory($categoryId);
@ -225,34 +241,36 @@ sub getCategory {
#-------------------------------------------------------------------
=head2 getEditableFields ( )
=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 $self = shift;
my $class = shift;
my $session = shift;
my @fields = ();
foreach my $fieldName ($self->session->db->buildArray("select fieldName from userProfileField where required=1 or editable=1 order by sequenceNumber")) {
push(@fields,WebGUI::ProfileField->new($self->session,$fieldName));
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 ( )
=head2 getFields ( session )
Returns an array reference of WebGUI::ProfileField objects. This is a class method.
=cut
sub getFields {
my $self = shift;
my $class = shift;
my $session = shift;
my @fields = ();
foreach my $fieldName ($self->session->db->buildArray("select fieldName from userProfileField order by profileCategoryId, sequenceNumber")) {
push(@fields,WebGUI::ProfileField->new($self->session,$fieldName));
foreach my $fieldName ($session->db->buildArray("select fieldName from userProfileField order by profileCategoryId, sequenceNumber")) {
push(@fields,WebGUI::ProfileField->new($session,$fieldName));
}
return \@fields;
}
@ -287,17 +305,18 @@ sub getLabel {
#-------------------------------------------------------------------
=head2 getRequiredFields ( )
=head2 getRequiredFields ( session )
Returns an array reference of WebGUI::ProfileField objects that are marked "required". This is a class method.
=cut
sub getRequiredFields {
my $self = shift;
my $class = shift;
my $session = shift;
my @fields = ();
foreach my $fieldName ($self->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($self->session,$fieldName));
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;
}
@ -417,7 +436,10 @@ sub new {
my $session = shift;
my $id = shift;
return undef unless ($id);
return undef if $class->isReservedFieldName($id);
my $properties = $session->db->getRow("userProfileField","fieldName",$id);
# Reject properties that don't exist.
return undef unless scalar keys %$properties;
bless {_session=>$session, _properties=>$properties}, $class;
}