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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
<?php
namespace Model;
/**
* Transition model
*
* @package model
* @author Frederic Guillot
*/
class Transition extends Base
{
/**
* SQL table name
*
* @var string
*/
const TABLE = 'transitions';
/**
* Save transition event
*
* @access public
* @param integer $user_id
* @param array $task
* @return boolean
*/
public function save($user_id, array $task)
{
return $this->db->table(self::TABLE)->insert(array(
'user_id' => $user_id,
'project_id' => $task['project_id'],
'task_id' => $task['task_id'],
'src_column_id' => $task['src_column_id'],
'dst_column_id' => $task['dst_column_id'],
'date' => time(),
'time_spent' => time() - $task['date_moved']
));
}
/**
* Get all transitions by task
*
* @access public
* @param integer $task_id
* @return array
*/
public function getAllByTask($task_id)
{
return $this->db->table(self::TABLE)
->columns(
'src.title as src_column',
'dst.title as dst_column',
User::TABLE.'.name',
User::TABLE.'.username',
self::TABLE.'.user_id',
self::TABLE.'.date',
self::TABLE.'.time_spent'
)
->eq('task_id', $task_id)
->desc('date')
->join(User::TABLE, 'id', 'user_id')
->join(Board::TABLE.' as src', 'id', 'src_column_id', self::TABLE, 'src')
->join(Board::TABLE.' as dst', 'id', 'dst_column_id', self::TABLE, 'dst')
->findAll();
}
}
|