FOSSology  4.4.0
Open Source License Compliance by Open Source Software
admin-dashboard-stats.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2019 Orange
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 define("TITLE_DASHBOARD_STATISTICS", _("Statistics Dashboard"));
9 
11 
13 {
14  protected $pgVersion;
15 
17  private $dbManager;
18 
19  function __construct()
20  {
21  $this->Name = "dashboard-statistics";
22  $this->Title = TITLE_DASHBOARD_STATISTICS;
23  $this->MenuList = "Admin::Dashboards::Statistics";
24  $this->DBaccess = PLUGIN_DB_ADMIN;
25  parent::__construct();
26  $this->dbManager = $GLOBALS['container']->get('db.manager');
27  }
28 
32  function CountAllJobs($fromRest = false)
33  {
34  $query = "SELECT ag.agent_name,ag.agent_desc,count(jq.*) AS fired_jobs ";
35  $query.= "FROM agent ag LEFT OUTER JOIN jobqueue jq ON (jq.jq_type = ag.agent_name) ";
36  $query.= "GROUP BY ag.agent_name,ag.agent_desc ORDER BY fired_jobs DESC;";
37  $restRes = [];
38  $rows = $this->dbManager->getRows($query);
39 
40  $V = "<table border=1>";
41  $V .= "<tr><th>".("AgentName")."</th><th>"._("Description")."</th><th>"._("Number of jobs")."</th></tr>";
42 
43  foreach ($rows as $agData) {
44  $V .= "<tr><td>".$agData['agent_name']."</td><td>".$agData['agent_desc']."</td><td align='right'>".$agData['fired_jobs']."</td></tr>";
45  $restRes[] = [
46  'agentName' => $agData['agent_name'],
47  'agentDesc' => $agData['agent_desc'],
48  'firedJobs' => intval($agData['fired_jobs']),
49  ];
50  }
51 
52  $V .= "</table>";
53 
54  if ($fromRest) {
55  return $restRes;
56  }
57  return $V;
58  }
59 
60  public function Output()
61  {
62  $V = "<h1> Statistics </h1>";
63  $V .= "<table style='width: 100%;' border=0>\n";
64 
65  $V .= "<tr>";
66  $V .= "<td class='dashboard'>";
67  $text = _("Jobs Sumary");
68  $V .= "<h2>$text</h2>\n";
69  $V .= $this->CountAllJobs();
70  $V .= "</td>";
71  $V .= "</tr>";
72 
73  $V .= "</table>";
74 
75  return $V;
76  }
77 }
78 
79 $dash = new dashboardReporting ;
80 $dash->Initialize();
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:57
Output()
This function is called when user output is requested. This function is responsible for content....
__construct()
base constructor. Most plugins will just use this
CountAllJobs($fromRest=false)
Lists number of ever quequed jobs per job type (agent)..
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
Definition: libfossology.h:39
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16