HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //home/timetracker.panomity.com/tm.old/Controller/ReportController.php
<?php

/*
 * This file is part of the TaskManagementBundle for Kimai 2.
 * All rights reserved by Kevin Papst (www.kevinpapst.de).
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace KimaiPlugin\TaskManagementBundle\Controller;

use App\Controller\AbstractController;
use Exception;
use KimaiPlugin\TaskManagementBundle\Entity\Task;
use KimaiPlugin\TaskManagementBundle\Repository\Query\TaskQuery;
use KimaiPlugin\TaskManagementBundle\Repository\TaskRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
 * @Route(path="/reporting")
 * @Security("is_granted('view_reporting')")
 */
final class ReportController extends AbstractController
{
    /**
     * @Route(path="/assigned-tasks", name="report_tasks_assigned", methods={"GET","POST"})
     *
     * @param Request $request
     * @param TaskRepository $repository
     * @return Response
     * @throws Exception
     */
    public function assignedTasks(Request $request, TaskRepository $repository): Response
    {
        $currentUser = $this->getUser();

        $query = new TaskQuery();
        $query->setCurrentUser($currentUser);
        if (!$this->isGranted('view_other_timesheet')) {
            $query->setUser($currentUser);
        }
        $query->setStatus([Task::STATUS_PENDING, Task::STATUS_IN_PROGRESS]);

        $tasks = $repository->getTasksForQuery($query);

        $hasEstimation = false;
        $template = [
            'total' => 0,
            'estimation' => 0,
            'duration' => 0,
            'no_estimation' => 0,
            'with_estimation' => 0,
            'started' => 0,
            'not_started' => 0,
            'overdue' => 0,
        ];

        $data = [];
        $total = $template;
        $total['estimation_duration'] = 0;
        foreach ($tasks as $task) {
            $user = $task->getUser();
            // we only calculate data for tasks with an assigned user
            if ($user === null) {
                continue;
            }

            if (!\array_key_exists($user->getId(), $data)) {
                $data[$user->getId()] = $template;
                $data[$user->getId()]['user'] = $user;
            }

            $data[$user->getId()]['total']++;
            $total['total']++;

            $duration = $task->getDuration();
            if ($duration === null) {
                $data[$user->getId()]['not_started']++;
                $total['not_started']++;
            } else {
                $data[$user->getId()]['started']++;
                $data[$user->getId()]['duration'] += $duration;
                $total['started']++;
                $total['duration'] += $duration;
            }

            $estimation = $task->getEstimation();
            if ($estimation === null) {
                $data[$user->getId()]['no_estimation']++;
                $total['no_estimation']++;
            } else {
                $data[$user->getId()]['with_estimation']++;
                $data[$user->getId()]['estimation'] += $estimation;
                $total['with_estimation']++;
                $total['estimation'] += $estimation;
                if ($duration !== null) {
                    $total['estimation_duration'] += $duration;
                }
                $hasEstimation = true;
            }

            if ($task->isOverdue()) {
                $data[$user->getId()]['overdue']++;
                $total['overdue']++;
            }
        }

        return $this->render('@TaskManagement/report-assigned-tasks.html.twig', [
            'data' => $data,
            'hasEstimation' => $hasEstimation,
            'totals' => $total,
        ]);
    }

    /**
     * @Route(path="/team-tasks", name="report_tasks_teams", methods={"GET","POST"})
     *
     * @param Request $request
     * @param TaskRepository $repository
     * @return Response
     * @throws Exception
     */
    public function teamTasks(Request $request, TaskRepository $repository): Response
    {
        $currentUser = $this->getUser();

        $query = new TaskQuery();
        $query->setCurrentUser($currentUser);
        if (!$this->isGranted('view_other_timesheet')) {
            $query->setTeams($currentUser->getTeams());
        }
        $query->setStatus([Task::STATUS_PENDING, Task::STATUS_IN_PROGRESS]);

        $tasks = $repository->getTasksForQuery($query);

        $hasEstimation = false;
        $template = [
            'total' => 0,
            'estimation' => 0,
            'duration' => 0,
            'no_estimation' => 0,
            'with_estimation' => 0,
            'started' => 0,
            'not_started' => 0,
            'overdue' => 0,
        ];

        $data = [];
        $total = $template;
        $total['estimation_duration'] = 0;
        foreach ($tasks as $task) {
            $team = $task->getTeam();
            // we only calculate data for tasks with an assigned team
            if ($team === null) {
                continue;
            }

            if (!\array_key_exists($team->getId(), $data)) {
                $data[$team->getId()] = $template;
                $data[$team->getId()]['team'] = $team;
            }

            $data[$team->getId()]['total']++;
            $total['total']++;

            $duration = $task->getDuration();
            if ($duration === null) {
                $data[$team->getId()]['not_started']++;
                $total['not_started']++;
            } else {
                $data[$team->getId()]['started']++;
                $data[$team->getId()]['duration'] += $duration;
                $total['started']++;
                $total['duration'] += $duration;
            }

            $estimation = $task->getEstimation();
            if ($estimation === null) {
                $data[$team->getId()]['no_estimation']++;
                $total['no_estimation']++;
            } else {
                $data[$team->getId()]['with_estimation']++;
                $data[$team->getId()]['estimation'] += $estimation;
                $total['with_estimation']++;
                $total['estimation'] += $estimation;
                if ($duration !== null) {
                    $total['estimation_duration'] += $duration;
                }
                $hasEstimation = true;
            }

            if ($task->isOverdue()) {
                $data[$team->getId()]['overdue']++;
                $total['overdue']++;
            }
        }

        return $this->render('@TaskManagement/report-team-tasks.html.twig', [
            'data' => $data,
            'hasEstimation' => $hasEstimation,
            'totals' => $total,
        ]);
    }
}