Example #1
0
 public function incrementAdCampaignBannerImpressionsCounterAndSpend($buyer_id, $banner_id, $impressions_value_to_increment, $spend_value_to_increment_gross, $spend_value_to_increment_net)
 {
     $BuySideHourlyImpressionsCounterCurrentSpendFactory = \_factory\BuySideHourlyImpressionsCounterCurrentSpend::get_instance();
     $current_hour = date("m/d/Y h");
     $params = array();
     $params["BuySidePartnerID"] = $buyer_id;
     $params["AdCampaignBannerID"] = $banner_id;
     $params["MDYH"] = $current_hour;
     $BuySideHourlyImpressionsCounterCurrentSpend = $BuySideHourlyImpressionsCounterCurrentSpendFactory->get_row($params);
     $buyside_hourly_impressions_counter_current_spend = new \model\BuySideHourlyImpressionsCounterCurrentSpend();
     $buyside_hourly_impressions_counter_current_spend->AdCampaignBannerID = $banner_id;
     $buyside_hourly_impressions_counter_current_spend->BuySidePartnerID = $buyer_id;
     if ($BuySideHourlyImpressionsCounterCurrentSpend != null) {
         /*
          * Increment Current Impressions Counter plus Current Spend
          * Remember that the bids are counted by CPM,
          * so it takes 1000 impressions to make a CPM bid amount
          */
         $buyside_hourly_impressions_counter_current_spend->BuySideHourlyImpressionsCounterCurrentSpendID = $BuySideHourlyImpressionsCounterCurrentSpend->BuySideHourlyImpressionsCounterCurrentSpendID;
         $buyside_hourly_impressions_counter_current_spend->CurrentSpendGross = floatval($BuySideHourlyImpressionsCounterCurrentSpend->CurrentSpendGross) + $spend_value_to_increment_gross;
         $buyside_hourly_impressions_counter_current_spend->CurrentSpendNet = floatval($BuySideHourlyImpressionsCounterCurrentSpend->CurrentSpendNet) + $spend_value_to_increment_net;
         $buyside_hourly_impressions_counter_current_spend->ImpressionsCounter = $BuySideHourlyImpressionsCounterCurrentSpend->ImpressionsCounter + $impressions_value_to_increment;
         $BuySideHourlyImpressionsCounterCurrentSpendFactory->updateBuySideHourlyImpressionsCounterCurrentSpend($buyside_hourly_impressions_counter_current_spend);
     } else {
         $buyside_hourly_impressions_counter_current_spend->MDYH = $current_hour;
         $buyside_hourly_impressions_counter_current_spend->CurrentSpendGross = $spend_value_to_increment_gross;
         $buyside_hourly_impressions_counter_current_spend->CurrentSpendNet = $spend_value_to_increment_net;
         $buyside_hourly_impressions_counter_current_spend->ImpressionsCounter = $impressions_value_to_increment;
         $buyside_hourly_impressions_counter_current_spend->DateCreated = date("Y-m-d H:i:s");
         $BuySideHourlyImpressionsCounterCurrentSpendFactory->insertBuySideHourlyImpressionsCounterCurrentSpend($buyside_hourly_impressions_counter_current_spend);
     }
 }
