Kimai_Database_Mysql::get_duration PHP Method

get_duration() public method

returns time summary of current timesheet
Author: th
public get_duration ( integer $start, integer $end, null $users = null, null $customers = null, null $projects = null, null $activities = null, null $filterCleared = null ) : integer
$start integer start of timeframe in unix seconds
$end integer end of timeframe in unix seconds
$users null
$customers null
$projects null
$activities null
$filterCleared null
return integer
    public function get_duration($start, $end, $users = null, $customers = null, $projects = null, $activities = null, $filterCleared = null)
    {
        // -1 for disabled, 0 for only not cleared entries
        if (!is_numeric($filterCleared)) {
            $filterCleared = -1;
            if ($this->kga->getSettings()->isHideClearedEntries()) {
                $filterCleared = 0;
            }
        }
        $start = MySQL::SQLValue($start, MySQL::SQLVALUE_NUMBER);
        $end = MySQL::SQLValue($end, MySQL::SQLVALUE_NUMBER);
        $p = $this->kga['server_prefix'];
        $whereClauses = $this->timeSheet_whereClausesFromFilters($users, $customers, $projects, $activities);
        if ($start) {
            $whereClauses[] = "end > {$start}";
        }
        if ($end) {
            $whereClauses[] = "start < {$end}";
        }
        if ($filterCleared > -1) {
            $whereClauses[] = "cleared = {$filterCleared}";
        }
        $query = "SELECT start,end,duration FROM {$p}timeSheet\n              JOIN {$p}projects USING(projectID)\n              JOIN {$p}customers USING(customerID)\n              JOIN {$p}users USING(userID)\n              JOIN {$p}activities USING(activityID) " . (count($whereClauses) > 0 ? " WHERE " : " ") . implode(" AND ", $whereClauses);
        $this->conn->Query($query);
        $this->conn->MoveFirst();
        $sum = 0;
        $consideredStart = 0;
        // Consider start of selected range if real start is before
        $consideredEnd = 0;
        // Consider end of selected range if real end is afterwards
        while (!$this->conn->EndOfSeek()) {
            $row = $this->conn->Row();
            if ($row->start <= $start && $row->end < $end) {
                $consideredStart = $start;
                $consideredEnd = $row->end;
            } elseif ($row->start <= $start && $row->end >= $end) {
                $consideredStart = $start;
                $consideredEnd = $end;
            } elseif ($row->start > $start && $row->end < $end) {
                $consideredStart = $row->start;
                $consideredEnd = $row->end;
            } elseif ($row->start > $start && $row->end >= $end) {
                $consideredStart = $row->start;
                $consideredEnd = $end;
            }
            $sum += (int) ($consideredEnd - $consideredStart);
        }
        return $sum;
    }
Kimai_Database_Mysql