summaryrefslogtreecommitdiff
path: root/app/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'app/Controller')
-rw-r--r--app/Controller/Analytic.php34
-rw-r--r--app/Controller/App.php132
-rw-r--r--app/Controller/Base.php62
-rw-r--r--app/Controller/Category.php10
-rw-r--r--app/Controller/Project.php8
5 files changed, 208 insertions, 38 deletions
diff --git a/app/Controller/Analytic.php b/app/Controller/Analytic.php
index 68177c83..7d112e6a 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/Controller/App.php b/app/Controller/App.php
index 9f8ded19..2458800a 100644
--- a/app/Controller/App.php
+++ b/app/Controller/App.php
@@ -3,6 +3,7 @@
namespace Controller;
use Model\Project as ProjectModel;
+use Model\SubTask;
/**
* Application controller
@@ -19,16 +20,137 @@ class App extends Base
*/
public function index()
{
+ $paginate = $this->request->getStringParam('paginate', 'userTasks');
+ $offset = $this->request->getIntegerParam('offset', 0);
+ $direction = $this->request->getStringParam('direction');
+ $order = $this->request->getStringParam('order');
+
$user_id = $this->acl->getUserId();
$projects = $this->projectPermission->getMemberProjects($user_id);
$project_ids = array_keys($projects);
- $this->response->html($this->template->layout('app/index', array(
+ $params = array(
+ 'title' => t('Dashboard'),
'board_selector' => $this->projectPermission->getAllowedProjects($user_id),
'events' => $this->projectActivity->getProjects($project_ids, 10),
- 'tasks' => $this->taskFinder->getAllTasksByUser($user_id),
- 'projects' => $this->project->getSummary($project_ids),
- 'title' => t('Dashboard'),
- )));
+ );
+
+ $params += $this->getTaskPagination($user_id, $paginate, $offset, $order, $direction);
+ $params += $this->getSubtaskPagination($user_id, $paginate, $offset, $order, $direction);
+ $params += $this->getProjectPagination($project_ids, $paginate, $offset, $order, $direction);
+
+ $this->response->html($this->template->layout('app/dashboard', $params));
+ }
+
+ /**
+ * Get tasks pagination
+ *
+ * @access public
+ */
+ private function getTaskPagination($user_id, $paginate, $offset, $order, $direction)
+ {
+ $limit = 10;
+
+ if (! in_array($order, array('tasks.id', 'project_name', 'title'))) {
+ $order = 'tasks.id';
+ $direction = 'ASC';
+ }
+
+ if ($paginate === 'userTasks') {
+ $tasks = $this->taskPaginator->userTasks($user_id, $offset, $limit, $order, $direction);
+ }
+ else {
+ $offset = 0;
+ $tasks = $this->taskPaginator->userTasks($user_id, $offset, $limit);
+ }
+
+ return array(
+ 'tasks' => $tasks,
+ 'task_pagination' => array(
+ 'controller' => 'app',
+ 'action' => 'index',
+ 'params' => array('paginate' => 'userTasks'),
+ 'direction' => $direction,
+ 'order' => $order,
+ 'total' => $this->taskPaginator->countUserTasks($user_id),
+ 'offset' => $offset,
+ 'limit' => $limit,
+ )
+ );
+ }
+
+ /**
+ * Get subtasks pagination
+ *
+ * @access public
+ */
+ private function getSubtaskPagination($user_id, $paginate, $offset, $order, $direction)
+ {
+ $status = array(SubTask::STATUS_TODO, SubTask::STATUS_INPROGRESS);
+ $limit = 10;
+
+ if (! in_array($order, array('tasks.id', 'project_name', 'status', 'title'))) {
+ $order = 'tasks.id';
+ $direction = 'ASC';
+ }
+
+ if ($paginate === 'userSubtasks') {
+ $subtasks = $this->subtaskPaginator->userSubtasks($user_id, $status, $offset, $limit, $order, $direction);
+ }
+ else {
+ $offset = 0;
+ $subtasks = $this->subtaskPaginator->userSubtasks($user_id, $status, $offset, $limit);
+ }
+
+ return array(
+ 'subtasks' => $subtasks,
+ 'subtask_pagination' => array(
+ 'controller' => 'app',
+ 'action' => 'index',
+ 'params' => array('paginate' => 'userSubtasks'),
+ 'direction' => $direction,
+ 'order' => $order,
+ 'total' => $this->subtaskPaginator->countUserSubtasks($user_id, $status),
+ 'offset' => $offset,
+ 'limit' => $limit,
+ )
+ );
+ }
+
+ /**
+ * Get projects pagination
+ *
+ * @access public
+ */
+ private function getProjectPagination($project_ids, $paginate, $offset, $order, $direction)
+ {
+ $limit = 5;
+
+ if (! in_array($order, array('id', 'name'))) {
+ $order = 'name';
+ $direction = 'ASC';
+ }
+
+ if ($paginate === 'projectSummaries') {
+ $projects = $this->projectPaginator->projectSummaries($project_ids, $offset, $limit, $order, $direction);
+ }
+ else {
+ $offset = 0;
+ $projects = $this->projectPaginator->projectSummaries($project_ids, $offset, $limit);
+ }
+
+ return array(
+ 'projects' => $projects,
+ 'project_pagination' => array(
+ 'controller' => 'app',
+ 'action' => 'index',
+ 'params' => array('paginate' => 'projectSummaries'),
+ 'direction' => $direction,
+ 'order' => $order,
+ 'total' => count($project_ids),
+ 'offset' => $offset,
+ 'limit' => $limit,
+ )
+ );
}
}
diff --git a/app/Controller/Base.php b/app/Controller/Base.php
index 2c8fb221..b0252ecb 100644
--- a/app/Controller/Base.php
+++ b/app/Controller/Base.php
@@ -2,9 +2,13 @@
namespace Controller;
+use Pimple\Container;
use Core\Tool;
-use Core\Registry;
use Core\Security;
+use Core\Request;
+use Core\Response;
+use Core\Template;
+use Core\Session;
use Model\LastLogin;
/**
@@ -45,64 +49,78 @@ abstract class Base
/**
* Request instance
*
- * @accesss public
- * @var \Core\Request
+ * @accesss protected
+ * @var Core\Request
*/
- public $request;
+ protected $request;
/**
* Response instance
*
- * @accesss public
- * @var \Core\Response
+ * @accesss protected
+ * @var Core\Response
*/
- public $response;
+ protected $response;
/**
* Template instance
*
- * @accesss public
- * @var \Core\Template
+ * @accesss protected
+ * @var Core\Template
*/
- public $template;
+ protected $template;
/**
* Session instance
*
* @accesss public
- * @var \Core\Session
+ * @var Core\Session
*/
- public $session;
+ protected $session;
/**
- * Registry instance
+ * Container instance
*
* @access private
- * @var \Core\Registry
+ * @var Pimple\Container
*/
- private $registry;
+ private $container;
/**
* Constructor
*
* @access public
- * @param \Core\Registry $registry Registry instance
+ * @param Pimple\Container $container
*/
- public function __construct(Registry $registry)
+ public function __construct(Container $container)
{
- $this->registry = $registry;
+ $this->container = $container;
+ $this->request = new Request;
+ $this->response = new Response;
+ $this->session = new Session;
+ $this->template = new Template;
+ }
+
+ /**
+ * Destructor
+ *
+ * @access public
+ */
+ public function __destruct()
+ {
+ // $this->container['logger']->addDebug(var_export($this->container['db']->getLogMessages(), true));
}
/**
* Load automatically models
*
* @access public
- * @param string $name Model name
+ * @param string $name Model name
* @return mixed
*/
public function __get($name)
{
- return Tool::loadModel($this->registry, $name);
+ return Tool::loadModel($this->container, $name);
}
/**
@@ -143,7 +161,9 @@ abstract class Base
}
// Attach events
- $this->attachEvents();
+ if ($controller === 'board') {
+ $this->attachEvents();
+ }
}
/**
diff --git a/app/Controller/Category.php b/app/Controller/Category.php
index 4a0128f3..d69ed115 100644
--- a/app/Controller/Category.php
+++ b/app/Controller/Category.php
@@ -38,7 +38,7 @@ class Category extends Base
{
$project = $this->getProjectManagement();
- $this->response->html($this->projectLayout('category_index', array(
+ $this->response->html($this->projectLayout('category/index', array(
'categories' => $this->category->getList($project['id'], false),
'values' => array('project_id' => $project['id']),
'errors' => array(),
@@ -70,7 +70,7 @@ class Category extends Base
}
}
- $this->response->html($this->projectLayout('category_index', array(
+ $this->response->html($this->projectLayout('category/index', array(
'categories' => $this->category->getList($project['id'], false),
'values' => $values,
'errors' => $errors,
@@ -89,7 +89,7 @@ class Category extends Base
$project = $this->getProjectManagement();
$category = $this->getCategory($project['id']);
- $this->response->html($this->projectLayout('category_edit', array(
+ $this->response->html($this->projectLayout('category/edit', array(
'values' => $category,
'errors' => array(),
'project' => $project,
@@ -120,7 +120,7 @@ class Category extends Base
}
}
- $this->response->html($this->projectLayout('category_edit', array(
+ $this->response->html($this->projectLayout('category/edit', array(
'values' => $values,
'errors' => $errors,
'project' => $project,
@@ -138,7 +138,7 @@ class Category extends Base
$project = $this->getProjectManagement();
$category = $this->getCategory($project['id']);
- $this->response->html($this->projectLayout('category_remove', array(
+ $this->response->html($this->projectLayout('category/remove', array(
'project' => $project,
'category' => $category,
'title' => t('Remove a category')
diff --git a/app/Controller/Project.php b/app/Controller/Project.php
index a479b1d6..cac5e0b8 100644
--- a/app/Controller/Project.php
+++ b/app/Controller/Project.php
@@ -428,8 +428,8 @@ class Project extends Base
$limit = 25;
if ($search !== '') {
- $tasks = $this->taskFinder->search($project['id'], $search, $offset, $limit, $order, $direction);
- $nb_tasks = $this->taskFinder->countSearch($project['id'], $search);
+ $tasks = $this->taskPaginator->searchTasks($project['id'], $search, $offset, $limit, $order, $direction);
+ $nb_tasks = $this->taskPaginator->countSearchTasks($project['id'], $search);
}
$this->response->html($this->template->layout('project_search', array(
@@ -472,8 +472,8 @@ class Project extends Base
$offset = $this->request->getIntegerParam('offset', 0);
$limit = 25;
- $tasks = $this->taskFinder->getClosedTasks($project['id'], $offset, $limit, $order, $direction);
- $nb_tasks = $this->taskFinder->countByProjectId($project['id'], array(TaskModel::STATUS_CLOSED));
+ $tasks = $this->taskPaginator->closedTasks($project['id'], $offset, $limit, $order, $direction);
+ $nb_tasks = $this->taskPaginator->countClosedTasks($project['id']);
$this->response->html($this->template->layout('project_tasks', array(
'board_selector' => $this->projectPermission->getAllowedProjects($this->acl->getUserId()),