]> _ Git - cubeextranet.git/commitdiff
(no commit message)
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Mon, 13 Feb 2012 13:22:17 +0000 (13:22 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Mon, 13 Feb 2012 13:22:17 +0000 (13:22 +0000)
inc/ws/Controlleur/class.ws.stats.php
inc/ws/Controlleur/class.ws.url.php

index 9e4575a319002ea40efd9c25496afc7f40a1056d..94dc50697b9dcbb4c5f736d716d83aff8ada67b7 100644 (file)
@@ -4,11 +4,54 @@ class wsStats {
 \r
        public static $datestocorrect = array(array(22, 11, 2009), array(23, 11, 2009), array(8, 12, 2009), array(9, 12, 2009));\r
 \r
+       /**\r
+        * @var PHPExcel\r
+        */\r
+       public static $xls;\r
+\r
+       public static function exportXLS($bid, $annee = null, $mois = null) {\r
+               $xname = self::_getXLSFile($bid, $annee, $mois);\r
+               $fname = 'stats_' . $bid;\r
+               if (!is_null($annee)) {\r
+                       $fname.='_' . $annee;\r
+                       if (!is_null($mois)) {\r
+                               $fname.='_' . $mois;\r
+                       }\r
+               }\r
+               $fname.='.xlsx';\r
+\r
+               files::$mimeType['xlsx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';\r
+\r
+               cubeHTTP::downloadFile($xname, $fname);\r
+       }\r
+\r
+       protected static function _getXLSFile($bid, $annee = null, $mois = null) {\r
+               $xname = '/home/stats/www/xls/' . $bid;\r
+               if (!is_null($annee)) {\r
+                       $xname.='/' . $annee;\r
+                       if (!is_null($mois)) {\r
+                               $xname.='/' . $mois;\r
+                       }\r
+               }\r
+\r
+               $xname.='.xlsx';\r
+\r
+               $dir = dirname($xname);\r
+               if (!file_exists($dir)) {\r
+                       mkdir($dir, 0777, true);\r
+               }\r
+\r
+               return $xname;\r
+       }\r
+\r
        public static function display($bid, $annee = null, $mois = null) {\r
                global $core;\r
 \r
                cubePHP::set_memory('512M');\r
 \r
+               self::$xls = new PHPExcel();\r
+               self::$xls->removeSheetByIndex(0);\r
+\r
                $global = self::load_stats($bid);\r
 \r
                $exporturl = SITE_PATH . 'statsxls/' . $bid;\r
@@ -19,6 +62,8 @@ class wsStats {
                        }\r
                }\r
 \r
+\r
+\r
                $actions = array();\r
                $actions[] = '<a href="' . $exporturl . '">' . $core->typo->Ajouter('Exporter au format Excel') . '</a>';\r
 \r
@@ -63,24 +108,14 @@ class wsStats {
                        $res .= self::vue_mensuelle($bid, $annee, $mois);\r
                }\r
                $res .= commonPage::bMain();\r
-               return $res;\r
-       }\r
 \r
-       public static function exportXLS($bid, $annee = null, $mois = null) {\r
-               $xls = new PHPExcel();\r
-               if (is_null($annee)) {\r
-                       // Export global\r
-               } else if (is_null($mois)) {\r
-                       // Export annee\r
-               } else {\r
-                       // Export mois\r
-               }\r
 \r
-               cubeHTTP::forceDownload('stats_' . $bid . '.xls', false);\r
-       }\r
+               self::$xls->setActiveSheetIndex(0);\r
+               $writer = new PHPExcel_Writer_Excel2007();\r
+               $writer->setPHPExcel(self::$xls);\r
+               $writer->save(self::_getXLSFile($bid, $annee, $mois));\r
 \r
-       public static function addSheetFromTable() {\r
-               \r
+               return $res;\r
        }\r
 \r
        public static function getExtra($extra) {\r
@@ -316,7 +351,20 @@ class wsStats {
                return $res;\r
        }\r
 \r
+       /**\r
+        *\r
+        * @param string $name \r
+        * @return PHPExcel_Worksheet\r
+        */\r
+       protected static function _createSheet($name) {\r
+               $s = self::$xls->createSheet();\r
+               $s->setTitle($name);\r
+               return $s;\r
+       }\r
+\r
        public static function globalDatas($titre, $date_creation, $book, $stats, $afriend, $aprint, $adown, $adownp, $aextra) {\r
+               global $xls;\r
+\r
                $colsTitles = array('', '');\r
                $lines = array();\r
                $class = array('liste', 'max');\r
@@ -343,6 +391,8 @@ class wsStats {
                        $lines[] = array(__('Accès à la rubrique') . ' ' . $extra, $stats['extras']);\r
                }\r
 \r
+               self::setSheetFromDatas(__('Résumé'), null, $lines);\r
+\r
                return self::table($titre, $colsTitles, $lines, $class);\r
        }\r
 \r
@@ -467,7 +517,6 @@ class wsStats {
 \r
        public static function detailPeriode($book, $stats, $bid, $annee) {\r
                self::getActives($stats, $book, $aextra, $adown, $adownp, $aprint, $afriend);\r
-\r
                $title = '';\r
 \r
                $colsTitles = array(__('Période'), __('Lieux de visite'), __('Visiteurs uniques'), __('Visites'), __('Pages vues'));\r
@@ -508,9 +557,42 @@ class wsStats {
                        }\r
                }\r
 \r
+               self::setSheetFromDatas(__('Détail'), $colsTitles, $lines);\r
+\r
                return self::table($title, $colsTitles, $lines, array('max', 'liste'), true, false, $noOdd);\r
        }\r
 \r
+       protected static function setSheetFromDatas($title, $columns, $lines) {\r
+               $s = self::_createSheet($title);\r
+               $offset = 1;\r
+               if (!is_null($columns)) {\r
+                       $offset = 2;\r
+                       foreach ($columns as $k => $c) {\r
+\r
+                               $s->setCellValueByColumnAndRow($k, 1, $c);\r
+                               $s->getStyleByColumnAndRow($k, 1)->getFont()->setBold(true);\r
+\r
+                               if ($k == 0) {\r
+                                       $s->getStyleByColumnAndRow($k, 1)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);\r
+                               } else {\r
+                                       $s->getStyleByColumnAndRow($k, 1)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);\r
+                               }\r
+                       }\r
+               }\r
+               foreach ($lines as $k => $l) {\r
+                       foreach ($l as $c => $v) {\r
+                               $s->getColumnDimensionByColumn($c)->setAutoSize(true);\r
+                               $s->setCellValueByColumnAndRow($c, $k + $offset, strip_tags($v));\r
+\r
+                               if ($c == 0) {\r
+                                       $s->getStyleByColumnAndRow($c, $k + $offset)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);\r
+                               } else {\r
+                                       $s->getStyleByColumnAndRow($c, $k + $offset)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
        public static function linePeriod($stats, $bid, $afriend, $aprint, $adown, $adownp, $aextra) {\r
                $line = array();\r
                $url = SITE_PATH . 'stats/' . $bid;\r
@@ -552,6 +634,7 @@ class wsStats {
        public static function detailJour($book, $annee, $mois, $stats) {\r
                $colsTitles = array(__('Jour'), __('Lieux de visite'), __('Visiteurs uniques'), __('Visites'), __('Pages vues'), __('Liens cliqués'));\r
                $lines = array();\r
+               $xlines = array();\r
 \r
                foreach ($stats->days->day as $day) {\r
                        $lines[] = array(strftime('%A %d', mktime(0, 0, 0, $mois, (string) $day['day'], $annee)),\r
@@ -560,9 +643,17 @@ class wsStats {
                                $day['visits'],\r
                                $day['views'],\r
                                $day['links']);\r
+                       $xlines[] = array(strftime('%d', mktime(0, 0, 0, $mois, (string) $day['day'], $annee)),\r
+                               $day['places'],\r
+                               $day['visitors'],\r
+                               $day['visits'],\r
+                               $day['views'],\r
+                               $day['links']);\r
                }\r
                $time_page = mktime(0, 0, 0, $mois, 15, $annee);\r
 \r
+               self::setSheetFromDatas(__('Jours'), $colsTitles, $xlines);\r
+\r
                return self::table(__('Détail par jour') . ' - ' . strftime('%B %Y', $time_page), $colsTitles, $lines, array('liste', 'max'), true);\r
        }\r
 \r
@@ -613,12 +704,16 @@ class wsStats {
                        $lines[] = $line;\r
                }\r
                $time_page = mktime(0, 0, 0, $mois, 15, $annee);\r
+\r
+               self::setSheetFromDatas(__('Pages'), $colsTitles, $lines);\r
+\r
                return self::table(__('Détail par page') . ' - ' . strftime('%B %Y', $time_page), $colsTitles, $lines, array('liste', 'max'));\r
        }\r
 \r
        public static function detailLiens($book, $stats) {\r
                $colsTitles = array(__('URL'), __('Clics'));\r
                $lines = array();\r
+               $xlines = array();\r
 \r
                foreach ($stats->links->link as $link) {\r
                        $uurl = (string) $link['url'];\r
@@ -633,8 +728,10 @@ class wsStats {
                        }\r
 \r
                        $lines[] = array('<a href="' . $uurl . '" class="blank" title="' . $uurl . '">' . $url . '</a>', $nb);\r
+                       $xlines[] = array($uurl, $nb);\r
                }\r
 \r
+               self::setSheetFromDatas(__('Liens'), $colsTitles, $xlines);\r
                return self::table(__('Liens les plus cliqués'), $colsTitles, $lines, array('liste', 'max'));\r
        }\r
 \r
@@ -649,12 +746,14 @@ class wsStats {
                        }\r
                        $lines[] = array($q, $search['count']);\r
                }\r
+               self::setSheetFromDatas(__('Recherches'), $colsTitles, $lines);\r
                return self::table(__('Mots les plus recherchés'), $colsTitles, $lines, array('liste', 'max'));\r
        }\r
 \r
        public static function detailOrigine($book, $stats) {\r
                $colsTitles = array(__('Pays'), __('Visiteurs'));\r
                $lines = array();\r
+               $xlines = array();\r
                $i = 0;\r
 \r
                foreach ($stats->countries->country as $country) {\r
@@ -664,8 +763,10 @@ class wsStats {
                                $c = __('Origine inconnue');\r
                        }\r
                        $lines[] = array(cubeCountry::getFlag($pays) . ' ' . ucfirst(mb_strtolower($c)), $country['visitors']);\r
+                       $xlines[] = array(ucfirst(mb_strtolower($c)), $country['visitors']);\r
                        $i++;\r
                }\r
+               self::setSheetFromDatas(__('Origines'), $colsTitles, $xlines);\r
                return self::table(__('Origine des visiteurs'), $colsTitles, $lines, array('liste', 'max'));\r
        }\r
 \r
index 69d9888631fd823776006b483a97fe040cd61410..8b803e7d94b4b3d8adb3479adfef5c2351b25540 100644 (file)
@@ -846,7 +846,9 @@ html{height:100%}' . "\n";
 \r
        public static function statsxls($args) {\r
                $bid = (isset($args[1])) ? $args[1] : null;\r
-               wsStats::exportXLS($bid);\r
+               $annee = (isset($args[2])) ? $args[2] : null;\r
+               $mois = (isset($args[3])) ? $args[3] : null;\r
+               wsStats::exportXLS($bid, $annee, $mois);\r
        }\r
 \r
        public static function chooseExistingBook() {\r
@@ -1525,6 +1527,7 @@ html{height:100%}' . "\n";
                $res .= commonPage::bMain();\r
                return $res;\r
        }\r
+\r
 }\r
 \r
 ?>
\ No newline at end of file