コード例 #1
0
ファイル: OpenRTBWorkflow.php プロジェクト: kh0r/nginad
 public function process_business_rules_workflow($logger, $config, $rtb_seat_id, &$no_bid_reason, \model\openrtb\RtbBidRequest &$RtbBidRequest)
 {
     $this->config = $config;
     $this->rtb_seat_id = $rtb_seat_id;
     // $logger = \rtbbuyv22\RtbBuyV22Logger::get_instance();
     $InsertionOrderLineItem_Match_List = array();
     $InsertionOrderFactory = \_factory\InsertionOrder::get_instance();
     $params = array();
     $params["Active"] = 1;
     $InsertionOrderList = $InsertionOrderFactory->get_cached($this->config, $params);
     $this->current_time = time();
     $InsertionOrderLineItemFactory = \_factory\InsertionOrderLineItem::get_instance();
     $InsertionOrderLineItemDomainExclusionFactory = \_factory\InsertionOrderLineItemDomainExclusion::get_instance();
     $InsertionOrderLineItemExclusiveInclusionFactory = \_factory\InsertionOrderLineItemDomainExclusiveInclusion::get_instance();
     $InsertionOrderLineItemRestrictionsFactory = \_factory\InsertionOrderLineItemRestrictions::get_instance();
     $InsertionOrderLineItemVideoRestrictionsFactory = \_factory\InsertionOrderLineItemVideoRestrictions::get_instance();
     // match ip against country code
     \buyrtb\workflows\tasklets\common\insertionorder\GetGeoCodeCountry::execute($logger, $this, $RtbBidRequest);
     foreach ($InsertionOrderList as $InsertionOrder) {
         // Check campaign date
         if (\buyrtb\workflows\tasklets\common\insertionorder\CheckCampaignDate::execute($logger, $this, $RtbBidRequest, $InsertionOrder) === false) {
             continue;
         }
         // Check max spend
         if (\buyrtb\workflows\tasklets\common\insertionorder\CheckMaxSpend::execute($logger, $this, $RtbBidRequest, $InsertionOrder) === false) {
             continue;
         }
         // Check max impressions
         if (\buyrtb\workflows\tasklets\common\insertionorder\CheckMaxImpressions::execute($logger, $this, $RtbBidRequest, $InsertionOrder) === false) {
             continue;
         }
         // get markup rate for ad campaign
         $markup_rate = \util\Markup::getMarkupRate($InsertionOrder, $this->config);
         // iterate the active banners for this ad campaign
         $params = array();
         $params["InsertionOrderID"] = $InsertionOrder->InsertionOrderID;
         $params["Active"] = 1;
         $InsertionOrderLineItemList = $InsertionOrderLineItemFactory->get_cached($this->config, $params);
         foreach ($RtbBidRequest->RtbBidRequestImpList as $RtbBidRequestImp) {
             foreach ($InsertionOrderLineItemList as $InsertionOrderLineItem) {
                 if (empty($RtbBidRequestImp->RtbBidRequestVideo) && $InsertionOrderLineItem->ImpressionType == 'video' || !empty($RtbBidRequestImp->RtbBidRequestVideo) && ($InsertionOrderLineItem->ImpressionType == 'banner' || $InsertionOrderLineItem->ImpressionType == 'image')) {
                     continue;
                 }
                 /*
                  * check the business rules against the banner
                  */
                 // Check PMP
                 if (\buyrtb\workflows\tasklets\common\insertionorderlineitem\CheckPrivateMarketPlace::execute($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $InsertionOrderLineItem) === false) {
                     continue;
                 }
                 // Check Domain Admin SSP Channel Selections
                 if (\buyrtb\workflows\tasklets\common\insertionorderlineitem\CheckSspChannelSelections::execute($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $InsertionOrderLineItem) === false) {
                     continue;
                 }
                 // Check banner date
                 if (\buyrtb\workflows\tasklets\common\insertionorderlineitem\CheckBannerDate::execute($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $InsertionOrderLineItem) === false) {
                     continue;
                 }
                 // Check impression price floor
                 if (\buyrtb\workflows\tasklets\common\insertionorderlineitem\CheckPriceFloor::execute($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $InsertionOrderLineItem, $markup_rate) === false) {
                     continue;
                 }
                 // Check banner domain exclusive inclusions
                 if (\buyrtb\workflows\tasklets\common\insertionorderlineitem\CheckExclusiveInclusion::execute($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $InsertionOrderLineItem, $InsertionOrderLineItemExclusiveInclusionFactory) === false) {
                     continue;
                 }
                 // Check banner domain exclusions match
                 if (\buyrtb\workflows\tasklets\common\insertionorderlineitem\CheckDomainExclusion::execute($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $InsertionOrderLineItem, $InsertionOrderLineItemDomainExclusionFactory) === false) {
                     continue;
                 }
                 if (!empty($RtbBidRequestImp->RtbBidRequestVideo)) {
                     // Video Workflow
                     $VideoWorkflow = new \buyrtb\workflows\VideoWorkflow();
                     $passed_child_workflow = $VideoWorkflow->process_business_rules_workflow($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $InsertionOrderLineItem, $InsertionOrderLineItemVideoRestrictionsFactory);
                 } else {
                     // Display Banner Workflow - Default [ banner/ad tag/image creative types ]
                     $DisplayWorkflow = new \buyrtb\workflows\DisplayWorkflow();
                     $passed_child_workflow = $DisplayWorkflow->process_business_rules_workflow($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $InsertionOrderLineItem, $InsertionOrderLineItemRestrictionsFactory);
                 }
                 if ($passed_child_workflow === false) {
                     continue;
                 }
                 /*
                  * PASSED ALL THE BUSINESS RULES, ADD TO THE RESULTS
                  */
                 $InsertionOrderLineItemFactory->incrementInsertionOrderLineItemBidsCounterCached($this->config, $rtb_seat_id, $InsertionOrderLineItem->InsertionOrderLineItemID);
                 /*
                  * Adjust the bid rate according to the markup
                  */
                 $mark_down = floatval($InsertionOrderLineItem->BidAmount) * floatval($markup_rate);
                 $adusted_amount = floatval($InsertionOrderLineItem->BidAmount) - floatval($mark_down);
                 $InsertionOrderLineItem->BidAmount = sprintf("%1.4f", $adusted_amount);
                 // default in config
                 $currency = $this->config['settings']['rtb']['auction_currency'];
                 if (isset($RtbBidRequest->cur[0])) {
                     $currency = $RtbBidRequest->cur[0];
                 }
                 $InsertionOrderLineItem_Match_List[(string) $InsertionOrderLineItem->UserID][] = array("currency" => $currency, "impid" => $RtbBidRequestImp->id, "InsertionOrderLineItem" => $InsertionOrderLineItem);
             }
         }
     }
     if (count($InsertionOrderLineItem_Match_List)) {
         // Check Publisher Score
         if (\buyrtb\workflows\tasklets\common\thirdparty\CheckPublisherScore::execute($logger, $this, $RtbBidRequest) === false) {
             $no_bid_reason = NOBID_BAD_PUBLISHER;
             return array();
         }
         // Check Ad Fraud
         if (\buyrtb\workflows\tasklets\common\thirdparty\CheckAdFraud::execute($logger, $this, $RtbBidRequest) === false) {
             $no_bid_reason = NOBID_AD_FRAUD;
             return array();
         }
         // Check Cookie Match
         if (\buyrtb\workflows\tasklets\common\thirdparty\CheckCookieMatch::execute($logger, $this, $RtbBidRequest) === false) {
             $no_bid_reason = NOBID_UNMATCHED_USER;
             return array();
         }
     }
     return $InsertionOrderLineItem_Match_List;
 }
