fixed a bunch of bugs related to ad management system and finished writing the ui

This commit is contained in:
JT Smith 2006-04-07 01:53:36 +00:00
parent fba5580d15
commit 540523d6dd
3 changed files with 193 additions and 21 deletions

View file

@ -58,8 +58,9 @@ The properties used to create this object. See the set() method for details.
sub create {
my $class = shift;
my $session = shift;
my $adSpaceId = shift;
my $properties = shift;
my $id = $session->db->setRow("adSpace","adSpaceId",{adSpaceId=>"new"});
my $id = $session->db->setRow("advertisement","adId",{adSpaceId=>$adSpaceId, adId=>"new"});
my $self = $class->new($session, $id);
$self->set($properties);
return $self;
@ -76,8 +77,8 @@ Deletes this ad.
sub delete {
my $self = shift;
my $storage = WebGUI::Storage::Image->new($self->session, $self->get("storageId"));
$storage->delete;
my $storage = WebGUI::Storage::Image->get($self->session, $self->get("storageId"));
$storage->delete if defined $storage;
$self->session->db->deleteRow("advertisement","adId",$self->getId);
$self = undef;
}
@ -186,10 +187,6 @@ A chunk of text, no longer than 255 characters that will be displayed in text ad
The id of the storage location that holds the image for an image style ad.
=head4 filename
The name of the file from the storage location to display for an image ad.
=head4 richMedia
A chunk of HTML that will be inserted into the page for rich media ads.
@ -244,7 +241,6 @@ sub set {
$self->{_properties}{impressionsBought} = $properties->{impressionsBought} || $self->{_properties}{impressionsBought};
$self->{_properties}{url} = $properties->{url} || $self->{_properties}{url};
$self->{_properties}{adText} = $properties->{adText} || $self->{_properties}{adText};
$self->{_properties}{filename} = $properties->{filename} || $self->{_properties}{filename};
$self->{_properties}{storageId} = $properties->{storageId} || $self->{_properties}{storageId};
$self->{_properties}{richMedia} = $properties->{richMedia} || $self->{_properties}{richMedia};
$self->{_properties}{ownerUserId} = $properties->{ownerUserId} || $self->{_properties}{ownerUserId} || "3";
@ -257,10 +253,16 @@ sub set {
# prerender the ad for faster display
my $adSpace = WebGUI::AdSpace->new($self->session, $self->get("adSpaceId"));
if ($self->get("type") eq "text") {
$self->{_properties}{renderedAd} = '<a href="'.$self->session->url->gateway(undef, "op=clickAd;id=".$self->getId).'"><div style="overflow: hidden; width: '.$adSpace->get("width").'px; height: '.$adSpace->get("height").'px; color: '.$self->get("textColor").'; background-color: '.$self->get("backgroundColor").'; border: 1px solid '.$self->get("borderColor").';"><b>'.$self->get("title").'</b><br />'.$self->get("adText").'</div></a>';
$self->{_properties}{renderedAd} = '<a href="'.$self->session->url->gateway(undef, "op=clickAd;id=".$self->getId)
.'"><div style="overflow: hidden; width: '.$adSpace->get("width")
.'px; height: '.$adSpace->get("height").'px; color: '
.$self->get("textColor")
.'; background-color: '.$self->get("backgroundColor")
.'; border: 1px solid '.$self->get("borderColor").';"><b>'
.$self->get("title").'</b><br />'.$self->get("adText").'</div></a>';
} elsif ($self->get("type") eq "image") {
my $storage = WebGUI::Storage::Image->new($self->session, $self->get("storageId"));
$self->{_properties}{renderedAd} = '<a href="'.$self->session->url->gateway(undef, "op=clickAd;id=".$self->getId).'"><div style="overflow: hidden; width: '.$adSpace->get("width").'px; height: '.$adSpace->get("height").'px;"><img src="'.$storage->getUrl($self->get("filename")).'" style="border: 0px;" alt="'.$self->get("title").'" /></div></a>';
my $storage = WebGUI::Storage::Image->get($self->session, $self->get("storageId"));
$self->{_properties}{renderedAd} = '<a href="'.$self->session->url->gateway(undef, "op=clickAd;id=".$self->getId).'"><div style="overflow: hidden; width: '.$adSpace->get("width").'px; height: '.$adSpace->get("height").'px;"><img src="'.$storage->getUrl($storage->getFiles->[0]).'" style="border: 0px;" alt="'.$self->get("title").'" /></div></a>';
} elsif ($self->get("type") eq "rich") {
$self->{_properties}{renderedAd} = $self->get("richMedia");

View file

@ -16,6 +16,7 @@ use WebGUI::AdSpace::Ad;
use WebGUI::AdminConsole;
use WebGUI::International;
use WebGUI::HTMLForm;
use WebGUI::Storage::Image;
=head1 NAME
@ -46,6 +47,36 @@ sub www_clickAd {
#-------------------------------------------------------------------
=head2 www_deleteAd ( )
Deletes an ad.
=cut
sub www_deleteAd {
my $session = shift;
return $session->privilege->insufficient unless ($session->user->isInGroup("pbgroup000000000000017"));
WebGUI::AdSpace::Ad->new($session, $session->form->param("adId"))->delete;
return www_editAdSpace($session);
}
#-------------------------------------------------------------------
=head2 www_deleteAdSpace ( )
Deletes an ad space.
=cut
sub www_deleteAdSpace {
my $session = shift;
return $session->privilege->insufficient unless ($session->user->isInGroup("pbgroup000000000000017"));
WebGUI::AdSpace->new($session, $session->form->param("adSpaceId"))->delete;
return www_manageAdSpaces($session);
}
#-------------------------------------------------------------------
=head2 www_editAd ( )
Displays form for editing an ad.
@ -59,7 +90,7 @@ sub www_editAd {
my $ac = WebGUI::AdminConsole->new($session,"adSpace");
my $i18n = WebGUI::International->new($session,"AdSpace");
my $ad = WebGUI::AdSpace::Ad->new($session,$id);
$ac->addSubmenuItem($session->url->page("op=editAdSpace;adSpace=".$session->form->param("adSpace")), $i18n->get("edit this ad space"));
$ac->addSubmenuItem($session->url->page("op=editAdSpace;adSpaceId=".$session->form->param("adSpaceId")), $i18n->get("edit this ad space"));
$ac->addSubmenuItem($session->url->page("op=editAdSpace"), $i18n->get("add ad space"));
$ac->addSubmenuItem($session->url->page("op=manageAdSpaces"), $i18n->get("manage ad spaces"));
my $f = WebGUI::HTMLForm->new($session);
@ -67,7 +98,7 @@ sub www_editAd {
$f->hidden(name=>"adId", value=>$id);
$f->hidden(name=>"adSpaceId", value=> $session->form->param("adSpaceId"));
$f->readOnly(label=>$i18n->get("ad id"), value=>$id);
$f->hidden(name=>"op", value=>"editAdSpaceSave");
$f->hidden(name=>"op", value=>"editAdSave");
my $value = $ad->get("isActive") if defined $ad;
$f->yesNo(
name=>"isActive",
@ -82,6 +113,20 @@ sub www_editAd {
hoverHelp => $i18n->get("title help"),
label=>$i18n->get("title")
);
my $value = $ad->get("url") if defined $ad;
$f->url(
name=>"url",
value=>$value,
hoverHelp => $i18n->get("url help"),
label=>$i18n->get("url")
);
my $value = $ad->get("priority") if defined $ad;
$f->integer(
name=>"priority",
value=>$value,
hoverHelp => $i18n->get("priority help"),
label=>$i18n->get("priority"),
);
my $value = $ad->get("impressionsBought") if defined $ad;
$f->integer(
name=>"impressionsBought",
@ -108,13 +153,14 @@ sub www_editAd {
rich=>$i18n->get("rich"),
},
defaultValue=>"text",
hoverHelp => $i18n->get("top help"),
label=>$i18n->get("title")
hoverHelp => $i18n->get("type help"),
label=>$i18n->get("type")
);
$f->fieldSetStart($i18n->get("text"));
my $value = $ad->get("adText") if defined $ad;
$f->text(
name=>"adText",
size=>60,
value=>$value,
hoverHelp => $i18n->get("ad text help"),
label=>$i18n->get("ad text")
@ -125,7 +171,7 @@ sub www_editAd {
value=>$value,
defaultValue=>"#000000",
hoverHelp => $i18n->get("border color help"),
label=>$i18n->get("border color text")
label=>$i18n->get("border color")
);
my $value = $ad->get("textColor") if defined $ad;
$f->color(
@ -133,7 +179,7 @@ sub www_editAd {
value=>$value,
defaultValue=>"#000000",
hoverHelp => $i18n->get("text color help"),
label=>$i18n->get("text color text")
label=>$i18n->get("text color")
);
my $value = $ad->get("backgroundColor") if defined $ad;
$f->color(
@ -141,12 +187,14 @@ sub www_editAd {
value=>$value,
defaultValue=>"#ffffff",
hoverHelp => $i18n->get("background color help"),
label=>$i18n->get("background color text")
label=>$i18n->get("background color")
);
$f->fieldSetEnd;
$f->fieldSetStart($i18n->get("image"));
$f->image(
label=>$i18n->get("image")
label=>$i18n->get("image"),
hoverHelp=>$i18n->get("image help"),
name=>"image"
);
$f->fieldSetEnd;
$f->fieldSetStart($i18n->get("rich"));
@ -162,6 +210,46 @@ sub www_editAd {
$ac->render($f->print, $i18n->get("edit advertisement"));
}
#-------------------------------------------------------------------
=head2 www_editAdSave ( )
The save method for www_editAd()
=cut
sub www_editAdSave {
my $session = shift;
return $session->privilege->insufficient unless ($session->user->isInGroup("pbgroup000000000000017"));
my %properties = (
type=>$session->form->process("type", "selectBox"),
url=>$session->form->process("url", "url"),
isActive=>$session->form->process("isActive", "yesNo"),
textColor=>$session->form->process("textColor", "color"),
backgroundColor=>$session->form->process("backgroundColor", "color"),
borderColor=>$session->form->process("borderColor", "color"),
title=>$session->form->process("title", "text"),
adText=>$session->form->process("adText", "text"),
richMedia=>$session->form->process("richMedia", "codearea"),
priority=>$session->form->process("priority", "integer"),
impressionsBought=>$session->form->process("impressionsBought", "integer"),
clicksBought=>$session->form->process("clicksBought", "integer"),
);
my $storageId = $session->form->process("image","image");
$properties{storageId} = $storageId if (defined $storageId);
if ($session->form->param("adId") eq "new") {
WebGUI::AdSpace::Ad->create($session, $session->form->param("adSpaceId"), \%properties);
} else {
my $ad = WebGUI::AdSpace::Ad->new($session, $session->form->param("adId"));
if (defined $storageId && $ad->get("storageId")) {
WebGUI::Storage::Image->get($session, $ad->get("storageId"))->delete;
}
$ad->set(\%properties);
}
return www_editAdSpace($session);
}
#-------------------------------------------------------------------
=head2 www_editAdSpace ( )
@ -177,9 +265,10 @@ sub www_editAdSpace {
my $ac = WebGUI::AdminConsole->new($session,"adSpace");
my $i18n = WebGUI::International->new($session,"AdSpace");
my $adSpace = WebGUI::AdSpace->new($session, $id);
$ac->addSubmenuItem($session->url->page("op=editAd"), $i18n->get("add an ad")) if defined $adSpace;
$ac->addSubmenuItem($session->url->page("op=editAd;adSpaceId=".$id), $i18n->get("add an ad")) if defined $adSpace;
$ac->addSubmenuItem($session->url->page("op=manageAdSpaces"), $i18n->get("manage ad spaces"));
my $f = WebGUI::HTMLForm->new($session);
$f->submit;
$f->hidden(name=>"adSpaceId", value=>$id);
$f->readOnly(label=>$i18n->get("ad space id"), value=>$id);
$f->hidden(name=>"op", value=>"editAdSpaceSave");
@ -223,12 +312,15 @@ sub www_editAdSpace {
$f->submit;
my $ads = "";
if (defined $adSpace) {
my $rs = $session->db->read("select adId, title from advertisement where adId=?",[$id]);
$ads .= '<p style="padding: 10px; line-height: 30px; text-align: center; border: 3px outset black; width: 250px; float: right;">'.$i18n->get("macro code prompt").'<br /><b>&#94;AdSpace('.$adSpace->get("name").');</b></p>'
."<p>";
my $rs = $session->db->read("select adId, title from advertisement where adSpaceId=?",[$id]);
while (my ($adId, $title) = $rs->array) {
$ads .= $session->icon->delete("op=deleteAd;adSpaceId=".$id.";adId=".$adId, undef, $i18n->get("confirm ad delete"))
.$session->icon->edit("op=editAd;adSpaceId=".$id.";adId=".$adId)
.' '.$title.'<br />';
}
$ads .= "</p>";
}
$ac->render($f->print.$ads, $i18n->get("edit ad space"));
}

View file

@ -2,6 +2,84 @@ package WebGUI::i18n::English::AdSpace;
our $I18N = {
'macro code prompt' => {
message => q|Use this code to place this ad space:|,
lastUpdated => 0,
context => q|this is a label for the output of macro code that the user can use to place his/her ad space|
},
'border color' => {
message => q|Border Color|,
lastUpdated => 0,
context => q|a form property in the ad editor|
},
'border color help' => {
message => q|The hex value of the color of the border to be used around this text ad.|,
lastUpdated => 0,
context => q|help for a form property in the ad editor|
},
'text color' => {
message => q|Text Color|,
lastUpdated => 0,
context => q|a form property in the ad editor|
},
'text color help' => {
message => q|The hex value of the color of the text in this text ad.|,
lastUpdated => 0,
context => q|help for a form property in the ad editor|
},
'background color' => {
message => q|Background Color|,
lastUpdated => 0,
context => q|a form property in the ad editor|
},
'background color help' => {
message => q|The hex value of the color of the background in this text ad.|,
lastUpdated => 0,
context => q|help for a form property in the ad editor|
},
'url' => {
message => q|URL|,
lastUpdated => 0,
context => q|a form property in the ad editor|
},
'url help' => {
message => q|The URL that this ad will link to. Note that this won't be used for Rich Media ads.|,
lastUpdated => 0,
context => q|help for a form property in the ad editor|
},
'image help' => {
message => q|The image file that will be displayed on each ad impression.|,
lastUpdated => 0,
context => q|help for a form property in the ad editor|
},
'rich help' => {
message => q|Place the code here that will be used to generate the ad to be displayed.|,
lastUpdated => 0,
context => q|help for a form property in the ad editor|
},
'priority' => {
message => q|Priority|,
lastUpdated => 0,
context => q|a form property in the ad editor|
},
'priority help' => {
message => q|A scaling mechanism to determine how often an ad should be displayed. The lower this number the more often it will be displayed. This really has no affect low traffic sites. If ad A has a priority of 0 and ad B has a priority of 10, and the site averages about one impression per second then ad A will be displayed roughly 100 times more frequently than ad B. Note that since this property is a scaling mechanism, it is not an exact ratio. The heavier the traffic is on the site, the more impact priority has.|,
lastUpdated => 0,
context => q|help for a form property in the ad editor|
},
'ad text' => {
message => q|Ad Text|,
lastUpdated => 0,