Completed
Push — master ( 18cdc2...7b9bde )
by Simon
03:22
created

StatsFastCloses.php ➔ statsFastClosesRowCallback()   B

Complexity

Conditions 6
Paths 9

Size

Total Lines 33
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 17
nc 9
nop 2
dl 0
loc 33
rs 8.439
c 0
b 0
f 0
1
<?php
2
/**************************************************************************
3
**********      English Wikipedia Account Request Interface      **********
4
***************************************************************************
5
** Wikipedia Account Request Graphic Design by Charles Melbye,           **
6
** which is licensed under a Creative Commons                            **
7
** Attribution-Noncommercial-Share Alike 3.0 United States License.      **
8
**                                                                       **
9
** All other code are released under the Public Domain                   **
10
** by the ACC Development Team.                                          **
11
**                                                                       **
12
** See CREDITS for the list of developers.                               **
13
***************************************************************************/
14
15
class StatsFastCloses extends StatisticsPage
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
16
{
17
	protected function execute()
18
	{
19
		$query = <<<SQL
20
SELECT
21
  log_closed.objectid AS Request,
22
  user.username AS User,
23
  log_closed.user AS UserID,
24
  TIMEDIFF(log_closed.timestamp, log_reserved.timestamp) AS 'Time Taken',
25
  closes.mail_desc AS 'Close Type',
26
  log_closed.timestamp AS 'Date'
27
28
FROM log log_closed
29
INNER JOIN log log_reserved ON log_closed.objectid = log_reserved.objectid 
30
	AND log_closed.objecttype = log_reserved.objecttype
31
INNER JOIN closes ON closes.`closes` = log_closed.action
32
LEFT JOIN user ON log_closed.user = user.id
33
34
WHERE log_closed.action LIKE 'Closed%'
35
  AND log_reserved.action = 'Reserved'
36
  AND TIMEDIFF(log_closed.timestamp, log_reserved.timestamp) < '00:00:30'
37
  AND log_closed.user = log_reserved.user
38
  AND TIMEDIFF(log_closed.timestamp, log_reserved.timestamp) > '00:00:00'
39
  AND DATE(log_closed.timestamp) > DATE(NOW()-INTERVAL 3 MONTH)
40
41
ORDER BY TIMEDIFF(log_closed.timestamp, log_reserved.timestamp) ASC
42
;
43
SQL;
44
45
		$qb = new QueryBrowser();
46
		$qb->tableCallbackFunction = "statsFastClosesRowCallback";
47
		$qb->overrideTableTitles =
48
			array("Request", "User", "Time Taken", "Close Type", "Date");
49
		$qb->rowFetchMode = PDO::FETCH_NUM;
50
		$r = $qb->executeQueryToTable($query);
51
52
		return $r;
53
	}
54
55
	public function getPageName()
56
	{
57
		return "FastCloses";
58
	}
59
60
	public function getPageTitle()
61
	{
62
		return "Requests closed less than 30 seconds after reservation in the past 3 months";
63
	}
64
65
	public function isProtected()
66
	{
67
		return true;
68
	}
69
70
	public function requiresWikiDatabase()
71
	{
72
		return false;
73
	}
74
}
75
76
function statsFastClosesRowCallback($row, $currentreq)
0 ignored issues
show
Unused Code introduced by
The parameter $currentreq is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
77
{
78
	$out = '<tr>';
79
80
	global $baseurl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
81
82
	$rowCount = count($row);
83
84
	for ($colid = 0; $colid < $rowCount; $colid++) {
85
		$cell = $row[$colid];
86
87
		$out .= "<td>";
88
89
		if ($colid == 0) {
90
			$out .= "<a href=\"" . $baseurl . "/acc.php?action=zoom&id=" . $cell . "\">";
91
		}
92
		if ($colid == 1) {
93
			$out .= "<a href=\"" . $baseurl . "/statistics.php/Users?user=" . $row[++$colid] . "\">";
94
		}
95
96
		$out .= $cell;
97
98
		if ($colid == 0 || $colid == 2) {
99
			$out .= "</a>"; // colid is now 2 if triggered from above due to postinc
100
		}
101
102
		$out .= "</td>";
103
	}
104
105
	$out .= "</tr>";
106
107
	return $out;
108
}
109