diff options
Diffstat (limited to 'app/Analytic/UserDistributionAnalytic.php')
-rw-r--r-- | app/Analytic/UserDistributionAnalytic.php | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/app/Analytic/UserDistributionAnalytic.php b/app/Analytic/UserDistributionAnalytic.php new file mode 100644 index 00000000..e1815f9c --- /dev/null +++ b/app/Analytic/UserDistributionAnalytic.php @@ -0,0 +1,56 @@ +<?php + +namespace Kanboard\Analytic; + +use Kanboard\Core\Base; + +/** + * User Distribution + * + * @package analytic + * @author Frederic Guillot + */ +class UserDistributionAnalytic extends Base +{ + /** + * Build Report + * + * @access public + * @param integer $project_id + * @return array + */ + public function build($project_id) + { + $metrics = array(); + $total = 0; + $tasks = $this->taskFinder->getAll($project_id); + $users = $this->projectUserRole->getAssignableUsersList($project_id); + + foreach ($tasks as $task) { + $user = isset($users[$task['owner_id']]) ? $users[$task['owner_id']] : $users[0]; + $total++; + + if (! isset($metrics[$user])) { + $metrics[$user] = array( + 'nb_tasks' => 0, + 'percentage' => 0, + 'user' => $user, + ); + } + + $metrics[$user]['nb_tasks']++; + } + + if ($total === 0) { + return array(); + } + + foreach ($metrics as &$metric) { + $metric['percentage'] = round(($metric['nb_tasks'] * 100) / $total, 2); + } + + ksort($metrics); + + return array_values($metrics); + } +} |