Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
Switch to ranges from TTT v1.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
kimbtech committed Feb 24, 2022
1 parent 641ef5b commit 33c6b17
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
4 changes: 2 additions & 2 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
latest
0.5.7
0.5
0.6.0
0.6
0
4 changes: 2 additions & 2 deletions php/core/DataAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function __construct( Login $login, Share $share ) {
public function setParams(string $time, string $rFrom, string $rTo, string $cats, string $names, array $devices ) : void {
$this->cmd = array();
$this->cmdSemantical = array();
$times = array("today", "day", "week", "month", "range", "all");

$times = array("cDay", "cWeek", "cMonth", "cYear", "lDay", "lWeek", "lMonth", "lYear", "range", "all");
if( isset($time) && in_array($time, $times)){
$this->cmd[] = $time;
$this->cmdSemantical['time'] = $time;
Expand Down
12 changes: 8 additions & 4 deletions php/core/templates/stats_en.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ <h3>Select data</h3>
<label for="time" class="col-sm-2 col-form-label">Timespan</label>
<div class="col-sm-10">
<select name="time" id="time" class="custom-select">
<option value="today" selected>Today</option>
<option value="day">Day</option>
<option value="week">Week</option>
<option value="month">Month</option>
<option value="cDay" selected>Today</option>
<option value="cWeek">Current week</option>
<option value="cMonth">Current month</option>
<option value="cYear">Current year</option>
<option value="lDay">Last day (24 hours)</option>
<option value="lWeek">Last week (7 days)</option>
<option value="lMonth">Last month (30 days)</option>
<option value="lYear">Last year (365 days)</option>
<option value="range">Range</option>
<option value="all">All</option>
</select>
Expand Down
36 changes: 26 additions & 10 deletions php/core/ttt/TTTStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,42 @@ public function __construct(array $commands, string $path) {

private function parseCommands(array $commands) : void {
switch( $commands[0] ) {
case "day":
$this->backUntil(time() - 86400, array_slice($commands, 1));
case "cDay":
$commands = array_slice($commands, 1);
$this->todayview = true;
$this->backUntil(strtotime("today"), $commands);
case "cWeek":
$this->backUntil(strtotime("last Monday"), array_slice($commands, 1));
break;
case "cMonth":
$this->backUntil(strtotime(date("Y-m")."-01"), array_slice($commands, 1));
break;
case "cYear":
$this->backUntil(strtotime(date("Y")."-01-01"), array_slice($commands, 1));
break;

case "lDay":
$this->backUntil(time() - 24*60*60, array_slice($commands, 1));
break;
case "week":
$this->backUntil(time() - 604800, array_slice($commands, 1));
case "lWeek":
$this->backUntil(time() - 7*24*60*60, array_slice($commands, 1));
break;
case "month":
$this->backUntil(time() - 2628000, array_slice($commands, 1));
case "lMonth":
$this->backUntil(time() - 30*24*60*60, array_slice($commands, 1));
break;
case "lYear":
$this->backUntil(time() - 365*24*60*60, array_slice($commands, 1));
break;

case "all":
$this->backUntil(0, array_slice($commands, 1));
break;
case "range":
$this->rangeStats(array_slice($commands, 1));
break;
case "today":
$commands = array_slice($commands, 1);

default:
$this->todayview = true;
$this->backUntil(strtotime("today"), $commands);
# will not happen, cause command checked in DataAccess
}
}

Expand Down

0 comments on commit 33c6b17

Please sign in to comment.