Merge branch 'master' into WebGUI8

This commit is contained in:
Graham Knop 2010-04-13 07:50:02 -05:00
commit 2400f19099
797 changed files with 33894 additions and 27196 deletions

View file

@ -1,5 +1,6 @@
package WebGUI::Asset::Wobject::EventManagementSystem;
=head1 LEGAL
-------------------------------------------------------------------
@ -83,6 +84,38 @@ property printTicketTemplateId => (
hoverHelp => ['print ticket template help', 'Asset_EventManagementSystem'],
namespace => 'EMS/PrintTicket',
);
property eventSubmissionMainTemplateId => (
fieldType => 'template',
default => 'DoVNijm6lMDE0cYrtvEbDQ',
tab => 'display',
label => ['event submission main template', 'Asset_EventManagementSystem'],
hoverHelp => ['event submission main template help', 'Asset_EventManagementSystem'],
namespace => 'EMS/SubmissionMain',
);
property eventSubmissionTemplateId => (
fieldType => 'template',
default => '8tqyQx-LwYUHIWOlKPjJrA',
tab => 'display',
label => ['event submission template', 'Asset_EventManagementSystem'],
hoverHelp => ['event submission template help', 'Asset_EventManagementSystem'],
namespace => 'EMS/Submission',
);
property eventSubmissionQueueTemplateId => (
fieldType => 'template',
default => 'ktSvKU8riGimhcsxXwqvPQ',
tab => 'display',
label => ['event submission queue template', 'Asset_EventManagementSystem'],
hoverHelp => ['event submission queue template help', 'Asset_EventManagementSystem'],
namespace => 'EMS/SubmissionQueue',
);
property printRemainingTicketsTemplateId => (
fieldType => 'template',
default => 'hreA_bgxiTX-EzWCSZCZJw',
tab => 'display',
label => ['print remaining ticket template', 'Asset_EventManagementSystem'],
hoverHelp => ['print remaining ticket template help', 'Asset_EventManagementSystem'],
namespace => 'EMS/PrintRemainingTickets',
);
property badgeInstructions => (
fieldType => 'HTMLArea',
builder => '_badgeInstructions_builder',
@ -142,6 +175,18 @@ property registrationStaffGroupId => (
label => ['registration staff group', 'Asset_EventManagementSystem'],
hoverHelp => ['registration staff group help', 'Asset_EventManagementSystem'],
);
property submittedLocationsList => (
fieldType => 'textarea',
tab => 'properties',
default => '',
label => ['submitted location list label', 'Asset_EventManagementSystem'],
hoverHelp => ['submitted location list help', 'Asset_EventManagementSystem'],
);
property eventSubmissionGroups => (
fieldType => 'hidden',
default => '',
noFormPost => 1,
);
use Digest::MD5;
@ -161,6 +206,89 @@ use WebGUI::Utility;
use WebGUI::Workflow::Instance;
use Data::Dumper;
#-------------------------------------------------------------------
=head2 addGroupToSubmitList ( groupId )
adds the parameter to eventSubmissionGroups
=cut
sub addGroupToSubmitList {
my $self = shift;
my $groupId = shift;
my ($idString) = $self->session->db->read('select eventSubmissionGroups from EventManagementSystem where assetId = ?', [ $self->getId ] )->array;
my @ids = split(' ', $idString);
my %h;
@ids = map { $h{$_}++ == 0 ? $_ : () } ( $groupId, @ids );
$self->update({eventSubmissionGroups => join( ' ', @ids ) });
}
#-------------------------------------------------------------------
=head2 addSubmissionForm
creates a child of class WG::Asset::EMSSubmissionForm
=head3 params
parameters that define the form
=head4 title
the title for the form
=head4 canSubmitGroupId ( optional )
group id for the users that are allowed to submit via this form
defaults to 2 -- registered users
=head4 daysBeforeCleanup ( optional )
number fo days to leave denied/created status items in the database before deleting
defaults to 7
=head4 deleteCreatedItems ( optional )
1 indicates that items with status 'created' should be deleted as well as denied
default: 0
=head4 formDescription
a JSON description of the form data fields -- a hash of the names of fields (each is 1 for active, 0 for inactive) plus
'_fieldList' added as an ARRAYREF of the fields that are active
=cut
sub addSubmissionForm {
my $self = shift;
my $params = shift;
$params->{className} = 'WebGUI::Asset::EMSSubmissionForm';
$params->{canSubmitGroupId} ||= 2;
$self->addGroupToSubmitList($params->{canSubmitGroupId});
my $newAsset = $self->addChild($params);
WebGUI::VersionTag->autoCommitWorkingIfEnabled($self->session);
$self = $self->cloneFromDb;
return $newAsset;
}
#-------------------------------------------------------------------
=head2 canSubmit
returns true is the current user can submit to any form attached to this EMS
=cut
sub canSubmit {
my $self = shift;
my $user = $self->session->user;
return 0 if ! $self->hasSubmissionForms;
for my $groupId (split ' ', $self->get('eventSubmissionGroups')) {
return 1 if $user->isInGroup($groupId);
}
return 0;
}
#------------------------------------------------------------------
@ -178,6 +306,21 @@ sub deleteEventMetaField {
}
#-------------------------------------------------------------------
=head2 ems
this is called by the submission sub-system
it is for compatability and ensures that the ems
object is used for certain calls
=cut
sub ems {
my $self = shift;
return $self;
}
#-------------------------------------------------------------------
=head2 getBadges ()
@ -276,6 +419,7 @@ sub getEventFieldsForImport {
type => $field->{dataType},
options => $field->{possibleValues},
defaultValue => $field->{defaultValues},
helpText => $field->{defaultValues},
});
}
return \@fields;
@ -292,33 +436,37 @@ may be SQL optimized for quick access
sub getLocations {
my $self = shift;
my $dateRef = shift || [ ];
my $dateRef = shift;
my %hash;
my %hashDate;
my %h;
my $tickets = $self->getTickets;
for my $ticket ( @$tickets ) {
my $name = $ticket->location;
my $date = $ticket->startDate;
$hash{$name} = 1 if defined $name;
# cut off the time from the startDate.
$date =~ s/\s*\d+:\d+(:\d+)?// if defined $date;
$hashDate{$date} = 1 if defined $date;
# this is a really compact 'uniq' operation
my @locations = map { $h{$_}++ == 0 ? $_ : () } ( map { $_->location } ( @$tickets ) );
# the dates have the time data removed with a pattern substitution
if( $dateRef ) {
push @$dateRef, map { s/\s*\d+:\d+(:\d+)?//; $h{$_}++ == 0 ? $_ : () } ( map { $_->startDate } ( @$tickets ) );
}
my @locations = sort keys %hash;
push @$dateRef, sort keys %hashDate ;
# @locations = $self->session->db->read(q{
# select distinct(EMSTicket.location)
# from EMSTicket join asset using (assetId)
# where asset.parentId = ?
# order by EMSTicket.location
# },[$self->getId])->array;
return @locations;
}
#-------------------------------------------------------------------
=head2 getNextSubmissionId
get a sequence number for the submission id
=cut
sub getNextSubmissionId {
my $self = shift;
return $self->session->db->getNextId( 'SubmissionId' );
}
#-------------------------------------------------------------------
=head2 getRegistrant ( badgeId )
Returns a hash reference containing the properties of a registrant.
@ -349,6 +497,80 @@ sub getRibbons {
#-------------------------------------------------------------------
=head2 getSubmissionLocations
retuns an arrayref of the locations found in the submission location list
=cut
sub getSubmissionLocations {
my $self = shift;
my $text = $self->get('submittedLocationsList');
return undef if $text eq '';
return [ split( /[\n]+/, $text ) ];
}
#-------------------------------------------------------------------
=head2 getSubmissionForms
returns a list of objects; one for each submission form related to this EMS
this function is called twice in just a few lines of code so the results are cached
to prevent extra hits to the database
=cut
sub getSubmissionForms {
my $self = shift;
return $self->{_submissionForms} if $self->{_submissionFormTime} > time;
$self->{_submissionForms} = $self->getLineage( ['children'], { returnObjects => 1,
includeOnlyClasses => ['WebGUI::Asset::EMSSubmissionForm'],
} );
$self->{_submissionFormTime} = time + 60;
return $self->{_submissionForms};
}
#-------------------------------------------------------------------
=head2 getSubmissionStatus
returns internationalized hash of submission status values or one internationalized name if a status is passed in
=cut
sub getSubmissionStatus {
my $self = shift;
my $key = shift;
unless ($self->{_status}) {
tie my %hash, "Tie::IxHash";
my $i18n = $self->i18n;
for my $item (
'pending',
'feedback',
'denied',
'approved',
'created',
'failed',
) {
$hash{$item} = $i18n->get($item),
}
$self->{_status} = \%hash;
}
if($key) {
return $self->{_status}{$key};
}
return $self->{_status};
}
#-------------------------------------------------------------------
=head2 getTickets ()
Returns an array reference of ticket objects.
@ -384,6 +606,54 @@ sub getTokens {
#-------------------------------------------------------------------
=head2 hasSubmissionForms
returns true if the EMS has subission forms attached
=cut
sub hasSubmissionForms {
my $self = shift;
# are there ~any~ forms attached to this ems?
my $res = $self->getLineage(['children'],{ limit => 1,
includeOnlyClasses => ['WebGUI::Asset::EMSSubmissionForm'],
} );
return scalar(@$res);
}
#-------------------------------------------------------------------
=head2 hasSubmissions
returns true if the current user has submission forms in this EMS
=cut
sub hasSubmissions {
my $self = shift;
return 0 if ! $self->canSubmit;
my $res = $self->getLineage(['descendants'],{ limit => 1,
includeOnlyClasses => ['WebGUI::Asset::EMSSubmission'],
whereClause => q{createdBy='} . $self->session->user->userId . q/'/,
} );
return scalar(@$res);
}
#-------------------------------------------------------------------
=head2 i18n
returns the internationalisation object for this asset
=cut
sub i18n {
my $self = shift;
return $self->{_i18n} ||= WebGUI::International->new($self->session,'Asset_EventManagementSystem');
}
#-------------------------------------------------------------------
=head2 isRegistrationStaff ( [ user ] )
Returns a boolean indicating whether the user is a member of the registration staff.
@ -397,7 +667,7 @@ A WebGUI::User object. Defaults to $session->user.
sub isRegistrationStaff {
my $self = shift;
my $user = shift || $self->session->user;
$user->isInGroup($self->registrationStaffGroupId);
$user->isInGroup($self->registrationStaffGroupId) || $self->canEdit;
}
#-------------------------------------------------------------------
@ -477,9 +747,18 @@ sub view {
addBadgeUrl => $self->getUrl('func=add;class=WebGUI::Asset::Sku::EMSBadge'),
buildBadgeUrl => $self->getUrl('func=buildBadge'),
viewScheduleUrl => $self->getUrl('func=viewSchedule'),
addSubmissionUrl => $self->getUrl('func=viewSubmissionQueue'),
# addSubmissionUrl => $self->getUrl('func=viewSubmissionQueue#addSubmission'),
viewSubmissionQueueUrl => $self->getUrl('func=viewSubmissionQueue'),
addSubmissionFormUrl => $self->getUrl('func=viewSubmissionQueue'),
# addSubmissionFormUrl => $self->getUrl('func=viewSubmissionQueue#addSubmissionForm'),
manageBadgeGroupsUrl=> $self->getUrl('func=manageBadgeGroups'),
getBadgesUrl => $self->getUrl('func=getBadgesAsJson'),
canEdit => $self->canEdit,
isRegistrationStaff => $self->isRegistrationStaff,
canEdit => $self->canEdit,
canSubmit => $self->canSubmit && ! $self->isRegistrationStaff,
hasSubmissions => $self->hasSubmissions,
hasSubmissionForms => $self->hasSubmissionForms,
lookupRegistrantUrl => $self->getUrl('func=lookupRegistrant'),
);
@ -510,6 +789,76 @@ sub www_addRibbonToBadge {
#-------------------------------------------------------------------
=head2 www_addSubmission ()
display a form or links to forms to create a new submission
=cut
sub www_addSubmission {
my $self = shift;
my $params = shift || {};
my $session = $self->session;
my $formId = $params->{formId} || $session->form->get('formId');
my $i18n = WebGUI::International->new($session,'Asset_EventManagementSystem');
my $form;
if( ! defined $formId ) {
my $res = $self->getSubmissionForms;
my @new = map { $_->canSubmit ? $_ : () } ( @$res);
if( scalar(@new) == 0 ) {
return $self->www_view;
} elsif( scalar(@new) == 1 ) {
$form = $new[0];
$formId = $form->getId;
} else {
my $makeAnchorList =sub{ my $u=shift; my $n=shift; my $d=shift;
return qq{<li><a href='$u' onclick='WebGUI.EMS.loadItemFromAnchor(this)' title='$d'>$n</a></li>} } ;
my $listOfLinks = join '', ( map {
$makeAnchorList->(
$self->getUrl('func=viewSubmissionQueue#' . $_->getId . '_new' ), # _new has to match same in sub www_viewSubmissionQueue in this module
$_->get('title'),
WebGUI::HTML::filter($_->get('description'),'all')
)
} ( @new ) );
my $title = $i18n->get('select form to submit') ;
my $asJson = $session->form->get('asJson');
if( $asJson ) {
$session->http->setMimeType( 'application/json' );
} else {
$session->http->setMimeType( 'text/html' );
}
my $content = '<h1>' . $title . '</h1><ul>' . $listOfLinks . '</ul>' ;
if( $asJson ) {
return JSON->new->encode( { text => $content, title => $title, id => 'list' . rand } );
} else {
return $self->ProcessStyle( $content );
}
}
}
$form = WebGUI::Asset->newByDynamicClass($session,$formId);
if (!defined $form) {
$session->errorHandler->error(__PACKAGE__ . " - failed to instanciate asset with assetId $formId");
}
return $form->www_addSubmission;
}
#-------------------------------------------------------------------
=head2 www_addSubmissionForm ()
call www_editSubmissionForm with assetId == new
=cut
sub www_addSubmissionForm {
my $self = shift;
my $params = shift || { };
$self->www_editSubmissionForm( { assetId => 'new', %$params } );
}
#-------------------------------------------------------------------
=head2 www_addTicketsToBadge ()
Adds selected tickets to a badge. Expects two form parameters, assetId (multiples fine) and badgeId, where assetId represents the ticket and badgeId represents the badge.
@ -572,6 +921,7 @@ sub www_buildBadge {
importTicketsUrl => $self->getUrl('func=importEvents'),
exportTicketsUrl => $self->getUrl('func=exportEvents'),
getTicketsUrl => $self->getUrl('func=getTicketsAsJson;badgeId='.$badgeId),
printRemainingTicketsUrl => $self->getUrl('func=printRemainingTickets'),
canEdit => $self->canEdit,
hasBadge => ($badgeId ne ""),
badgeId => $badgeId,
@ -686,6 +1036,62 @@ sub www_editBadgeGroupSave {
#-------------------------------------------------------------------
=head2 www_editSubmission
use getLineage to find the item to edit based on submissionId
then call www_editSubmission on it
=cut
sub www_editSubmission {
my $self = shift;
my $submissionId = $self->session->form->get('submissionId');
my $asset = $self->getLineage(['descendants'], { returnObjects => 1,
joinClass => "WebGUI::Asset::EMSSubmission",
whereClause => 'submissionId = ' . int($submissionId),
includeOnlyClasses => ['WebGUI::Asset::EMSSubmission'],
} );
return $asset->[0]->www_editSubmission;
}
#-------------------------------------------------------------------
=head2 www_editSubmissionForm
calls editSubmissionForm in WebGUI::Asset::EMSSubmissionForm
=cut
sub www_editSubmissionForm {
my $self = shift;
return $self->session->privilege->insufficient() unless $self->isRegistrationStaff || $self->canEdit;
return WebGUI::Asset::EMSSubmissionForm->www_editSubmissionForm($self,shift);
}
#-------------------------------------------------------------------
=head2 www_editSubmissionFormSave
test and save data posted from editSubmissionForm...
=cut
sub www_editSubmissionFormSave {
my $self = shift;
return $self->session->privilege->insufficient() unless $self->isRegistrationStaff || $self->canEdit;
my $formParams = WebGUI::Asset::EMSSubmissionForm->processForm($self);
if( $formParams->{_isValid} ) {
delete $formParams->{_isValid};
$self->addSubmissionForm($formParams);
return $self->www_viewSubmissionQueue;
} else {
return $self->www_editSubmissionForm($formParams);
}
}
#-------------------------------------------------------------------
=head2 www_editEventMetaField ( )
Displays the edit form for event meta fields.
@ -712,6 +1118,7 @@ sub www_editEventMetaField {
required => $self->session->form->process("required",'yesNo'),
possibleValues => $self->session->form->process("possibleValues",'textarea'),
defaultValues => $self->session->form->process("defaultValues",'textarea'),
helpText => $self->session->form->process("helpText",'textarea'),
};
$f->readOnly(
-name => 'error',
@ -768,6 +1175,12 @@ sub www_editEventMetaField {
-hoverHelp => $i18n->get('488 description'),
-value => $data->{defaultValues},
);
$f->textarea(
-name => "helpText",
-label => $i18n2->get('meta field help text'),
-hoverHelp => $i18n2->get('meta field help text description'),
-value => $data->{helpText},
);
$f->submit;
return $self->processStyle($f->print);
}
@ -800,6 +1213,7 @@ sub www_editEventMetaFieldSave {
required => $self->session->form->process("required",'yesNo'),
possibleValues => $self->session->form->process("possibleValues",'textarea'),
defaultValues => $self->session->form->process("defaultValues",'textarea'),
helpText => $self->session->form->process("helpText",'textarea'),
},1,1);
return $self->www_manageEventMetaFields();
}
@ -884,6 +1298,90 @@ sub www_exportEvents {
return "chunked";
}
#----------------------------------------------------------------------------
=head2 www_getAllSubmissions ( )
Get a page of Asset Manager data, ajax style. Returns a JSON array to be
formatted in a WebGUI submission queue data table.
=cut
sub www_getAllSubmissions {
my $self = shift;
my $session = $self->session;
my $datetime = $session->datetime;
my $form = $session->form;
my $tableInfo = {};
return $session->privilege->insufficient unless $self->canSubmit || $self->isRegistrationStaff;
my $orderByColumn = $form->get( 'orderByColumn' ) || $self->get("sortColumn");
my $dir = $form->get('orderByDirection') || $self->get('sortOrder');
my $orderByDirection = lc ($dir) eq "asc" ? "ASC" : "DESC";
my $whereClause ;
if(!$self->isRegistrationStaff) {
my $userId = $session->user->userId;
$whereClause .= qq{ createdBy='$userId'};
}
my $rules;
$rules->{'joinClass' } = "WebGUI::Asset::EMSSubmission";
$rules->{'whereClause' } = $whereClause;
$rules->{'includeOnlyClasses'} = ['WebGUI::Asset::EMSSubmission'];
$rules->{'orderByClause' } = $session->db->dbh->quote_identifier( $orderByColumn ) . ' ' . $orderByDirection if $orderByColumn;
my $sql = "";
$sql = $self->getLineageSql(['descendants'], $rules);
my $startIndex = $form->get( 'startIndex' ) || 1;
my $rowsPerPage = $form->get( 'rowsPerPage' ) || 25;
my $currentPage = int ( $startIndex / $rowsPerPage ) + 1;
my $p = WebGUI::Paginator->new( $session, '', $rowsPerPage, 'pn', $currentPage );
$p->setDataByQuery($sql);
$tableInfo->{'recordsReturned'} = $rowsPerPage;
$tableInfo->{'totalRecords' } = $p->getRowCount;
$tableInfo->{'startIndex' } = $startIndex;
$tableInfo->{'sort' } = $orderByColumn;
$tableInfo->{'dir' } = $orderByDirection;
$tableInfo->{'records' } = [];
for my $record ( @{ $p->getPageData } ) {
my $asset = WebGUI::Asset->newByDynamicClass( $session, $record->{assetId} );
my $lastReplyBy = $asset->get("lastReplyBy");
if ($lastReplyBy) {
$lastReplyBy = WebGUI::User->new($session,$lastReplyBy)->username;
}
# Populate the required fields to fill in
my $lastReplyDate = $asset->get("lastReplyDate");
if($lastReplyDate) {
$lastReplyDate = $datetime->epochToHuman($lastReplyDate,"%y-%m-%d @ %H:%n %p");
}
my %fields = (
submissionId => $asset->get("submissionId"),
url => $asset->getQueueUrl,
title => $asset->get( "title" ),
createdBy => WebGUI::User->new($session,$asset->get( "createdBy" ))->username,
creationDate => $datetime->epochToSet($asset->get( "creationDate" )),
submissionStatus => $self->getSubmissionStatus($asset->get( "submissionStatus" ) || 'pending' ),
lastReplyDate => $lastReplyDate || '',
lastReplyBy => $lastReplyBy || '',
);
push @{ $tableInfo->{ records } }, \%fields;
}
$session->http->setMimeType( 'application/json' );
return JSON->new->encode( $tableInfo );
}
#-------------------------------------------------------------------
=head2 www_getBadgesAsJson ()
@ -922,6 +1420,36 @@ sub www_getBadgesAsJson {
#-------------------------------------------------------------------
=head2 www_getSubmissionById
returns a JSON dataset with info about the requested submission
=cut
sub www_getSubmissionById {
my $self = shift;
my $submissionId = $self->session->form->get('submissionId');
my $result;
my $res = $self->getLineage(['descendants'],{ limit => 1, returnObjects=>1,
includeOnlyClasses => ['WebGUI::Asset::EMSSubmission'],
joinClass => "WebGUI::Asset::EMSSubmission",
whereClause => q{submissionId='} . $submissionId . q/'/,
} );
if( scalar(@$res) == 0 ) {
$result->{hasError} = 1;
$result->{errors} = [ 'failed to load submission' ];
} else {
$result->{text} = $res->[0]->www_editSubmission;
$result->{title} = $submissionId;
$result->{id} = $submissionId;
}
$self->session->http->setMimeType('application/json');
return JSON->new->encode($result);
}
#-------------------------------------------------------------------
=head2 www_getRegistrantAsJson ( )
Retrieves the properties of a specific badge and the items attached to it. Expects badgeId to be one of the form params.
@ -1206,7 +1734,7 @@ sub www_getScheduleDataJSON {
and ( assetData.status = 'approved'
or assetData.tagId = ? )
)
order by EMSTicket.startDate
order by EMSTicket.startDate, eventNumber asc
},[ $self->getId, $currentDate,
$session->scratch->get("versionTag")
]);
@ -1214,8 +1742,10 @@ sub www_getScheduleDataJSON {
tie %hash, 'Tie::IxHash';
while( my $row = $tickets->hashRef ) {
$row->{type} = 'ticket';
$hash{$row->{startDate}}{$row->{location}} = $row;
$row->{location} = '&nbsp;' if $row->{location} eq '';
push @{$hash{$row->{startDate}}{$row->{location}}}, $row;
}
grep { $_ = '&nbsp;' if defined $_ && $_ eq '' } @ticketLocations;
my %results = ();
$results{records} = []; ##Initialize to an empty array
my $ctr = 0;
@ -1223,20 +1753,25 @@ sub www_getScheduleDataJSON {
# fill out the columns in the table
while( $ctr < $locationsPerPage ) { $locationMap{ 'col' . ++$ctr } = '' };
push @{$results{records}}, { colDate => '' , map { $_ , { type => 'label', title => $locationMap{$_} || '' } } ( keys %locationMap ) };
my $redo = 0;
for my $startDate ( keys %hash ) {
$redo = 0;
my $row = { colDate => $startDate };
my $empty = 1;
for my $col ( keys %locationMap ) {
my $location = $locationMap{$col};
if( exists $hash{$startDate}{$location} ) {
$row->{$col} = $hash{$startDate}{$location};
$row->{$col} = pop @{$hash{$startDate}{$location}};
$empty = 0;
$redo = 1 if scalar(@{$hash{$startDate}{$location}}) > 0;
delete $hash{$startDate}{$location} if scalar(@{$hash{$startDate}{$location}}) == 0;
} else {
$row->{$col} = { type => 'empty' };
}
}
next if $empty;
push @{$results{records}}, $row;
redo if $redo;
}
my $rowCount = scalar(@{$results{records}});
@ -1257,8 +1792,6 @@ sub www_getScheduleDataJSON {
return JSON->new->encode(\%results);
}
#-------------------------------------------------------------------
=head2 www_getTicketsAsJson ()
@ -1969,6 +2502,75 @@ sub www_printBadge {
#-------------------------------------------------------------------
=head2 www_printRemainingTickets ()
Displays all of the remaining tickets for this EMS
=cut
sub www_printRemainingTickets {
my $self = shift;
my $session = $self->session;
return $session->privilege->insufficient() unless ($self->isRegistrationStaff);
my $var = $self->get;
my $sth = $session->db->read(qq{
SELECT
asset.creationDate,
assetData.*,
assetData.title as ticketTitle,
EMSTicket.price,
EMSTicket.seatsAvailable,
EMSTicket.startDate as ticketStart,
EMSTicket.duration as ticketDuration,
EMSTicket.eventNumber as ticketEventNumber,
EMSTicket.location as ticketLocation,
EMSTicket.relatedBadgeGroups,
EMSTicket.relatedRibbons,
EMSTicket.eventMetaData,
(seatsAvailable - (select count(*) from EMSRegistrantTicket where ticketAssetId = asset.assetId)) as seatsRemaining
FROM
asset
join assetData using (assetId)
left join EMSTicket using (assetId)
WHERE
parentId=?
and className='WebGUI::Asset::Sku::EMSTicket'
and state='published'
and EMSTicket.revisionDate=(select max(revisionDate) from EMSTicket where assetId=asset.assetId)
and (seatsAvailable - (select count(*) from EMSRegistrantTicket where ticketAssetId = asset.assetId)) > 0
GROUP BY
asset.assetId
ORDER BY
title desc
},[$self->getId]);
$var->{'tickets_loop'} = [];
while (my $hash = $sth->hashRef) {
my $seatsRemaining = $hash->{seatsRemaining};
#Put start time in the correct timezone
my $startTime = WebGUI::DateTime->new($hash->{ticketStart})->set_time_zone($self->get('timezone'));
$hash->{ticketStart} = $startTime->strftime('%F %R');
$hash->{ticketStart_epoch} = $startTime->epoch;
#Add meta data fields
my $data = $hash->{eventMetaData} || '{}';
my $meta = JSON->new->decode($data);
foreach my $key (keys %{$meta}) {
my $tmplKey = $key;
$tmplKey =~ s/[\s\W]/_/g;
$hash->{'ticketMeta_'.$tmplKey} = $meta->{$key};
}
#Add to the loop
for (my $i = 0; $i < $seatsRemaining; $i++ ) {
push(@{$var->{'tickets_loop'}},$hash);
}
}
return $self->processTemplate($var,$self->get('printRemainingTicketsTemplateId'));
}
#-------------------------------------------------------------------
=head2 www_printTicket ( )
Prints a ticket using a template.
@ -2049,7 +2651,7 @@ Toggles the registrant checked in flag.
sub www_toggleRegistrantCheckedIn {
my $self = shift;
return $self->session->privilege->insfufficient() unless ($self->isRegistrationStaff);
return $self->session->privilege->insufficient() unless ($self->isRegistrationStaff);
my $db = $self->session->db;
my $badgeId = $self->session->form->param('badgeId');
my $flag = $db->quickScalar("select hasCheckedIn from EMSRegistrant where badgeId=?",[$badgeId]);
@ -2058,7 +2660,6 @@ sub www_toggleRegistrantCheckedIn {
return $self->www_manageRegistrant;
}
#-------------------------------------------------------------------
=head2 www_viewSchedule ()
@ -2070,7 +2671,6 @@ View the schedule table.
sub www_viewSchedule {
my $self = shift;
return $self->session->privilege->insufficient() unless $self->canView;
my $db = $self->session->db;
my $rowsPerPage = 25;
my $locationsPerPage = $self->scheduleColumnsPerPage;
@ -2091,5 +2691,80 @@ sub www_viewSchedule {
}
#---------------------------------------------
=head2 www_viewSubmissionQueue
=cut
sub www_viewSubmissionQueue {
my $self = shift;
my $isRegistrationStaff = $self->isRegistrationStaff;
my $canSubmit = $self->canSubmit && ! $isRegistrationStaff;
my $canEdit = $self->canEdit;
my $i18n = $self->i18n;
return $self->session->privilege->insufficient() unless $canSubmit || $isRegistrationStaff;
# this map returns an array of hash refs with an id,url pair to describe the submissionForm assets
my @submissionFormUrls = map { { # edit form
id => $_->getId,
edit => 1,
title => $_->get('title'),
linkUrl => $self->getUrl('func=viewSubmissionQueue#' . $_->getId ),
ajaxUrl => $_->getUrl('func=editSubmissionForm'),
},{ # new submission ( _new has to match same in sub www_addSubmission in this module
id => $_->getId . '_new',
title => $_->get('title') . ' - ' . $i18n->get('add submission'),
linkUrl => $self->getUrl('func=viewSubmissionQueue#' . $_->getId . '_new' ),
ajaxUrl => $_->getUrl('func=addSubmission'),
} } (
@{$self->getSubmissionForms}
);
my $params = {
backUrl => $self->getUrl,
isRegistrationStaff => $isRegistrationStaff,
canEdit => $canEdit,
canSubmit => $canSubmit,
hasSubmissionForms => $self->hasSubmissionForms,
getSubmissionQueueDataUrl => $self->getUrl('func=getAllSubmissions'),
editSubmissionUrl => $self->getUrl('func=viewSubmissionQueue#editSubmission'),
editSubmissionFormUrl => $self->getUrl('func=viewSubmissionQueue#editSubmissionForm'),
addSubmissionFormUrl => $self->getUrl('func=viewSubmissionQueue#addSubmissionForm'),
addSubmissionUrl => $self->getUrl('func=viewSubmissionQueue#addSubmission'),
editSubmissionAjaxUrl => $self->getUrl('func=editSubmission'),
editSubmissionFormAjaxUrl => $self->getUrl('func=editSubmissionForm'),
addSubmissionFormAjaxUrl => $self->getUrl('func=addSubmissionForm'),
addSubmissionAjaxUrl => $self->getUrl('func=addSubmission'),
submissionFormUrls => \@submissionFormUrls,
};
push( @{$params->{tabs}}, {
title => $isRegistrationStaff ? $i18n->get('submission queue') : $i18n->get('my submissions'),
text => $self->processTemplate($params,$self->get('eventSubmissionQueueTemplateId')),
} );
if( $isRegistrationStaff ) {
for my $tabSource ( @{$self->getSubmissionForms} ) {
push @{$params->{tabs}}, $tabSource->www_editSubmissionForm( { asHashRef => 1 } );
}
push @{$params->{tabs}}, $self->www_addSubmissionForm( { asHashRef => 1 } );
if( scalar( @{$params->{tabs}} ) == 2 ) { # there were no existing forms
$params->{tabs}[1]{selected} = 1; # the new submission form tab
} else {
$params->{tabs}[0]{selected} = 1; # the submission queue tab
}
}
elsif( $canSubmit ) {
for my $tabSource ( @{$self->getSubmissionForms} ) {
next unless $tabSource->canSubmit;
push @{$params->{tabs}}, $tabSource->www_addSubmission( { asHashRef => 1 } );
}
$params->{tabs}[0]{selected} = 1;
}
my $tabid = 'tab01';
for my $tab ( @{$params->{tabs}} ) { $tab->{id} = $tabid ++; }
return $self->processStyle(
$self->processTemplate( $params, $self->get('eventSubmissionMainTemplateId')));
}
1;