diff --git a/app/Controller/Analytic.php b/app/Controller/Analytic.php index 68177c832..7d112e6aa 100644 --- a/app/Controller/Analytic.php +++ b/app/Controller/Analytic.php @@ -27,11 +27,11 @@ class Analytic extends Base } /** - * Show task distribution graph + * Show tasks distribution graph * * @access public */ - public function repartition() + public function tasks() { $project = $this->getProject(); $metrics = $this->projectAnalytic->getTaskRepartition($project['id']); @@ -46,11 +46,39 @@ class Analytic extends Base )); } else { - $this->response->html($this->layout('analytic/repartition', array( + $this->response->html($this->layout('analytic/tasks', array( 'project' => $project, 'metrics' => $metrics, 'title' => t('Task repartition for "%s"', $project['name']), ))); } } + + /** + * Show users repartition + * + * @access public + */ + public function users() + { + $project = $this->getProject(); + $metrics = $this->projectAnalytic->getUserRepartition($project['id']); + + if ($this->request->isAjax()) { + $this->response->json(array( + 'metrics' => $metrics, + 'labels' => array( + 'user' => t('User'), + 'nb_tasks' => t('Number of tasks'), + ) + )); + } + else { + $this->response->html($this->layout('analytic/users', array( + 'project' => $project, + 'metrics' => $metrics, + 'title' => t('User repartition for "%s"', $project['name']), + ))); + } + } } diff --git a/app/Locale/da_DK/translations.php b/app/Locale/da_DK/translations.php index 2cb772402..6e355f51b 100644 --- a/app/Locale/da_DK/translations.php +++ b/app/Locale/da_DK/translations.php @@ -573,4 +573,6 @@ return array( // 'Analytics' => '', // 'Subtask' => '', // 'My subtasks' => '', + // 'User repartition' => '', + // 'User repartition for "%s"' => '', ); diff --git a/app/Locale/de_DE/translations.php b/app/Locale/de_DE/translations.php index fb03b6164..1a8109c18 100644 --- a/app/Locale/de_DE/translations.php +++ b/app/Locale/de_DE/translations.php @@ -573,4 +573,6 @@ return array( // 'Analytics' => '', // 'Subtask' => '', // 'My subtasks' => '', + // 'User repartition' => '', + // 'User repartition for "%s"' => '', ); diff --git a/app/Locale/es_ES/translations.php b/app/Locale/es_ES/translations.php index c54267ffc..e0b47923f 100644 --- a/app/Locale/es_ES/translations.php +++ b/app/Locale/es_ES/translations.php @@ -573,4 +573,6 @@ return array( // 'Analytics' => '', // 'Subtask' => '', // 'My subtasks' => '', + // 'User repartition' => '', + // 'User repartition for "%s"' => '', ); diff --git a/app/Locale/fi_FI/translations.php b/app/Locale/fi_FI/translations.php index 59cea9f76..200b74e7d 100644 --- a/app/Locale/fi_FI/translations.php +++ b/app/Locale/fi_FI/translations.php @@ -573,4 +573,6 @@ return array( // 'Analytics' => '', // 'Subtask' => '', // 'My subtasks' => '', + // 'User repartition' => '', + // 'User repartition for "%s"' => '', ); diff --git a/app/Locale/fr_FR/translations.php b/app/Locale/fr_FR/translations.php index d36b0e934..e4edb4338 100644 --- a/app/Locale/fr_FR/translations.php +++ b/app/Locale/fr_FR/translations.php @@ -573,4 +573,6 @@ return array( 'Analytics' => 'Analytique', 'Subtask' => 'Sous-tâche', 'My subtasks' => 'Mes sous-tâches', + 'User repartition' => 'Répartition des utilisateurs', + 'User repartition for "%s"' => 'Répartition des utilisateurs pour « %s »', ); diff --git a/app/Locale/it_IT/translations.php b/app/Locale/it_IT/translations.php index e4f9fc8b0..7ef579a74 100644 --- a/app/Locale/it_IT/translations.php +++ b/app/Locale/it_IT/translations.php @@ -573,4 +573,6 @@ return array( // 'Analytics' => '', // 'Subtask' => '', // 'My subtasks' => '', + // 'User repartition' => '', + // 'User repartition for "%s"' => '', ); diff --git a/app/Locale/ja_JP/translations.php b/app/Locale/ja_JP/translations.php index 0e75fc237..c1625c485 100644 --- a/app/Locale/ja_JP/translations.php +++ b/app/Locale/ja_JP/translations.php @@ -573,4 +573,6 @@ return array( // 'Analytics' => '', // 'Subtask' => '', // 'My subtasks' => '', + // 'User repartition' => '', + // 'User repartition for "%s"' => '', ); diff --git a/app/Locale/pl_PL/translations.php b/app/Locale/pl_PL/translations.php index f02774297..0c7b4834f 100644 --- a/app/Locale/pl_PL/translations.php +++ b/app/Locale/pl_PL/translations.php @@ -573,4 +573,6 @@ return array( // 'Analytics' => '', // 'Subtask' => '', // 'My subtasks' => '', + // 'User repartition' => '', + // 'User repartition for "%s"' => '', ); diff --git a/app/Locale/pt_BR/translations.php b/app/Locale/pt_BR/translations.php index fd1fc1cfd..e0969b6d8 100644 --- a/app/Locale/pt_BR/translations.php +++ b/app/Locale/pt_BR/translations.php @@ -573,4 +573,6 @@ return array( // 'Analytics' => '', // 'Subtask' => '', // 'My subtasks' => '', + // 'User repartition' => '', + // 'User repartition for "%s"' => '', ); diff --git a/app/Locale/ru_RU/translations.php b/app/Locale/ru_RU/translations.php index 9c486ff4a..27f9644e0 100644 --- a/app/Locale/ru_RU/translations.php +++ b/app/Locale/ru_RU/translations.php @@ -573,4 +573,6 @@ return array( // 'Analytics' => '', // 'Subtask' => '', // 'My subtasks' => '', + // 'User repartition' => '', + // 'User repartition for "%s"' => '', ); diff --git a/app/Locale/sv_SE/translations.php b/app/Locale/sv_SE/translations.php index a56c7db58..f5f4f080b 100644 --- a/app/Locale/sv_SE/translations.php +++ b/app/Locale/sv_SE/translations.php @@ -573,4 +573,6 @@ return array( // 'Analytics' => '', // 'Subtask' => '', // 'My subtasks' => '', + // 'User repartition' => '', + // 'User repartition for "%s"' => '', ); diff --git a/app/Locale/th_TH/translations.php b/app/Locale/th_TH/translations.php index f2e51d125..7099891f5 100644 --- a/app/Locale/th_TH/translations.php +++ b/app/Locale/th_TH/translations.php @@ -573,4 +573,6 @@ return array( // 'Analytics' => '', // 'Subtask' => '', // 'My subtasks' => '', + // 'User repartition' => '', + // 'User repartition for "%s"' => '', ); diff --git a/app/Locale/zh_CN/translations.php b/app/Locale/zh_CN/translations.php index 4b86a7e13..2490709b1 100644 --- a/app/Locale/zh_CN/translations.php +++ b/app/Locale/zh_CN/translations.php @@ -573,4 +573,6 @@ return array( // 'Analytics' => '', // 'Subtask' => '', // 'My subtasks' => '', + // 'User repartition' => '', + // 'User repartition for "%s"' => '', ); diff --git a/app/Model/Acl.php b/app/Model/Acl.php index 52957130b..25e988500 100644 --- a/app/Model/Acl.php +++ b/app/Model/Acl.php @@ -41,7 +41,7 @@ class Acl extends Base 'task' => array('show', 'create', 'save', 'edit', 'update', 'close', 'open', 'duplicate', 'remove', 'description', 'move', 'copy', 'time'), 'category' => array('index', 'save', 'edit', 'update', 'confirm', 'remove'), 'action' => array('index', 'event', 'params', 'create', 'confirm', 'remove'), - 'analytic' => array('repartition'), + 'analytic' => array('tasks', 'users'), ); /** diff --git a/app/Model/ProjectAnalytic.php b/app/Model/ProjectAnalytic.php index ccd2c4c99..8ecbf1f08 100644 --- a/app/Model/ProjectAnalytic.php +++ b/app/Model/ProjectAnalytic.php @@ -11,7 +11,7 @@ namespace Model; class ProjectAnalytic extends Base { /** - * Get task repartition + * Get tasks repartition * * @access public * @param integer $project_id Project id @@ -40,4 +40,41 @@ class ProjectAnalytic extends Base return $metrics; } + + /** + * Get users repartition + * + * @access public + * @param integer $project_id Project id + * @return array + */ + public function getUserRepartition($project_id) + { + $metrics = array(); + $total = 0; + $tasks = $this->taskFinder->getAll($project_id); + $users = $this->projectPermission->getMemberList($project_id); + + foreach ($tasks as $task) { + + $user = $users[$task['owner_id']]; + $total++; + + if (! isset($metrics[$user])) { + $metrics[$user] = array( + 'nb_tasks' => 0, + 'percentage' => 0, + 'user' => $user, + ); + } + + $metrics[$user]['nb_tasks']++; + } + + foreach ($metrics as &$metric) { + $metric['percentage'] = round(($metric['nb_tasks'] * 100) / $total, 2); + } + + return array_values($metrics); + } } diff --git a/app/Template/analytic/sidebar.php b/app/Template/analytic/sidebar.php index df6835ee3..dded245a6 100644 --- a/app/Template/analytic/sidebar.php +++ b/app/Template/analytic/sidebar.php @@ -2,7 +2,10 @@
| = t('User') ?> | += t('Number of tasks') ?> | += t('Percentage') ?> | +
|---|---|---|
| + = Helper\escape($metric['user']) ?> + | ++ = $metric['nb_tasks'] ?> + | ++ = n($metric['percentage']) ?>% + | +