updated profile field and profile category to use the new session api
This commit is contained in:
parent
388cd8f306
commit
02c5a65857
6 changed files with 102 additions and 46 deletions
|
|
@ -803,6 +803,17 @@ WebGUI::Product now accepts session in the constructor.
|
|||
perl -pi.bak -e 's!WebGUI\:\:Product\-\>new\(!WebGUI::Product->new(\$self->session,!g' fileNameGoesHere
|
||||
|
||||
|
||||
5.23.20 WebGUI::ProfileCategory and WebGUI::ProfileField Refactored
|
||||
|
||||
These API's now accept session in their constructors.
|
||||
|
||||
perl -pi.bak -e 's!WebGUI\:\:ProfileCategory\-\>new\(!WebGUI::ProfileCategory->new(\$self->session,!g' fileNameGoesHere
|
||||
perl -pi.bak -e 's!WebGUI\:\:ProfileCategory\-\>create\(!WebGUI::ProfileCategory->create(\$self->session,!g' fileNameGoesHere
|
||||
perl -pi.bak -e 's!WebGUI\:\:ProfileField\-\>new\(!WebGUI::ProfileField->new(\$self->session,!g' fileNameGoesHere
|
||||
perl -pi.bak -e 's!WebGUI\:\:ProfileField\-\>create\(!WebGUI::ProfileField->create(\$self->session,!g' fileNameGoesHere
|
||||
|
||||
|
||||
|
||||
|
||||
6. Automatic list of Assets in Help System.
|
||||
-------------------------------------
|
||||
|
|
|
|||
|
|
@ -404,7 +404,7 @@ sub getOverrides {
|
|||
my $u = WebGUI::User->new($self->discernUserId);
|
||||
my @userPrefs = $self->getPrefFieldsToImport;
|
||||
foreach my $fieldId (@userPrefs) {
|
||||
my $field = WebGUI::ProfileField->new($fieldId);
|
||||
my $field = WebGUI::ProfileField->new($self->session,$fieldId);
|
||||
next unless $field;
|
||||
my $fieldName = $field->getId;
|
||||
my $fieldValue = $u->profileField($field->getId);
|
||||
|
|
@ -651,7 +651,7 @@ sub www_getUserPrefsForm {
|
|||
-value => 'saveUserPrefs'
|
||||
);
|
||||
foreach my $fieldId (@fielden) {
|
||||
my $field = WebGUI::ProfileField->new($fieldId);
|
||||
my $field = WebGUI::ProfileField->new($self->session,$fieldId);
|
||||
next unless $field;
|
||||
my $params = {};
|
||||
if (lc($field->get("fieldType")) eq 'textarea') {
|
||||
|
|
@ -712,7 +712,7 @@ sub www_saveUserPrefs {
|
|||
my $i18n = WebGUI::International->new($self->session);
|
||||
my $u = WebGUI::User->new($self->discernUserId);
|
||||
foreach my $fieldId (keys %{$session{form}}) {
|
||||
my $field = WebGUI::ProfileField->new($fieldId);
|
||||
my $field = WebGUI::ProfileField->new($self->session,$fieldId);
|
||||
next unless $field;
|
||||
$data{$field->getId} = $field->formProcess;
|
||||
if ($field->getId eq 'email' && WebGUI::Operation::Profile::isDuplicateEmail($data{$field->getId})) {
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ sub getEditForm {
|
|||
#-------------------------------------------------------------------
|
||||
sub initialize {
|
||||
my $self = shift;
|
||||
my $userPrefField = WebGUI::ProfileField->create($self->getId.'contentPositions',{
|
||||
my $userPrefField = WebGUI::ProfileField->create($self->session,$self->getId.'contentPositions',{
|
||||
label=>'\'Dashboard User Preference - Content Positions\'',
|
||||
visible=>0,
|
||||
protected=>1,
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ sub _submenu {
|
|||
sub www_deleteProfileCategoryConfirm {
|
||||
my $session = shift;
|
||||
return $session->privilege->adminOnly() unless ($session->user->isInGroup(3));
|
||||
my $category = WebGUI::ProfileCategory->new($session->form->process("cid"));
|
||||
my $category = WebGUI::ProfileCategory->new($session,$session->form->process("cid"));
|
||||
return WebGUI::AdminConsole->new($session,"userProfiling")->render($session->privilege->vitalComponent()) if ($category->isProtected);
|
||||
$category->delete;
|
||||
return www_editProfileSettings();
|
||||
|
|
@ -64,7 +64,7 @@ sub www_deleteProfileCategoryConfirm {
|
|||
sub www_deleteProfileFieldConfirm {
|
||||
my $session = shift;
|
||||
return $session->privilege->adminOnly() unless ($session->user->isInGroup(3));
|
||||
my $field = WebGUI::ProfileField->new($session->form->process("fid"));
|
||||
my $field = WebGUI::ProfileField->new($session,$session->form->process("fid"));
|
||||
return WebGUI::AdminConsole->new($session,"userProfiling")->render($session->privilege->vitalComponent()) if ($field->isProtected);
|
||||
$field->delete;
|
||||
return www_editProfileSettings();
|
||||
|
|
@ -90,7 +90,7 @@ sub www_editProfileCategory {
|
|||
-name => $session->form->process("cid"),
|
||||
-label => $i18n->get(469),
|
||||
);
|
||||
$data = WebGUI::ProfileCategory->new($session->form->process("cid"))->get;
|
||||
$data = WebGUI::ProfileCategory->new($session,$session->form->process("cid"))->get;
|
||||
} else {
|
||||
$f->hidden(
|
||||
-name => "cid",
|
||||
|
|
@ -129,10 +129,10 @@ sub www_editProfileCategorySave {
|
|||
editable=>$session->form->yesNo("editable"),
|
||||
);
|
||||
if ($session->form->process("cid") eq "new") {
|
||||
my $category = WebGUI::ProfileCategory->create(\%data);
|
||||
my $category = WebGUI::ProfileCategory->create($session,\%data);
|
||||
$session->form->process("cid") = $category->getId;
|
||||
} else {
|
||||
WebGUI::ProfileCategory->new($session->form->process("cid"))->set(\%data);
|
||||
WebGUI::ProfileCategory->new($session,$session->form->process("cid"))->set(\%data);
|
||||
}
|
||||
return www_editProfileSettings();
|
||||
}
|
||||
|
|
@ -158,7 +158,7 @@ sub www_editProfileField {
|
|||
-label => $i18n->get(475),
|
||||
-hoverHelp => $i18n->get('475 description'),
|
||||
);
|
||||
$data = WebGUI::ProfileField->new($session->form->process("fid"))->get;
|
||||
$data = WebGUI::ProfileField->new($session,$session->form->process("fid"))->get;
|
||||
} else {
|
||||
$f->hidden(
|
||||
-name => "new",
|
||||
|
|
@ -254,10 +254,10 @@ sub www_editProfileFieldSave {
|
|||
);
|
||||
my $categoryId = $session->form->selectBox("profileCategoryId");
|
||||
if ($session->form->process("new")) {
|
||||
my $field = WebGUI::ProfileField->create($session->form->text("fid"), \%data, $categoryId);
|
||||
my $field = WebGUI::ProfileField->create($session,$session->form->text("fid"), \%data, $categoryId);
|
||||
$session->form->process("fid") = $field->getId;
|
||||
} else {
|
||||
my $field = WebGUI::ProfileField->new($session->form->process("fid"));
|
||||
my $field = WebGUI::ProfileField->new($session,$session->form->process("fid"));
|
||||
$field->set(\%data);
|
||||
$field->setCategory($categoryId);
|
||||
}
|
||||
|
|
@ -293,7 +293,7 @@ sub www_editProfileSettings {
|
|||
sub www_moveProfileCategoryDown {
|
||||
my $session = shift;
|
||||
return $session->privilege->adminOnly() unless ($session->user->isInGroup(3));
|
||||
WebGUI::ProfileCategory->new($session->form->process("cid"))->moveDown;
|
||||
WebGUI::ProfileCategory->new($session,$session->form->process("cid"))->moveDown;
|
||||
return www_editProfileSettings();
|
||||
}
|
||||
|
||||
|
|
@ -301,7 +301,7 @@ sub www_moveProfileCategoryDown {
|
|||
sub www_moveProfileCategoryUp {
|
||||
my $session = shift;
|
||||
return $session->privilege->adminOnly() unless ($session->user->isInGroup(3));
|
||||
WebGUI::ProfileCategory->new($session->form->process("cid"))->moveUp;
|
||||
WebGUI::ProfileCategory->new($session,$session->form->process("cid"))->moveUp;
|
||||
return www_editProfileSettings();
|
||||
}
|
||||
|
||||
|
|
@ -309,7 +309,7 @@ sub www_moveProfileCategoryUp {
|
|||
sub www_moveProfileFieldDown {
|
||||
my $session = shift;
|
||||
return $session->privilege->adminOnly() unless ($session->user->isInGroup(3));
|
||||
WebGUI::ProfileField->new($session->form->process("fid"))->moveDown;
|
||||
WebGUI::ProfileField->new($session,$session->form->process("fid"))->moveDown;
|
||||
return www_editProfileSettings();
|
||||
}
|
||||
|
||||
|
|
@ -317,7 +317,7 @@ sub www_moveProfileFieldDown {
|
|||
sub www_moveProfileFieldUp {
|
||||
my $session = shift;
|
||||
return $session->privilege->adminOnly() unless ($session->user->isInGroup(3));
|
||||
WebGUI::ProfileField->new($session->form->process("fid"))->moveUp;
|
||||
WebGUI::ProfileField->new($session,$session->form->process("fid"))->moveUp;
|
||||
return www_editProfileSettings();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ These methods are available from this package:
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub _reorderCategories {
|
||||
my $self = shift;
|
||||
my ($sth, $i, $id);
|
||||
$sth = $self->session->db->read("select profileCategoryId from userProfileCategory order by sequenceNumber");
|
||||
while (($id) = $sth->array) {
|
||||
|
|
@ -53,10 +54,14 @@ sub _reorderCategories {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 create ( [ properties] )
|
||||
=head2 create ( session, [ properties] )
|
||||
|
||||
Add a new category to the system. Returns a WebGUI::ProfileCategory object if created successfully, otherwise returns undef.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 properties
|
||||
|
||||
A hash reference containing the properties of this field. See the set() method for details.
|
||||
|
|
@ -65,10 +70,11 @@ A hash reference containing the properties of this field. See the set() method f
|
|||
|
||||
sub create {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $properties = shift;
|
||||
my ($sequenceNumber) = $self->session->db->quickArray("select max(sequenceNumber) from userProfileCategory");
|
||||
my $id = $self->session->db->setRow("userProfileCategory","profileCategoryId",{profileCategoryId=>"new", sequenceNumber=>$sequenceNumber+1});
|
||||
my $self = $class->new($id);
|
||||
my ($sequenceNumber) = $session->db->quickArray("select max(sequenceNumber) from userProfileCategory");
|
||||
my $id = $session->db->setRow("userProfileCategory","profileCategoryId",{profileCategoryId=>"new", sequenceNumber=>$sequenceNumber+1});
|
||||
my $self = $class->new($session,$id);
|
||||
$self->set($properties);
|
||||
return $self;
|
||||
}
|
||||
|
|
@ -122,7 +128,7 @@ sub getCategories {
|
|||
my $self = shift;
|
||||
my @categories = ();
|
||||
foreach my $id ($self->session->db->buildArray("select profileCategoryId from userProfileCategory order by sequenceNumber")) {
|
||||
push(@categories,WebGUI::ProfileCategory->new($id));
|
||||
push(@categories,WebGUI::ProfileCategory->new($self->session,$id));
|
||||
}
|
||||
return \@categories;
|
||||
}
|
||||
|
|
@ -140,7 +146,7 @@ sub getFields {
|
|||
my $self = shift;
|
||||
my @fields = ();
|
||||
foreach my $fieldName ($self->session->db->buildArray("select fieldName from userProfileField where profileCategoryId=".$self->session->db->quote($self->getId)." order by sequenceNumber")){
|
||||
push(@fields,WebGUI::ProfileField->new($fieldName));
|
||||
push(@fields,WebGUI::ProfileField->new($self->session,$fieldName));
|
||||
}
|
||||
return \@fields;
|
||||
}
|
||||
|
|
@ -228,7 +234,7 @@ sub moveDown {
|
|||
if ($id ne "") {
|
||||
$self->session->db->write("update userProfileCategory set sequenceNumber=sequenceNumber+1 where profileCategoryId=".$self->session->db->quote($self->getId));
|
||||
$self->session->db->write("update userProfileCategory set sequenceNumber=sequenceNumber-1 where profileCategoryId=".$self->session->db->quote($id));
|
||||
_reorderCategories();
|
||||
$self->_reorderCategories();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -248,15 +254,19 @@ sub moveUp {
|
|||
if ($id ne "") {
|
||||
$self->session->db->write("update userProfileCategory set sequenceNumber=sequenceNumber-1 where profileCategoryId=".$self->session->db->quote($self->getId));
|
||||
$self->session->db->write("update userProfileCategory set sequenceNumber=sequenceNumber+1 where profileCategoryId=".$self->session->db->quote($id));
|
||||
_reorderCategories();
|
||||
$self->_reorderCategories();
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( id )
|
||||
=head2 new ( session, id )
|
||||
|
||||
Constructor
|
||||
Constructor.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 id
|
||||
|
||||
|
|
@ -266,13 +276,27 @@ The unique id of this category.
|
|||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $id = shift;
|
||||
return undef unless ($id);
|
||||
my $properties = $self->session->db->getRow("userProfileCategory","profileCategoryId",$id);
|
||||
bless {_properties=>$properties}, $class;
|
||||
my $properties = $session->db->getRow("userProfileCategory","profileCategoryId",$id);
|
||||
bless {_session=>$session, _properties=>$properties}, $class;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 session ( )
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=cut
|
||||
|
||||
sub session {
|
||||
my $self = shift;
|
||||
return $self->{_session};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 set ( properties )
|
||||
|
|
|
|||
|
|
@ -17,10 +17,7 @@ package WebGUI::ProfileField;
|
|||
|
||||
use strict;
|
||||
use WebGUI::ProfileCategory;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::Form::DynamicField;
|
||||
use WebGUI::FormProcessor;
|
||||
use WebGUI::Operation::Shared;
|
||||
use WebGUI::HTML;
|
||||
use WebGUI::User;
|
||||
|
|
@ -46,6 +43,7 @@ These methods are available from this package:
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub _reorderFields {
|
||||
my $self = shift;
|
||||
my $category = shift;
|
||||
my ($sth, $i, $id);
|
||||
$sth = $self->session->db->read("select fieldName from userProfileField where profileCategoryId=".$self->session->db->quote($category)." order by sequenceNumber");
|
||||
|
|
@ -58,10 +56,14 @@ sub _reorderFields {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 create ( fieldName [, properties, categoryId] )
|
||||
=head2 create ( session, fieldName [, properties, categoryId] )
|
||||
|
||||
Add a new field to the system. Returns a WebGUI::ProfileField object if created successfully, otherwise returns undef.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 fieldName
|
||||
|
||||
The unique name of this field.
|
||||
|
|
@ -78,13 +80,14 @@ The unique id of the category to assign this field to. Defaults to "1" (misc).
|
|||
|
||||
sub create {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $fieldName = shift;
|
||||
my $properties = shift;
|
||||
my $categoryId = shift || "1";
|
||||
my ($fieldNameExists) = $self->session->db->quickArray("select count(*) from userProfileField where fieldName=".$self->session->db->quote($fieldName));
|
||||
my ($fieldNameExists) = $session->db->quickArray("select count(*) from userProfileField where fieldName=".$session->db->quote($fieldName));
|
||||
return undef if ($fieldNameExists);
|
||||
my $id = $self->session->db->setRow("userProfileField","fieldName",{fieldName=>"new"},undef,$fieldName);
|
||||
my $self = $class->new($id);
|
||||
my $id = $session->db->setRow("userProfileField","fieldName",{fieldName=>"new"},undef,$fieldName);
|
||||
my $self = $class->new($session,$id);
|
||||
$self->setCategory($categoryId);
|
||||
$self->set($properties);
|
||||
return $self;
|
||||
|
|
@ -214,7 +217,7 @@ Returns a WebGUI::ProfileCategory object for the category that this profile fiel
|
|||
|
||||
sub getCategory {
|
||||
my $self = shift;
|
||||
return WebGUI::ProfileCategory->new($self->get("categoryId"));
|
||||
return WebGUI::ProfileCategory->new($self->session,$self->get("categoryId"));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -230,7 +233,7 @@ sub getEditableFields {
|
|||
my $self = 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($fieldName));
|
||||
push(@fields,WebGUI::ProfileField->new($self->session,$fieldName));
|
||||
}
|
||||
return \@fields;
|
||||
}
|
||||
|
|
@ -247,7 +250,7 @@ sub getFields {
|
|||
my $self = shift;
|
||||
my @fields = ();
|
||||
foreach my $fieldName ($self->session->db->buildArray("select fieldName from userProfileField order by profileCategoryId, sequenceNumber")) {
|
||||
push(@fields,WebGUI::ProfileField->new($fieldName));
|
||||
push(@fields,WebGUI::ProfileField->new($self->session,$fieldName));
|
||||
}
|
||||
return \@fields;
|
||||
}
|
||||
|
|
@ -292,7 +295,7 @@ sub getRequiredFields {
|
|||
my $self = shift;
|
||||
my @fields = ();
|
||||
foreach my $fieldName ($self->session->db->buildArray("select fieldName from userProfileField where required=1 order by sequenceNumber")) {
|
||||
push(@fields,WebGUI::ProfileField->new($fieldName));
|
||||
push(@fields,WebGUI::ProfileField->new($self->session,$fieldName));
|
||||
}
|
||||
return \@fields;
|
||||
}
|
||||
|
|
@ -366,7 +369,7 @@ sub moveDown {
|
|||
if ($id ne "") {
|
||||
$self->session->db->write("update userProfileField set sequenceNumber=sequenceNumber+1 where fieldName=".$self->session->db->quote($self->getId));
|
||||
$self->session->db->write("update userProfileField set sequenceNumber=sequenceNumber-1 where fieldName=".$self->session->db->quote($id));
|
||||
_reorderFields($profileCategoryId);
|
||||
$self->_reorderFields($profileCategoryId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -386,17 +389,21 @@ sub moveUp {
|
|||
if ($id ne "") {
|
||||
$self->session->db->write("update userProfileField set sequenceNumber=sequenceNumber-1 where fieldName=".$self->session->db->quote($self->getId));
|
||||
$self->session->db->write("update userProfileField set sequenceNumber=sequenceNumber+1 where fieldName=".$self->session->db->quote($id));
|
||||
_reorderFields($profileCategoryId);
|
||||
$self->_reorderFields($profileCategoryId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( fieldName )
|
||||
=head2 new ( session, fieldName )
|
||||
|
||||
Constructor
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 fieldName
|
||||
|
||||
The unique name of this field.
|
||||
|
|
@ -405,10 +412,11 @@ The unique name of this field.
|
|||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $id = shift;
|
||||
return undef unless ($id);
|
||||
my $properties = $self->session->db->getRow("userProfileField","fieldName",$id);
|
||||
bless {_properties=>$properties}, $class;
|
||||
my $properties = $session->db->getRow("userProfileField","fieldName",$id);
|
||||
bless {_session=>$session, _properties=>$properties}, $class;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -435,6 +443,19 @@ sub rename {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 session ( )
|
||||
|
||||
Returns a reference to the current session.
|
||||
|
||||
=cut
|
||||
|
||||
sub session {
|
||||
my $self = shift;
|
||||
return $self->{_session};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 set ( properties )
|
||||
|
|
@ -524,8 +545,8 @@ sub setCategory {
|
|||
$self->session->db->setRow("userProfileField","fieldName",{fieldName=>$self->getId, profileCategoryId=>$categoryId, sequenceNumber=>$sequenceNumber+1});
|
||||
$self->{_property}{profileCategoryId} = $categoryId;
|
||||
$self->{_property}{sequenceNumber} = $sequenceNumber+1;
|
||||
_reorderFields($currentCategoryId) if ($currentCategoryId);
|
||||
_reorderFields($categoryId);
|
||||
$self->_reorderFields($currentCategoryId) if ($currentCategoryId);
|
||||
$self->_reorderFields($categoryId);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue