public static function incrementSellSideBidsCounter(\model\SellSidePartnerHourlyBids $SellSidePartnerHourlyBidsToAdd) { $SellSidePartnerHourlyBidsFactory = \_factory\SellSidePartnerHourlyBids::get_instance(); $current_hour = date("m/d/Y H"); $params = array(); $params["SellSidePartnerID"] = $SellSidePartnerHourlyBidsToAdd->SellSidePartnerID; $params["PublisherAdZoneID"] = $SellSidePartnerHourlyBidsToAdd->PublisherAdZoneID; $params["MDYH"] = $current_hour; $SellSidePartnerHourlyBids = $SellSidePartnerHourlyBidsFactory->get_row($params); $sellside_partner_hourly_bids_counter = new \model\SellSidePartnerHourlyBids(); $sellside_partner_hourly_bids_counter->SellSidePartnerID = $SellSidePartnerHourlyBidsToAdd->SellSidePartnerID; $sellside_partner_hourly_bids_counter->PublisherAdZoneID = $SellSidePartnerHourlyBidsToAdd->PublisherAdZoneID; if ($SellSidePartnerHourlyBids != null) { $sellside_partner_hourly_bids_counter->SellSidePartnerHourlyBidsID = $SellSidePartnerHourlyBids->SellSidePartnerHourlyBidsID; $sellside_partner_hourly_bids_counter->BidsWonCounter = $SellSidePartnerHourlyBids->BidsWonCounter + $SellSidePartnerHourlyBidsToAdd->BidsWonCounter; $sellside_partner_hourly_bids_counter->BidsLostCounter = $SellSidePartnerHourlyBids->BidsLostCounter + $SellSidePartnerHourlyBidsToAdd->BidsLostCounter; $sellside_partner_hourly_bids_counter->BidsErrorCounter = $SellSidePartnerHourlyBids->BidsErrorCounter + $SellSidePartnerHourlyBidsToAdd->BidsErrorCounter; $sellside_partner_hourly_bids_counter->SpendTotalGross = floatval($SellSidePartnerHourlyBids->SpendTotalGross) + $SellSidePartnerHourlyBidsToAdd->SpendTotalGross; $sellside_partner_hourly_bids_counter->SpendTotalPrivateExchangeGross = floatval($SellSidePartnerHourlyBids->SpendTotalPrivateExchangeGross) + $SellSidePartnerHourlyBidsToAdd->SpendTotalPrivateExchangeGross; $sellside_partner_hourly_bids_counter->SpendTotalNet = floatval($SellSidePartnerHourlyBids->SpendTotalNet) + $SellSidePartnerHourlyBidsToAdd->SpendTotalNet; $SellSidePartnerHourlyBidsFactory->updateSellSidePartnerHourlyBids($sellside_partner_hourly_bids_counter); } else { $sellside_partner_hourly_bids_counter->MDYH = $current_hour; $sellside_partner_hourly_bids_counter->BidsWonCounter = $SellSidePartnerHourlyBidsToAdd->BidsWonCounter; $sellside_partner_hourly_bids_counter->BidsLostCounter = $SellSidePartnerHourlyBidsToAdd->BidsLostCounter; $sellside_partner_hourly_bids_counter->BidsErrorCounter = $SellSidePartnerHourlyBidsToAdd->BidsErrorCounter; $sellside_partner_hourly_bids_counter->SpendTotalGross = $SellSidePartnerHourlyBidsToAdd->SpendTotalGross; $sellside_partner_hourly_bids_counter->SpendTotalPrivateExchangeGross = $SellSidePartnerHourlyBidsToAdd->SpendTotalPrivateExchangeGross; $sellside_partner_hourly_bids_counter->SpendTotalNet = $SellSidePartnerHourlyBidsToAdd->SpendTotalNet; $sellside_partner_hourly_bids_counter->DateCreated = date("Y-m-d H:i:s"); $SellSidePartnerHourlyBidsFactory->insertSellSidePartnerHourlyBids($sellside_partner_hourly_bids_counter); } }
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 getOutgoingBidsPerTimeExcelAction() { $initialized = $this->initialize(); if ($initialized !== true) { return $initialized; } if (!$this->is_admin) { die("bad request"); } $outgoing_bid = \_factory\SellSidePartnerHourlyBids::get_instance(); $extra_params = array(); $stats = json_decode($this->getPerTime($outgoing_bid, $extra_params), TRUE); $outgoing_bid_headers = $outgoing_bid->getPerTimeHeader($this->is_admin); $dates = $this->getDatesForExcelReport(); $title = "Outgoing Bids"; \util\ReportHelper::download_excel_file($stats['data'], $outgoing_bid_headers, $stats['totals'], $title, $dates); }
public function getOutgoingBidsPerTimeAction() { return $this->getResponse()->setContent($this->getPerTime(\_factory\SellSidePartnerHourlyBids::get_instance())); }