summaryrefslogtreecommitdiff
path: root/app/Model
diff options
context:
space:
mode:
Diffstat (limited to 'app/Model')
-rw-r--r--app/Model/Acl.php2
-rw-r--r--app/Model/Action.php2
-rw-r--r--app/Model/Authentication.php6
-rw-r--r--app/Model/Base.php20
-rw-r--r--app/Model/Notification.php7
-rw-r--r--app/Model/Project.php36
-rw-r--r--app/Model/ProjectActivity.php2
-rw-r--r--app/Model/ProjectAnalytic.php47
-rw-r--r--app/Model/ProjectPaginator.php49
-rw-r--r--app/Model/SubtaskPaginator.php68
-rw-r--r--app/Model/TaskFinder.php94
-rw-r--r--app/Model/TaskPaginator.php139
-rw-r--r--app/Model/Webhook.php4
13 files changed, 327 insertions, 149 deletions
diff --git a/app/Model/Acl.php b/app/Model/Acl.php
index 52957130..25e98850 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/Action.php b/app/Model/Action.php
index c3acdc5b..f8dbd88e 100644
--- a/app/Model/Action.php
+++ b/app/Model/Action.php
@@ -264,7 +264,7 @@ class Action extends Base
public function load($name, $project_id, $event)
{
$className = '\Action\\'.$name;
- return new $className($this->registry, $project_id, $event);
+ return new $className($this->container, $project_id, $event);
}
/**
diff --git a/app/Model/Authentication.php b/app/Model/Authentication.php
index b9ebcfe2..a0e9684f 100644
--- a/app/Model/Authentication.php
+++ b/app/Model/Authentication.php
@@ -24,12 +24,12 @@ class Authentication extends Base
*/
public function backend($name)
{
- if (! isset($this->registry->$name)) {
+ if (! isset($this->container[$name])) {
$class = '\Auth\\'.ucfirst($name);
- $this->registry->$name = new $class($this->registry);
+ $this->container[$name] = new $class($this->container);
}
- return $this->registry->shared($name);
+ return $this->container[$name];
}
/**
diff --git a/app/Model/Base.php b/app/Model/Base.php
index 72d91c3c..5a8d8f1c 100644
--- a/app/Model/Base.php
+++ b/app/Model/Base.php
@@ -4,7 +4,7 @@ namespace Model;
use Core\Event;
use Core\Tool;
-use Core\Registry;
+use Pimple\Container;
use PicoDb\Database;
/**
@@ -58,24 +58,24 @@ abstract class Base
public $event;
/**
- * Registry instance
+ * Container instance
*
* @access protected
- * @var \Core\Registry
+ * @var Pimple\Container
*/
- protected $registry;
+ protected $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->db = $this->registry->shared('db');
- $this->event = $this->registry->shared('event');
+ $this->container = $container;
+ $this->db = $this->container['db'];
+ $this->event = $this->container['event'];
}
/**
@@ -87,7 +87,7 @@ abstract class Base
*/
public function __get($name)
{
- return Tool::loadModel($this->registry, $name);
+ return Tool::loadModel($this->container, $name);
}
/**
diff --git a/app/Model/Notification.php b/app/Model/Notification.php
index d2fcf525..32765041 100644
--- a/app/Model/Notification.php
+++ b/app/Model/Notification.php
@@ -117,7 +117,7 @@ class Notification extends Base
foreach ($events as $event_name => $template_name) {
- $listener = new NotificationListener($this->registry);
+ $listener = new NotificationListener($this->container);
$listener->setTemplate($template_name);
$this->event->attach($event_name, $listener);
@@ -135,8 +135,7 @@ class Notification extends Base
public function sendEmails($template, array $users, array $data)
{
try {
- $transport = $this->registry->shared('mailer');
- $mailer = Swift_Mailer::newInstance($transport);
+ $mailer = Swift_Mailer::newInstance($this->container['mailer']);
$message = Swift_Message::newInstance()
->setSubject($this->getMailSubject($template, $data))
@@ -149,7 +148,7 @@ class Notification extends Base
}
}
catch (Swift_TransportException $e) {
- debug($e->getMessage());
+ $this->container['logger']->addError($e->getMessage());
}
}
diff --git a/app/Model/Project.php b/app/Model/Project.php
index 305e3f1e..8b842519 100644
--- a/app/Model/Project.php
+++ b/app/Model/Project.php
@@ -96,40 +96,6 @@ class Project extends Base
}
/**
- * Get project summary for a list of project (number of tasks for each column)
- *
- * @access public
- * @param array $project_ids List of project id
- * @param integer $status Project status
- * @param string $order Sort on this column
- * @param string $direction Sorting direction
- * @return array Project properties
- */
- public function getSummary(array $project_ids, $status = self::ACTIVE, $order = 'name', $direction = 'asc')
- {
- if (empty($project_ids)) {
- return array();
- }
-
- $projects = $this->db->table(self::TABLE)
- ->in('id', $project_ids)
- ->eq('is_active', $status)
- ->orderby($order, $direction)
- ->findAll();
-
- foreach ($projects as &$project) {
-
- $project['columns'] = $this->board->getColumns($project['id']);
-
- foreach ($project['columns'] as &$column) {
- $column['nb_tasks'] = $this->taskFinder->countByColumnId($project['id'], $column['id']);
- }
- }
-
- return $projects;
- }
-
- /**
* Get all projects, optionaly fetch stats for each project and can check users permissions
*
* @access public
@@ -546,7 +512,7 @@ class Project extends Base
GithubWebhook::EVENT_COMMIT,
);
- $listener = new ProjectModificationDateListener($this->registry);
+ $listener = new ProjectModificationDateListener($this->container);
foreach ($events as $event_name) {
$this->event->attach($event_name, $listener);
diff --git a/app/Model/ProjectActivity.php b/app/Model/ProjectActivity.php
index 6d6ef454..9d7ecfac 100644
--- a/app/Model/ProjectActivity.php
+++ b/app/Model/ProjectActivity.php
@@ -147,7 +147,7 @@ class ProjectActivity extends Base
SubTask::EVENT_CREATE,
);
- $listener = new ProjectActivityListener($this->registry);
+ $listener = new ProjectActivityListener($this->container);
foreach ($events as $event_name) {
$this->event->attach($event_name, $listener);
diff --git a/app/Model/ProjectAnalytic.php b/app/Model/ProjectAnalytic.php
index ccd2c4c9..46f2242d 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
@@ -34,10 +34,55 @@ class ProjectAnalytic extends Base
);
}
+ if ($total === 0) {
+ return array();
+ }
+
foreach ($metrics as &$metric) {
$metric['percentage'] = round(($metric['nb_tasks'] * 100) / $total, 2);
}
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 = 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);
+ }
+
+ return array_values($metrics);
+ }
}
diff --git a/app/Model/ProjectPaginator.php b/app/Model/ProjectPaginator.php
new file mode 100644
index 00000000..9f1c39f0
--- /dev/null
+++ b/app/Model/ProjectPaginator.php
@@ -0,0 +1,49 @@
+<?php
+
+namespace Model;
+
+/**
+ * Project Paginator
+ *
+ * @package model
+ * @author Frederic Guillot
+ */
+class ProjectPaginator extends Base
+{
+ /**
+ * Get project summary for a list of project (number of tasks for each column)
+ *
+ * @access public
+ * @param array $project_ids List of project id
+ * @param integer $offset Offset
+ * @param integer $limit Limit
+ * @param string $column Sorting column
+ * @param string $direction Sorting direction
+ * @return array
+ */
+ public function projectSummaries(array $project_ids, $offset = 0, $limit = 25, $column = 'name', $direction = 'asc')
+ {
+ if (empty($project_ids)) {
+ return array();
+ }
+
+ $projects = $this->db
+ ->table(Project::TABLE)
+ ->in('id', $project_ids)
+ ->offset($offset)
+ ->limit($limit)
+ ->orderBy($column, $direction)
+ ->findAll();
+
+ foreach ($projects as &$project) {
+
+ $project['columns'] = $this->board->getColumns($project['id']);
+
+ foreach ($project['columns'] as &$column) {
+ $column['nb_tasks'] = $this->taskFinder->countByColumnId($project['id'], $column['id']);
+ }
+ }
+
+ return $projects;
+ }
+}
diff --git a/app/Model/SubtaskPaginator.php b/app/Model/SubtaskPaginator.php
new file mode 100644
index 00000000..8ccbd696
--- /dev/null
+++ b/app/Model/SubtaskPaginator.php
@@ -0,0 +1,68 @@
+<?php
+
+namespace Model;
+
+/**
+ * Subtask Paginator
+ *
+ * @package model
+ * @author Frederic Guillot
+ */
+class SubtaskPaginator extends Base
+{
+ /**
+ * Get all subtasks assigned to a user
+ *
+ * @access public
+ * @param integer $user_id User id
+ * @param array $status List of status
+ * @param integer $offset Offset
+ * @param integer $limit Limit
+ * @param string $column Sorting column
+ * @param string $direction Sorting direction
+ * @return array
+ */
+ public function userSubtasks($user_id, array $status, $offset = 0, $limit = 25, $column = 'tasks.id', $direction = 'asc')
+ {
+ $status_list = $this->subTask->getStatusList();
+
+ $subtasks = $this->db->table(SubTask::TABLE)
+ ->columns(
+ SubTask::TABLE.'.*',
+ Task::TABLE.'.project_id',
+ Task::TABLE.'.color_id',
+ Project::TABLE.'.name AS project_name'
+ )
+ ->eq('user_id', $user_id)
+ ->in(SubTask::TABLE.'.status', $status)
+ ->join(Task::TABLE, 'id', 'task_id')
+ ->join(Project::TABLE, 'id', 'project_id', Task::TABLE)
+ ->offset($offset)
+ ->limit($limit)
+ ->orderBy($column, $direction)
+ ->findAll();
+
+ foreach ($subtasks as &$subtask) {
+ $subtask['status_name'] = $status_list[$subtask['status']];
+ }
+
+ return $subtasks;
+ }
+
+ /**
+ * Count all subtasks assigned to the user
+ *
+ * @access public
+ * @param integer $user_id User id
+ * @param array $status List of status
+ * @return integer
+ */
+ public function countUserSubtasks($user_id, array $status)
+ {
+ return $this->db
+ ->table(SubTask::TABLE)
+ ->eq('user_id', $user_id)
+ ->in('status', $status)
+ ->count();
+ }
+}
diff --git a/app/Model/TaskFinder.php b/app/Model/TaskFinder.php
index 56795152..0e581025 100644
--- a/app/Model/TaskFinder.php
+++ b/app/Model/TaskFinder.php
@@ -15,10 +15,10 @@ class TaskFinder extends Base
/**
* Common request to fetch a list of tasks
*
- * @access private
+ * @access public
* @return \PicoDb\Table
*/
- private function prepareRequestList()
+ public function getQuery()
{
return $this->db
->table(Task::TABLE)
@@ -51,51 +51,6 @@ class TaskFinder extends Base
}
/**
- * Task search with pagination
- *
- * @access public
- * @param integer $project_id Project id
- * @param string $search Search terms
- * @param integer $offset Offset
- * @param integer $limit Limit
- * @param string $column Sorting column
- * @param string $direction Sorting direction
- * @return array
- */
- public function search($project_id, $search, $offset = 0, $limit = 25, $column = 'tasks.id', $direction = 'DESC')
- {
- return $this->prepareRequestList()
- ->eq('project_id', $project_id)
- ->like('title', '%'.$search.'%')
- ->offset($offset)
- ->limit($limit)
- ->orderBy($column, $direction)
- ->findAll();
- }
-
- /**
- * Get all completed tasks with pagination
- *
- * @access public
- * @param integer $project_id Project id
- * @param integer $offset Offset
- * @param integer $limit Limit
- * @param string $column Sorting column
- * @param string $direction Sorting direction
- * @return array
- */
- public function getClosedTasks($project_id, $offset = 0, $limit = 25, $column = 'tasks.date_completed', $direction = 'DESC')
- {
- return $this->prepareRequestList()
- ->eq('project_id', $project_id)
- ->eq('is_active', Task::STATUS_CLOSED)
- ->offset($offset)
- ->limit($limit)
- ->orderBy($column, $direction)
- ->findAll();
- }
-
- /**
* Get all tasks shown on the board (sorted by position)
*
* @access public
@@ -104,7 +59,7 @@ class TaskFinder extends Base
*/
public function getTasksOnBoard($project_id)
{
- return $this->prepareRequestList()
+ return $this->getQuery()
->eq('project_id', $project_id)
->eq('is_active', Task::STATUS_OPEN)
->asc('tasks.position')
@@ -112,33 +67,6 @@ class TaskFinder extends Base
}
/**
- * Get all open tasks for a given user
- *
- * @access public
- * @param integer $user_id User id
- * @return array
- */
- public function getAllTasksByUser($user_id)
- {
- return $this->db
- ->table(Task::TABLE)
- ->columns(
- 'tasks.id',
- 'tasks.title',
- 'tasks.date_due',
- 'tasks.date_creation',
- 'tasks.project_id',
- 'tasks.color_id',
- 'projects.name AS project_name'
- )
- ->join(Project::TABLE, 'id', 'project_id')
- ->eq('tasks.owner_id', $user_id)
- ->eq('tasks.is_active', Task::STATUS_OPEN)
- ->asc('tasks.id')
- ->findAll();
- }
-
- /**
* Get all tasks for a given project and status
*
* @access public
@@ -296,22 +224,6 @@ class TaskFinder extends Base
}
/**
- * Count the number of tasks for a custom search
- *
- * @access public
- * @param integer $project_id Project id
- * @param string $search Search terms
- * @return integer
- */
- public function countSearch($project_id, $search)
- {
- return $this->db->table(Task::TABLE)
- ->eq('project_id', $project_id)
- ->like('title', '%'.$search.'%')
- ->count();
- }
-
- /**
* Return true if the task exists
*
* @access public
diff --git a/app/Model/TaskPaginator.php b/app/Model/TaskPaginator.php
new file mode 100644
index 00000000..4ae3566c
--- /dev/null
+++ b/app/Model/TaskPaginator.php
@@ -0,0 +1,139 @@
+<?php
+
+namespace Model;
+
+/**
+ * Task Paginator model
+ *
+ * @package model
+ * @author Frederic Guillot
+ */
+class TaskPaginator extends Base
+{
+ /**
+ * Task search with pagination
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @param string $search Search terms
+ * @param integer $offset Offset
+ * @param integer $limit Limit
+ * @param string $column Sorting column
+ * @param string $direction Sorting direction
+ * @return array
+ */
+ public function searchTasks($project_id, $search, $offset = 0, $limit = 25, $column = 'tasks.id', $direction = 'DESC')
+ {
+ return $this->taskFinder->getQuery()
+ ->eq('project_id', $project_id)
+ ->like('title', '%'.$search.'%')
+ ->offset($offset)
+ ->limit($limit)
+ ->orderBy($column, $direction)
+ ->findAll();
+ }
+
+ /**
+ * Count the number of tasks for a custom search
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @param string $search Search terms
+ * @return integer
+ */
+ public function countSearchTasks($project_id, $search)
+ {
+ return $this->db->table(Task::TABLE)
+ ->eq('project_id', $project_id)
+ ->like('title', '%'.$search.'%')
+ ->count();
+ }
+
+ /**
+ * Get all completed tasks with pagination
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @param integer $offset Offset
+ * @param integer $limit Limit
+ * @param string $column Sorting column
+ * @param string $direction Sorting direction
+ * @return array
+ */
+ public function closedTasks($project_id, $offset = 0, $limit = 25, $column = 'tasks.date_completed', $direction = 'DESC')
+ {
+ return $this->taskFinder->getQuery()
+ ->eq('project_id', $project_id)
+ ->eq('is_active', Task::STATUS_CLOSED)
+ ->offset($offset)
+ ->limit($limit)
+ ->orderBy($column, $direction)
+ ->findAll();
+ }
+
+ /**
+ * Count all closed tasks
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @param array $status List of status id
+ * @return integer
+ */
+ public function countClosedTasks($project_id)
+ {
+ return $this->db
+ ->table(Task::TABLE)
+ ->eq('project_id', $project_id)
+ ->eq('is_active', Task::STATUS_CLOSED)
+ ->count();
+ }
+
+ /**
+ * Get all open tasks for a given user
+ *
+ * @access public
+ * @param integer $user_id User id
+ * @param integer $offset Offset
+ * @param integer $limit Limit
+ * @param string $column Sorting column
+ * @param string $direction Sorting direction
+ * @return array
+ */
+ public function userTasks($user_id, $offset = 0, $limit = 25, $column = 'tasks.id', $direction = 'ASC')
+ {
+ return $this->db
+ ->table(Task::TABLE)
+ ->columns(
+ 'tasks.id',
+ 'tasks.title',
+ 'tasks.date_due',
+ 'tasks.date_creation',
+ 'tasks.project_id',
+ 'tasks.color_id',
+ 'projects.name AS project_name'
+ )
+ ->join(Project::TABLE, 'id', 'project_id')
+ ->eq('tasks.owner_id', $user_id)
+ ->eq('tasks.is_active', Task::STATUS_OPEN)
+ ->offset($offset)
+ ->limit($limit)
+ ->orderBy($column, $direction)
+ ->findAll();
+ }
+
+ /**
+ * Count all tasks assigned to the user
+ *
+ * @access public
+ * @param integer $user_id User id
+ * @return integer
+ */
+ public function countUserTasks($user_id)
+ {
+ return $this->db
+ ->table(Task::TABLE)
+ ->eq('owner_id', $user_id)
+ ->eq('is_active', Task::STATUS_OPEN)
+ ->count();
+ }
+}
diff --git a/app/Model/Webhook.php b/app/Model/Webhook.php
index b84728cf..14d50684 100644
--- a/app/Model/Webhook.php
+++ b/app/Model/Webhook.php
@@ -93,7 +93,7 @@ class Webhook extends Base
Task::EVENT_ASSIGNEE_CHANGE,
);
- $listener = new WebhookListener($this->registry);
+ $listener = new WebhookListener($this->container);
$listener->setUrl($this->url_task_modification);
foreach ($events as $event_name) {
@@ -108,7 +108,7 @@ class Webhook extends Base
*/
public function attachCreateEvents()
{
- $listener = new WebhookListener($this->registry);
+ $listener = new WebhookListener($this->container);
$listener->setUrl($this->url_task_creation);
$this->event->attach(Task::EVENT_CREATE, $listener);