yet another check point

This commit is contained in:
David Delikat 2009-03-19 01:42:22 +00:00
parent 3c56bb64ae
commit 66c6c0fae5
3 changed files with 209 additions and 149 deletions

View file

@ -1,5 +1,8 @@
package WebGUI::Asset::Sku::Ad; package WebGUI::Asset::Sku::Ad;
use lib '/root/pb/lib';
use dav;
=head1 LEGAL =head1 LEGAL
------------------------------------------------------------------- -------------------------------------------------------------------
@ -20,6 +23,7 @@ use base 'WebGUI::Asset::Sku';
use WebGUI::Asset::Template; use WebGUI::Asset::Template;
use WebGUI::Form; use WebGUI::Form;
use WebGUI::Shop::Pay; use WebGUI::Shop::Pay;
use WebGUI::AssetCollateral::Sku::Ad::Ad;
=head1 NAME =head1 NAME
@ -136,6 +140,99 @@ sub definition {
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 getDiscountText -- class level function
returns a string with a coma seperated list of counts fromt he discount text
=cut
sub getDiscountText {
my($format,$discounts) = @_;
return sprintf( $format, join( ',', (map { $_->[1] } ( parseDiscountText( $discounts ) ) ) ) );
}
#-------------------------------------------------------------------
=head2 getClickDiscountText
returns the text to display the number of clicks purchasaed where discounts apply
=cut
sub getClickDiscountText {
my $self = shift;
return getDiscountText($self->i18n->get('click discount'),
$self->get('clickDiscounts'));
}
#-------------------------------------------------------------------
=head2 getImpressionDiscountText
returns the text to display the number of impressions purchased where discounts apply
=cut
sub getImpressionDiscountText {
my $self = shift;
return getDiscountText($self->i18n->get('impression discount'),
$self->get('impressionDiscounts'));
}
#-------------------------------------------------------------------
=head2 i18n
returns an internationalization object for this class
=cut
sub i18n {
my $self = shift;
return WebGUI::International->new($self->session, "Asset_AdSku");
}
#-------------------------------------------------------------------
=head2 manage
generate template vars for manage page
=cut
sub manage {
my ($self) = @_;
my $session = $self->session;
my $i18n = WebGUI::International->new($session, "Asset_AdSku");
my %var;
$var{purchaseLink} = $self->getUrl;
#WebGUI::AssetCollateral::Sku::Ad::Ad->crud_createTable($session);
my $iterator = WebGUI::AssetCollateral::Sku::Ad::Ad->getAllIterator($session,{
constraints => [ { "adSkuPurchase.userId = ?" => $self->session->user->userId } ],
joinUsing => [ { "advertisement" => "adId" }, ],
'join' => [ "transactionItem on transactionItem.itemId = adSkuPurchase.transactionItemId",
"transaction on transaction.transactionId = transactionItem.transactionId",
],
orderBy => 'transaction.dateOfPurchase',
});
my %testHash; # used to eliminate duplicate ads
while( my $object = $iterator->() ) {
next if exists $testHash{$object->get('adId')};
$testHash{$object->get('adId')} = 1;
push @{$var{myAds}}, {
rowTitle => $object->get('title'),
rowClicks => $object->get('clicks') . '/' . $object->get('clicksBought'),
rowImpressions => $object->get('impressions') . '/' . $object->get('impressionsBought'),
rowDeleted => $object->get('isDeleted'),
rowRenewLink => $self->getUrl('renew=' . $object->get('adId') ),
};
}
return $self->processTemplate(\%var,undef,$self->{_viewTemplate});
}
#-------------------------------------------------------------------
=head2 onCompletePurchase =head2 onCompletePurchase
Applies the first term of the subscription. This method is called when the payment is successful. Applies the first term of the subscription. This method is called when the payment is successful.
@ -150,6 +247,46 @@ sub onCompletePurchase {
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 parseDiscountText -- class level function
returns an array of array ref's that are extracted from the discount description text
=cut
sub parseDiscountText {
my $discountDescription = shift;
dav::log $discountDescription;
my @lines = split "\n", $discountDescription;
my @discounts;
foreach my $line ( @lines ) {
dav::log $line;
if( $line =~ /^(\d+)\@(\d+)/ ) {
dav::log 'match';
push @discounts, [ $1, $2 ];
}
}
return @discounts;
}
#-------------------------------------------------------------------
=head2 prepareManage
Prepares the template.
=cut
sub prepareManage {
my $self = shift;
$self->SUPER::prepareView();
my $templateId = $self->get("manageTemplate");
my $template = WebGUI::Asset::Template->new($self->session, $templateId);
$template->prepare($self->getMetaDataAsTemplateVariables);
$self->{_viewTemplate} = $template;
}
#-------------------------------------------------------------------
=head2 prepareView =head2 prepareView
Prepares the template. Prepares the template.
@ -167,19 +304,63 @@ sub prepareView {
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 prepareManage =head2 view
Prepares the template. Displays the purchase adspace form
=cut =cut
sub prepareManage { sub view {
my $self = shift; my ($self) = @_;
$self->SUPER::prepareView(); my $session = $self->session;
my $templateId = $self->get("manageTemplate");
my $template = WebGUI::Asset::Template->new($self->session, $templateId); my $i18n = WebGUI::International->new($session, "Asset_AdSku");
$template->prepare($self->getMetaDataAsTemplateVariables); my %var = (
$self->{_viewTemplate} = $template; formHeader => WebGUI::Form::formHeader($session, { action=>$self->getUrl })
. WebGUI::Form::hidden( $session, { name=>"func", value=>"addToCart" }),
formFooter => WebGUI::Form::formFooter($session),
formSubmit => WebGUI::Form::submit( $session, { value => $i18n->get("purchase button") }),
hasAddedToCart => $self->{_hasAddedToCart},
continueShoppingUrl => $self->getUrl,
manageLink => $self->getUrl("func=manage"),
adSkuTitle => $self->get('title'),
adSkuDescription => $self->get('description'),
form_title => WebGUI::Form::text($session, {
-name=>"form_title",
-value=>$self->{title},
-size=>40
-default=>'untitled',
}),
form_link => WebGUI::Form::Url($session, {
-name=>"form_link",
-value=>$self->{link},
-size=>40
-required=>1,
}),
form_image => WebGUI::Form::Image($session, {
-name=>"form_image",
-value=>$self->{image},
-size=>40
-required=>1,
}),
form_clicks => WebGUI::Form::Integer($session, {
-name=>"form_clicks",
-value=>$self->{clicks},
-size=>40
-required=>1,
}),
form_impressions => WebGUI::Form::Integer($session, {
-name=>"form_impressions",
-value=>$self->{impressions},
-size=>40
-required=>1,
}),
click_price => $self->get('pricePerClick'),
impression_price => $self->get('pricePerImpression'),
click_discount => $self->getClickDiscountText,
impression_discount => $self->getImpressionDiscountText,
);
return $self->processTemplate(\%var,undef,$self->{_viewTemplate});
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -207,141 +388,13 @@ sub www_manage {
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 manage =head2 www_addToCart
generate template vars for manage page
=cut
sub manage {
my ($self) = @_;
my $session = $self->session;
my $i18n = WebGUI::International->new($session, "Asset_AdSku");
# TODO get the user id, get the asset collateral crud by uid, sort by purchase date descending, pull out unique adids
my %var = (
formHeader => WebGUI::Form::formHeader($session, { action=>$self->getUrl })
. WebGUI::Form::hidden( $session, { name=>"func", value=>"purchaseAdSku" }),
formFooter => WebGUI::Form::formFooter($session),
form_submit => WebGUI::Form::submit( $session, { value => $i18n->get("purchase button") }),
hasAddedToCart => $self->{_hasAddedToCart},
continueShoppingUrl => $self->getUrl,
purchaseLink => $self->getUrl,
myAds => [
# TODO foreach unique adis create a row here
{ rowTitle => 'here is an ad', rowClicks => '5/200', rowImpressions => '100/2000', rowDeleted => 0, rowRenewLink => '' },
{ rowTitle => 'yet another ad', rowClicks => '99/4000', rowImpressions => '10/200', rowDeleted => 1, rowRenewLink => '' },
],
);
return $self->processTemplate(\%var,undef,$self->{_viewTemplate});
}
#-------------------------------------------------------------------
=head2 view
Displays the purchase adspace form
=cut
sub view {
my ($self) = @_;
my $session = $self->session;
my $i18n = WebGUI::International->new($session, "Asset_AdSku");
my %var = (
formHeader => WebGUI::Form::formHeader($session, { action=>$self->getUrl })
. WebGUI::Form::hidden( $session, { name=>"func", value=>"purchaseAdSku" }),
formFooter => WebGUI::Form::formFooter($session),
form_submit => WebGUI::Form::submit( $session, { value => $i18n->get("purchase button") }),
hasAddedToCart => $self->{_hasAddedToCart},
continueShoppingUrl => $self->getUrl,
manageLink => $self->getUrl("func=manage"),
adSkuTitle => $self->get('title'),
adSkuDescription => $self->get('description'),
form_title => WebGUI::Form::text($session, {
-name=>"form_title",
-value=>$self->{title},
-size=>40
}),
form_link => WebGUI::Form::Url($session, {
-name=>"form_link",
-value=>$self->{link},
-size=>40
}),
form_image => WebGUI::Form::Image($session, {
-name=>"form_image",
-value=>$self->{image},
-size=>40
}),
form_clicks => WebGUI::Form::Integer($session, {
-name=>"form_clicks",
-value=>$self->{clicks},
-size=>40
}),
form_impressions => WebGUI::Form::Integer($session, {
-name=>"form_impressions",
-value=>$self->{impressions},
-size=>40
}),
click_price => $self->get('pricePerClick'),
impression_price => $self->get('pricePerImpression'),
click_discount => $self->getClickDiscountText,
impression_discount => $self->getImpressionDiscountText,
);
return $self->processTemplate(\%var,undef,$self->{_viewTemplate});
}
#-------------------------------------------------------------------
=head2 getDiscountCountList -- class level function
returns a string with a coma seperated list of counts fromt he discount text
=cut
sub getDiscountCountList {
# TODO
# parse the discount text -- for each line, get the first number
# join all the number in a coma,list
return '500';
}
#-------------------------------------------------------------------
=head2 getClickDiscountText
returns the text to display the number of clicks purchasaed where discounts apply
=cut
sub getClickDiscountText {
my $self = shift;
return getDiscountCountList($self->get('ClickDiscounts'));
}
#-------------------------------------------------------------------
=head2 getImpressionDiscountText
returns the text to display the number of impressions purchased where discounts apply
=cut
sub getImpressionDiscountText {
my $self = shift;
return getDiscountCountList($self->get('impressionDiscounts'));
}
#-------------------------------------------------------------------
=head2 www_purchaseAdSKu
Add this subscription to the cart. Add this subscription to the cart.
=cut =cut
sub www_purchaseAdSku { sub www_addToCart {
my $self = shift; my $self = shift;
if ($self->canView) { if ($self->canView) {
$self->{_hasAddedToCart} = 1; $self->{_hasAddedToCart} = 1;

View file

@ -16,7 +16,7 @@ package WebGUI::AssetCollateral::Sku::Ad::Ad;
use strict; use strict;
use base WebGUI::Crud; use base 'WebGUI::Crud';
#------------------------------------------------ #------------------------------------------------
@ -24,14 +24,14 @@ use base WebGUI::Crud;
defines the field this crud will contain defines the field this crud will contain
userID => the id of the user that purchased the ad userID = the id of the user that purchased the ad
transactionItemid => the id if the transaction item that completes this purchase transactionItemid = the id if the transaction item that completes this purchase
adId => th id if the ad purchased adId = th id if the ad purchased
clicksPurchased => the number of clicks the user purchased clicksPurchased = the number of clicks the user purchased
impressionsPurchased => the number of impressions the user purchased impressionsPurchased = the number of impressions the user purchased
storedImage => temp storage for the image storedImage = temp storage for the image
isRenewal => indicates if this purchase is a renewal -- are the counts increased or just assigned isRenewal = indicates if this purchase is a renewal -- are the counts increased or just assigned
isDeleted => boolean that indicates whether the ad has been deleted from the system isDeleted = boolean that indicates whether the ad has been deleted from the system
=cut =cut
@ -45,7 +45,7 @@ sub crud_definition {
fieldType => 'user', fieldType => 'user',
defaultValue => undef, defaultValue => undef,
}, },
transactionItemid => { transactionItemId => {
fieldType => 'guid', fieldType => 'guid',
defaultValue => undef, defaultValue => undef,
}, },
@ -77,4 +77,5 @@ sub crud_definition {
return $definition; return $definition;
} }
1;

View file

@ -225,6 +225,12 @@ our $I18N = {
context => q|contents for the renew field on the manage ads table: indicates a renewable item| context => q|contents for the renew field on the manage ads table: indicates a renewable item|
}, },
'purchase button' => {
message => q|Add To Cart|,
lastUpdated => 0,
context => q|add the described item to the shopping cart|
},
'TODO' => { 'TODO' => {
message => q|TODO|, message => q|TODO|,
lastUpdated => 0, lastUpdated => 0,