From ac3c7d18b9332f55122029166c9c1f26bc687931 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Fri, 4 Apr 2008 18:37:53 +0000 Subject: [PATCH] fixed a limitation with buildSearchQuery in SQL started working on registrant search in EMS --- docs/upgrades/upgrade_7.5.2-7.5.3.pl | 1 + .../Asset/Wobject/EventManagementSystem.pm | 88 ++++++++++++++++++- lib/WebGUI/SQL.pm | 35 +++++--- lib/WebGUI/Shop/Tax.pm | 2 +- lib/WebGUI/Shop/Transaction.pm | 3 +- .../English/Asset_EventManagementSystem.pm | 12 +++ 6 files changed, 123 insertions(+), 18 deletions(-) diff --git a/docs/upgrades/upgrade_7.5.2-7.5.3.pl b/docs/upgrades/upgrade_7.5.2-7.5.3.pl index 25d5fab14..9d62ef1f0 100644 --- a/docs/upgrades/upgrade_7.5.2-7.5.3.pl +++ b/docs/upgrades/upgrade_7.5.2-7.5.3.pl @@ -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, diff --git a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm index a019736b0..fc84b3197 100644 --- a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm +++ b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm @@ -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"); } diff --git a/lib/WebGUI/SQL.pm b/lib/WebGUI/SQL.pm index 800efd733..003bcaa3e 100644 --- a/lib/WebGUI/SQL.pm +++ b/lib/WebGUI/SQL.pm @@ -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 .= ')'; } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Shop/Tax.pm b/lib/WebGUI/Shop/Tax.pm index 82805b36e..93022a213 100644 --- a/lib/WebGUI/Shop/Tax.pm +++ b/lib/WebGUI/Shop/Tax.pm @@ -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 ?,?'; diff --git a/lib/WebGUI/Shop/Transaction.pm b/lib/WebGUI/Shop/Transaction.pm index 55d28a47b..564839fcf 100644 --- a/lib/WebGUI/Shop/Transaction.pm +++ b/lib/WebGUI/Shop/Transaction.pm @@ -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; diff --git a/lib/WebGUI/i18n/English/Asset_EventManagementSystem.pm b/lib/WebGUI/i18n/English/Asset_EventManagementSystem.pm index 800bc31a9..c2f859bd2 100644 --- a/lib/WebGUI/i18n/English/Asset_EventManagementSystem.pm +++ b/lib/WebGUI/i18n/English/Asset_EventManagementSystem.pm @@ -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,