-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
169 lines (149 loc) · 4.97 KB
/
index.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
// page meta settings
$page_title = 'This Week';
$page_slug = '/';
$page_lead = 'Daily tallies and Weekly totals/averages from your Harvest account.';
require_once( dirname(__FILE__) . '/header.php' ); ?>
<div class="container py-5">
<div class="row">
<header class="col-sm">
<h1><?= $page_title ?></h1>
<?php
if( $page_lead )
echo "<p>$page_lead</p>";
if( $dashboard_url )
echo "<p><a href='$dashboard_url' target='_blank' class='btn btn-lg btn-info'>Harvest Dashboard</a></p>";
?>
</header><!-- .col -->
</div><!-- .row -->
</div><!-- .container -->
<!-- <code> -->
<?php
// date vars
// date_default_timezone_set($time_zone);
$today = strtotime('now');
$weekdays_so_far = date('w');
$day_of_year = date('z');
$year = date('Y', time());
// create day of year array for Harvest
$days_in_week = array();
for ($x = 0; $x < $weekdays_so_far; $x++) {
$this_day_of_year = $day_of_year-$x;
$days_in_week[] = $this_day_of_year;
// echo '<pre>This Day: ' . $this_day_of_year . '<br>x: ' . $x . '</pre>';
}
$days_in_week = array_reverse($days_in_week);
?>
<?php
// echo '<pre>';
// echo 'Timezone: ' . $time_zone . '<br>';
// echo 'Today: ' . date('D', $today) . ' (' . date('z', $today) . ')<br>';
// $today_harvest_format = date('D, d M Y', $today);
// echo strtotime($today_harvest_format) . ' | ' . $today . '<br>';
// echo 'Year: ' . $year . '<br>';
// echo 'Weekdays so far: ';
// var_dump($days_in_week);
// echo '</pre>';
// echo '<pre>';
// foreach( $days_in_week as $day ) {
// echo $day . '<br>';
// }
// echo '</pre>';
?>
<!-- </code> -->
<div class="bg-light border-bottom border-top py-5">
<div class="container">
<div class="row row-eq-height">
<?php
$weekly_total = 0;
$days_in_week_total = 0;
foreach( $days_in_week as $day ) :
$result = $api->getDailyActivity( $day, $year );
if( $result->isSuccess() ) :
$entry_timestamp = strtotime($result->data->forDay);
$entry_label = date( 'D', $entry_timestamp );
if( !in_array( $entry_label, array('Sat', 'Sun') ) ) :
// tally weekly/daily activity
$days_in_week_total++;
$daily_total = 0;
foreach( $result->data->dayEntries as $entry )
$daily_total += $entry->get( 'hours' );
// calculate class based on $daily_target
$add_class = ( $daily_total >= $daily_target ) ? 'success' : 'warning';
?>
<section class="col-sm my-2">
<div class="text-center card">
<header class="card-header">
<h1 class="text-uppercase text-dark m-0 h3" data-date="<?= $result->data->forDay ?>" data-day="<?= $day ?>"><?= $entry_label ?></h1>
</header>
<div class="card-body">
<p class="">
<span class="display-4 text-<?= $add_class ?>"><?= $daily_total ?></span>
<small class="text-secondary d-none d-lg-inline">hrs</small>
</p>
</div>
</div>
</section>
<?php
endif; // is weekday
endif; // $result->isSuccess
// tally weekly total
$weekly_total += $daily_total;
endforeach;
?>
</div><!-- .row -->
</div><!-- .container -->
</div><!-- .bg-light -->
<div class="container py-5">
<div class="row d-flex justify-content-around">
<section class="col-sm col-md-5 col-lg-4">
<div class="card text-center my-2">
<header class="card-header">
<h1 class="text-uppercase text-dark m-0 h2">Total</h1>
</header>
<div class="card-body">
<span class="display-3 text-primary"><?= $weekly_total ?></span>
<span class="d-none d-lg-inline text-muted">hrs</span>
</div>
</div>
</section>
<section class="col-sm col-md-5 col-lg-4">
<div class="card text-center my-2">
<header class="card-header">
<h1 class="text-uppercase text-dark m-0 h2">Average</h1>
</header>
<div class="card-body">
<?php
$weekly_average = round( ($weekly_total / $days_in_week_total), 2 );
$add_class = ( $weekly_average >= $daily_target ) ? ' text-success' : ' text-warning';
?>
<span class="display-3 <?= $add_class ?>"><?= $weekly_average ?></span>
<span class="d-none d-lg-inline text-muted">hrs</span>
</div>
</div>
</section>
</div><!-- .row -->
</div><!-- .container -->
<div class="container pb-5">
<div class="row">
<div class="col-sm text-center">
<?php
// calculate alert based on $daily_target
$daily_target_third = $daily_target / 3;
if( $weekly_average <= $daily_target_third ) {
$alert_class = 'danger';
$alert_text = 'Work harder!';
} elseif( $weekly_average <= ($daily_target_third * 2) ) {
$alert_class = 'warning';
$alert_text = 'Keep working, you can do better!';
} else {
$alert_class = 'success';
$alert_text = 'Good work, keep it up!';
} ?>
<div class="alert alert-<?= $alert_class ?>" role="alert">
<h5 class="alert-heading m-0"><?= $alert_text ?></h5>
</div>
</div><!-- .col -->
</div><!-- .row -->
</div><!-- .container -->
<?php require_once( dirname(__FILE__) . '/footer.php' ); ?>