fixed a limitation with buildSearchQuery in SQL
started working on registrant search in EMS
This commit is contained in:
parent
4ca80ad734
commit
ac3c7d18b9
6 changed files with 123 additions and 18 deletions
|
|
@ -75,6 +75,7 @@ sub upgradeEMS {
|
|||
$db->write("alter table EventManagementSystem add column ribbonInstructions mediumtext");
|
||||
$db->write("alter table EventManagementSystem add column ticketInstructions mediumtext");
|
||||
$db->write("alter table EventManagementSystem add column tokenInstructions mediumtext");
|
||||
$db->write("alter table EventManagementSystem add column registrationStaffGroupId varchar(22) binary not null");
|
||||
print "\t\tCreating new tables.\n" unless ($quiet);
|
||||
$db->write("create table EMSRegistrant (
|
||||
badgeId varchar(22) binary not null primary key,
|
||||
|
|
|
|||
|
|
@ -95,6 +95,13 @@ sub definition {
|
|||
label => $i18n->get('token instructions'),
|
||||
hoverHelp => $i18n->get('token instructions help'),
|
||||
},
|
||||
registrationStaffGroupId => {
|
||||
fieldType => 'group',
|
||||
defaultValue => [3],
|
||||
tab => 'security',
|
||||
label => $i18n->get('registration staff group'),
|
||||
hoverHelp => $i18n->get('registration staff group help'),
|
||||
},
|
||||
);
|
||||
push(@{$definition}, {
|
||||
assetName=>$i18n->get('assetName'),
|
||||
|
|
@ -174,6 +181,24 @@ sub getTokens {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 isRegistrationStaff ( [ user ] )
|
||||
|
||||
Returns a boolean indicating whether the user is a member of the registration staff.
|
||||
|
||||
=head3 user
|
||||
|
||||
A WebGUI::User object. Defaults to $session->user.
|
||||
|
||||
=cut
|
||||
|
||||
sub isRegistrationStaff {
|
||||
my $self = shift;
|
||||
my $user = shift || $self->session->user;
|
||||
$user->isInGroup($self->get('registrationStaffGroupId'));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 prepareView ( )
|
||||
|
||||
See WebGUI::Asset::prepareView() for details.
|
||||
|
|
@ -570,7 +595,7 @@ sub www_getBadgesAsJson {
|
|||
|
||||
=head2 www_getRegistrantAsJson ( )
|
||||
|
||||
Retrieves the properties of the current badge and the items attached to it.
|
||||
Retrieves the properties of a specific badge and the items attached to it. Expects badgeId to be one of the form params.
|
||||
|
||||
=cut
|
||||
|
||||
|
|
@ -696,6 +721,66 @@ sub www_getRegistrantAsJson {
|
|||
return JSON::to_json($badgeInfo);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_getRegistrantsAsJson ( )
|
||||
|
||||
Returns a list of registrants in the system. Can be a narrowed search by submitting a keywords form param with the request.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_getRegistrantsAsJson {
|
||||
my ($self) = @_;
|
||||
my $session = $self->session;
|
||||
return $session->privilege->insufficient() unless $self->canView;
|
||||
my ($db, $form) = $session->quick(qw(db form));
|
||||
my $startIndex = $form->get('startIndex') || 0;
|
||||
my $numberOfResults = $form->get('results') || 25;
|
||||
my $keywords = $form->get('keywords');
|
||||
|
||||
my $sql = "select SQL_CALC_FOUND_ROWS * from EMSRegistrant where purchaseComplete=1 and emsAssetId=?";
|
||||
my @params = ($self->getId);
|
||||
|
||||
# user or staff
|
||||
my $isEventStaff = 1;
|
||||
unless ($self->isRegistrationStaff) {
|
||||
$isEventStaff = 0;
|
||||
$sql .= " and userId=?";
|
||||
push @params, $session->user->userId;
|
||||
}
|
||||
|
||||
# keyword search
|
||||
if ($keywords ne "") {
|
||||
$db->buildSearchQuery(\$sql, \@params, $keywords, [qw{badgeNumber name address1 address2 address3 city state country email notes zipcode phoneNumber organization}])
|
||||
}
|
||||
|
||||
# limit
|
||||
$sql .= 'limit ?,?';
|
||||
push(@params, $startIndex, $numberOfResults);
|
||||
|
||||
# get badge info
|
||||
my @records = ();
|
||||
my %results = ();
|
||||
my $badges = $db->read($sql,\@params);
|
||||
while (my $badgeInfo = $badges->hashRef) {
|
||||
my $badge = WebGUI::Asset::Sku::EMSBadge->new($session, $badgeInfo->{badgeAssetId});
|
||||
$badgeInfo->{title} = $badge->getTitle;
|
||||
$badgeInfo->{sku} = $badge->get('sku');
|
||||
$badgeInfo->{assetId} = $badge->getId;
|
||||
push(@records, $badgeInfo);
|
||||
}
|
||||
$results{'recordsReturned'} = $badges->rows()+0;
|
||||
$results{'totalRecords'} = $db->quickScalar('select found_rows()') + 0; ##Convert to numeric
|
||||
$results{'records'} = \@records;
|
||||
$results{'startIndex'} = $startIndex;
|
||||
$results{'sort'} = undef;
|
||||
$results{'dir'} = "asc";
|
||||
|
||||
# build json datasource
|
||||
$session->http->setMimeType('text/json');
|
||||
return JSON::to_json(\%results);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -895,6 +980,7 @@ Displays the
|
|||
|
||||
sub www_lookupRegistrant {
|
||||
my $self = shift;
|
||||
return $self->www_getRegistrantsAsJson;
|
||||
return $self->processStyle("here you will be able to look up a registrant by name");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -314,7 +314,7 @@ sub buildHashRefOfHashRefs {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 buildSearchQuery ( $sql, $keywords, $columns )
|
||||
=head2 buildSearchQuery ( $sql, $placeholders, $keywords, $columns )
|
||||
|
||||
Append information to an existing SQL statement for implementing
|
||||
basic search functions. The ammended SQL and an array of placeholder
|
||||
|
|
@ -322,9 +322,13 @@ variables will be returned.
|
|||
|
||||
=head3 $sql
|
||||
|
||||
An SQL query. The clauses to add search-like capabilities will be
|
||||
A scalar reference to an SQL query. The clauses to add search-like capabilities will be
|
||||
appended to the end of the query.
|
||||
|
||||
=head3 $placeholders
|
||||
|
||||
An array reference of placeholders already added to the query.
|
||||
|
||||
=head3 $keywords
|
||||
|
||||
This is the data that will be searched for in columns. An SQL wildcard '%' will
|
||||
|
|
@ -337,19 +341,22 @@ An arrayref of column names that should be searched for $keywords.
|
|||
=cut
|
||||
|
||||
sub buildSearchQuery {
|
||||
my $self = shift;
|
||||
my $sql = shift;
|
||||
my $keywords = shift;
|
||||
my $columns = shift || [];
|
||||
my @placeholders;
|
||||
$sql .= ' where';
|
||||
$keywords = '%'.$keywords.'%';
|
||||
foreach my $field (@{ $columns }) {
|
||||
$sql .= ' or' if (scalar @placeholders > 0);
|
||||
$sql .= qq{ $field like ?};
|
||||
push(@placeholders, $keywords);
|
||||
my ($self, $sql, $placeHolders, $keywords, $columns) = @_;
|
||||
if ($$sql =~ m/where/) {
|
||||
$$sql .= ' and (';
|
||||
}
|
||||
return ($sql, @placeholders);
|
||||
else {
|
||||
$$sql .= ' where (';
|
||||
}
|
||||
$keywords = '%'.$keywords.'%';
|
||||
my $counter = 0;
|
||||
foreach my $field (@{ $columns }) {
|
||||
$$sql .= ' or' if ($counter > 0);
|
||||
$$sql .= qq{ $field like ?};
|
||||
push(@{$placeHolders}, $keywords);
|
||||
$counter++;
|
||||
}
|
||||
$$sql .= ')';
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -428,7 +428,7 @@ sub www_getTaxesAsJson {
|
|||
my $sql = 'select SQL_CALC_FOUND_ROWS * from tax';
|
||||
my $keywords = $form->get("keywords");
|
||||
if ($keywords ne "") {
|
||||
($sql, @placeholders) = $db->buildSearchQuery($sql, $keywords, [qw{country state city code}])
|
||||
$db->buildSearchQuery(\$sql, \@placeholders, $keywords, [qw{country state city code}])
|
||||
}
|
||||
push(@placeholders, $sortKey, $sortDir, $startIndex, $numberOfResults);
|
||||
$sql .= ' order by ? ? limit ?,?';
|
||||
|
|
|
|||
|
|
@ -423,7 +423,7 @@ sub www_getTransactionsAsJson {
|
|||
from transaction';
|
||||
my $keywords = $form->get("keywords");
|
||||
if ($keywords ne "") {
|
||||
($sql, @placeholders) = $db->buildSearchQuery($sql, $keywords, [qw{amount username orderNumber shippingAddressName shippingAddress1 paymentAddressName paymentAddress1}])
|
||||
$db->buildSearchQuery(\$sql, \@placeholders, $keywords, [qw{amount username orderNumber shippingAddressName shippingAddress1 paymentAddressName paymentAddress1}])
|
||||
}
|
||||
push(@placeholders, $startIndex, $numberOfResults);
|
||||
$sql .= ' order by dateOfPurchase desc limit ?,?';
|
||||
|
|
@ -434,7 +434,6 @@ sub www_getTransactionsAsJson {
|
|||
push(@records,$record);
|
||||
}
|
||||
$results{'recordsReturned'} = $sth->rows()+0;
|
||||
$sth->finish;
|
||||
$results{'totalRecords'} = $db->quickScalar('select found_rows()') + 0; ##Convert to numeric
|
||||
$results{'records'} = \@records;
|
||||
$results{'startIndex'} = $startIndex;
|
||||
|
|
|
|||
|
|
@ -344,6 +344,18 @@ our $I18N = {
|
|||
context => q|a button on the add badge to cart screen|,
|
||||
},
|
||||
|
||||
'registration staff group' => {
|
||||
message => q|Registration Staff Group|,
|
||||
lastUpdated => 0,
|
||||
context => q|an ems property label|,
|
||||
},
|
||||
|
||||
'registration staff group help' => {
|
||||
message => q|Pick a group of users that will handle registration. These users will be able to look up and manage badge registrations for any attendee.|,
|
||||
lastUpdated => 0,
|
||||
context => q|help for an ems property label|,
|
||||
},
|
||||
|
||||
'related badge groups' => {
|
||||
message => q|Related Badge Groups|,
|
||||
lastUpdated => 0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue