5 * Copyright 2011, Alcatel-Lucent
6 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * Standard Alcatel-Lucent disclaimer for contributing to open source
27 * "The Roadmap ("Contribution") has not been tested and/or
28 * validated for release as or in products, combinations with products or
29 * other commercial use. Any use of the Contribution is entirely made at
30 * the user's own responsibility and the user can not rely on any features,
31 * functionalities or performances Alcatel-Lucent has attributed to the
34 * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
35 * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
36 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
37 * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
38 * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
39 * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
40 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
41 * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
42 * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
46 require_once $gfcommon.'include/FFError.class.php';
48 class Roadmap extends FFError {
63 function __construct($group, $roadmap_id=0, $data=false) {
64 parent::__construct();
66 if (is_object($group)) {
67 if ($group->isError()) {
68 $this->setError('in Roadmap, '.$group->getErrorMessage());
71 $this->group = $group;
72 $this->group_id = $group->getID();
74 $this->setError(_('Invalid Project'));
78 /*if (! $this->userCanView()) {
79 $this->setPermissionDeniedError();
80 $this->data_array = null;
84 $this->roadmap_id = $roadmap_id;
87 $this->release_order = false;
88 $this->is_default = 0;
90 $this->data_array = array();
91 $this->_fetchData($data);
96 public function create($name) {
97 if (! $this->_isAdmin()) {
100 $result = db_query_params ('SELECT * FROM roadmap WHERE group_id=$1 AND name=$2',
101 array ($this->group_id, $name));
102 if ($result && db_numrows($result)) {
103 $this->setError(sprintf(_('ā%sā roadmap already exists'), $name));
107 $result = db_query_params('INSERT INTO roadmap (group_id, name, enable, release_order, is_default) VALUES ($1, $2, $3, $4, $5)',
108 array ($this->group_id,
111 $this->release_order,
114 $this->setError('in create, '.db_error());
117 $this->roadmap_id = db_insertid($result, 'roadmap', 'roadmap_id');
122 public function delete() {
123 if (!$this->_isAdmin()) {
126 $result = db_query_params('DELETE FROM roadmap_list WHERE roadmap_id=$1',
127 array ($this->roadmap_id));
129 $this->setError('in delete, '.db_error());
132 $result = db_query_params('DELETE FROM roadmap WHERE roadmap_id=$1',
133 array ($this->roadmap_id));
135 $this->setError('in delete, '.db_error());
138 $this->roadmap_id = 0;
141 $this->release_order = false;
142 $this->is_default = 0;
143 $this->data_array = array();
147 public function getID() {
148 return $this->roadmap_id;
151 public function rename($name) {
152 if (!$this->_isAdmin()) {
156 $result = db_query_params('UPDATE roadmap SET name=$1 WHERE roadmap_id=$2',
160 $this->setError('in rename, '.db_error());
167 public function getName() {
171 public function enable() {
172 if (! $this->_isAdmin()) {
175 return $this->_setState(1);
178 public function disable() {
179 if (! $this->_isAdmin()) {
182 return $this->_setState(0);
185 public function setState($state) {
186 if (! $this->_isAdmin()) {
192 $result = $this->disable();
197 $result = $this->enable();
206 $this->setError('in setState, '.db_error());
212 public function getState() {
213 return $this->enable;
216 public function setReleaseOrder($release_order) {
217 if (! $this->_isAdmin()) {
220 $result = db_query_params('UPDATE roadmap SET release_order=$1 WHERE roadmap_id=$2',
221 array (serialize($release_order),
224 $this->setError('in setReleaseOrder, '.db_error());
227 $this->release_order = $release_order;
231 public function getReleaseOrder() {
232 return $this->release_order;
235 public function setDefault($default) {
236 if (! $this->_isAdmin()) {
239 $result = db_query_params('UPDATE roadmap SET is_default=$1 WHERE roadmap_id=$2',
243 $this->setError('in setDefault, '.db_error());
246 $this->is_default = $default;
250 public function isDefault($default=-1) {
251 if ($default == -1) {
252 return $this->is_default;
255 return $this->setDefault($default);
259 public function setList($arg1, $arg2=false) {
260 if (! $this->_isAdmin()) {
263 if (is_array($arg1)) {
265 foreach ($arg1 as $artifact_type_id => $field_id) {
266 $result = $this->_setList($artifact_type_id, $field_id);
270 $this->setError('in setList, '.db_error());
277 $result = $this->_setList($arg1, $arg2);
280 $this->setError('in setList, '.db_error());
288 public function getList($artifact_type_id=false) {
289 if ($artifact_type_id === false) {
290 return $this->data_array;
293 if (array_key_exists($artifact_type_id, $this->data_array)) {
294 return $this->data_array[$artifact_type_id];
301 public function getReleases() {
302 $atf = new ArtifactTypeFactory($this->group);
303 if (!$atf || !is_object($atf) || $atf->isError()) {
304 $this->setError('in getReleases, could not get ArtifactTypeFactory');
307 $at_arr = $atf->getArtifactTypes();
308 if (!$at_arr || count($at_arr) < 1) {
312 $artifact_type_list = $this->getList();
313 $release_order_arr = $this->getReleaseOrder();
317 if (is_array($release_order_arr)) {
318 foreach ($release_order_arr as $release_value) {
319 $releases[$release_value] = false;
323 $releases2add = array();
324 foreach ($at_arr as $artifact_type) {
325 if (!is_object($artifact_type)) {
327 } elseif ($artifact_type->isError()) {
328 $this->setError($artifact_type->getErrorMessage());
332 if (! array_key_exists($artifact_type->getID(), $artifact_type_list) || ! $artifact_type_list[$artifact_type->getID()]) {
333 // This tracker is not used for the roadmap
336 $field_id = $artifact_type_list[$artifact_type->getID()];
338 $ath = new ArtifactTypeHtml($this->group, $artifact_type->getID());
340 if (!forge_check_perm ('tracker', $artifact_type->getID(), 'read')) {
344 $ef_elements = $ath->getExtraFieldElements($field_id);
345 if (is_array($ef_elements)) {
346 foreach ($ef_elements as $ef_element) {
347 $releases2add[] = $ef_element['element_name'];
353 usort($releases2add, 'version_compare');
354 foreach ($releases2add as $release_value) {
355 $releases[$release_value] = true;
358 // Remove release values of the release_order field (from 'roadmap' db table) that are no longer used
359 if (is_array($release_order)) {
360 foreach ($release_order as $release_value) {
361 if ($releases[$release_value] === false) {
362 unset($releases[$release_value]);
367 return array_keys($releases);
372 private function _fetchData($data=false) {
373 if (is_array($data)) {
374 foreach ($data as $key => $value) {
375 switch ((string)$key) {
376 case 'release_order':
378 $this->release_order = unserialize($value);
380 $this->release_order = array();
389 $this->{$key} = $value;
393 $this->data_array = $this->getList();
394 } elseif (isset($this->roadmap_id) && $this->roadmap_id) {
395 $result = db_query_params ('SELECT * FROM roadmap WHERE roadmap_id=$1',
396 array ($this->roadmap_id));
398 $this->setError('in _fetchData, '.db_error());
401 if (db_numrows($result)) {
402 $this->name = db_result($result, 0, 'name');
403 $this->enable = db_result($result, 0, 'enable');
404 $tmp = db_result($result, 0, 'release_order');
406 $this->release_order = unserialize($tmp);
408 $this->is_default = db_result($result, 0, 'is_default');
409 db_free_result($result);
413 if ($this->roadmap_id) {
414 $result = db_query_params ('SELECT * FROM roadmap_list WHERE roadmap_id=$1 ORDER BY artifact_type_id',
415 array ($this->roadmap_id));
417 $this->setError('in _fetchData, '.db_error());
420 while($entry = db_fetch_array($result)) {
421 $this->data_array[$entry['artifact_type_id']] = $entry['field_id'];
423 db_free_result($result);
429 private function _setState($state) {
430 $result = db_query_params('UPDATE roadmap SET enable=$1 WHERE group_id=$2 AND name=$3',
438 $this->enable = $state;
442 private function _insertList($artifact_type_id, $field_id) {
443 $result = db_query_params('INSERT INTO roadmap_list (roadmap_id, artifact_type_id, field_id) VALUES ($1, $2, $3)',
444 array ($this->roadmap_id,
450 $this->data_array[$artifact_type_id] = $field_id;
454 private function _updateList($artifact_type_id, $field_id) {
455 $result = db_query_params('UPDATE roadmap_list SET field_id=$1 WHERE roadmap_id=$2 AND artifact_type_id=$3',
462 $this->data_array[$artifact_type_id] = $field_id;
466 private function _deleteList($artifact_type_id) {
467 $result = db_query_params('DELETE FROM roadmap_list WHERE roadmap_id=$1 AND artifact_type_id=$2',
468 array ($this->roadmap_id,
473 $this->data_array[$artifact_type_id] = 0;
477 private function _setList($artifact_type_id, $field_id) {
479 $result = $this->_deleteList($artifact_type_id);
480 } elseif (array_key_exists($artifact_type_id, $this->data_array)) {
481 $result = $this->_updateList($artifact_type_id, $field_id);
483 $result = $this->_insertList($artifact_type_id, $field_id);
488 private function _isAdmin() {
489 if (isset($this->is_admin)) {
490 if ($this->is_admin) {
493 $this->setPermissionDeniedError();
497 $perm =& $this->group->getPermission();
499 if (!$perm || !is_object($perm) || !$perm->isArtifactAdmin()) {
500 $this->setPermissionDeniedError();