/**
  * 
  * @param $from
  * @param $to
  */
 protected function _exportTemporalStatement($from, $to)
 {
     $active_sheet = $this->getDocument()->getActiveSheet();
     $acts = Doctrine_Query::create()->select('a.designation')->from('Act a')->where('a.disabled = ?', 0)->orderBy('a.designation')->execute();
     $numberOfActs = Doctrine_Query::create()->select('COUNT(*) as total')->from('Act a')->where('a.disabled = ?', 0)->fetchOne();
     $statement = Statistics::getTemporalStatementValuesByAct($from, $to);
     //Format the statement data into times:
     $statement = self::formatStatement($statement);
     /*Print all the acts at the top:*/
     $this->_exportQuantitativeStatementHeader($statement);
     $columns = Statistics::getTemporalStatementColumns($from, $to);
     $total = Statistics::getTotalTemporalStatementValues($from, $to);
     //Format the total data into times:
     $total = self::formatTotal($total);
     foreach ($columns as $stat_type => $stat) {
         $this->_exportQuantitativeStatementRessourceByString($columns, $statement, $stat_type, $total);
     }
     foreach ($columns as $stat_type => $stat) {
         $this->_exportQuantitativeStatementRessourceById($columns, $statement, $stat_type, $total);
     }
     //Specific exportations:
     $this->_exportQuantitativeStatementByCountry($columns, $statement, $total, $from, $to);
     $this->nextLine(3);
     $this->_exportQuantitativeStatementByDay($columns, $statement, $total);
     $this->nextLine(3);
     $this->_exportQuantitativeStatementByBuilding($columns, $statement, $total);
     $this->nextLine(3);
     //Details per category:
     $detailsPerCategory = Statistics::getTemporalDetailsPerCategory($from, $to, $total);
     $detailsPerCategory = self::formatStatement($detailsPerCategory);
     $this->_exportDetailsPerCategory($columns, $detailsPerCategory, $total);
     $this->nextLine(3);
     //Details per time slot:
     $detailsPerTimeSlot = Statistics::getTemporalDetailsPerTimeSlot($from, $to, $total);
     $detailsPerTimeSlot = self::formatStatement($detailsPerTimeSlot);
     $this->_exportDetailsPerTimeSlot($columns, $detailsPerTimeSlot, $total);
     $this->nextLine(3);
     //Page setup:
     $page_setup = new PHPExcel_Worksheet_PageSetup();
     $page_setup->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
     $page_setup->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
     $page_setup->setHorizontalCentered(true);
     $active_sheet->setPageSetup($page_setup);
     $active_sheet->setShowGridlines(true);
     $active_sheet->setPrintGridlines(true);
     //Margins:
     $active_sheet->getPageMargins()->setTop(0.4);
     $active_sheet->getPageMargins()->setRight(0.2);
     $active_sheet->getPageMargins()->setLeft(0.2);
     $active_sheet->getPageMargins()->setBottom(0.4);
 }
Esempio n. 2
0
 public function executeTemporalStatement(sfWebRequest $request)
 {
     $from = $request->getParameter('formattedFrom');
     $to = $request->getParameter('formattedTo');
     $countries = array();
     $citiesTable = array();
     $cities = array();
     $this->acts = Doctrine_Query::create()->select('a.designation')->from('Act a')->where('a.disabled = ?', 0)->orderBy('a.designation')->execute();
     $this->numberOfActs = Doctrine_Query::create()->select('COUNT(*) as total')->from('Act a')->where('a.disabled = ?', 0)->fetchOne();
     $imputations = Doctrine_Query::create()->select('i.*')->from('ImputationArchive i')->where('imputation_date BETWEEN ? AND ?', array($from, $to))->execute();
     foreach ($imputations as $imputation) {
         $country = $imputation->getUserArchive()->getCountry();
         $city = $imputation->getUserArchive()->getCityName();
         if (!in_array($country, $countries)) {
             $countries[] = $country;
         }
         if (!in_array($city, $citiesTable)) {
             $citiesTable[] = $city;
             $cities[$country][] = $city;
         }
     }
     $this->countries = $countries;
     $this->cities = $cities;
     $this->statement = Statistics::getTemporalStatementValuesByAct($from, $to);
     $this->detailsPerCategory = Statistics::getTemporalDetailsPerCategory($from, $to);
     $this->detailsPerTimeSlot = Statistics::getTemporalDetailsPerTimeSlot($from, $to);
     $this->total = Statistics::getTotalTemporalStatementValues($from, $to);
     $this->columns = Statistics::getTemporalStatementColumns($from, $to);
     $this->from = $from;
     $this->to = $to;
     $this->setLayout('emptyLayout');
 }