public function mailerAction()
 {
     die("under construction");
     $initialized = $this->initialize();
     if ($initialized !== true) {
         return $initialized;
     }
     if ($this->is_admin) {
         $this->EffectiveID;
         $this->adminFunctionsSufix = 'Admin';
         $user_role = 1;
     } elseif ($this->PublisherInfoID != null) {
         $user_role = 2;
     } elseif ($this->DemandCustomerInfoID != null) {
         $user_role = 3;
     }
     $view = new ViewModel();
     $view->setTerminal(true);
     $view->setTemplate('dashboard-manager/report/header.phtml');
     $view->setVariables(array('action' => 'mailer', 'user_role' => $user_role));
     $menu_tpl = $this->getServiceLocator()->get('viewrenderer')->render($view);
     $ReportSubscription = \_factory\ReportSubscription::get_instance();
     $params = $this->params()->fromPost();
     if (!empty($params['action']) && $params['action'] == 'update_subscription') {
         if (!empty($params['subscription'])) {
             $status = 1;
         } else {
             $status = 0;
         }
         $subscription_record = $ReportSubscription->get_row(array('UserId' => $this->EffectiveID));
         $subscription_record['Status'] = $status;
         $subscription_record['UserID'] = $this->EffectiveID;
         $ReportSubscriptionModel = new \model\ReportSubscription();
         $ReportSubscriptionModel->initialize($subscription_record);
         $ReportSubscription->updateReportSubscription($ReportSubscriptionModel);
     } else {
         $subscription_record = $ReportSubscription->get_row(array('UserId' => $this->EffectiveID));
     }
     $view = new ViewModel(array('action' => 'mailer', 'menu_tpl' => $menu_tpl, 'subscription' => $subscription_record, 'user_id_list' => $this->user_id_list, 'user_identity' => $this->identity(), 'true_user_name' => $this->auth->getUserName(), 'header_title' => 'Reports', 'is_admin' => $this->is_admin, 'effective_id' => $this->auth->getEffectiveIdentityID(), 'impersonate_id' => $this->ImpersonateID));
     return $view;
 }
示例#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);
 }