blob: f2c756b40c34ae2d5f792282f70b2036af73ab56 (
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
<?php
namespace Kanboard\Model;
/**
* Task External Link Model
*
* @package model
* @author Frederic Guillot
*/
class TaskExternalLink extends Base
{
/**
* SQL table name
*
* @var string
*/
const TABLE = 'task_has_external_links';
/**
* Get all links
*
* @access public
* @param integer $task_id
* @return array
*/
public function getAll($task_id)
{
$types = $this->externalLinkManager->getTypes();
$links = $this->db->table(self::TABLE)
->columns(self::TABLE.'.*', User::TABLE.'.name AS creator_name', User::TABLE.'.username AS creator_username')
->eq('task_id', $task_id)
->asc('title')
->join(User::TABLE, 'id', 'creator_id')
->findAll();
foreach ($links as &$link) {
$link['dependency_label'] = $this->externalLinkManager->getDependencyLabel($link['link_type'], $link['dependency']);
$link['type'] = isset($types[$link['link_type']]) ? $types[$link['link_type']] : t('Unknown');
}
return $links;
}
/**
* Get link
*
* @access public
* @param integer $link_id
* @return array
*/
public function getById($link_id)
{
return $this->db->table(self::TABLE)->eq('id', $link_id)->findOne();
}
/**
* Add a new link in the database
*
* @access public
* @param array $values Form values
* @return boolean|integer
*/
public function create(array $values)
{
unset($values['id']);
$values['creator_id'] = $this->userSession->getId();
$values['date_creation'] = time();
$values['date_modification'] = $values['date_creation'];
return $this->persist(self::TABLE, $values);
}
/**
* Modify external link
*
* @access public
* @param array $values Form values
* @return boolean
*/
public function update(array $values)
{
$values['date_modification'] = time();
return $this->db->table(self::TABLE)->eq('id', $values['id'])->update($values);
}
/**
* Remove a link
*
* @access public
* @param integer $link_id
* @return boolean
*/
public function remove($link_id)
{
return $this->db->table(self::TABLE)->eq('id', $link_id)->remove();
}
}
|