Example #2
0
 public function dailyAction()
 {
     $date = date('Y-m-d', time() - 60 * 60 * 24);
     $config = $this->getServiceLocator()->get('Config');
     $ReportSubscription = \_factory\ReportSubscription::get_instance();
     $subscibe_users = $ReportSubscription->get(array('Status' => 1, 'user_role' => 1));
     $transport = $this->getServiceLocator()->get('mail.transport');
     $where_params = array('DateCreatedGreater' => $date . ' 00:00:00', 'DateCreatedLower' => $date . ' 23:59:59');
     $letters = range('A', 'Z');
     foreach ($subscibe_users as $one) {
         $is_admin = $one['user_role'] != 1 ? TRUE : FALSE;
         $impressions_obj = \_factory\BuySideHourlyImpressionsByTLD::get_instance();
         $impressions = $impressions_obj->getPerTimeCached($config, $where_params, 900, TRUE, $is_admin);
         $impressions_header = $impressions_obj->getPerTimeHeader($is_admin);
         $text = new Mime\Part('Hi!');
         $text->type = Mime\Mime::TYPE_TEXT;
         $text->charset = 'utf-8';
         $objPHPExcel = new \PHPExcel();
         $objPHPExcel->getProperties()->setCreator("nginad.com")->setLastModifiedBy("nginad.com")->setTitle("Statistic reports")->setSubject("")->setDescription("")->setKeywords("")->setCategory("");
         //
         //            Strat first sheet
         if ($one['user_role'] != 2) {
             $objPHPExcel->setActiveSheetIndex(0);
             $objPHPExcel->getSheet(0)->setTitle('Impressions');
             $objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Impressions stats for ' . $date);
             $objPHPExcel->getActiveSheet()->mergeCells('A1:' . $letters[count($impressions_header) - 1] . '1');
             for ($i = 0; $i < count($impressions_header); $i++) {
                 $objPHPExcel->getActiveSheet()->SetCellValue($letters[$i] . '3', $impressions_header[$i]);
             }
             if (empty($impressions)) {
                 $objPHPExcel->getActiveSheet()->SetCellValue('A5', 'No records');
                 $objPHPExcel->getActiveSheet()->mergeCells('A5:' . $letters[count($impressions_header) - 1] . '5');
             } else {
                 $i = 5;
                 foreach ($impressions as $impression) {
                     $impression = array_values((array) $impression);
                     for ($j = 0; $j < count($impressions_header); $j++) {
                         $objPHPExcel->getActiveSheet()->SetCellValue($letters[$j] . $i, $impression[$j]);
                     }
                     $i++;
                 }
             }
             foreach ($letters as $columnID) {
                 $objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
             }
         }
         //
         //            Strat second sheet
         //
         if ($one['user_role'] != 2) {
             $incoming_bids_obj = \_factory\BuySideHourlyBidsCounter::get_instance();
             $incoming_bids = $incoming_bids_obj->getPerTimeCached($config, $where_params, 900, TRUE, $is_admin);
             $incoming_bids_header = $incoming_bids_obj->getPerTimeHeader($is_admin);
             $objPHPExcel->createSheet(1);
             $objPHPExcel->getSheet(1)->setTitle('Incoming bids');
             $objPHPExcel->setActiveSheetIndex(1);
             $objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Incoming bids stats for ' . $date);
             $objPHPExcel->getActiveSheet()->mergeCells('A1:' . $letters[count($incoming_bids_header) - 1] . '1');
             for ($i = 0; $i < count($incoming_bids_header); $i++) {
                 $objPHPExcel->getActiveSheet()->SetCellValue($letters[$i] . '3', $incoming_bids_header[$i]);
             }
             if (empty($incoming_bids)) {
                 $objPHPExcel->getActiveSheet()->SetCellValue('A5', 'No records');
                 $objPHPExcel->getActiveSheet()->mergeCells('A5:' . $letters[count($incoming_bids_header) - 1] . '5');
             } else {
                 $i = 5;
                 foreach ($incoming_bids as $bid) {
                     $bid = array_values((array) $bid);
                     for ($j = 0; $j < count($incoming_bids_header); $j++) {
                         $objPHPExcel->getActiveSheet()->SetCellValue($letters[$j] . $i, $bid[$j]);
                     }
                     $i++;
                 }
             }
             foreach ($letters as $columnID) {
                 $objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
             }
         }
         //
         //            Strat third sheet
         //
         //
         if ($one['user_role'] != 3) {
             $outgoing_bids_obj = \_factory\SellSidePartnerHourlyBids::get_instance();
             $outgoing_bids = $outgoing_bids_obj->getPerTimeCached($config, $where_params, 900, TRUE, $is_admin);
             $outgoing_bids_header = $outgoing_bids_obj->getPerTimeHeader($is_admin);
             $objPHPExcel->createSheet(2);
             $objPHPExcel->getSheet(2)->setTitle('Outgoing bids');
             $objPHPExcel->setActiveSheetIndex(2);
             $objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Outgoing bids stats for ' . $date);
             $objPHPExcel->getActiveSheet()->mergeCells('A1:' . $letters[count($outgoing_bids_header) - 1] . '1');
             for ($i = 0; $i < count($outgoing_bids_header); $i++) {
                 $objPHPExcel->getActiveSheet()->SetCellValue($letters[$i] . '3', $outgoing_bids_header[$i]);
             }
             if (empty($outgoing_bids)) {
                 $objPHPExcel->getActiveSheet()->SetCellValue('A5', 'No records');
                 $objPHPExcel->getActiveSheet()->mergeCells('A5:' . $letters[count($outgoing_bids_header) - 1] . '5');
             } else {
                 $i = 5;
                 foreach ($outgoing_bids as $bid) {
                     $bid = array_values((array) $bid);
                     for ($j = 0; $j < count($outgoing_bids_header); $j++) {
                         $objPHPExcel->getActiveSheet()->SetCellValue($letters[$j] . $i, $bid[$j]);
                     }
                     $i++;
                 }
             }
             foreach ($letters as $columnID) {
                 $objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
             }
         }
         //
         //            Strat fourth sheet
         //
         if ($one['user_role'] != 3) {
             $contracts_obj = \_factory\ContractPublisherZoneHourlyImpressions::get_instance();
             $contracts = $contracts_obj->getPerTimeCached($config, $where_params, 900, TRUE, $is_admin);
             $contracts_header = $contracts_obj->getPerTimeHeader($is_admin);
             $objPHPExcel->createSheet(3);
             $objPHPExcel->getSheet(3)->setTitle('Contract impressions');
             $objPHPExcel->setActiveSheetIndex(3);
             $objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Contract impressions stats for ' . $date);
             $objPHPExcel->getActiveSheet()->mergeCells('A1:' . $letters[count($contracts_header) - 1] . '1');
             for ($i = 0; $i < count($contracts_header); $i++) {
                 $objPHPExcel->getActiveSheet()->SetCellValue($letters[$i] . '3', $contracts_header[$i]);
             }
             if (empty($contracts)) {
                 $objPHPExcel->getActiveSheet()->SetCellValue('A5', 'No records');
                 $objPHPExcel->getActiveSheet()->mergeCells('A5:' . $letters[count($contracts_header) - 1] . '5');
             } else {
                 $i = 5;
                 foreach ($contracts as $contract) {
                     $contract = array_values((array) $contract);
                     for ($j = 0; $j < count($contracts_header); $j++) {
                         $objPHPExcel->getActiveSheet()->SetCellValue($letters[$j] . $i, $contract[$j]);
                     }
                     $i++;
                 }
             }
             foreach ($letters as $columnID) {
                 $objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
             }
         }
         //
         //            Strat fifth sheet
         //
         if ($one['user_role'] != 2) {
             $current_spend_obj = \_factory\BuySideHourlyImpressionsCounterCurrentSpend::get_instance();
             $current_spend = $current_spend_obj->getPerTimeCached($config, $where_params, 900, TRUE, $is_admin);
             $current_spend_header = $current_spend_obj->getPerTimeHeader($is_admin);
             $objPHPExcel->createSheet(4);
             $objPHPExcel->getSheet(4)->setTitle('Current spend');
             $objPHPExcel->setActiveSheetIndex(4);
             $objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Current spend stats for ' . $date);
             $objPHPExcel->getActiveSheet()->mergeCells('A1:' . $letters[count($current_spend_header) - 1] . '1');
             for ($i = 0; $i < count($current_spend_header); $i++) {
                 $objPHPExcel->getActiveSheet()->SetCellValue($letters[$i] . '3', $current_spend_header[$i]);
             }
             if (empty($current_spend)) {
                 $objPHPExcel->getActiveSheet()->SetCellValue('A5', 'No records');
                 $objPHPExcel->getActiveSheet()->mergeCells('A5:' . $letters[count($current_spend_header) - 1] . '5');
             } else {
                 $i = 5;
                 foreach ($current_spend as $impression) {
                     $impression = array_values((array) $impression);
                     for ($j = 0; $j < count($current_spend_header); $j++) {
                         $objPHPExcel->getActiveSheet()->SetCellValue($letters[$j] . $i, $impression[$j]);
                     }
                     $i++;
                 }
             }
             foreach ($letters as $columnID) {
                 $objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
             }
         }
         //            header('Content-type: application/vnd.ms-excel');
         //            header('Content-Disposition: attachment; filename="file.xls"');
         $objPHPExcel->setActiveSheetIndex(0);
         $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
         ob_start();
         $objWriter->save('php://output');
         $fileContent = ob_get_contents();
         ob_end_clean();
         $attachment = new Mime\Part($fileContent);
         $attachment->type = 'application/vnd.ms-excel';
         $attachment->filename = 'statistic-' . $date . '.xls';
         $attachment->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
         $attachment->type = 'application/octet-stream';
         $attachment->encoding = Mime\Mime::ENCODING_BASE64;
         $mimeMessage = new Mime\Message();
         $mimeMessage->setParts(array($text, $attachment));
         $message = new Message();
         //            $message->addTo('*****@*****.**')
         $message->addTo($one['user_email'])->addFrom($config['mail']['reply-to']['email'], $config['mail']['reply-to']['name'])->setSubject('Statistic for ' . $date)->setBody($mimeMessage);
         $transport->send($message);
         //            die();
     }
     exit(1);
 }
 public function getImpressionsCurrentSpendPerTimeAction()
 {
     $initialized = $this->initialize();
     if ($initialized !== true) {
         return $initialized;
     }
     if (!$this->is_admin) {
         die("bad request");
     }
     return $this->getResponse()->setContent($this->getPerTime(\_factory\BuySideHourlyImpressionsCounterCurrentSpend::get_instance()));
 }
Example #4
0
 public function getImpressionsCurrentSpendPerTimeAction()
 {
     return $this->getResponse()->setContent($this->getPerTime(\_factory\BuySideHourlyImpressionsCounterCurrentSpend::get_instance()));
 }