Enalean /
tuleap
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Copyright (c) Enalean, 2012-2015. 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 | require_once 'common/TreeNode/TreeNodeMapper.class.php'; |
||
| 22 | require_once 'common/templating/TemplateRendererFactory.class.php'; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * A pane to be displayed in AgileDashboard |
||
| 26 | */ |
||
| 27 | class Cardwall_Pane extends AgileDashboard_Pane { |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var Cardwall_PaneInfo |
||
| 31 | */ |
||
| 32 | private $info; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var Planning_Milestone |
||
| 36 | */ |
||
| 37 | private $milestone; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var Cardwall_OnTop_Config |
||
| 41 | */ |
||
| 42 | private $config; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var PFUser |
||
| 46 | */ |
||
| 47 | private $user; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var Planning_MilestoneFactory |
||
| 51 | */ |
||
| 52 | private $milestone_factory; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var Tracker_ArtifactFactory |
||
| 56 | */ |
||
| 57 | private $artifact_factory; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var Tracker_FormElementFactory |
||
| 61 | */ |
||
| 62 | private $tracker_form_element_factory; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var UserManager |
||
| 66 | */ |
||
| 67 | private $user_manager; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var PlanningFactory |
||
| 71 | */ |
||
| 72 | private $planning_factory; |
||
| 73 | |||
| 74 | public function __construct( |
||
| 75 | Cardwall_PaneInfo $info, |
||
| 76 | Planning_Milestone $milestone, |
||
| 77 | Cardwall_OnTop_Config $config, |
||
| 78 | PFUser $user, |
||
| 79 | Planning_MilestoneFactory $milestone_factory |
||
| 80 | ) { |
||
| 81 | $this->info = $info; |
||
| 82 | $this->milestone = $milestone; |
||
| 83 | $this->config = $config; |
||
| 84 | $this->user = $user; |
||
| 85 | $this->milestone_factory = $milestone_factory; |
||
| 86 | $this->artifact_factory = Tracker_ArtifactFactory::instance(); |
||
| 87 | $this->tracker_form_element_factory = Tracker_FormElementFactory::instance(); |
||
| 88 | $this->user_manager = UserManager::instance(); |
||
| 89 | $this->planning_factory = PlanningFactory::build(); |
||
| 90 | } |
||
| 91 | |||
| 92 | public function getIdentifier() { |
||
| 93 | return $this->info->getIdentifier(); |
||
| 94 | } |
||
| 95 | |||
| 96 | public function getUriForMilestone(Planning_Milestone $milestone) { |
||
| 97 | return $this->info->getUriForMilestone($milestone); |
||
| 98 | } |
||
| 99 | |||
| 100 | |||
| 101 | /** |
||
| 102 | * @see AgileDashboard_Pane::getFullContent() |
||
| 103 | */ |
||
| 104 | public function getFullContent() { |
||
| 105 | return $this->getPaneContent('agiledashboard-fullpane'); |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @see AgileDashboard_Pane::getMinimalContent() |
||
| 110 | */ |
||
| 111 | public function getMinimalContent() { |
||
| 112 | return $this->getPaneContent('agiledashboard-minimalpane'); |
||
| 113 | } |
||
| 114 | |||
| 115 | private function getPaneContent($template) { |
||
| 116 | $event_manager = EventManager::instance(); |
||
| 117 | $columns = $this->config->getDashboardColumns(); |
||
| 118 | $renderer = TemplateRendererFactory::build()->getRenderer(dirname(__FILE__).'/../templates'); |
||
| 119 | $html = $renderer->renderToString($template, $this->getPresenterUsingMappedFields($columns)); |
||
| 120 | // TODO what if no semantic status and no mapping???? |
||
| 121 | |||
| 122 | $event_manager->processEvent(CARDWALL_EVENT_DISPLAYED, array('html' => &$html)); |
||
| 123 | |||
| 124 | return $html; |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @return Cardwall_PaneContentPresenter |
||
| 129 | */ |
||
| 130 | private function getPresenterUsingMappedFields(Cardwall_OnTop_Config_ColumnCollection $columns) { |
||
| 131 | $planning = $this->milestone->getPlanning(); |
||
| 132 | |||
| 133 | $raw_board_builder = new Cardwall_RawBoardBuilder(); |
||
| 134 | $display_preferences = $raw_board_builder->getDisplayPreferences($this->milestone, $this->user); |
||
| 135 | $column_preferences = new Cardwall_UserPreferences_Autostack_AutostackDashboard($this->user, $this->config->getTracker()); |
||
| 136 | $column_autostack = new Cardwall_UserPreferences_UserPreferencesAutostackFactory(); |
||
| 137 | $column_autostack->setAutostack($columns, $column_preferences); |
||
| 138 | |||
| 139 | $redirect_parameter = 'cardwall[agile]['. $planning->getId() .']='. $this->milestone->getArtifactId(); |
||
| 140 | |||
| 141 | $this->milestone = $this->milestone_factory->updateMilestoneContextualInfo($this->user, $this->milestone); |
||
| 142 | $board = $raw_board_builder->buildBoardUsingMappedFields($this->user, $this->artifact_factory,$this->milestone, $this->config, $columns); |
||
| 143 | |||
| 144 | return new Cardwall_PaneContentPresenter( |
||
| 145 | $board, |
||
| 146 | $redirect_parameter, |
||
| 147 | $this->getSwitchDisplayAvatarsURL(), |
||
|
0 ignored issues
–
show
Security
Bug
introduced
by
Loading history...
|
|||
| 148 | $display_preferences->shouldDisplayAvatars(), |
||
| 149 | $planning, |
||
| 150 | $this->milestone, |
||
| 151 | $this->getProgressPresenter() |
||
| 152 | ); |
||
| 153 | } |
||
| 154 | |||
| 155 | /** |
||
| 156 | * We display an effort based progress bar if and only if all backlog elements |
||
| 157 | * have an initial effort. Otherwise, you might ends with a progress bar at |
||
| 158 | * 100% done with cards "not done". |
||
| 159 | * |
||
| 160 | * @return Cardwall_EffortProgressPresenter |
||
| 161 | */ |
||
| 162 | private function getProgressPresenter() { |
||
| 163 | try { |
||
| 164 | return new Cardwall_RemainingEffortProgressPresenter( |
||
| 165 | $this->getInitialEffort(), |
||
| 166 | $this->milestone->getCapacity(), |
||
| 167 | $this->milestone->getRemainingEffort() |
||
| 168 | ); |
||
| 169 | } catch (InitialEffortNotDefinedException $exception) { |
||
| 170 | $status_count = $this->milestone_factory->getMilestoneStatusCount($this->user, $this->milestone); |
||
| 171 | return new Cardwall_OpenClosedEffortProgressPresenter( |
||
| 172 | $status_count[Tracker_Artifact::STATUS_OPEN], |
||
| 173 | $status_count[Tracker_Artifact::STATUS_CLOSED] |
||
| 174 | ); |
||
| 175 | } |
||
| 176 | } |
||
| 177 | |||
| 178 | private function getInitialEffort() { |
||
| 179 | $milestone_initial_effort = 0; |
||
| 180 | |||
| 181 | foreach ($this->getMilestoneContentItems() as $content) { |
||
|
0 ignored issues
–
show
|
|||
| 182 | $milestone_initial_effort = $this->addInitialEffort($milestone_initial_effort, $content->getInitialEffort()); |
||
| 183 | } |
||
| 184 | |||
| 185 | return $milestone_initial_effort; |
||
| 186 | } |
||
| 187 | |||
| 188 | /** |
||
| 189 | * This method ensures that initial effort is correctly defined |
||
| 190 | * for all the milestone's backlog items |
||
| 191 | * |
||
| 192 | * @param type $milestone_initial_effort |
||
| 193 | * @param type $backlog_item_initial_effort |
||
| 194 | * @return float |
||
| 195 | * |
||
| 196 | * @throws InitialEffortNotDefinedException |
||
| 197 | */ |
||
| 198 | private function addInitialEffort($milestone_initial_effort, $backlog_item_initial_effort) { |
||
| 199 | if (! is_null($backlog_item_initial_effort) && $backlog_item_initial_effort !== '' && $backlog_item_initial_effort >= 0) { |
||
| 200 | return $milestone_initial_effort + floatval($backlog_item_initial_effort); |
||
| 201 | } |
||
| 202 | |||
| 203 | throw new InitialEffortNotDefinedException(); |
||
| 204 | } |
||
| 205 | |||
| 206 | |||
| 207 | private function getMilestoneContentItems() { |
||
| 208 | $backlog_item_collection_factory = new AgileDashboard_Milestone_Backlog_BacklogItemCollectionFactory( |
||
| 209 | new AgileDashboard_BacklogItemDao(), |
||
| 210 | $this->artifact_factory, |
||
| 211 | $this->tracker_form_element_factory, |
||
| 212 | $this->milestone_factory, |
||
| 213 | $this->planning_factory, |
||
| 214 | new AgileDashboard_Milestone_Backlog_BacklogItemBuilder() |
||
| 215 | ); |
||
| 216 | |||
| 217 | $strategy_factory = new AgileDashboard_Milestone_Backlog_BacklogStrategyFactory( |
||
| 218 | new AgileDashboard_BacklogItemDao(), |
||
| 219 | $this->artifact_factory, |
||
| 220 | $this->planning_factory |
||
| 221 | ); |
||
| 222 | |||
| 223 | return $backlog_item_collection_factory->getAllCollection( |
||
| 224 | $this->user_manager->getCurrentUser(), |
||
| 225 | $this->milestone, |
||
| 226 | $strategy_factory->getSelfBacklogStrategy($this->milestone), |
||
| 227 | '' |
||
| 228 | ); |
||
| 229 | } |
||
| 230 | |||
| 231 | private function getSwitchDisplayAvatarsURL() { |
||
| 232 | if ($this->user->isAnonymous()) { |
||
| 233 | return false; |
||
| 234 | } |
||
| 235 | |||
| 236 | $group_id = $this->milestone->getGroupId(); |
||
| 237 | $planning_id = $this->milestone->getPlanningId(); |
||
| 238 | $tracker_id = $this->milestone->getTrackerId(); |
||
| 239 | $artifact_id = $this->milestone->getArtifactId(); |
||
| 240 | |||
| 241 | $action = 'toggle_user_display_avatar'; |
||
| 242 | |||
| 243 | $switch_display_username_url = |
||
| 244 | CARDWALL_BASE_URL |
||
| 245 | . '/?group_id=' . $group_id |
||
| 246 | . '&planning_id=' . $planning_id |
||
| 247 | . '&tracker_id=' . $tracker_id |
||
| 248 | . '&aid=' . $artifact_id |
||
| 249 | . '&action=' . $action; |
||
| 250 | |||
| 251 | return $switch_display_username_url; |
||
| 252 | } |
||
| 253 | } |
||
| 254 |