plugin/dashboard/Manager/DashboardManager.php
public function getDashboardWorkspaceSpentTimes(Workspace $workspace, User $user, $all = false)
    {
        $datas = [];
        // user(s) concerned by the query
        if ($all) {
            // get all users involved in the workspace
            $ids = $this->getWorkspaceUsersIds($workspace);
        } else {
            // only the current user
            $ids[] = $user->getId();
        }

        // for each user (ie user ids) -> get first 'workspace-enter' event for the given workspace
        foreach ($ids as $uid) {
            $userSqlSelect = 'SELECT first_name, last_name FROM claro_user WHERE id = :uid';
            $userSqlSelectStmt = $this->em->getConnection()->prepare($userSqlSelect);
            $userSqlSelectStmt->bindValue('uid', $uid);
            $userSqlSelectStmt->execute();
            $userData = $userSqlSelectStmt->fetch();

            // select first "workspace-enter" actions for the given user and workspace
            $selectEnterEventOnThisWorkspace = "SELECT DISTINCT date_log FROM claro_log WHERE workspace_id = :wid AND action = 'workspace-enter' AND doer_id = :uid ORDER BY date_log ASC LIMIT 1";
            $selectEnterEventOnThisWorkspaceStmt = $this->em->getConnection()->prepare($selectEnterEventOnThisWorkspace);
            $selectEnterEventOnThisWorkspaceStmt->bindValue('uid', $uid);
            $selectEnterEventOnThisWorkspaceStmt->bindValue('wid', $workspace->getId());
            $selectEnterEventOnThisWorkspaceStmt->execute();
            $enterOnThisWorksapceDateResult = $selectEnterEventOnThisWorkspaceStmt->fetch();
            $refDate = $enterOnThisWorksapceDateResult['date_log'];

            $total = 0;
            if ($refDate) {
                $total = $this->computeTimeForUserAndWorkspace($refDate, $uid, $workspace->getId(), 0);
            }

            $datas[] = [
              'user' => [
                'id' => $uid,
                'firstName' => $userData['first_name'],
                'lastName' => $userData['last_name'],
              ],
              'time' => $total,
            ];
        }

        return $datas;
    }
public function getDashboardWorkspaceSpentTimes(Workspace $workspace, User $user, $all = false)
    {
        $datas = [];
        // user(s) concerned by the query
        if ($all) {
            // get all users involved in the workspace
            $ids = $this->getWorkspaceUsersIds($workspace);
        } else {
            // only the current user
            $ids[] = $user->getId();
        }

        // for each user (ie user ids) -> get first 'workspace-enter' event for the given workspace
        foreach ($ids as $uid) {
            $userSqlSelect = 'SELECT first_name, last_name FROM claro_user WHERE id = :uid';
            $userSqlSelectStmt = $this->em->getConnection()->prepare($userSqlSelect);
            $userSqlSelectStmt->bindValue('uid', $uid);
            $userSqlSelectStmt->execute();
            $userData = $userSqlSelectStmt->fetch();

            // select first "workspace-enter" actions for the given user and workspace
            $selectEnterEventOnThisWorkspace = "SELECT DISTINCT date_log FROM claro_log WHERE workspace_id = :wid AND action = 'workspace-enter' AND doer_id = :uid ORDER BY date_log ASC LIMIT 1";
            $selectEnterEventOnThisWorkspaceStmt = $this->em->getConnection()->prepare($selectEnterEventOnThisWorkspace);
            $selectEnterEventOnThisWorkspaceStmt->bindValue('uid', $uid);
            $selectEnterEventOnThisWorkspaceStmt->bindValue('wid', $workspace->getId());
            $selectEnterEventOnThisWorkspaceStmt->execute();
            $enterOnThisWorksapceDateResult = $selectEnterEventOnThisWorkspaceStmt->fetch();
            $refDate = $enterOnThisWorksapceDateResult['date_log'];

            $total = 0;
            if ($refDate) {
                $total = $this->computeTimeForUserAndWorkspace($refDate, $uid, $workspace->getId(), 0);
            }

            $datas[] = [
              'user' => [
                'id' => $uid,
                'firstName' => $userData['first_name'],
                'lastName' => $userData['last_name'],
              ],
              'time' => $total,
            ];
        }

        return $datas;
    }
public function getDashboardWorkspaceSpentTimes ( Workspace $ workspace , User $ user , $ all = false ) { $ datas = [ ] ; // user(s) concerned by the query if ( $ all ) { // get all users involved in the workspace $ ids = $ this -> getWorkspaceUsersIds ( $ workspace ) ; } else { // only the current user $ ids [ ] = $ user -> getId ( ) ; } // for each user (ie user ids) -> get first 'workspace-enter' event for the given workspace foreach ( $ ids as $ uid ) { $ userSqlSelect = 'SELECT first_name, last_name FROM claro_user WHERE id = :uid' ; $ userSqlSelectStmt = $ this -> em -> getConnection ( ) -> prepare ( $ userSqlSelect ) ; $ userSqlSelectStmt -> bindValue ( 'uid' , $ uid ) ; $ userSqlSelectStmt -> execute ( ) ; $ userData = $ userSqlSelectStmt -> fetch ( ) ; // select first "workspace-enter" actions for the given user and workspace $ selectEnterEventOnThisWorkspace = "SELECT DISTINCT date_log FROM claro_log WHERE workspace_id = :wid AND action = 'workspace-enter' AND doer_id = :uid ORDER BY date_log ASC LIMIT 1" ; $ selectEnterEventOnThisWorkspaceStmt = $ this -> em -> getConnection ( ) -> prepare ( $ selectEnterEventOnThisWorkspace ) ; $ selectEnterEventOnThisWorkspaceStmt -> bindValue ( 'uid' , $ uid ) ; $ selectEnterEventOnThisWorkspaceStmt -> bindValue ( 'wid' , $ workspace -> getId ( ) ) ; $ selectEnterEventOnThisWorkspaceStmt -> execute ( ) ; $ enterOnThisWorksapceDateResult = $ selectEnterEventOnThisWorkspaceStmt -> fetch ( ) ; $ refDate = $ enterOnThisWorksapceDateResult [ 'date_log' ] ; $ total = 0 ; if ( $ refDate ) { $ total = $ this -> computeTimeForUserAndWorkspace ( $ refDate , $ uid , $ workspace -> getId ( ) , 0 ) ; } $ datas [ ] = [ 'user' => [ 'id' => $ uid , 'firstName' => $ userData [ 'first_name' ] , 'lastName' => $ userData [ 'last_name' ] , ] , 'time' => $ total , ] ; } return $ datas ; }
Compute spent time for each user in a given workspace.
Compute spent time for each user in a given workspace .