|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright Enalean (c) 2013. All rights reserved. |
|
4
|
|
|
* |
|
5
|
|
|
* Tuleap and Enalean names and logos are registrated trademarks owned by |
|
6
|
|
|
* Enalean SAS. All other trademarks or names are properties of their respective |
|
7
|
|
|
* owners. |
|
8
|
|
|
* |
|
9
|
|
|
* This file is a part of Tuleap. |
|
10
|
|
|
* |
|
11
|
|
|
* Tuleap is free software; you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU General Public License as published by |
|
13
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
|
14
|
|
|
* (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* Tuleap is distributed in the hope that it will be useful, |
|
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19
|
|
|
* GNU General Public License for more details. |
|
20
|
|
|
* |
|
21
|
|
|
* You should have received a copy of the GNU General Public License |
|
22
|
|
|
* along with Tuleap. If not, see <http://www.gnu.org/licenses/>. |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
class Cardwall_SingleCardBuilder { |
|
26
|
|
|
|
|
27
|
|
|
/** @var Cardwall_OnTop_ConfigFactory */ |
|
28
|
|
|
private $config_factory; |
|
29
|
|
|
|
|
30
|
|
|
/** @var UserManager */ |
|
31
|
|
|
private $card_fields; |
|
32
|
|
|
|
|
33
|
|
|
/** @var PlanningFactory */ |
|
34
|
|
|
private $planning_factory; |
|
35
|
|
|
|
|
36
|
|
|
/** @var Tracker_ArtifactFactory */ |
|
37
|
|
|
private $artifact_factory; |
|
38
|
|
|
|
|
39
|
|
|
public function __construct( |
|
40
|
|
|
Cardwall_OnTop_ConfigFactory $config_factory, |
|
41
|
|
|
Cardwall_CardFields $card_fields, |
|
42
|
|
|
Tracker_ArtifactFactory $artifact_factory, |
|
43
|
|
|
PlanningFactory $planning_factory |
|
44
|
|
|
) { |
|
45
|
|
|
$this->config_factory = $config_factory; |
|
46
|
|
|
$this->card_fields = $card_fields; |
|
47
|
|
|
$this->artifact_factory = $artifact_factory; |
|
48
|
|
|
$this->planning_factory = $planning_factory; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Return a new card controller |
|
53
|
|
|
* |
|
54
|
|
|
* @param Codendi_Request $request |
|
|
|
|
|
|
55
|
|
|
* |
|
56
|
|
|
* @return Cardwall_CardController |
|
57
|
|
|
* |
|
58
|
|
|
* @throws Exception |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getSingleCard(PFUser $user, $artifact_id, $planning_id) { |
|
61
|
|
|
$card_artifact = $this->getArtifact($artifact_id); |
|
62
|
|
|
$config = $this->getConfig($planning_id); |
|
63
|
|
|
$field_provider = $this->getFieldRetriever($config); |
|
64
|
|
|
$columns = $config->getDashboardColumns(); |
|
65
|
|
|
$display_preferences = new Cardwall_UserPreferences_UserPreferencesDisplayUser(Cardwall_UserPreferences_UserPreferencesDisplayUser::DISPLAY_AVATARS); |
|
66
|
|
|
|
|
67
|
|
|
$presenter_factory = $this->getCardInCellPresenterFactory($config, $card_artifact, $field_provider, $columns); |
|
68
|
|
|
|
|
69
|
|
|
$card_in_cell_presenter = $this->getCardInCellPresenter($presenter_factory, $user, $card_artifact, $this->card_fields, $display_preferences); |
|
70
|
|
|
|
|
71
|
|
|
return new Cardwall_SingleCard( |
|
72
|
|
|
$card_in_cell_presenter, |
|
73
|
|
|
$this->card_fields, |
|
74
|
|
|
$display_preferences, |
|
75
|
|
|
$this->getColumnId($card_artifact, $columns, $config, $field_provider), |
|
76
|
|
|
$config->getMappingFor($card_artifact->getTracker()) |
|
77
|
|
|
); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return Cardwall_CardInCellPresenter |
|
82
|
|
|
*/ |
|
83
|
|
|
protected function getCardInCellPresenter($presenter_factory, PFUser $user, Tracker_Artifact $artifact, Cardwall_CardFields $card_fields, Cardwall_UserPreferences_UserPreferencesDisplayUser $display_preferences) { |
|
84
|
|
|
return $presenter_factory->getCardInCellPresenter($this->getCardPresenter($user, $artifact, $card_fields, $display_preferences)); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return Cardwall_CardPresenter |
|
89
|
|
|
*/ |
|
90
|
|
|
private function getCardPresenter(PFUser $user, Tracker_Artifact $artifact, Cardwall_CardFields $card_fields, Cardwall_UserPreferences_UserPreferencesDisplayUser $display_preferences) { |
|
91
|
|
|
$parent_artifact = $artifact->getParent($user); |
|
92
|
|
|
|
|
93
|
|
|
return new Cardwall_CardPresenter( |
|
94
|
|
|
$artifact, |
|
95
|
|
|
$card_fields, |
|
96
|
|
|
$artifact->getCardAccentColor($user), |
|
97
|
|
|
$display_preferences, |
|
98
|
|
|
null, |
|
99
|
|
|
$artifact->getAllowedChildrenTypesForUser($user), |
|
100
|
|
|
$parent_artifact |
|
101
|
|
|
); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
private function getColumnId(Tracker_Artifact $artifact, Cardwall_OnTop_Config_ColumnCollection $columns, Cardwall_OnTop_Config $config, Cardwall_OnTop_Config_MappedFieldProvider $field_provider) { |
|
105
|
|
|
foreach ($columns as $column) { |
|
106
|
|
|
if ($config->isInColumn($artifact, $field_provider, $column)) { |
|
107
|
|
|
return $column->getId(); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
return -1; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
private function getArtifact($artifact_id) { |
|
114
|
|
|
$artifact = $this->artifact_factory->getArtifactById($artifact_id); |
|
115
|
|
|
if ($artifact) { |
|
116
|
|
|
return $artifact; |
|
117
|
|
|
} |
|
118
|
|
|
throw new CardControllerBuilderRequestIdException(); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
private function getConfig($planning_id) { |
|
122
|
|
|
$config = $this->config_factory->getOnTopConfigByPlanning($this->getPlanning($planning_id)); |
|
123
|
|
|
if ($config && $config->isEnabled()) { |
|
124
|
|
|
return $config; |
|
125
|
|
|
} |
|
126
|
|
|
throw new CardControllerBuilderRequestDataException(); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
private function getPlanning($planning_id) { |
|
130
|
|
|
$planning = $this->planning_factory->getPlanning($planning_id); |
|
131
|
|
|
if ($planning) { |
|
132
|
|
|
return $planning; |
|
133
|
|
|
} |
|
134
|
|
|
throw new CardControllerBuilderRequestPlanningIdException(); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
private function getFieldRetriever(Cardwall_OnTop_Config $config) { |
|
138
|
|
|
return new Cardwall_OnTop_Config_MappedFieldProvider( |
|
139
|
|
|
$config, |
|
140
|
|
|
new Cardwall_FieldProviders_SemanticStatusFieldRetriever() |
|
141
|
|
|
); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
private function getCardInCellPresenterFactory(Cardwall_OnTop_Config $config, Tracker_Artifact $artifact, Cardwall_FieldProviders_IProvideFieldGivenAnArtifact $field_provider, Cardwall_OnTop_Config_ColumnCollection $columns) { |
|
145
|
|
|
$field = $field_provider->getField($artifact->getTracker()); |
|
146
|
|
|
$status_fields[$field->getId()] = $field; |
|
147
|
|
|
return new Cardwall_CardInCellPresenterFactory( |
|
148
|
|
|
$field_provider, |
|
149
|
|
|
$config->getCardwallMappings($status_fields, $columns) |
|
150
|
|
|
); |
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
?> |
|
155
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.