-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate-companies-top.php
124 lines (100 loc) · 2.3 KB
/
template-companies-top.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* Template Name: Companies Top
*/
get_header();
// Globals
global $wpdb;
// Condition
$where = '1 = 1';
$start = filter_input( INPUT_GET, 'start', FILTER_SANITIZE_STRING );
$start = empty( $start ) ? '-1 week' : $start;
if ( ! empty( $start ) ) {
$where = $wpdb->prepare(
'timesheet.date BETWEEN %s AND %s',
date( 'Y-m-d', strtotime( $start ) ),
date( 'Y-m-d' )
);
}
// Query
$query = "
SELECT
company.id AS company_id,
company.name AS company_name,
company.post_id AS company_post_id,
SUM( timesheet.number_seconds ) AS subscription_seconds
FROM
$wpdb->orbis_timesheets AS timesheet
LEFT JOIN
$wpdb->orbis_companies AS company
ON timesheet.company_id = company.id
WHERE
%s
GROUP BY
company.id
ORDER BY
subscription_seconds DESC
LIMIT
0, 100
;
";
$query = sprintf( $query, $where );
$results = $wpdb->get_results( $query );
?>
<form class="form-inline" method="get" action="">
<div class="row">
<div class="col-md-2">
</div>
<div class="col-md-6">
</div>
<div class="col-md-4">
<div class="pull-right">
<select name="start" id="user" class="form-control">
<?php
$filter = array(
'' => 'Totaal',
'-1 year' => 'Afgelopen jaar',
'-6 months' => 'Afgelopen half jaar',
'-3 months' => 'Afgelopen 3 maanden',
'-1 month' => 'Afgelopen maand',
'-1 week' => 'Afgelopen week',
);
foreach ( $filter as $value => $label ) {
printf(
'<option value="%s" %s>%s</option>',
esc_attr( $value ),
selected( $start, $value, false ),
esc_html( $label )
);
}
?>
</select>
<button type="submit" class="btn btn-default">Filter</button>
</div>
</div>
</div>
</form>
<hr />
<table class="table table-striped table-bordered panel">
<thead>
<tr>
<th><?php _e( 'Company', 'orbis_pronamic' ); ?></th>
<th><?php _e( 'Time', 'orbis_pronamic' ); ?></th>
</tr>
</thead>
<tbody>
<?php foreach( $results as $row ) : ?>
<tr>
<td>
<a href="<?php echo add_query_arg( 'p', $row->company_post_id, home_url( '/' ) ); ?>">
<?php echo $row->company_name; ?>
</a>
</td>
<td>
<?php echo orbis_time( $row->subscription_seconds ); ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php get_footer(); ?>