summaryrefslogtreecommitdiff
path: root/app/Model
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-02-04 22:19:32 -0500
committerFrederic Guillot <fred@kanboard.net>2015-02-04 22:19:32 -0500
commitb24b1e7e4e5ee0551ee56aa0f21c4425b479db2e (patch)
tree5fffaeb461707dada9f2909101d51c9da3c77a50 /app/Model
parent2d070627d751bf5728ec98a5efaf163532594cd9 (diff)
Add subtasks restrictions and time tracking
Diffstat (limited to 'app/Model')
-rw-r--r--app/Model/SubTask.php32
-rw-r--r--app/Model/SubtaskTimeTracking.php80
2 files changed, 111 insertions, 1 deletions
diff --git a/app/Model/SubTask.php b/app/Model/SubTask.php
index 3fccad47..dd243b1f 100644
--- a/app/Model/SubTask.php
+++ b/app/Model/SubTask.php
@@ -223,13 +223,43 @@ class SubTask extends Base
$values = array(
'id' => $subtask['id'],
'status' => ($subtask['status'] + 1) % 3,
- 'task_id' => $subtask['task_id'],
);
return $this->update($values);
}
/**
+ * Get the subtask in progress for this user
+ *
+ * @access public
+ * @param integer $user_id
+ * @return array
+ */
+ public function getSubtaskInProgress($user_id)
+ {
+ return $this->db->table(self::TABLE)
+ ->eq('status', self::STATUS_INPROGRESS)
+ ->eq('user_id', $user_id)
+ ->findOne();
+ }
+
+ /**
+ * Return true if the user have a subtask in progress
+ *
+ * @access public
+ * @param integer $user_id
+ * @return boolean
+ */
+ public function hasSubtaskInProgress($user_id)
+ {
+ return $this->config->get('subtask_restriction') == 1 &&
+ $this->db->table(self::TABLE)
+ ->eq('status', self::STATUS_INPROGRESS)
+ ->eq('user_id', $user_id)
+ ->count() === 1;
+ }
+
+ /**
* Remove
*
* @access public
diff --git a/app/Model/SubtaskTimeTracking.php b/app/Model/SubtaskTimeTracking.php
new file mode 100644
index 00000000..5c8a7c81
--- /dev/null
+++ b/app/Model/SubtaskTimeTracking.php
@@ -0,0 +1,80 @@
+<?php
+
+namespace Model;
+
+/**
+ * Subtask timesheet
+ *
+ * @package model
+ * @author Frederic Guillot
+ */
+class SubtaskTimeTracking extends Base
+{
+ /**
+ * SQL table name
+ *
+ * @var string
+ */
+ const TABLE = 'subtask_time_tracking';
+
+ /**
+ * Get query for user timesheet (pagination)
+ *
+ * @access public
+ * @param integer $user_id User id
+ * @return \PicoDb\Table
+ */
+ public function getUserQuery($user_id)
+ {
+ return $this->db
+ ->table(self::TABLE)
+ ->columns(
+ self::TABLE.'.id',
+ self::TABLE.'.subtask_id',
+ self::TABLE.'.end',
+ self::TABLE.'.start',
+ SubTask::TABLE.'.task_id',
+ SubTask::TABLE.'.title AS subtask_title',
+ Task::TABLE.'.title AS task_title',
+ Task::TABLE.'.project_id'
+ )
+ ->join(SubTask::TABLE, 'id', 'subtask_id')
+ ->join(Task::TABLE, 'id', 'task_id', SubTask::TABLE)
+ ->eq(self::TABLE.'.user_id', $user_id);
+ }
+
+ /**
+ * Log start time
+ *
+ * @access public
+ * @param integer $subtask_id
+ * @param integer $user_id
+ * @return boolean
+ */
+ public function logStartTime($subtask_id, $user_id)
+ {
+ return $this->db
+ ->table(self::TABLE)
+ ->insert(array('subtask_id' => $subtask_id, 'user_id' => $user_id, 'start' => time()));
+ }
+
+ /**
+ * Log end time
+ *
+ * @access public
+ * @param integer $subtask_id
+ * @param integer $user_id
+ * @return boolean
+ */
+ public function logEndTime($subtask_id, $user_id)
+ {
+ return $this->db
+ ->table(self::TABLE)
+ ->eq('subtask_id', $subtask_id)
+ ->eq('user_id', $user_id)
+ ->eq('end', 0)
+ ->update(array(
+ 'end' => time()
+ ));
+ }
+}