plugin/dashboard/Manager/DashboardManager.php
private function computeTimeForUserAndWorkspace($startDate, $userId, $workspaceId, $time)
    {
        // select first "out of this workspace event" (ie "workspace enter" on another workspace)
        $sql = "SELECT date_log FROM claro_log WHERE action LIKE 'workspace-enter' AND doer_id = :uid  AND date_log > :dateLog ORDER BY date_log ASC LIMIT 1";
        $stmt = $this->em->getConnection()->prepare($sql);
        $stmt->bindValue('uid', $userId);
        $stmt->bindValue('dateLog', $startDate);
        $stmt->execute();
        $action = $stmt->fetch();

        // if there is an action we can compute time
        if ($action['date_log']) {
            $t1 = strtotime($startDate);
            $t2 = strtotime($action['date_log']);
            $seconds = $t2 - $t1;

            // add time only if bewteen 30s and 2 hours <= totally arbitrary !
            if ($seconds > 5 && ($seconds / 60) <= 120) {
                $time += $seconds;
            }
            // get next "enter the requested workspace enter event"
            $sql = "SELECT date_log FROM claro_log WHERE action LIKE 'workspace-enter' AND doer_id = :uid AND date_log > :dateLog AND workspace_id = :wid ORDER BY date_log ASC LIMIT 1";
            $stmt = $this->em->getConnection()->prepare($sql);
            $stmt->bindValue('uid', $userId);
            $stmt->bindValue('dateLog', $action['date_log']);
            $stmt->bindValue('wid', $workspaceId);
            $stmt->execute();
            $nextEnterEvent = $stmt->fetch();
            // if there is an "enter-workspace" action after the current one recall the method
            if ($nextEnterEvent['date_log']) {
                return $this->computeTimeForUserAndWorkspace($nextEnterEvent['date_log'], $userId, $workspaceId, $time);
            } else {
                return $time;
            }
        }

        return $time;
    }
private function computeTimeForUserAndWorkspace($startDate, $userId, $workspaceId, $time)
    {
        // select first "out of this workspace event" (ie "workspace enter" on another workspace)
        $sql = "SELECT date_log FROM claro_log WHERE action LIKE 'workspace-enter' AND doer_id = :uid  AND date_log > :dateLog ORDER BY date_log ASC LIMIT 1";
        $stmt = $this->em->getConnection()->prepare($sql);
        $stmt->bindValue('uid', $userId);
        $stmt->bindValue('dateLog', $startDate);
        $stmt->execute();
        $action = $stmt->fetch();

        // if there is an action we can compute time
        if ($action['date_log']) {
            $t1 = strtotime($startDate);
            $t2 = strtotime($action['date_log']);
            $seconds = $t2 - $t1;

            // add time only if bewteen 30s and 2 hours <= totally arbitrary !
            if ($seconds > 5 && ($seconds / 60) <= 120) {
                $time += $seconds;
            }
            // get next "enter the requested workspace enter event"
            $sql = "SELECT date_log FROM claro_log WHERE action LIKE 'workspace-enter' AND doer_id = :uid AND date_log > :dateLog AND workspace_id = :wid ORDER BY date_log ASC LIMIT 1";
            $stmt = $this->em->getConnection()->prepare($sql);
            $stmt->bindValue('uid', $userId);
            $stmt->bindValue('dateLog', $action['date_log']);
            $stmt->bindValue('wid', $workspaceId);
            $stmt->execute();
            $nextEnterEvent = $stmt->fetch();
            // if there is an "enter-workspace" action after the current one recall the method
            if ($nextEnterEvent['date_log']) {
                return $this->computeTimeForUserAndWorkspace($nextEnterEvent['date_log'], $userId, $workspaceId, $time);
            } else {
                return $time;
            }
        }

        return $time;
    }
private function computeTimeForUserAndWorkspace ( $ startDate , $ userId , $ workspaceId , $ time ) { // select first "out of this workspace event" (ie "workspace enter" on another workspace) $ sql = "SELECT date_log FROM claro_log WHERE action LIKE 'workspace-enter' AND doer_id = :uid  AND date_log > :dateLog ORDER BY date_log ASC LIMIT 1" ; $ stmt = $ this -> em -> getConnection ( ) -> prepare ( $ sql ) ; $ stmt -> bindValue ( 'uid' , $ userId ) ; $ stmt -> bindValue ( 'dateLog' , $ startDate ) ; $ stmt -> execute ( ) ; $ action = $ stmt -> fetch ( ) ; // if there is an action we can compute time if ( $ action [ 'date_log' ] ) { $ t1 = strtotime ( $ startDate ) ; $ t2 = strtotime ( $ action [ 'date_log' ] ) ; $ seconds = $ t2 - $ t1 ; // add time only if bewteen 30s and 2 hours <= totally arbitrary ! if ( $ seconds > 5 && ( $ seconds / 60 ) <= 120 ) { $ time += $ seconds ; } // get next "enter the requested workspace enter event" $ sql = "SELECT date_log FROM claro_log WHERE action LIKE 'workspace-enter' AND doer_id = :uid AND date_log > :dateLog AND workspace_id = :wid ORDER BY date_log ASC LIMIT 1" ; $ stmt = $ this -> em -> getConnection ( ) -> prepare ( $ sql ) ; $ stmt -> bindValue ( 'uid' , $ userId ) ; $ stmt -> bindValue ( 'dateLog' , $ action [ 'date_log' ] ) ; $ stmt -> bindValue ( 'wid' , $ workspaceId ) ; $ stmt -> execute ( ) ; $ nextEnterEvent = $ stmt -> fetch ( ) ; // if there is an "enter-workspace" action after the current one recall the method if ( $ nextEnterEvent [ 'date_log' ] ) { return $ this -> computeTimeForUserAndWorkspace ( $ nextEnterEvent [ 'date_log' ] , $ userId , $ workspaceId , $ time ) ; } else { return $ time ; } } return $ time ; }
Search for out and in events on a given wokspace, for a given user and relativly to a date.
Search for out and in events on a given wokspace for a given user and relativly to a date .