3 * FusionForge top-level information
5 * Copyright 2002, GForge, LLC
6 * Copyright 2009-2011, Roland Mas
7 * Copyright 2015, Franck Villaume - TrivialDev
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 require_once $gfcommon.'include/FFError.class.php';
27 class FusionForge extends FFError {
29 var $software_name = "FusionForge";
30 var $software_version;
32 public static $instance;
34 function __construct() {
35 parent::__construct();
37 $pkg = dirname(dirname(__FILE__)).'/pkginfo.inc.php';
38 if (file_exists($pkg)) {
42 if (isset($forge_pkg_version)) {
43 $this->software_version = $forge_pkg_version;
45 $this->software_version = trim(file_get_contents(dirname(__FILE__).'/../../VERSION'));
48 self::$instance = $this;
51 public static function getInstance() {
52 if (self::$instance === null) {
53 self::$instance = new self();
55 return self::$instance;
59 * List full number of hosted projects, public and private
61 * @param array $params array of columns and values to filter query: $params['status'] = 'A' ...
62 * @param string $extended_qpa string of SQL to be part of the QPA query
65 function getNumberOfProjects($params = array(), $extended_qpa = null) {
66 $qpa = db_construct_qpa(false, 'SELECT count(*) AS count FROM groups');
67 if (count($params) > 1) {
68 $qpa = db_construct_qpa($qpa, ' WHERE ');
70 foreach ($params as $key => $value) {
72 $qpa = db_construct_qpa($qpa, $key.' = $1 ', array($value));
73 if ($i < count($params)) {
74 $qpa = db_construct_qpa($qpa, ' AND ');
78 if (strlen($extended_qpa) > 1) {
79 if (!strpos($qpa[0], 'WHERE')) {
80 $qpa = db_construct_qpa($qpa, ' WHERE ');
82 if (strpos($qpa[0], 'AND')) {
83 $qpa = db_construct_qpa($qpa, ' AND ');
85 $qpa = db_construct_qpa($qpa, $extended_qpa);
87 $res = db_query_qpa($qpa);
88 if (!$res || db_numrows($res) < 1) {
89 $this->setError('Unable to get hosted project count: '.db_error());
92 return $this->parseCount($res);
95 function getNumberOfActiveProjects() {
96 return $this->getNumberOfProjects(array('status' => 'A'));
99 function getNumberOfDeletedProjects() {
100 return $this->getNumberOfProjects(array('status' => 'D'));
103 function getNumberOfSuspendedProjects() {
104 return $this->getNumberOfProjects(array('status' => 'S'));
107 function getNumberOfActiveUsers() {
108 return $this->getNumberOfUsers('A');
111 function getNumberOfDeletedUsers() {
112 return $this->getNumberOfUsers('D');
115 function getNumberOfSuspendedUsers() {
116 return $this->getNumberOfUsers('S');
119 function getNumberOfProjectsFilteredByGroupName($filter) {
120 $res = db_query_params('SELECT count(*) AS count FROM groups WHERE lower(group_name) LIKE $1', array(strtolower("$filter%")));
121 if (!$res || db_numrows($res) < 1) {
122 $this->setError('Unable to get project count: '.db_error());
125 return $this->parseCount($res);
128 function getNumberOfUsersUsingAPlugin($plugin_name) {
129 $res = db_query_params ('SELECT count(u.user_id) AS count FROM plugins p, user_plugin up, users u WHERE p.plugin_name = $1 and up.user_id = u.user_id AND p.plugin_id = up.plugin_id and users.user_id != 100',
130 array($plugin_name));
131 if (!$res || db_numrows($res) < 1) {
132 $this->setError('Unable to get user count: '.db_error());
135 return $this->parseCount($res);
138 function getNumberOfUsers($status) {
139 $qpa = db_construct_qpa(false, 'SELECT count(*) AS count FROM users WHERE user_id != 100');
141 $qpa = db_construct_qpa($qpa, ' and status = $1', array($status));
143 $res = db_query_qpa($qpa);
144 if (!$res || db_numrows($res) < 1) {
145 $this->setError('Unable to get user count: '.db_error());
148 return $this->parseCount($res);
151 function getPublicProjectNames() {
152 $res = db_query_params ('SELECT unix_group_name, group_id FROM groups WHERE status=$1 ORDER BY unix_group_name',
155 $this->setError('Unable to get list of public projects: '.db_error());
159 $ra = RoleAnonymous::getInstance() ;
160 while ($row = db_fetch_array($res)) {
161 if ($ra->hasPermission('project_read', $row['group_id'])) {
162 $result[] = $row['unix_group_name'];
168 function getNumberOfProjectsUsingTags($params = array(), $extended_qpa = null) {
169 $qpa = db_construct_qpa(false, 'SELECT count(*) AS count FROM groups, project_tags WHERE groups.group_id = project_tags.group_id ');
170 if (count($params) > 1) {
171 $qpa = db_construct_qpa($qpa, ' AND ');
173 foreach ($params as $key => $value) {
175 $qpa = db_construct_qpa($qpa, $key.' = $1 ', array($value));
176 if ($i < count($params)) {
177 $qpa = db_construct_qpa($qpa, ' AND ');
181 if (strlen($extended_qpa) > 1) {
182 if (strpos($qpa[0], 'AND')) {
183 $qpa = db_construct_qpa($qpa, ' AND ');
185 $qpa = db_construct_qpa($qpa, $extended_qpa);
187 $res = db_query_qpa($qpa);
188 if (!$res || db_numrows($res) < 1) {
189 $this->setError('Unable to get hosted project count: '.db_error());
192 return $this->parseCount($res);
196 function parseCount($res) {
197 $row_count = db_fetch_array($res);
198 return (int)$row_count['count'];
204 // c-file-style: "bsd"