summaryrefslogtreecommitdiff
path: root/app/Model
diff options
context:
space:
mode:
Diffstat (limited to 'app/Model')
-rw-r--r--app/Model/Acl.php1
-rw-r--r--app/Model/Budget.php2
-rw-r--r--app/Model/Project.php2
-rw-r--r--app/Model/Subtask.php17
-rw-r--r--app/Model/SubtaskTimeTracking.php23
-rw-r--r--app/Model/TaskFilter.php2
-rw-r--r--app/Model/TaskFinder.php4
7 files changed, 41 insertions, 10 deletions
diff --git a/app/Model/Acl.php b/app/Model/Acl.php
index c9e155ed..684fae13 100644
--- a/app/Model/Acl.php
+++ b/app/Model/Acl.php
@@ -41,6 +41,7 @@ class Acl extends Base
'subtask' => '*',
'task' => '*',
'tasklink' => '*',
+ 'timer' => '*',
'calendar' => array('show', 'project'),
);
diff --git a/app/Model/Budget.php b/app/Model/Budget.php
index d74dd870..76c42ca9 100644
--- a/app/Model/Budget.php
+++ b/app/Model/Budget.php
@@ -75,7 +75,7 @@ class Budget extends Base
->join(Task::TABLE, 'id', 'task_id', Subtask::TABLE)
->join(User::TABLE, 'id', 'user_id')
->eq(Task::TABLE.'.project_id', $project_id)
- ->filter(array($this, 'applyUserRate'));
+ ->callback(array($this, 'applyUserRate'));
}
/**
diff --git a/app/Model/Project.php b/app/Model/Project.php
index 71c660b9..ef7340ee 100644
--- a/app/Model/Project.php
+++ b/app/Model/Project.php
@@ -276,7 +276,7 @@ class Project extends Base
return $this->db
->table(Project::TABLE)
->in('id', $project_ids)
- ->filter(array($this, 'applyColumnStats'));
+ ->callback(array($this, 'applyColumnStats'));
}
/**
diff --git a/app/Model/Subtask.php b/app/Model/Subtask.php
index ee000e32..b9cc6ded 100644
--- a/app/Model/Subtask.php
+++ b/app/Model/Subtask.php
@@ -78,6 +78,8 @@ class Subtask extends Base
foreach ($subtasks as &$subtask) {
$subtask['status_name'] = $status[$subtask['status']];
+ $subtask['timer_start_date'] = isset($subtask['timer_start_date']) ? $subtask['timer_start_date'] : 0;
+ $subtask['is_timer_started'] = ! empty($subtask['timer_start_date']);
}
return $subtasks;
@@ -101,12 +103,13 @@ class Subtask extends Base
Task::TABLE.'.title AS task_name',
Project::TABLE.'.name AS project_name'
)
+ ->subquery($this->subtaskTimeTracking->getTimerQuery($user_id), 'timer_start_date')
->eq('user_id', $user_id)
->eq(Project::TABLE.'.is_active', Project::ACTIVE)
->in(Subtask::TABLE.'.status', $status)
->join(Task::TABLE, 'id', 'task_id')
->join(Project::TABLE, 'id', 'project_id', Task::TABLE)
- ->filter(array($this, 'addStatusName'));
+ ->callback(array($this, 'addStatusName'));
}
/**
@@ -121,10 +124,15 @@ class Subtask extends Base
return $this->db
->table(self::TABLE)
->eq('task_id', $task_id)
- ->columns(self::TABLE.'.*', User::TABLE.'.username', User::TABLE.'.name')
+ ->columns(
+ self::TABLE.'.*',
+ User::TABLE.'.username',
+ User::TABLE.'.name'
+ )
+ ->subquery($this->subtaskTimeTracking->getTimerQuery($this->userSession->getId()), 'timer_start_date')
->join(User::TABLE, 'id', 'user_id')
->asc(self::TABLE.'.position')
- ->filter(array($this, 'addStatusName'))
+ ->callback(array($this, 'addStatusName'))
->findAll();
}
@@ -144,8 +152,9 @@ class Subtask extends Base
->table(self::TABLE)
->eq(self::TABLE.'.id', $subtask_id)
->columns(self::TABLE.'.*', User::TABLE.'.username', User::TABLE.'.name')
+ ->subquery($this->subtaskTimeTracking->getTimerQuery($this->userSession->getId()), 'timer_start_date')
->join(User::TABLE, 'id', 'user_id')
- ->filter(array($this, 'addStatusName'))
+ ->callback(array($this, 'addStatusName'))
->findOne();
}
diff --git a/app/Model/SubtaskTimeTracking.php b/app/Model/SubtaskTimeTracking.php
index 93a698b6..51743198 100644
--- a/app/Model/SubtaskTimeTracking.php
+++ b/app/Model/SubtaskTimeTracking.php
@@ -20,6 +20,27 @@ class SubtaskTimeTracking extends Base
const TABLE = 'subtask_time_tracking';
/**
+ * Get query to check if a timer is started for the given user and subtask
+ *
+ * @access public
+ * @param integer $user_id User id
+ * @return string
+ */
+ public function getTimerQuery($user_id)
+ {
+ return sprintf(
+ "SELECT %s FROM %s WHERE %s='%d' AND %s='0' AND %s=%s",
+ $this->db->escapeIdentifier('start'),
+ $this->db->escapeIdentifier(self::TABLE),
+ $this->db->escapeIdentifier('user_id'),
+ $user_id,
+ $this->db->escapeIdentifier('end'),
+ $this->db->escapeIdentifier('subtask_id'),
+ Subtask::TABLE.'.id'
+ );
+ }
+
+ /**
* Get query for user timesheet (pagination)
*
* @access public
@@ -217,7 +238,7 @@ class SubtaskTimeTracking extends Base
{
return $this->db
->table(self::TABLE)
- ->insert(array('subtask_id' => $subtask_id, 'user_id' => $user_id, 'start' => time()));
+ ->insert(array('subtask_id' => $subtask_id, 'user_id' => $user_id, 'start' => time(), 'end' => 0));
}
/**
diff --git a/app/Model/TaskFilter.php b/app/Model/TaskFilter.php
index 3d58c060..e99f36fb 100644
--- a/app/Model/TaskFilter.php
+++ b/app/Model/TaskFilter.php
@@ -301,7 +301,7 @@ class TaskFilter extends Base
*/
public function toAutoCompletion()
{
- return $this->query->columns('id', 'title')->filter(function(array $results) {
+ return $this->query->columns('id', 'title')->callback(function(array $results) {
foreach ($results as &$result) {
$result['value'] = $result['title'];
diff --git a/app/Model/TaskFinder.php b/app/Model/TaskFinder.php
index 234101ec..ead60b4b 100644
--- a/app/Model/TaskFinder.php
+++ b/app/Model/TaskFinder.php
@@ -316,7 +316,7 @@ class TaskFinder extends Base
->table(Task::TABLE)
->eq('project_id', $project_id)
->eq('column_id', $column_id)
- ->in('is_active', 1)
+ ->eq('is_active', 1)
->count();
}
@@ -336,7 +336,7 @@ class TaskFinder extends Base
->eq('project_id', $project_id)
->eq('column_id', $column_id)
->eq('swimlane_id', $swimlane_id)
- ->in('is_active', 1)
+ ->eq('is_active', 1)
->count();
}