1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
|
<?php
/**
* FusionForge trackers
*
* Copyright 2011, Alcatel-Lucent
* Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
*
* This file is part of FusionForge. FusionForge is free software;
* you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software
* Foundation; either version 2 of the Licence, or (at your option)
* any later version.
*
* FusionForge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with FusionForge; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
* Standard Alcatel-Lucent disclaimer for contributing to open source
*
* "The Roadmap ("Contribution") has not been tested and/or
* validated for release as or in products, combinations with products or
* other commercial use. Any use of the Contribution is entirely made at
* the user's own responsibility and the user can not rely on any features,
* functionalities or performances Alcatel-Lucent has attributed to the
* Contribution.
*
* THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
* OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
* NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
* CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
* TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
* ALONE BASIS."
*/
require_once $gfcommon.'include/Error.class.php';
class Roadmap extends Error {
var $group;
var $group_id;
var $is_admin;
var $roadmap_id;
var $name;
var $enable;
var $release_order;
var $is_default;
var $data_array;
function __construct($group, $roadmap_id=0, $data=false) {
$this->Error();
if (is_object($group)) {
if ($group->isError()) {
$this->setError('in Roadmap, '.$group->getErrorMessage());
return;
}
$this->group = $group;
$this->group_id = $group->getID();
}
else {
$this->setError(_('Invalid Group'));
return;
}
/*if (! $this->userCanView()) {
$this->setPermissionDeniedError();
$this->data_array = null;
return false;
}*/
$this->roadmap_id = $roadmap_id;
$this->name = '';
$this->enable = 1;
$this->release_order = false;
$this->is_default = 0;
$this->data_array = array();
$this->_fetchData($data);
}
// Public methods
public function create($name) {
if (! $this->_isAdmin()) return false;
$result = db_query_params ('SELECT * FROM roadmap WHERE group_id=$1 AND name=$2',
array ($this->group_id, $name));
if ($result && db_numrows($result)) {
$this->setError(sprintf(_('ā%sā roadmap already exists'), $name));
return false;
}
$result = db_query_params('INSERT INTO roadmap (group_id, name, enable, release_order, is_default) VALUES ($1, $2, $3, $4, $5)',
array ($this->group_id,
$name,
$this->enable,
$this->release_order,
$this->is_default));
if (! $result) {
$this->setError('in create, '.db_error());
return false;
}
$this->roadmap_id = db_insertid($result, 'roadmap', 'roadmap_id');
$this->name = $name;
return true;
}
public function delete() {
if (! $this->_isAdmin()) return false;
$result = db_query_params('DELETE FROM roadmap_list WHERE roadmap_id=$1',
array ($this->roadmap_id));
if (! $result) {
$this->setError('in delete, '.db_error());
return false;
}
$result = db_query_params('DELETE FROM roadmap WHERE roadmap_id=$1',
array ($this->roadmap_id));
if (! $result) {
$this->setError('in delete, '.db_error());
return false;
}
$this->roadmap_id = 0;
$this->name = '';
$this->enable = 0;
$this->release_order = false;
$this->is_default = 0;
$this->data_array = array();
return true;
}
public function getID() {
return $this->roadmap_id;
}
public function rename($name) {
if (! $this->_isAdmin()) return false;
$result = db_query_params('UPDATE roadmap SET name=$1 WHERE roadmap_id=$2',
array ($name,
$this->roadmap_id));
if (! $result) {
$this->setError('in rename, '.db_error());
return false;
}
$this->name = $name;
return true;
}
public function getName() {
return $this->name;
}
public function enable() {
if (! $this->_isAdmin()) return false;
return $this->_setState(1);
}
public function disable() {
if (! $this->_isAdmin()) return false;
return $this->_setState(0);
}
public function setState($state) {
if (! $this->_isAdmin()) return false;
switch ($state) {
case 0:
case false:
$result = $this->disable();
break;
case 1:
case true:
$result = $this->enable();
break;
default:
$result = false;
break;
}
if (! $result) {
$this->setError('in setState, '.db_error());
}
return $result;
}
public function getState() {
return $this->enable;
}
public function setReleaseOrder($release_order) {
if (! $this->_isAdmin()) return false;
$result = db_query_params('UPDATE roadmap SET release_order=$1 WHERE roadmap_id=$2',
array (serialize($release_order),
$this->roadmap_id));
if (! $result) {
$this->setError('in setReleaseOrder, '.db_error());
return false;
}
$this->release_order = $release_order;
return true;
}
public function getReleaseOrder() {
return $this->release_order;
}
public function setDefault($default) {
if (! $this->_isAdmin()) return false;
$result = db_query_params('UPDATE roadmap SET is_default=$1 WHERE roadmap_id=$2',
array ($default,
$this->roadmap_id));
if (! $result) {
$this->setError('in setDefault, '.db_error());
return false;
}
$this->is_default = $default;
return true;
}
public function isDefault($default=-1) {
if ($default == -1) {
return $this->is_default;
}
else {
return $this->setDefault($default);
}
}
public function setList($arg1, $arg2=false) {
if (! $this->_isAdmin()) return false;
if (is_array($arg1)) {
db_begin();
foreach ($arg1 as $artifact_type_id => $field_id) {
$result = $this->_setList($artifact_type_id, $field_id);
if (!$result) {
db_rollback();
$this->_fetchData();
$this->setError('in setList, '.db_error());
return false;
}
}
db_commit();
}
else {
$result = $this->_setList($arg1, $arg2);
if (!$result) {
$this->_fetchData();
$this->setError('in setList, '.db_error());
return false;
}
}
return true;
}
public function getList($artifact_type_id=false) {
if ($artifact_type_id === false) {
return $this->data_array;
}
else {
if (array_key_exists($artifact_type_id, $this->data_array)) {
return $this->data_array[$artifact_type_id];
}
}
return false;
}
public function getReleases() {
$atf = new ArtifactTypeFactory($this->group);
if (!$atf || !is_object($atf) || $atf->isError()) {
$this->setError('in getReleases, could not get ArtifactTypeFactory');
}
$at_arr = $atf->getArtifactTypes();
if (!$at_arr || count($at_arr) < 1) {
return false;
}
$artifact_type_list = $this->getList();
$release_order = $this->getReleaseOrder();
$releases = array();
if (is_array($release_order)) {
foreach ($release_order as $release_value) {
$releases[$release_value] = false;
}
}
$releases2add = array();
foreach ($at_arr as $artifact_type) {
if (!is_object($artifact_type)) {
//just skip it
} elseif ($artifact_type->isError()) {
$this->setError($artifact_type->getErrorMessage());
// But continue?
} else {
if (! array_key_exists($artifact_type->getID(), $artifact_type_list) || ! $artifact_type_list[$artifact_type->getID()]) {
// This tracker is not used for the roadmap
continue;
}
$field_id = $artifact_type_list[$artifact_type->getID()];
$ath = new ArtifactTypeHtml($this->group, $artifact_type->getID());
if (!forge_check_perm ('tracker', $artifact_type->getID(), 'read')) {
continue;
}
$ef_elements = $ath->getExtraFieldElements($field_id);
if (is_array($ef_elements)) {
foreach ($ef_elements as $ef_element) {
$releases2add[] = $ef_element['element_name'];
}
}
}
}
usort($releases2add, 'version_compare');
foreach ($releases2add as $release_value) {
$releases[$release_value] = true;
}
// Remove release values of the release_order field (from 'roadmap' db table) that are no longer used
if (is_array($release_order)) {
foreach ($release_order as $release_value) {
if ($releases[$release_value] === false) {
unset($releases[$release_value]);
}
}
}
return array_keys($releases);
}
// Private methods
private function _fetchData($data=false) {
if (is_array($data)) {
foreach ($data as $key => $value) {
switch ((string)$key) {
case 'release_order':
if ($value) {
$this->release_order = unserialize($value);
}
else {
$this->release_order = array();
}
break;
case 'roadmap_id':
case 'group_id':
case 'name':
case 'enable':
case 'is_default':
$this->{$key} = $value;
break;
}
}
$this->data_array = $this->getList();
}
elseif (isset($this->roadmap_id) && $this->roadmap_id) {
$result = db_query_params ('SELECT * FROM roadmap WHERE roadmap_id=$1',
array ($this->roadmap_id));
if (! $result) {
$this->setError('in _fetchData, '.db_error());
return false;
}
if (db_numrows($result)) {
$this->name = db_result($result, 0, 'name');
$this->enable = db_result($result, 0, 'enable');
$tmp = db_result($result, 0, 'release_order');
if ($tmp) $this->release_order = unserialize($tmp);
$this->is_default = db_result($result, 0, 'is_default');
db_free_result($result);
}
}
if ($this->roadmap_id) {
$result = db_query_params ('SELECT * FROM roadmap_list WHERE roadmap_id=$1 ORDER BY artifact_type_id',
array ($this->roadmap_id));
if (! $result) {
$this->setError('in _fetchData, '.db_error());
return false;
}
while($entry = db_fetch_array($result)) {
$this->data_array[$entry['artifact_type_id']] = $entry['field_id'];
}
db_free_result($result);
}
return true;
}
private function _setState($state) {
$result = db_query_params('UPDATE roadmap SET enable=$1 WHERE group_id=$2 AND name=$3',
array ($state,
$this->group_id,
$this->name));
if (! $result) {
return false;
}
$this->enable = $state;
return true;
}
private function _insertList($artifact_type_id, $field_id) {
$result = db_query_params('INSERT INTO roadmap_list (roadmap_id, artifact_type_id, field_id) VALUES ($1, $2, $3)',
array ($this->roadmap_id,
$artifact_type_id,
$field_id));
if (! $result) {
return false;
}
$this->data_array[$artifact_type_id] = $field_id;
return true;
}
private function _updateList($artifact_type_id, $field_id) {
$result = db_query_params('UPDATE roadmap_list SET field_id=$1 WHERE roadmap_id=$2 AND artifact_type_id=$3',
array ($field_id,
$this->roadmap_id,
$artifact_type_id));
if (! $result) {
return false;
}
$this->data_array[$artifact_type_id] = $field_id;
return true;
}
private function _deleteList($artifact_type_id) {
$result = db_query_params('DELETE FROM roadmap_list WHERE roadmap_id=$1 AND artifact_type_id=$2',
array ($this->roadmap_id,
$artifact_type_id));
if (! $result) {
return false;
}
$this->data_array[$artifact_type_id] = 0;
return true;
}
private function _setList($artifact_type_id, $field_id) {
if (! $field_id) {
$result = $this->_deleteList($artifact_type_id);
}
elseif (array_key_exists($artifact_type_id, $this->data_array)) {
$result = $this->_updateList($artifact_type_id, $field_id);
}
else {
$result = $this->_insertList($artifact_type_id, $field_id);
}
return $result;
}
private function _isAdmin() {
if (isset($this->is_admin)) {
if ($this->is_admin) {
return true;
}
else {
$this->setPermissionDeniedError();
return false;
}
}
$perm =& $this->group->getPermission();
if (!$perm || !is_object($perm) || !$perm->isArtifactAdmin()) {
$this->setPermissionDeniedError();
return false;
}
return true;
}
}
|