1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) Enalean, 2013. All Rights Reserved. |
4
|
|
|
* |
5
|
|
|
* This file is a part of Tuleap. |
6
|
|
|
* |
7
|
|
|
* Tuleap is free software; you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* Tuleap is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with Tuleap. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* This class is a wrapper on top of card in cell presenter to be used when |
23
|
|
|
* a card is rendered out of the board context. |
24
|
|
|
* |
25
|
|
|
* In other words it's what you need when you only want to have one single card |
26
|
|
|
*/ |
27
|
|
|
class Cardwall_SingleCard { |
28
|
|
|
|
29
|
|
|
/** @var Cardwall_CardInCellPresenter */ |
30
|
|
|
private $card_in_cell_presenter; |
31
|
|
|
|
32
|
|
|
/** @var Tracker_Artifact */ |
33
|
|
|
private $artifact; |
34
|
|
|
|
35
|
|
|
/** @var Cardwall_CardFields */ |
36
|
|
|
private $card_fields; |
37
|
|
|
|
38
|
|
|
/** @var Cardwall_UserPreferences_UserPreferencesDisplayUser */ |
39
|
|
|
private $display_preferences; |
40
|
|
|
|
41
|
|
|
/** @var int */ |
42
|
|
|
private $column_id; |
43
|
|
|
|
44
|
|
|
/** @var Cardwall_OnTop_Config_TrackerMapping */ |
45
|
|
|
private $mapping; |
46
|
|
|
|
47
|
|
|
/** @var array */ |
48
|
|
|
private $fields_cache = null; |
49
|
|
|
|
50
|
|
|
public function __construct( |
51
|
|
|
Cardwall_CardInCellPresenter $card_in_cell_presenter, |
52
|
|
|
Cardwall_CardFields $card_fields, |
53
|
|
|
Cardwall_UserPreferences_UserPreferencesDisplayUser $display_preferences, |
54
|
|
|
$column_id, |
55
|
|
|
Cardwall_OnTop_Config_TrackerMapping $mapping |
56
|
|
|
) { |
57
|
|
|
$this->card_in_cell_presenter = $card_in_cell_presenter; |
58
|
|
|
$this->artifact = $card_in_cell_presenter->getArtifact(); |
59
|
|
|
$this->card_fields = $card_fields; |
60
|
|
|
$this->display_preferences = $display_preferences; |
61
|
|
|
$this->column_id = $column_id; |
62
|
|
|
$this->mapping = $mapping; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return Cardwall_CardInCellPresenter |
67
|
|
|
*/ |
68
|
|
|
public function getCardInCellPresenter() { |
69
|
|
|
return $this->card_in_cell_presenter; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function getColumnId() { |
73
|
|
|
return $this->column_id; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function getFields() { |
77
|
|
|
return $this->card_fields->getFields($this->artifact); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Return a field on the card based on the card |
82
|
|
|
* |
83
|
|
|
* @param Integer $id |
84
|
|
|
* |
85
|
|
|
* @return Tracker_FormElement_Field |
86
|
|
|
*/ |
87
|
|
|
public function getFieldById($id) { |
88
|
|
|
if ($this->fields_cache === null) { |
89
|
|
|
foreach ($this->getFields() as $field) { |
90
|
|
|
$this->fields_cache[$field->getId()] = $field; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
if (isset($this->fields_cache[$id])) { |
94
|
|
|
return $this->fields_cache[$id]; |
95
|
|
|
} |
96
|
|
|
throw new Cardwall_FieldNotOnCardException($id); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return Tracker_Artifact |
101
|
|
|
*/ |
102
|
|
|
public function getArtifact() { |
103
|
|
|
return $this->artifact; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function getFieldJsonValue(PFUser $user, Tracker_FormElement_Field $field) { |
107
|
|
|
return $field->getJsonValue($user, $this->artifact->getLastChangeset()); |
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function getFieldHTMLValue(PFUser $user, Tracker_FormElement_Field $field) { |
111
|
|
|
return $field->fetchCardValue($this->artifact, $this->display_preferences); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function getMapping() { |
115
|
|
|
return $this->mapping; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: