From 15a2cbd8406ef663bb022cc3bcf7a98fef1a6c51 Mon Sep 17 00:00:00 2001 From: David Delikat Date: Fri, 27 Feb 2009 03:37:55 +0000 Subject: [PATCH] first part of coding --- lib/WebGUI/AdSpace/Ad.pm | 1 + lib/WebGUI/Asset/Sku/Ad.pm | 204 +++++++++++++++++++++++++++++++++++++ lib/WebGUI/Form/AdSpace.pm | 197 +++++++++++++++++++++++++++++++++++ t/AdSpace.t | 4 + t/AdSpace/Ad.t | 4 +- 5 files changed, 408 insertions(+), 2 deletions(-) create mode 100644 lib/WebGUI/Asset/Sku/Ad.pm create mode 100644 lib/WebGUI/Form/AdSpace.pm diff --git a/lib/WebGUI/AdSpace/Ad.pm b/lib/WebGUI/AdSpace/Ad.pm index dc0dc2fd6..bf2539437 100644 --- a/lib/WebGUI/AdSpace/Ad.pm +++ b/lib/WebGUI/AdSpace/Ad.pm @@ -82,6 +82,7 @@ Deletes this ad. sub delete { my $self = shift; my $storage = WebGUI::Storage->get($self->session, $self->get("storageId")); +# dav TODO update WebGUI::AssetColateral::Sku::Ad::Ad set delete flag for this AdId $storage->delete if defined $storage; $self->session->db->deleteRow("advertisement","adId",$self->getId); $self = undef; diff --git a/lib/WebGUI/Asset/Sku/Ad.pm b/lib/WebGUI/Asset/Sku/Ad.pm new file mode 100644 index 000000000..b0f12186d --- /dev/null +++ b/lib/WebGUI/Asset/Sku/Ad.pm @@ -0,0 +1,204 @@ +package WebGUI::Asset::Sku::Ad; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2009 Plain Black Corporation. + ------------------------------------------------------------------- + Please read the legal notices (docs/legal.txt) and the license + (docs/license.txt) that came with this distribution before using + this software. + ------------------------------------------------------------------- + http://www.plainblack.com info@plainblack.com + ------------------------------------------------------------------- + +=cut + +use strict; +use Tie::IxHash; +use base 'WebGUI::Asset::Sku'; +use WebGUI::Asset::Template; +use WebGUI::Form; +use WebGUI::Shop::Pay; + +=head1 NAME + +Package WebGUI::Asset::Sku::Ad + +=head1 DESCRIPTION + +This Asset allows ads to be purchased via WebGUI shopping + +=head1 SYNOPSIS + +use WebGUI::Asset::Sku::Ad; + +=head1 METHODS + +These methods are available from this class: + +=cut + +#------------------------------------------------------------------- + +=head2 definition + +Adds templateId, thankYouMessage, and defaultPrice fields. + +=cut + +sub definition { + my $class = shift; + my $session = shift; + my $definition = shift; + my %properties; + tie %properties, 'Tie::IxHash'; + my $i18n = WebGUI::International->new($session, "Asset_AdSku"); + %properties = ( + purchaseTemplate => { + tab => "display", + fieldType => "template", + namespace => "AdSku", + defaultValue => 'eqb9sWjFEVq0yHunGV8IGw', # TODO + label => $i18n->get("purchase template"), + hoverHelp => $i18n->get("purchase template help"), + }, + manageTemplate => { + tab => "display", + fieldType => "template", + namespace => "AdSku", + defaultValue => 'eqb9sWjFEVq0yHunGV8IGw', # TODO + label => $i18n->get("manage template"), + hoverHelp => $i18n->get("manage template help"), + }, + adSpace => { + tab => "properties", + fieldType => "AdSpace", + namespace => "AdSku", + label => $i18n->get("ad space"), + hoverHelp => $i18n->get("ad Space help"), + }, + pricePerClick => { + tab => "properties", + defaultValue => '0.00', + fieldType => "float", + label => $i18n->get("price per click"), + hoverHelp => $i18n->get("price per click help"), + }, + pricePerImpression => { + tab => "properties", + defaultValue => '0.00', + fieldType => "float", + label => $i18n->get("price per impression"), + hoverHelp => $i18n->get("price per impression help"), + }, + clickDiscounts => { + fieldType => 'textarea', + label => $i18n->get('click discounts'), + hoverHelp => $i18n->get('click discounts help'), + defaultValue => '', + }, + impressionDiscounts => { + fieldType => 'textarea', + label => $i18n->get('impression discounts'), + hoverHelp => $i18n->get('impression discounts help'), + defaultValue => '', + }, + ); + + # Show the karma field only if karma is enabled + if ($session->setting->get("useKarma")) { + $properties{ karma } = { + type => 'integer', + label => $i18n->get('adsku karma'), + hoverHelp => $i18n->get('adsku karma description'), + defaultvalue => 0, + }; + } + + push(@{$definition}, { + assetName => $i18n->get('assetName'), + icon => 'adsku.gif', + autoGenerateForms => 1, + tableName => 'AdSku', + className => 'WebGUI::Asset::Sku::AdSku', + properties => \%properties, + }); + return $class->SUPER::definition($session, $definition); +} + +#------------------------------------------------------------------- + +=head2 onCompletePurchase + +Applies the first term of the subscription. This method is called when the payment is successful. + +=cut + +sub onCompletePurchase { + my $self = shift; + + # $self->apply; +} + +#------------------------------------------------------------------- + +=head2 prepareView + +Prepares the template. + +=cut + +sub prepareView { + my $self = shift; + $self->SUPER::prepareView(); + my $templateId = $self->get("templateId"); + my $template = WebGUI::Asset::Template->new($self->session, $templateId); + $template->prepare($self->getMetaDataAsTemplateVariables); + $self->{_viewTemplate} = $template; +} + +#------------------------------------------------------------------- + +=head2 view + +Displays the donation 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), + purchaseButton => WebGUI::Form::submit( $session, { value => $i18n->get("purchase button") }), + hasAddedToCart => $self->{_hasAddedToCart}, + continueShoppingUrl => $self->getUrl, + price => sprintf("%.2f", $self->getPrice), + ); + return $self->processTemplate(\%var,undef,$self->{_viewTemplate}); +} + +#------------------------------------------------------------------- + +=head2 www_purchaseAdSKu + +Add this subscription to the cart. + +=cut + +sub www_purchaseAdSku { + my $self = shift; + if ($self->canView) { + $self->{_hasAddedToCart} = 1; + $self->addToCart({price => $self->getPrice}); + } + return $self->www_view; +} + +1; + diff --git a/lib/WebGUI/Form/AdSpace.pm b/lib/WebGUI/Form/AdSpace.pm new file mode 100644 index 000000000..f9231d9aa --- /dev/null +++ b/lib/WebGUI/Form/AdSpace.pm @@ -0,0 +1,197 @@ +package WebGUI::Form::AdSpace; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2009 Plain Black Corporation. + ------------------------------------------------------------------- + Please read the legal notices (docs/legal.txt) and the license + (docs/license.txt) that came with this distribution before using + this software. + ------------------------------------------------------------------- + http://www.plainblack.com info@plainblack.com + ------------------------------------------------------------------- + +=cut + +use strict; +use base 'WebGUI::Form::SelectList'; +use WebGUI::International; +use WebGUI::SQL; + +=head1 NAME + +Package WebGUI::Form::AdSpace + +=head1 DESCRIPTION + +Creates a group chooser field for AdSpace values. + +=head1 SEE ALSO + +This is a subclass of WebGUI::Form::SelectList. + +=head1 METHODS + +The following methods are specifically available from this class. Check the superclass for additional methods. + +=cut + +#------------------------------------------------------------------- + +=head2 areOptionsSettable ( ) + +Returns 0. + +=cut + +sub areOptionsSettable { + return 0; +} + +#------------------------------------------------------------------- + +=head2 definition ( [ additionalTerms ] ) + +See the super class for additional details. + +=head3 additionalTerms + +The following additional parameters have been added via this sub class. + +=head4 size + +How many rows should be displayed at once? Defaults to 1. + +=head4 multiple + +Set to "1" if multiple groups should be selectable. Defaults to 0. + +=head4 excludeGroups + +An array reference containing a list of groups to exclude from the list. Defaults to an empty array reference. + +=head4 defaultValue + +This will be used if no value is specified. Should be passed as an array reference. Defaults to 7 (Everyone). + +=cut + +sub definition { + my $class = shift; + my $session = shift; + my $definition = shift || []; + push(@{$definition}, { + size=>{ + defaultValue=>1 + }, + defaultValue=>{ + defaultValue=>[7] + }, + }); + return $class->SUPER::definition($session, $definition); +} + +#------------------------------------------------------------------- + +=head2 getDatabaseFieldType ( ) + +Returns "CHAR(22) BINARY". + +=cut + +sub getDatabaseFieldType { + return "CHAR(22) BINARY"; +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('Ad Space'); +} + +#------------------------------------------------------------------- + +=head2 getValueAsHtml ( ) + +Formats as a name. + +=cut + +sub getValueAsHtml { + my $self = shift; + my $group = WebGUI::Group->new($self->session, $self->getOriginalValue); + if (defined $group) { + return $group->name; + } + return undef; +} + + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Returns a group pull-down field. A group pull down provides a select list that provides name value pairs for all the groups in the WebGUI system. + +=cut + +sub toHtml { + my $self = shift; + $self->set('options', { map { $_->getId => $_->getName } ( WebGUI::AdSpace->getAdSpaces() ) } ); + return $self->SUPER::toHtml(); +} + +#------------------------------------------------------------------- + +=head2 toHtmlAsHidden ( ) + +Creates a series of hidden fields representing the data in the list. + +=cut + +sub toHtmlAsHidden { + my $self = shift; + $self->set('options', { map { $_->getId => $_->getName } ( WebGUI::AdSpace->getAdSpaces() ) } ); + return $self->SUPER::toHtmlAsHidden(); +} + +#------------------------------------------------------------------- + +=head2 toHtmlWithWrapper ( ) + +Renders the form field to HTML as a table row complete with labels, subtext, hoverhelp, etc. Also adds a manage icon next to the field if the current user is in the admins group. + +=cut + +sub toHtmlWithWrapper { + my $self = shift; + if ($self->session->user->isAdmin) { + my $subtext = $self->session->icon->manage("op=listGroups"); + $self->set("subtext",$subtext . $self->get("subtext")); + } + return $self->SUPER::toHtmlWithWrapper; +} + + +1; + diff --git a/t/AdSpace.t b/t/AdSpace.t index 9932de530..9e0b99167 100644 --- a/t/AdSpace.t +++ b/t/AdSpace.t @@ -40,6 +40,10 @@ plan tests => $numTests; my $loaded = use_ok('WebGUI::AdSpace'); my $session = WebGUI::Test->session; +# we need to set env vars to satisfy the 'requestNotViewed' +# test otherwise we will get nothing back... +$session->env()->{_env}{HTTP_USER_AGENT} = 'Mozilla'; +$session->env()->{_env}{REMOTE_ADDR} = '127.0.0.1'; my ($adSpace, $alfred, $alfred2, $bruce, $catWoman, $villianClone, $defaultAdSpace ); my ($jokerAd, $penguinAd, $twoFaceAd); diff --git a/t/AdSpace/Ad.t b/t/AdSpace/Ad.t index d0f725285..a3c01c85f 100644 --- a/t/AdSpace/Ad.t +++ b/t/AdSpace/Ad.t @@ -115,7 +115,7 @@ SKIP: { ##Link checks $token = $textP->get_tag("a"); - my $href = $token->[1]{href}; + my $href = $token->[1]{onclick}; like($href, qr/op=clickAd/, 'ad link has correct operation'); my $adId = $textAd->getId; @@ -159,7 +159,7 @@ SKIP: { ##Link checks $token = $textP->get_tag("a"); - my $href = $token->[1]{href}; + my $href = $token->[1]{onclick}; like($href, qr/op=clickAd/, 'ad link has correct operation, image'); $adId = $imageAd->getId;