summaryrefslogtreecommitdiff
path: root/app/Model
diff options
context:
space:
mode:
Diffstat (limited to 'app/Model')
-rw-r--r--app/Model/Acl.php4
-rw-r--r--app/Model/Action.php10
-rw-r--r--app/Model/Board.php17
-rw-r--r--app/Model/Notification.php2
-rw-r--r--app/Model/Project.php5
-rw-r--r--app/Model/ProjectPaginator.php3
-rw-r--r--app/Model/ProjectPermission.php12
-rw-r--r--app/Model/TaskFinder.php5
-rw-r--r--app/Model/User.php3
9 files changed, 46 insertions, 15 deletions
diff --git a/app/Model/Acl.php b/app/Model/Acl.php
index 0d26edc4..d717e12f 100644
--- a/app/Model/Acl.php
+++ b/app/Model/Acl.php
@@ -189,10 +189,6 @@ class Acl extends Base
public function isManagerActionAllowed($project_id)
{
- if ($this->userSession->isAdmin()) {
- return true;
- }
-
return $project_id > 0 && $this->projectPermission->isManager($project_id, $this->userSession->getId());
}
diff --git a/app/Model/Action.php b/app/Model/Action.php
index 95e22d27..2204ad37 100644
--- a/app/Model/Action.php
+++ b/app/Model/Action.php
@@ -199,6 +199,7 @@ class Action extends Base
*/
public function remove($action_id)
{
+ // $this->container['fileCache']->remove('proxy_action_getAll');
return $this->db->table(self::TABLE)->eq('id', $action_id)->remove();
}
@@ -242,6 +243,8 @@ class Action extends Base
$this->db->closeTransaction();
+ // $this->container['fileCache']->remove('proxy_action_getAll');
+
return true;
}
@@ -252,7 +255,10 @@ class Action extends Base
*/
public function attachEvents()
{
- foreach ($this->getAll() as $action) {
+ //$actions = $this->container['fileCache']->proxy('action', 'getAll');
+ $actions = $this->getAll();
+
+ foreach ($actions as $action) {
$listener = $this->load($action['action_name'], $action['project_id'], $action['event_name']);
@@ -315,6 +321,8 @@ class Action extends Base
}
}
+ // $this->container['fileCache']->remove('proxy_action_getAll');
+
return true;
}
diff --git a/app/Model/Board.php b/app/Model/Board.php
index 5ebec279..550009fa 100644
--- a/app/Model/Board.php
+++ b/app/Model/Board.php
@@ -254,6 +254,23 @@ class Board extends Base
}
/**
+ * Get the total of tasks per column
+ *
+ * @access public
+ * @param integer $project_id
+ * @return array
+ */
+ public function getColumnStats($project_id)
+ {
+ return $this->db
+ ->table(Task::TABLE)
+ ->eq('project_id', $project_id)
+ ->eq('is_active', 1)
+ ->groupBy('column_id')
+ ->listing('column_id', 'COUNT(*) AS total');
+ }
+
+ /**
* Get the first column id for a given project
*
* @access public
diff --git a/app/Model/Notification.php b/app/Model/Notification.php
index 8c13aada..95306e86 100644
--- a/app/Model/Notification.php
+++ b/app/Model/Notification.php
@@ -114,7 +114,7 @@ class Notification extends Base
}
}
catch (Swift_TransportException $e) {
- $this->container['logger']->addError($e->getMessage());
+ $this->container['logger']->error($e->getMessage());
}
}
diff --git a/app/Model/Project.php b/app/Model/Project.php
index de9408ec..6d8885b1 100644
--- a/app/Model/Project.php
+++ b/app/Model/Project.php
@@ -191,11 +191,12 @@ class Project extends Base
public function getStats($project_id)
{
$stats = array();
- $columns = $this->board->getColumns($project_id);
$stats['nb_active_tasks'] = 0;
+ $columns = $this->board->getColumns($project_id);
+ $column_stats = $this->board->getColumnStats($project_id);
foreach ($columns as &$column) {
- $column['nb_active_tasks'] = $this->taskFinder->countByColumnId($project_id, $column['id']);
+ $column['nb_active_tasks'] = isset($column_stats[$column['id']]) ? $column_stats[$column['id']] : 0;
$stats['nb_active_tasks'] += $column['nb_active_tasks'];
}
diff --git a/app/Model/ProjectPaginator.php b/app/Model/ProjectPaginator.php
index 9f1c39f0..68b216b1 100644
--- a/app/Model/ProjectPaginator.php
+++ b/app/Model/ProjectPaginator.php
@@ -38,9 +38,10 @@ class ProjectPaginator extends Base
foreach ($projects as &$project) {
$project['columns'] = $this->board->getColumns($project['id']);
+ $stats = $this->board->getColumnStats($project['id']);
foreach ($project['columns'] as &$column) {
- $column['nb_tasks'] = $this->taskFinder->countByColumnId($project['id'], $column['id']);
+ $column['nb_tasks'] = isset($stats[$column['id']]) ? $stats[$column['id']] : 0;
}
}
diff --git a/app/Model/ProjectPermission.php b/app/Model/ProjectPermission.php
index a53f9195..fc7ab0d5 100644
--- a/app/Model/ProjectPermission.php
+++ b/app/Model/ProjectPermission.php
@@ -298,7 +298,11 @@ class ProjectPermission extends Base
*/
public function getAllowedProjects($user_id)
{
- return $this->filterProjects($this->project->getListByStatus(Project::ACTIVE), $user_id, 'isUserAllowed');
+ if ($this->user->isAdmin($user_id)) {
+ return $this->project->getListByStatus(Project::ACTIVE);
+ }
+
+ return $this->getMemberProjects($user_id);
}
/**
@@ -310,7 +314,11 @@ class ProjectPermission extends Base
*/
public function getMemberProjects($user_id)
{
- return $this->filterProjects($this->project->getListByStatus(Project::ACTIVE), $user_id, 'isMember');
+ return $this->db
+ ->table(Project::TABLE)
+ ->eq('user_id', $user_id)
+ ->join(self::TABLE, 'project_id', 'id')
+ ->listing('projects.id', 'name');
}
/**
diff --git a/app/Model/TaskFinder.php b/app/Model/TaskFinder.php
index 7f66fa4d..eb86fe3e 100644
--- a/app/Model/TaskFinder.php
+++ b/app/Model/TaskFinder.php
@@ -216,16 +216,15 @@ class TaskFinder extends Base
* @access public
* @param integer $project_id Project id
* @param integer $column_id Column id
- * @param array $status List of status id
* @return integer
*/
- public function countByColumnId($project_id, $column_id, array $status = array(Task::STATUS_OPEN))
+ public function countByColumnId($project_id, $column_id)
{
return $this->db
->table(Task::TABLE)
->eq('project_id', $project_id)
->eq('column_id', $column_id)
- ->in('is_active', $status)
+ ->in('is_active', 1)
->count();
}
diff --git a/app/Model/User.php b/app/Model/User.php
index 78d44b47..29def6d4 100644
--- a/app/Model/User.php
+++ b/app/Model/User.php
@@ -48,7 +48,8 @@ class User extends Base
*/
public function isAdmin($user_id)
{
- return $this->db
+ return $this->userSession->isAdmin() || // Avoid SQL query if connected
+ $this->db
->table(User::TABLE)
->eq('id', $user_id)
->eq('is_admin', 1)