$from = CMbDT::date("-1 YEAR", $to); break; case "four-years": $from = CMbDT::date("-4 YEARS", $to); break; case "twenty-years": $from = CMbDT::date("-20 YEARS", $to); break; } $graphs = array(); $left = array($left_mode, $left_sampling); $right = array($right_mode, $right_sampling); switch ($groupmod) { case 0: case 1: $access_logs = CAccessLog::loadAggregation($from, $to, $groupmod, $module, $human_bot); $archive_logs = CAccessLogArchive::loadAggregation($from, $to, $groupmod, $module, $human_bot); $logs = array_merge($access_logs, $archive_logs); break; case 2: $logs = array(new CAccessLog()); break; default: return; } $graphs_by_module = array(); foreach ($logs as $log) { switch ($groupmod) { case 0: $_graph = call_user_func("{$log->_class}::graphAccessLog", $log->_module, $log->_action, $from, $to, $interval, $left, $right, $human_bot); if (!isset($graphs_by_module[$log->_module . "-" . $log->_action])) {
/** * Génération des données des graphiques du palmarès ressources * * @param string $module Module concerné * @param string $date Date de référence * @param string $element Type de données à afficher * @param string $interval Interval de temps à analyser * @param int $numelem Nombre d'éléments maximum * * @return array Les données de palmarès */ function graphRessourceLog($module, $date, $element = 'duration', $interval = 'day', $numelem = 4) { if (!$date) { $date = CMbDT::date(); } switch ($interval) { default: case "day": $startx = "{$date} 00:00:00"; $endx = "{$date} 23:59:59"; break; case "month": $startx = CMbDT::dateTime("-1 MONTH", "{$date} 00:00:00"); $endx = "{$date} 23:59:59"; break; case "year": $startx = CMbDT::dateTime("-27 WEEKS", "{$date} 00:00:00"); $endx = "{$date} 23:59:59"; break; } if ($module == "total") { $groupmod = 0; $module_name = null; } elseif ($module == "modules") { $groupmod = 1; $module_name = null; } else { $groupmod = 0; $module_name = $module; } $logs = CAccessLog::loadAggregation($startx, $endx, $groupmod, $module_name); $series = array(); $i = 0; foreach ($logs as $data) { $series[$i]["data"] = array(array(0, $data->{$element})); $series[$i]["label"] = $module != 'modules' ? $data->_action : $data->_module; $i++; } if (!function_exists('compareDataPie')) { /** * Comparaison entre deux données du graphique en pie * * @param array $a Première donnée * @param array $b Deuxième donnée * * @return bool La première valeur est-elle inférieure à la deuxième */ function compareDataPie($a, $b) { return $a["data"][0][1] < $b["data"][0][1]; } } usort($series, "compareDataPie"); $seriesNew = array_slice($series, 0, $numelem); if (count($series) > $numelem) { $other = array_slice($series, $numelem); $seriesNew[$numelem]["data"] = array(array(0, 0)); $seriesNew[$numelem]["label"] = "Autres"; $n = 0; foreach ($other as $_other) { $seriesNew[$numelem]["data"][0][1] += $_other["data"][0][1]; $n++; } $seriesNew[$numelem]["label"] .= " ({$n})"; } $series = $seriesNew; // Set up the title for the graph $title = CMbDT::format($date, "%A %d %b %Y"); if ($module) { $title .= " : " . CAppUI::tr($module); } $options = array('title' => utf8_encode($title), 'HtmlText' => false, 'grid' => array('verticalLines' => false, 'horizontalLines' => false, 'outlineWidth' => 0), 'xaxis' => array('showLabels' => false), 'yaxis' => array('showLabels' => false), 'pie' => array('show' => true, 'sizeRatio' => 0.5), 'legend' => array('backgroundOpacity' => 0.3)); return array('series' => $series, 'options' => $options); }
$from = CMbDT::date("-1 DAY", $next); break; case "month": $from = CMbDT::date("-1 MONTH", $next); break; case "year": $from = CMbDT::date("-6 MONTH", $next); break; } $graphs = array(); if ($groupres == 1) { if ($element != "_average_duration" && $element != "_average_request" && $element != "_average_nb_requests") { $graphs[] = graphRessourceLog('modules', $date, $element, $interval, $numelem); } $graphs[] = graphRessourceLog('total', $date, $element, $interval, $numelem); } else { $logs = CAccessLog::loadAggregation($from, $next, $groupres + 1, 0); foreach ($logs as $log) { $graphs[] = graphRessourceLog($log->_module, $date, $element, $interval, $numelem); } } // Création du template $smarty = new CSmartyDP(); $smarty->assign("graphs", $graphs); $smarty->assign("date", $date); $smarty->assign("groupres", $groupres); $smarty->assign("element", $element); $smarty->assign("interval", $interval); $smarty->assign("numelem", $numelem); $smarty->assign("listModules", CModule::getInstalled()); $smarty->display("view_ressources_logs.tpl");