summaryrefslogtreecommitdiff
path: root/app/Model/SubtaskTimeTracking.php
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/SubtaskTimeTracking.php
parent2d070627d751bf5728ec98a5efaf163532594cd9 (diff)
Add subtasks restrictions and time tracking
Diffstat (limited to 'app/Model/SubtaskTimeTracking.php')
-rw-r--r--app/Model/SubtaskTimeTracking.php80
1 files changed, 80 insertions, 0 deletions
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()
+ ));
+ }
+}