]> _ Git - cubeextranet.git/commitdiff
try #1761 @0.5
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 7 Nov 2017 15:25:56 +0000 (15:25 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 7 Nov 2017 15:25:56 +0000 (15:25 +0000)
inc/ws/Controlleur/class.ws.stats.php

index a6bb06cb74a484c855da3a249c5dfda3c460e001..282579f66a78a9466b2034ff3c98756c4c92853f 100644 (file)
@@ -13,12 +13,12 @@ class wsStats {
                $xname = self::_getXLSFile($bid, $annee, $mois);\r
                $fname = 'stats_' . $bid;\r
                if (!is_null($annee)) {\r
-                       $fname.='_' . $annee;\r
+                       $fname .= '_' . $annee;\r
                        if (!is_null($mois)) {\r
-                               $fname.='_' . $mois;\r
+                               $fname .= '_' . $mois;\r
                        }\r
                }\r
-               $fname.='.xlsx';\r
+               $fname .= '.xlsx';\r
 \r
                files::$mimeType['xlsx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';\r
 \r
@@ -26,17 +26,18 @@ class wsStats {
        }\r
 \r
        protected static function _getXLSFile($bid, $annee = null, $mois = null) {\r
+               self::forceComputation($bid);\r
                $e = explode('_', $bid);\r
                $bid = $e[0];\r
                $xname = '/home/stats/www/xls/' . $bid;\r
                if (!is_null($annee)) {\r
-                       $xname.='/' . $annee;\r
+                       $xname .= '/' . $annee;\r
                        if (!is_null($mois)) {\r
-                               $xname.='/' . $mois;\r
+                               $xname .= '/' . $mois;\r
                        }\r
                }\r
 \r
-               $xname.='.xlsx';\r
+               $xname .= '.xlsx';\r
 \r
                $dir = dirname($xname);\r
                if (!file_exists($dir)) {\r
@@ -49,6 +50,8 @@ class wsStats {
        public static function display($bid, $annee = null, $mois = null) {\r
                global $core;\r
 \r
+               self::forceComputation($bid);\r
+\r
                cubePHP::set_memory('512M');\r
 \r
                self::$xls = new PHPExcel();\r
@@ -75,22 +78,22 @@ class wsStats {
                $listeMois = null;\r
                foreach ($years as $y) {\r
                        $selectedYear = __('Toutes');\r
-                       if (!is_null($annee) && $annee == (string) $y['year']) {\r
+                       if (!is_null($annee) && $annee == (string)$y['year']) {\r
                                $months = $y->month;\r
-                               $moiss = array('<em>' . __('Tous') . '</em>' => SITE_PATH . 'stats/' . $bid . '/' . (string) $y['year']);\r
+                               $moiss = array('<em>' . __('Tous') . '</em>' => SITE_PATH . 'stats/' . $bid . '/' . (string)$y['year']);\r
                                $selectedMonth = __('Tous');\r
                                foreach ($months as $m) {\r
-                                       if ((string) $m['month'] == $mois) {\r
-                                               $selectedMonth = cubeDate::getMonth((string) $m['month']);\r
+                                       if ((string)$m['month'] == $mois) {\r
+                                               $selectedMonth = cubeDate::getMonth((string)$m['month']);\r
                                        }\r
-                                       $moiss[cubeDate::getMonth((string) $m['month'])] = SITE_PATH . 'stats/' . $bid . '/' . (string) $y['year'] . '/' . (string) $m['month'];\r
+                                       $moiss[cubeDate::getMonth((string)$m['month'])] = SITE_PATH . 'stats/' . $bid . '/' . (string)$y['year'] . '/' . (string)$m['month'];\r
                                }\r
                                $listeMois = new commonShortcuts(__('Mois'), $moiss, $selectedMonth);\r
                        }\r
-                       if ((string) $y['year'] == $annee) {\r
+                       if ((string)$y['year'] == $annee) {\r
                                $selectedYear = $annee;\r
                        }\r
-                       $annees[(string) $y['year']] = SITE_PATH . 'stats/' . $bid . '/' . (string) $y['year'];\r
+                       $annees[(string)$y['year']] = SITE_PATH . 'stats/' . $bid . '/' . (string)$y['year'];\r
                }\r
                $listeAnnees = new commonShortcuts(__('AnnĂ©e'), $annees, $selectedYear);\r
                $listeShortcuts[] = $listeAnnees;\r
@@ -116,7 +119,7 @@ class wsStats {
                        $writer->setPHPExcel(self::$xls);\r
                        $writer->save(self::_getXLSFile($bid, $annee, $mois));\r
                } catch (Exception $e) {\r
-                       \r
+\r
                }\r
 \r
                return $res;\r
@@ -124,13 +127,14 @@ class wsStats {
 \r
        public static function getExtra($extra) {\r
                $xml = simplexml_load_string('<extra>' . $extra . '</extra>');\r
-               if ((string) $xml->extraName != '') {\r
-                       return (string) $xml->extraName;\r
+               if ((string)$xml->extraName != '') {\r
+                       return (string)$xml->extraName;\r
                }\r
                return null;\r
        }\r
 \r
        public static function load_stats($bid, $annee = null, $mois = null) {\r
+\r
                $e = explode('_', $bid, 2);\r
                $bid = $e[0];\r
 \r
@@ -149,7 +153,7 @@ class wsStats {
                $xml .= '.xml';\r
                if ($x = @simplexml_load_file($xml)) {\r
                        if (!is_null($mois)) {\r
-                               \r
+\r
                        }\r
                        $x = call_user_func(array('wsStats', $sort), $x);\r
                        self::correctValues($x, $annee, $mois);\r
@@ -167,7 +171,7 @@ class wsStats {
                        foreach ($days as $day) {\r
                                break;\r
                        }\r
-                       $visitors = (string) $day['places'] * 1.2;\r
+                       $visitors = (string)$day['places'] * 1.2;\r
                        $visits = $visitors * 1.1;\r
                        cubeXML::removeAttribute($day, 'visitors');\r
                        cubeXML::removeAttribute($day, 'visits');\r
@@ -177,7 +181,7 @@ class wsStats {
        }\r
 \r
        public static function correctPlaces($x) {\r
-               \r
+\r
        }\r
 \r
        public static function globalSort($xml, $root = 'stats') {\r
@@ -187,7 +191,7 @@ class wsStats {
                }\r
                $years = array();\r
                foreach ($xml->year as $year) {\r
-                       $years[(string) $year['year']] = self::yearSort($year, 'year');\r
+                       $years[(string)$year['year']] = self::yearSort($year, 'year');\r
                }\r
                ksort($years);\r
                foreach ($years as $y) {\r
@@ -203,7 +207,7 @@ class wsStats {
                }\r
                $months = array();\r
                foreach ($xml->month as $month) {\r
-                       $months[(string) $month['month']] = $month;\r
+                       $months[(string)$month['month']] = $month;\r
                }\r
 \r
                ksort($months);\r
@@ -231,13 +235,13 @@ class wsStats {
                $x = $res->addChild('days');\r
                $days = array();\r
                foreach ($xml->days->day as $day) {\r
-                       $days[(string) $day['day']] = $day;\r
+                       $days[(string)$day['day']] = $day;\r
                }\r
                ksort($days);\r
                foreach ($days as $day) {\r
-                       $places = (string) $day['places'];\r
+                       $places = (string)$day['places'];\r
                        if ($places == 1) {\r
-                               $visitors = (string) $day['visitors'];\r
+                               $visitors = (string)$day['visitors'];\r
                                if ($visitors > 10) {\r
                                        cubeXML::removeAttribute($day, 'places');\r
                                        $day->addAttribute('places', round($visitors * 0.99));\r
@@ -252,8 +256,8 @@ class wsStats {
                $pages = array();\r
                $trans = array();\r
                foreach ($xml->pages->page as $page) {\r
-                       $pages[(string) $page['page']] = (string) $page['score'];\r
-                       $trans[(string) $page['page']] = $page;\r
+                       $pages[(string)$page['page']] = (string)$page['score'];\r
+                       $trans[(string)$page['page']] = $page;\r
                }\r
                arsort($pages);\r
                foreach ($pages as $num => $score) {\r
@@ -266,8 +270,8 @@ class wsStats {
                $links = array();\r
                $trans = array();\r
                foreach ($xml->links->link as $link) {\r
-                       $links[(string) $link['url']] = (string) $link['click'];\r
-                       $trans[(string) $link['url']] = $link;\r
+                       $links[(string)$link['url']] = (string)$link['click'];\r
+                       $trans[(string)$link['url']] = $link;\r
                }\r
                arsort($links);\r
                $links = array_slice($links, 0, 100, true);\r
@@ -281,8 +285,8 @@ class wsStats {
                $searches = array();\r
                $trans = array();\r
                foreach ($xml->searches->search as $search) {\r
-                       $searches[(string) $search['query']] = (string) $search['count'];\r
-                       $trans[(string) $search['query']] = $search;\r
+                       $searches[(string)$search['query']] = (string)$search['count'];\r
+                       $trans[(string)$search['query']] = $search;\r
                }\r
                arsort($searches);\r
                $searches = array_slice($searches, 0, 100, true);\r
@@ -296,8 +300,8 @@ class wsStats {
                $countries = array();\r
                $trans = array();\r
                foreach ($xml->countries->country as $country) {\r
-                       $countries[(string) $country['code']] = (string) $country['visitors'];\r
-                       $trans[(string) $country['code']] = $country;\r
+                       $countries[(string)$country['code']] = (string)$country['visitors'];\r
+                       $trans[(string)$country['code']] = $country;\r
                }\r
                arsort($countries);\r
                foreach ($countries as $code => $visitors) {\r
@@ -360,7 +364,7 @@ class wsStats {
 \r
        /**\r
         *\r
-        * @param string $name \r
+        * @param string $name\r
         * @return PHPExcel_Worksheet\r
         */\r
        protected static function _createSheet($name) {\r
@@ -491,7 +495,6 @@ class wsStats {
                $res .= commonPage::bf();\r
 \r
 \r
-\r
                // .\r
                $res .= commonPage::bh('stats_detail_pages');\r
                $res .= self::detailPages($book, $annee, $mois, $stats);\r
@@ -607,9 +610,9 @@ class wsStats {
                        $url .= '/' . $stats['year'];\r
                        if (isset($stats['month'])) {\r
                                $url .= '/' . $stats['month'];\r
-                               $date = strftime('%B %Y', mktime(0, 0, 0, (string) $stats['month'], 15, (string) $stats['year']));\r
+                               $date = strftime('%B %Y', mktime(0, 0, 0, (string)$stats['month'], 15, (string)$stats['year']));\r
                        } else {\r
-                               $date = (string) $stats['year'];\r
+                               $date = (string)$stats['year'];\r
                        }\r
                }\r
 \r
@@ -644,18 +647,18 @@ class wsStats {
                $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
-                               $day['places'],\r
-                               $day['visitors'],\r
-                               $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
+                       $lines[] = array(strftime('%A %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
+                       $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
@@ -680,7 +683,7 @@ class wsStats {
 \r
                $lines = array();\r
                foreach ($stats->pages->page as $page) {\r
-                       $p = (string) $page['page'];\r
+                       $p = (string)$page['page'];\r
                        if ($p > $book->pages || cubeMath::isOdd($p)) {\r
                                continue;\r
                        }\r
@@ -723,8 +726,8 @@ class wsStats {
                $xlines = array();\r
 \r
                foreach ($stats->links->link as $link) {\r
-                       $uurl = (string) $link['url'];\r
-                       $nb = (string) $link['click'];\r
+                       $uurl = (string)$link['url'];\r
+                       $nb = (string)$link['click'];\r
                        if (stristr($uurl, 'mailto:') || stristr($uurl, 'http://') || stristr($uurl, 'https://')) {\r
                                $url = substr($uurl, 7);\r
                        } else {\r
@@ -796,14 +799,14 @@ class wsStats {
                $maxb = 0;\r
                $s = array();\r
                foreach ($stats->month as $month) {\r
-                       $maxb = max($maxb, (string) $month['visits']);\r
-                       $maxp = max($maxp, (string) $month['pages']);\r
-                       $maxv = max($maxv, (string) $month['visitors']);\r
-                       $time = cubeDate::round(mktime(0, 0, 0, (string) $month['month'], 15, (string) $month['year']), 'm');\r
+                       $maxb = max($maxb, (string)$month['visits']);\r
+                       $maxp = max($maxp, (string)$month['pages']);\r
+                       $maxv = max($maxv, (string)$month['visitors']);\r
+                       $time = cubeDate::round(mktime(0, 0, 0, (string)$month['month'], 15, (string)$month['year']), 'm');\r
                        $s[$time] = array();\r
-                       $s[$time]['book'] = (string) $month['visits'];\r
-                       $s[$time]['page'] = (string) $month['pages'];\r
-                       $s[$time]['visit'] = (string) $month['visitors'];\r
+                       $s[$time]['book'] = (string)$month['visits'];\r
+                       $s[$time]['page'] = (string)$month['pages'];\r
+                       $s[$time]['visit'] = (string)$month['visitors'];\r
                }\r
                // .\r
                $max = max($maxb, $maxv);\r
@@ -890,7 +893,7 @@ class wsStats {
                $s = array();\r
                foreach ($stats->year as $year) {\r
                        foreach ($year->month as $month) {\r
-                               $time = mktime(0, 0, 0, intval((string) $month['month']), 15, (string) $month['year']);\r
+                               $time = mktime(0, 0, 0, intval((string)$month['month']), 15, (string)$month['year']);\r
                                $s[$time]['book'] = $month['visits'];\r
                                $s[$time]['page'] = $month['pages'];\r
                                $s[$time]['time'] = $time;\r
@@ -904,9 +907,9 @@ class wsStats {
                $maxp = 0;\r
                $maxb = 0;\r
                foreach ($s as $time => $d) {\r
-                       $maxb = max($maxb, (string) $d['book']);\r
-                       $maxp = max($maxp, (string) $d['page']);\r
-                       $maxv = max($maxv, (string) $d['visit']);\r
+                       $maxb = max($maxb, (string)$d['book']);\r
+                       $maxp = max($maxp, (string)$d['page']);\r
+                       $maxv = max($maxv, (string)$d['visit']);\r
                }\r
 \r
                $max = max($maxb, $maxv);\r
@@ -998,10 +1001,10 @@ class wsStats {
                $v = array();\r
                $s = array();\r
                foreach ($stats->days->day as $day) {\r
-                       $time = mktime(0, 0, 0, $m, (string) $day['day'], $a);\r
-                       $maxb = max($maxb, (string) $day['visits']);\r
-                       $maxp = max($maxp, (string) $day['views']);\r
-                       $maxv = max($maxv, (string) $day['visitors']);\r
+                       $time = mktime(0, 0, 0, $m, (string)$day['day'], $a);\r
+                       $maxb = max($maxb, (string)$day['visits']);\r
+                       $maxp = max($maxp, (string)$day['views']);\r
+                       $maxv = max($maxv, (string)$day['visitors']);\r
                        $s[$time]['book'] = $day['visits'];\r
                        $s[$time]['page'] = $day['views'];\r
                        $s[$time]['visit'] = $day['visitors'];\r
@@ -1087,6 +1090,7 @@ class wsStats {
                return $res;\r
        }\r
 \r
-}\r
-\r
-?>
\ No newline at end of file
+       public static function forceComputation($id) {\r
+               `/home/stats/www/FWStats.sh /home/stats/www onlybook=$id`;\r
+       }\r
+}
\ No newline at end of file