summaryrefslogtreecommitdiff
path: root/plugins/Timetrackingeditor/Model
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2020-05-05 14:25:42 +0200
committeremkael <emkael@tlen.pl>2020-05-05 14:25:42 +0200
commit62827e6cf470449c117624058fb36ad94804bcc0 (patch)
tree10cd1e4d36c34b694acfadaa69fc7f6ae2b1eabd /plugins/Timetrackingeditor/Model
parent7b66ddf2e4fbdb837e78d8b7dbaa9fc38391bc32 (diff)
Time tracking related pluginsHEADmaster
Diffstat (limited to 'plugins/Timetrackingeditor/Model')
-rw-r--r--plugins/Timetrackingeditor/Model/SubtaskTimeTrackingCreationModel.php53
-rw-r--r--plugins/Timetrackingeditor/Model/SubtaskTimeTrackingEditModel.php143
-rw-r--r--plugins/Timetrackingeditor/Model/SubtaskTimeTrackingModel.php133
3 files changed, 329 insertions, 0 deletions
diff --git a/plugins/Timetrackingeditor/Model/SubtaskTimeTrackingCreationModel.php b/plugins/Timetrackingeditor/Model/SubtaskTimeTrackingCreationModel.php
new file mode 100644
index 00000000..806d9345
--- /dev/null
+++ b/plugins/Timetrackingeditor/Model/SubtaskTimeTrackingCreationModel.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace Kanboard\Plugin\Timetrackingeditor\Model;
+
+use Kanboard\Core\Base;
+use Kanboard\Event\TaskEvent;
+use Kanboard\Model\SubtaskTimeTrackingModel;
+
+/**
+ * Task Creation
+ *
+ * @package Kanboard\Plugin\Timetrackingeditor\Model
+ * @author Thomas Stinner
+ */
+class SubtaskTimeTrackingCreationModel extends Base
+{
+ /**
+ * Create a time tracking event
+ *
+ * @access public
+ * @param array $values Form values
+ * @return integer
+ */
+ public function create(array $values)
+ {
+
+ $this->prepare($values);
+ $subtrackingid = $this->db->table(SubtaskTimeTrackingModel::TABLE)->persist($values);
+
+ return (int) $subtrackingid;
+ }
+
+ /**
+ * Prepare data
+ *
+ * @access public
+ * @param array $values Form values
+ */
+ public function prepare(array &$values)
+ {
+ if ($this->userSession->isLogged()) {
+ $values['user_id'] = $this->userSession->getId();
+ }
+
+ $values["subtask_id"] = $values["opposite_subtask_id"];
+
+ $this->helper->model->removeFields($values, array('project_id', 'task_id', 'opposite_subtask_id', 'subtask', 'add_another'));
+
+ // Calculate end time
+ $values = $this->dateParser->convert($values, array('start'), true);
+ $values["end"] = $values["start"] + ($values['time_spent']*60*60);
+ }
+}
diff --git a/plugins/Timetrackingeditor/Model/SubtaskTimeTrackingEditModel.php b/plugins/Timetrackingeditor/Model/SubtaskTimeTrackingEditModel.php
new file mode 100644
index 00000000..a6ee24dc
--- /dev/null
+++ b/plugins/Timetrackingeditor/Model/SubtaskTimeTrackingEditModel.php
@@ -0,0 +1,143 @@
+<?php
+
+namespace Kanboard\Plugin\Timetrackingeditor\Model;
+
+use Kanboard\Core\Base;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\TaskModel;
+
+/**
+ * Task Creation
+ *
+ * @package Kanboard\Plugin\Timetrackingeditor\Model
+ * @author Thomas Stinner
+ */
+class SubtaskTimeTrackingEditModel extends Base
+{
+
+ /**
+ * GetOpenTimer
+ * Returns the Open (started but not finished) Time Tracking entry
+ * for a specific user and subtask
+ *
+ * @access public
+ * @param integer $user_id User id
+ * @param integer $subtask_id Subtask id
+ * @return \Picodb\Table
+ */
+ public function getOpenTimer($user_id, $subtask_id)
+ {
+ return $this->db
+ ->table(SubtaskTimeTrackingModel::TABLE)
+ ->columns(
+ SubtaskTimeTrackingModel::TABLE.'.id',
+ SubtaskTimeTrackingModel::TABLE.'.subtask_id',
+ SubtaskTimeTrackingModel::TABLE.'.end',
+ SubtaskTimeTrackingModel::TABLE.'.start',
+ SubtaskTimeTrackingModel::TABLE.'.time_spent',
+ SubtaskTimeTrackingModel::TABLE.'.comment',
+ SubtaskTimeTrackingModel::TABLE.'.is_billable'
+ )
+ ->eq(SubtaskTimeTrackingModel::TABLE.'.subtask_id', $subtask_id)
+ ->eq(SubtaskTimeTrackingModel::TABLE.'.user_id', $user_id)
+ ->eq(SubtaskTimeTrackingModel::TABLE.'.end', 0)
+ ->findOne();
+ }
+
+ /**
+ * Get by Id
+ *
+ * @access public
+ * @param int $id TimetrackingId
+ * @return \PicoDb\Table
+ */
+ public function getById($id)
+ {
+ return $this->db
+ ->table(SubtaskTimeTrackingModel::TABLE)
+ ->columns(
+ SubtaskTimeTrackingModel::TABLE.'.id',
+ SubtaskTimeTrackingModel::TABLE.'.subtask_id',
+ SubtaskTimeTrackingModel::TABLE.'.end',
+ SubtaskTimeTrackingModel::TABLE.'.start',
+ SubtaskTimeTrackingModel::TABLE.'.time_spent',
+ SubtaskTimeTrackingModel::TABLE.'.comment',
+ SubtaskTimeTrackingModel::TABLE.'.is_billable',
+ SubtaskModel::TABLE.'.task_id',
+ SubtaskModel::TABLE.'.title AS subtask_title',
+ TaskModel::TABLE.'.title AS task_title',
+ TaskModel::TABLE.'.project_id',
+ TaskModel::TABLE.'.color_id'
+ )
+ ->join(SubtaskModel::TABLE, 'id', 'subtask_id')
+ ->join(TaskModel::TABLE, 'id', 'task_id', SubtaskModel::TABLE)
+ ->eq(SubtaskTimeTrackingModel::TABLE.'.id', $id)
+ ->findOne();
+
+ }
+
+ /**
+ * Create a time tracking event
+ *
+ * @access public
+ * @param array $values Form values
+ * @return integer
+ */
+ public function create(array $values)
+ {
+
+ $this->prepare($values);
+ $subtrackingid = $this->db->table(SubtaskTimeTrackingModel::TABLE)->persist($values);
+
+ return (int) $subtrackingid;
+ }
+
+ /**
+ * Update a time tracking event
+ *
+ * @access public
+ * @param array $values
+ * @return boolean
+ */
+ public function update(array $values)
+ {
+ $this->prepare($values);
+
+ return $this->db->table(SubtaskTimeTrackingModel::TABLE)->eq('id', $values['id'])->update($values);
+ }
+
+
+ /**
+ * remove an entry
+ *
+ * @access public
+ * @param int $id
+ * @return boolran
+ */
+ public function remove($id)
+ {
+ return $this->db->table(SubtaskTimeTrackingModel::TABLE)->eq('id', $id)->remove();
+
+ }
+
+ /**
+ * Prepare data
+ *
+ * @access public
+ * @param array $values Form values
+ */
+ public function prepare(array &$values)
+ {
+ if ($this->userSession->isLogged()) {
+ $values['user_id'] = $this->userSession->getId();
+ }
+
+ $values["subtask_id"] = $values["opposite_subtask_id"];
+
+ $this->helper->model->removeFields($values, array('project_id', 'task_id', 'opposite_subtask_id', 'subtask', 'add_another', 'old_time_spent', 'old_opposite_subtask_id'));
+
+ // Calculate end time
+ $values = $this->dateParser->convert($values, array('start'), true);
+ $values["end"] = $values["start"] + ($values['time_spent']*60*60);
+ }
+}
diff --git a/plugins/Timetrackingeditor/Model/SubtaskTimeTrackingModel.php b/plugins/Timetrackingeditor/Model/SubtaskTimeTrackingModel.php
new file mode 100644
index 00000000..1fcf8738
--- /dev/null
+++ b/plugins/Timetrackingeditor/Model/SubtaskTimeTrackingModel.php
@@ -0,0 +1,133 @@
+<?php
+
+namespace Kanboard\Plugin\TimetrackingEditor\Model;
+
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\UserModel;
+
+/**
+ * @author Thomas Stinner
+ */
+
+class SubtaskTimeTrackingModel extends \Kanboard\Model\SubtaskTimeTrackingModel
+{
+ /**
+ * Log start time
+ *
+ * @access public
+ * @param integer $subtask_id
+ * @param integer $user_id
+ * @return boolean
+ */
+ public function logStartTimeExtended($subtask_id, $user_id, $comment, $is_billable)
+ {
+ return
+ ! $this->hasTimer($subtask_id, $user_id) &&
+ $this->db
+ ->table(self::TABLE)
+ ->insert(array('subtask_id' => $subtask_id,
+ 'user_id' => $user_id,
+ 'comment' => $comment,
+ 'is_billable' => $is_billable,
+ 'start' => time(),
+ 'end' => 0));
+ }
+
+ /**
+ * Log end time
+ *
+ * @access public
+ * @param integer $subtask_id
+ * @param integer $user_id
+ * @return boolean
+ */
+ public function logEndTimeExtended($subtask_id, $user_id, $comment, $is_billable)
+ {
+ $time_spent = $this->getTimeSpent($subtask_id, $user_id);
+
+ if ($time_spent > 0) {
+ $this->updateSubtaskTimeSpent($subtask_id, $time_spent);
+ }
+
+ return $this->db
+ ->table(self::TABLE)
+ ->eq('subtask_id', $subtask_id)
+ ->eq('user_id', $user_id)
+ ->eq('end', 0)
+ ->update(array(
+ 'end' => time(),
+ 'time_spent' => $time_spent,
+ 'comment' => $comment,
+ 'is_billable' => $is_billable
+ ));
+ }
+
+ /**
+ * Get query for task timesheet (pagination)
+ *
+ * @access public
+ * @param integer $task_id Task id
+ * @return \PicoDb\Table
+ */
+ public function getTaskQuery($task_id)
+ {
+ return $this->db
+ ->table(self::TABLE)
+ ->columns(
+ self::TABLE.'.id',
+ self::TABLE.'.subtask_id',
+ self::TABLE.'.end',
+ self::TABLE.'.start',
+ self::TABLE.'.time_spent',
+ self::TABLE.'.user_id',
+ self::TABLE.'.comment',
+ self::TABLE.'.is_billable',
+ SubtaskModel::TABLE.'.task_id',
+ SubtaskModel::TABLE.'.title AS subtask_title',
+ TaskModel::TABLE.'.project_id',
+ UserModel::TABLE.'.username',
+ UserModel::TABLE.'.name AS user_fullname'
+ )
+ ->join(SubtaskModel::TABLE, 'id', 'subtask_id')
+ ->join(TaskModel::TABLE, 'id', 'task_id', SubtaskModel::TABLE)
+ ->join(UserModel::TABLE, 'id', 'user_id', self::TABLE)
+ ->eq(TaskModel::TABLE.'.id', $task_id);
+ }
+
+ /**
+ * Update subtask time billable
+ *
+ * @access public
+ * @param integer $subtask_id
+ * @param float $time_billable
+ * @return bool
+ */
+ public function updateSubtaskTimeBillable($subtask_id, $time_billable)
+ {
+ $subtask = $this->subtaskModel->getById($subtask_id);
+
+ return $this->subtaskModel->update(array(
+ 'id' => $subtask['id'],
+ 'time_billable' => $subtask['time_billable'] + $time_billable,
+ 'task_id' => $subtask['task_id'],
+ ), false);
+ }
+
+ /**
+ * get a Subtasktimetracking entry by Id
+ *
+ * @access public
+ * @param $id the subtasktimetracking id
+ * @return array
+ */
+ public function getById($id)
+ {
+ return $this->db
+ ->table(SubtaskTimeTrackingModel::TABLE)
+ ->eq('id', $id)
+ ->findOne();
+ }
+
+
+}