/** * @param string $campaignName * @param bool $anonymous * @throws NoAdsMatchingCriteriaException * @throws NoFallbackCampaign * @throws FallbackCampaignDisabled */ function __construct($campaignName, $anonymous = false) { global $wgPromoterFallbackCampaign; $this->anonymous = $anonymous; $campaign = new AdCampaign($campaignName); if (!AdCampaign::campaignExists($campaignName) || !$campaign->isEnabled()) { /* If the selected campaign doesn't exist or is disabled, fallback: */ $campaign = new AdCampaign($wgPromoterFallbackCampaign); if (!AdCampaign::campaignExists($wgPromoterFallbackCampaign)) { throw new NoFallbackCampaign(); } elseif (!$campaign->isEnabled()) { throw new FallbackCampaignDisabled(); } } $this->campaignName = $campaign->getName(); $this->ads = $campaign->getAds(); $this->filterAds(); if (count($this->ads) < 1) { throw new NoAdsMatchingCriteriaException($this->campaignName); } /* echo '<pre dir="ltr">'; print_r( $this->ads ); echo '</pre>'; */ $this->allocate(); //$chosenAd = $this->chooseAd(); }
/** * Updates a numeric setting on a campaign * * @param string $campaignName Name of the campaign * @param string $settingName Name of a numeric setting (preferred) * @param int $settingValue Value to use * @param int $max The max that the value can take, default 1 * @param int $min The min that the value can take, default 0 * @throws MWException|RangeException */ static function setNumericCampaignSetting($campaignName, $settingName, $settingValue, $max = 1, $min = 0) { if ($max <= $min) { throw new RangeException('Max must be greater than min.'); } if (!is_numeric($settingValue)) { throw new MWException('Setting value must be numeric.'); } if ($settingValue > $max) { $settingValue = $max; } if ($settingValue < $min) { $settingValue = $min; } if (!AdCampaign::campaignExists($campaignName)) { // Exit quietly since campaign may have been deleted at the same time. return; } else { $settingName = strtolower($settingName); $dbw = PRDatabase::getDb(); $dbw->update('pr_campaigns', array('cmp_' . $settingName => $settingValue), array('cmp_name' => $campaignName)); } }