FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
admin-dashboard-stats.php
1 <?php
2 /***********************************************************
3  Copyright (C) 2019 Orange
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  version 2 as published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  ***********************************************************/
18 
19 define("TITLE_DASHBOARD_STATISTICS", _("Statistics Dashboard"));
20 
22 
24 {
25  protected $pgVersion;
26 
28  private $dbManager;
29 
30  function __construct()
31  {
32  $this->Name = "dashboard-statistics";
33  $this->Title = TITLE_DASHBOARD_STATISTICS;
34  $this->MenuList = "Admin::Dashboards::Statistics";
35  $this->DBaccess = PLUGIN_DB_ADMIN;
36  parent::__construct();
37  $this->dbManager = $GLOBALS['container']->get('db.manager');
38  }
39 
43  function CountAllJobs()
44  {
45  $query = "SELECT ag.agent_name,ag.agent_desc,count(jq.*) AS fired_jobs ";
46  $query.= "FROM agent ag LEFT OUTER JOIN jobqueue jq ON (jq.jq_type = ag.agent_name) ";
47  $query.= "GROUP BY ag.agent_name,ag.agent_desc ORDER BY fired_jobs DESC;";
48 
49  $rows = $this->dbManager->getRows($query);
50 
51  $V = "<table border=1>";
52  $V .= "<tr><th>".("AgentName")."</th><th>"._("Description")."</th><th>"._("Number of jobs")."</th></tr>";
53 
54  foreach ($rows as $agData) {
55  $V .= "<tr><td>".$agData['agent_name']."</td><td>".$agData['agent_desc']."</td><td align='right'>".$agData['fired_jobs']."</td></tr>";
56  }
57 
58  $V .= "</table>";
59 
60  return $V;
61  }
62 
63  public function Output()
64  {
65  $V = "<h1> Statistics </h1>";
66  $V .= "<table style='width: 100%;' border=0>\n";
67 
68  $V .= "<tr>";
69  $V .= "<td class='dashboard'>";
70  $text = _("Jobs Sumary");
71  $V .= "<h2>$text</h2>\n";
72  $V .= $this->CountAllJobs();
73  $V .= "</td>";
74  $V .= "</tr>";
75 
76  $V .= "</table>";
77 
78  return $V;
79  }
80 }
81 
82 $dash = new dashboardReporting ;
83 $dash->Initialize();
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
Definition: libfossology.h:51
CountAllJobs()
Lists number of ever quequed jobs per job type (agent)..
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:28
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:67