summaryrefslogtreecommitdiff
path: root/plugins/Timetrackingeditor/Model/SubtaskTimeTrackingCreationModel.php
blob: 806d93458987c30a6284d80ca379c5a527637125 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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);
    }
}