Permalink
Browse files

allow listing all ads from a campaign

  • Loading branch information...
1 parent 3a8b023 commit 3446a12eab58a9b4f8e69c03f4fea55d0ae83a17 @nyeholt committed Jan 20, 2011
Showing with 15 additions and 0 deletions.
  1. +4 −0 code/dataobjects/AdCampaign.php
  2. +11 −0 code/extensions/AdvertisementExtension.php
@@ -12,6 +12,10 @@ class AdCampaign extends DataObject {
'Expires' => 'Date'
);
+ public static $has_many = array(
+ 'Advertisements' => 'Advertisement',
+ );
+
public static $has_one = array(
'Client' => 'AdClient',
);
@@ -19,6 +19,9 @@ public function extraStatics() {
),
'many_many' => array(
'Advertisements' => 'Advertisement',
+ ),
+ 'has_one' => array(
+ 'UseCampaign' => 'AdCampaign',
)
);
}
@@ -30,6 +33,7 @@ public function updateCMSFields(FieldSet &$fields) {
// $fields->addFieldToTab('Root.Advertisements', new CheckboxField('UseRandom', _t('Advertisements.USE_RANDOM', 'Use random selection')));
$fields->addFieldToTab('Root.Advertisements', new NumericField('NumberOfAds', _t('Advertisements.NUM_ADS', 'How many Ads should be returned?')));
$fields->addFieldToTab('Root.Advertisements', new ManyManyPickerField($this->owner, 'Advertisements'));
+ $fields->addFieldToTab('Root.Advertisements', new HasOnePickerField($this->owner, 'UseCampaign'));
}
public function AdList() {
@@ -44,11 +48,18 @@ public function AdList() {
}
$ads = null;
+
+ // If set to use a campaign, just switch to that as our context.
+ if ($toUse->UseCampaignID) {
+ $toUse = $toUse->UseCampaign();
+ }
+
if ($this->owner->NumberOfAds) {
$ads = $toUse->getManyManyComponents('Advertisements', '', '', '', $this->owner->NumberOfAds);
} else {
$ads = $toUse->Advertisements();
}
+
return $ads;
}
}

0 comments on commit 3446a12

Please sign in to comment.