|
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
|
|
|
* Build the artifact tree to be presented on the cardwall |
|
23
|
|
|
*/ |
|
24
|
|
|
class Cardwall_PaneBoardBuilder { |
|
25
|
|
|
|
|
26
|
|
|
private $artifact_factory; |
|
27
|
|
|
private $presenter_builder; |
|
28
|
|
|
private $dao; |
|
29
|
|
|
private $swimline_factory; |
|
30
|
|
|
|
|
31
|
|
|
public function __construct(Cardwall_CardInCellPresenterBuilder $presenter_builder, Tracker_ArtifactFactory $artifact_factory, AgileDashboard_BacklogItemDao $dao, Cardwall_SwimlineFactory $swimline_factory) { |
|
32
|
|
|
$this->presenter_builder = $presenter_builder; |
|
33
|
|
|
$this->artifact_factory = $artifact_factory; |
|
34
|
|
|
$this->dao = $dao; |
|
35
|
|
|
$this->swimline_factory = $swimline_factory; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Get the board |
|
40
|
|
|
* |
|
41
|
|
|
* @param PFUser $user |
|
42
|
|
|
* @param Tracker_Artifact $milestone_artifact |
|
43
|
|
|
* @param Cardwall_OnTop_Config_ColumnCollection $columns |
|
44
|
|
|
* @param Cardwall_MappingCollection $mapping_collection |
|
45
|
|
|
* @return \Cardwall_Board |
|
46
|
|
|
*/ |
|
47
|
|
|
public function getBoard(PFUser $user, Tracker_Artifact $milestone_artifact, Cardwall_OnTop_Config_ColumnCollection $columns, Cardwall_MappingCollection $mapping_collection) { |
|
48
|
|
|
return new Cardwall_Board( |
|
49
|
|
|
$this->getSwimlines($user, $milestone_artifact, $columns), |
|
50
|
|
|
$columns, |
|
51
|
|
|
$mapping_collection |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Retrieves the artifacts planned for the given milestone artifact. |
|
57
|
|
|
* |
|
58
|
|
|
* @param PFUser $user |
|
59
|
|
|
* @param Tracker_Artifact $milestone_artifact |
|
60
|
|
|
* @param Cardwall_OnTop_Config_ColumnCollection $columns |
|
61
|
|
|
* |
|
62
|
|
|
* @return Cardwall_Swimline[] |
|
63
|
|
|
*/ |
|
64
|
|
|
private function getSwimlines(PFUser $user, Tracker_Artifact $milestone_artifact, Cardwall_OnTop_Config_ColumnCollection $columns) { |
|
65
|
|
|
$swimlines = array(); |
|
66
|
|
|
foreach ($this->dao->getBacklogArtifacts($milestone_artifact->getId()) as $row) { |
|
|
|
|
|
|
67
|
|
|
$swimline_artifact = $this->artifact_factory->getInstanceFromRow($row); |
|
68
|
|
|
if ($swimline_artifact->userCanView($user)) { |
|
69
|
|
|
$swimlines[] = $this->buildSwimlineForArtifact($user, $swimline_artifact, $columns); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
return $swimlines; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
private function buildSwimlineForArtifact(PFUser $user, Tracker_Artifact $artifact, Cardwall_OnTop_Config_ColumnCollection $columns) { |
|
76
|
|
|
$artifact_presenter = $this->presenter_builder->getCardInCellPresenter($artifact, $artifact->getId()); |
|
77
|
|
|
$children = $artifact->getChildrenForUser($user); |
|
78
|
|
|
|
|
79
|
|
|
if ($children) { |
|
|
|
|
|
|
80
|
|
|
$children_presenters = $this->presenter_builder->getCardInCellPresenters($children, $artifact->getId()); |
|
81
|
|
|
return $this->buildSwimline($artifact_presenter, $columns, $children_presenters); |
|
82
|
|
|
} else { |
|
83
|
|
|
return $this->buildSwimlineSolo($artifact, $artifact_presenter, $columns); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
private function buildSwimlineSolo(Tracker_Artifact $artifact, Cardwall_CardInCellPresenter $artifact_presenter, Cardwall_OnTop_Config_ColumnCollection $columns) { |
|
88
|
|
|
$cells = $this->swimline_factory->getCells($columns, array($artifact_presenter)); |
|
89
|
|
|
|
|
90
|
|
|
if ($this->areSwimlineCellsEmpty($cells)) { |
|
91
|
|
|
return $this->buildSwimlineSoloNoMatchingColumns($artifact_presenter, $artifact, $cells); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return new Cardwall_SwimlineSolo( |
|
95
|
|
|
$artifact->getId(), |
|
96
|
|
|
$cells |
|
97
|
|
|
); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
private function areSwimlineCellsEmpty(array $cells) { |
|
101
|
|
|
foreach ($cells as $cell) { |
|
102
|
|
|
if ($cell['cardincell_presenters']) { |
|
103
|
|
|
return false; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
return true; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
private function buildSwimline(Cardwall_CardInCellPresenter $artifact_presenter, Cardwall_OnTop_Config_ColumnCollection $columns, array $children_presenters) { |
|
111
|
|
|
return new Cardwall_Swimline( |
|
112
|
|
|
$artifact_presenter, |
|
113
|
|
|
$this->swimline_factory->getCells($columns, $children_presenters) |
|
114
|
|
|
); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
private function buildSwimlineSoloNoMatchingColumns(Cardwall_CardInCellPresenter $artifact_presenter, Tracker_Artifact $artifact, array $cells) { |
|
118
|
|
|
return new Cardwall_SwimlineSoloNoMatchingColumns( |
|
119
|
|
|
$artifact_presenter, |
|
120
|
|
|
$artifact, |
|
121
|
|
|
$cells |
|
122
|
|
|
); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
?> |
|
127
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.