コード例 #2
0
 public function process_business_rules_workflow($logger, $config, $rtb_seat_id, &$no_bid_reason, \model\openrtb\RtbBidRequest &$RtbBidRequest)
 {
     $this->config = $config;
     $this->rtb_seat_id = $rtb_seat_id;
     // $logger = \rtbbuyv22\RtbBuyV22Logger::get_instance();
     $AdCampaignBanner_Match_List = array();
     $AdCampaignFactory = \_factory\AdCampaign::get_instance();
     $params = array();
     $params["Active"] = 1;
     $AdCampaignList = $AdCampaignFactory->get_cached($this->config, $params);
     $this->current_time = time();
     $AdCampaignBannerFactory = \_factory\AdCampaignBanner::get_instance();
     $AdCampaignBannerDomainExclusionFactory = \_factory\AdCampaignBannerDomainExclusion::get_instance();
     $AdCampaignBannerExclusiveInclusionFactory = \_factory\AdCampaignBannerDomainExclusiveInclusion::get_instance();
     $AdCampaignBannerRestrictionsFactory = \_factory\AdCampaignBannerRestrictions::get_instance();
     $AdCampaignVideoRestrictionsFactory = \_factory\AdCampaignVideoRestrictions::get_instance();
     // match ip against country code
     \buyrtb\workflows\tasklets\common\adcampaign\GetGeoCodeCountry::execute($logger, $this, $RtbBidRequest);
     // Check Ad Fraud
     if (\buyrtb\workflows\tasklets\common\thirdparty\CheckPublisherScore::execute($logger, $this, $RtbBidRequest) === false) {
         $no_bid_reason = NOBID_BAD_PUBLISHER;
         return $AdCampaignBanner_Match_List;
     }
     // Check Publisher Score
     if (\buyrtb\workflows\tasklets\common\thirdparty\CheckAdFraud::execute($logger, $this, $RtbBidRequest) === false) {
         $no_bid_reason = NOBID_AD_FRAUD;
         return $AdCampaignBanner_Match_List;
     }
     // Check Cookie Match
     if (\buyrtb\workflows\tasklets\common\thirdparty\CheckCookieMatch::execute($logger, $this, $RtbBidRequest) === false) {
         $no_bid_reason = NOBID_UNMATCHED_USER;
         return $AdCampaignBanner_Match_List;
     }
     foreach ($AdCampaignList as $AdCampaign) {
         // Check campaign date
         if (\buyrtb\workflows\tasklets\common\adcampaign\CheckCampaignDate::execute($logger, $this, $RtbBidRequest, $AdCampaign) === false) {
             continue;
         }
         // Check max spend
         if (\buyrtb\workflows\tasklets\common\adcampaign\CheckMaxSpend::execute($logger, $this, $RtbBidRequest, $AdCampaign) === false) {
             continue;
         }
         // Check max impressions
         if (\buyrtb\workflows\tasklets\common\adcampaign\CheckMaxImpressions::execute($logger, $this, $RtbBidRequest, $AdCampaign) === false) {
             continue;
         }
         // get markup rate for ad campaign
         $markup_rate = \util\Markup::getMarkupRate($AdCampaign, $this->config);
         // iterate the active banners for this ad campaign
         $params = array();
         $params["AdCampaignID"] = $AdCampaign->AdCampaignID;
         $params["Active"] = 1;
         $AdCampaignBannerList = $AdCampaignBannerFactory->get_cached($this->config, $params);
         foreach ($RtbBidRequest->RtbBidRequestImpList as $RtbBidRequestImp) {
             foreach ($AdCampaignBannerList as $AdCampaignBanner) {
                 if (empty($RtbBidRequestImp->RtbBidRequestVideo) && $AdCampaignBanner->ImpressionType == 'video' || !empty($RtbBidRequestImp->RtbBidRequestVideo) && $AdCampaignBanner->ImpressionType == 'banner') {
                     continue;
                 }
                 /*
                  * check the business rules against the banner
                  */
                 // Check banner date
                 if (\buyrtb\workflows\tasklets\common\adcampaignbanner\CheckBannerDate::execute($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $AdCampaignBanner) === false) {
                     continue;
                 }
                 // Check to see if this AdCampaginBanner is associated to a contract zone.
                 if (\buyrtb\workflows\tasklets\common\adcampaignbanner\CheckIsContract::execute($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $AdCampaignBanner) === false) {
                     continue;
                 }
                 // Check banner domain exclusive inclusions
                 if (\buyrtb\workflows\tasklets\common\adcampaignbanner\CheckExclusiveInclusion::execute($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $AdCampaignBanner, $AdCampaignBannerExclusiveInclusionFactory) === false) {
                     continue;
                 }
                 // Check banner domain exclusions match
                 if (\buyrtb\workflows\tasklets\common\adcampaignbanner\CheckDomainExclusion::execute($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $AdCampaignBanner, $AdCampaignBannerDomainExclusionFactory) === false) {
                     continue;
                 }
                 if (!empty($RtbBidRequestImp->RtbBidRequestVideo)) {
                     // Video Workflow
                     $VideoWorkflow = new \buyrtb\workflows\VideoWorkflow();
                     $passed_child_workflow = $VideoWorkflow->process_business_rules_workflow($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $AdCampaignBanner, $AdCampaignVideoRestrictionsFactory);
                 } else {
                     // Display Banner Workflow - Default
                     $DisplayWorkflow = new \buyrtb\workflows\DisplayWorkflow();
                     $passed_child_workflow = $DisplayWorkflow->process_business_rules_workflow($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $AdCampaignBanner, $AdCampaignBannerRestrictionsFactory);
                 }
                 if ($passed_child_workflow === false) {
                     continue;
                 }
                 /*
                  * PASSED ALL THE BUSINESS RULES, ADD TO THE RESULTS
                  */
                 $AdCampaignBannerFactory->incrementAdCampaignBannerBidsCounterCached($this->config, $rtb_seat_id, $AdCampaignBanner->AdCampaignBannerID);
                 /*
                  * Adjust the bid rate according to the markup
                  */
                 $mark_down = floatval($AdCampaignBanner->BidAmount) * floatval($markup_rate);
                 $adusted_amount = floatval($AdCampaignBanner->BidAmount) - floatval($mark_down);
                 $AdCampaignBanner->BidAmount = sprintf("%1.4f", $adusted_amount);
                 // default in config
                 $currency = $this->config['settings']['rtb']['auction_currency'];
                 if (isset($RtbBidRequest->cur[0])) {
                     $currency = $RtbBidRequest->cur[0];
                 }
                 $AdCampaignBanner_Match_List[(string) $AdCampaignBanner->UserID][] = array("currency" => $currency, "impid" => $RtbBidRequestImp->id, "AdCampaignBanner" => $AdCampaignBanner);
             }
         }
     }
     return $AdCampaignBanner_Match_List;
 }