Skip to content

Commit e8c3383

Browse files
committed
plugin importRelationshipTreeToCommand: save settings
allow in cmd dashboard
1 parent 058faeb commit e8c3383

File tree

6 files changed

+226
-76
lines changed

6 files changed

+226
-76
lines changed

classes/config.class.php

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class Config {
124124
const id_schedulerOptions = 'schedulerOptions';
125125
const id_blogPluginOptions = 'blogPluginOptions';
126126
const id_userGroups = 'userGroups';
127+
const id_importRelationshipTreeToCommandOptions = 'importRelationshipTreeToCommandOptions';
127128

128129
const default_timetrackingFilters = "onlyAssignedTo:0,hideResolved:0,hideForbidenStatus:1";
129130
const default_timetrackingForbidenStatusList = "90"; // 90:closed (do not include 'new')

import/import_dashboard.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php
22
require('../include/session.inc.php');
33
/*
44
This file is part of CodevTT
@@ -20,16 +20,16 @@
2020
require('../path.inc.php');
2121

2222
class ImportDashboardController extends Controller {
23-
23+
2424
/**
2525
* @var Logger The logger
2626
*/
27-
private static $logger;
28-
27+
private static $logger;
28+
2929
public static function staticInit() {
3030
self::$logger = Logger::getLogger(__CLASS__);
3131
}
32-
32+
3333
protected function display() {
3434
if (Tools::isConnectedUser()) {
3535

@@ -38,9 +38,11 @@ protected function display() {
3838

3939
// feed the PluginDataProvider
4040
$pluginDataProvider = PluginDataProvider::getInstance();
41+
$dashboardDomain = IndicatorPluginInterface::DOMAIN_IMPORT_EXPORT;
4142
$pluginDataProvider->setParam(PluginDataProviderInterface::PARAM_SESSION_USER_ID, $this->session_userid);
4243
$pluginDataProvider->setParam(PluginDataProviderInterface::PARAM_TEAM_ID, $this->teamid);
4344
$pluginDataProvider->setParam(PluginDataProviderInterface::PARAM_PROJECT_ID, $project_id);
45+
$pluginDataProvider->setParam(PluginDataProviderInterface::PARAM_DOMAIN, $dashboardDomain);
4446

4547
$dashboardName = 'Import'.$this->teamid;
4648

@@ -49,7 +51,7 @@ protected function display() {
4951

5052
// create the Dashboard
5153
$dashboard = new Dashboard($dashboardName);
52-
$dashboard->setDomain(IndicatorPluginInterface::DOMAIN_IMPORT_EXPORT);
54+
$dashboard->setDomain($dashboardDomain);
5355
$dashboard->setCategories(array(
5456
IndicatorPluginInterface::CATEGORY_IMPORT,
5557
));

management/command_tools.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private static function getProvisionList(Command $command, int $type = NULL) {
9898

9999
$formatedSummary = str_replace("'", "\'", $prov->getSummary());
100100
$formatedSummary = str_replace('"', "\'", $formatedSummary);
101-
101+
102102
$provArray["$id"] = array(
103103
'id' => $id,
104104
'date' => date("Y-m-d", $prov->getDate()),
@@ -122,12 +122,12 @@ private static function getProvisionList(Command $command, int $type = NULL) {
122122
private static function getProvisionTotalList(Command $command, $teamCurrency, int $type = NULL) {
123123

124124
$provTotalArray = NULL;
125-
125+
126126
// compute data
127127
$provisions = $command->getProvisionList($type);
128-
128+
129129
if (!empty($provisions)) {
130-
130+
131131
foreach ($provisions as $id => $prov) {
132132

133133
// a provision
@@ -295,12 +295,12 @@ public static function displayCommand(SmartyHelper $smartyHelper, Command $cmd,
295295
$cmdIssueSel = $cmd->getIssueSelection();
296296
$smartyHelper->assign('cmdNbIssues', $cmdIssueSel->getNbIssues());
297297
$smartyHelper->assign('cmdIssues', self::getCommandIssues($cmd));
298-
298+
299299
// used to create mantis link to view_all_bug_page.php:
300300
// view_all_set.php?type=1&temporary=y&FilterBugList_list=5079,5073,5108,5107,49396,5006
301301
#$mantisFilterBugList= implode(',', array_keys($cmdIssueSel->getIssueList()));
302302
#$smartyHelper->assign('mantisFilterBugList', $mantisFilterBugList);
303-
303+
304304
}
305305

306306
/**
@@ -341,6 +341,7 @@ public static function dashboardSettings(SmartyHelper $smartyHelper, Command $cm
341341
IndicatorPluginInterface::CATEGORY_PLANNING,
342342
IndicatorPluginInterface::CATEGORY_RISK,
343343
IndicatorPluginInterface::CATEGORY_FINANCIAL,
344+
IndicatorPluginInterface::CATEGORY_IMPORT,
344345
));
345346
$dashboard->setTeamid($cmd->getTeamid());
346347
$dashboard->setUserid($userid);

plugins/ImportRelationshipTreeToCommand/ImportRelationshipTreeToCommand.class.php

+77-14
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class ImportRelationshipTreeToCommand extends IndicatorPluginAbstract {
3030
const OPTION_IS_ROOT_TASK_LIST = 'isRootTaskList';
3131
const OPTION_IS_INCLUDE_PARENT_ISSUE = 'isIncludeParentIssue';
3232
const OPTION_IS_INCLUDE_PARENT_IN_ITS_OWN_WBS = 'isIncludeParentInItsOwnWbsFolder';
33+
const OPTION_IS_RESET_WBS = 'isResetWBS'; // remove all tasks & folders before the import (full reload)
3334

3435
private static $logger;
3536
private static $domains;
@@ -41,7 +42,7 @@ class ImportRelationshipTreeToCommand extends IndicatorPluginAbstract {
4142
private $teamId;
4243
private $issueId;
4344
private $bugidList;
44-
private $commandId;
45+
private $commandId = 0;
4546
private $command;
4647
private $isRootTaskList;
4748
private $isIncludeParentIssue;
@@ -50,6 +51,7 @@ class ImportRelationshipTreeToCommand extends IndicatorPluginAbstract {
5051
// internal
5152
private $sessionUserId;
5253
protected $execData;
54+
private $domain;
5355

5456

5557
/**
@@ -61,6 +63,7 @@ public static function staticInit() {
6163

6264
self::$domains = array (
6365
self::DOMAIN_IMPORT_EXPORT,
66+
self::DOMAIN_COMMAND,
6467
);
6568
self::$categories = array (
6669
self::CATEGORY_IMPORT
@@ -123,6 +126,27 @@ public function initialize(PluginDataProviderInterface $pluginDataProv) {
123126
} else {
124127
throw new Exception("Missing parameter: " . PluginDataProviderInterface::PARAM_TEAM_ID);
125128
}
129+
130+
if (NULL != $pluginDataProv->getParam(PluginDataProviderInterface::PARAM_DOMAIN)) {
131+
$this->domain = $pluginDataProv->getParam(PluginDataProviderInterface::PARAM_DOMAIN);
132+
} else {
133+
throw new Exception('Missing parameter: '.PluginDataProviderInterface::PARAM_DOMAIN);
134+
}
135+
switch ($this->domain) {
136+
case IndicatorPluginInterface::DOMAIN_IMPORT_EXPORT:
137+
// none
138+
break;
139+
case IndicatorPluginInterface::DOMAIN_COMMAND:
140+
if (NULL != $pluginDataProv->getParam(PluginDataProviderInterface::PARAM_COMMAND_ID)) {
141+
$this->commandId = $pluginDataProv->getParam(PluginDataProviderInterface::PARAM_COMMAND_ID);
142+
} else {
143+
throw new Exception('Missing parameter: '.PluginDataProviderInterface::PARAM_COMMAND_ID);
144+
}
145+
break;
146+
default:
147+
throw new Exception('Missing parameter related to domain : '.$this->domain);
148+
}
149+
126150
$this->isRootTaskList = false;
127151
$this->isIncludeParentIssue = false;
128152
$this->isIncludeParentInItsOwnWbsFolder = true;
@@ -257,6 +281,35 @@ private function addChild($issueId, $wbsRootId, $wbsParentId) {
257281
return $strActionLogs;
258282
}
259283

284+
private function getCommandOptions($commandId = 0) {
285+
286+
// default values
287+
$cmdOptions = array(
288+
'isRootTaskList' => 0, // determinates selected radioButton
289+
'bugidList' => '', // comma separated bugId list
290+
'isIncludeParentIssue' => 0,
291+
'isIncludeParentInItsOwnWbsFolder' => 1,
292+
);
293+
294+
if (0 !== $commandId) {
295+
$keyExists = Config::keyExists(Config::id_importRelationshipTreeToCommandOptions, array(0, 0, 0, 0, 0, $commandId));
296+
if (false != $keyExists) {
297+
$jsonOptions = Config::getValue(Config::id_importRelationshipTreeToCommandOptions, array(0, 0, 0, 0, 0, $commandId), true);
298+
if (null != $jsonOptions) {
299+
$options = json_decode($jsonOptions, true);
300+
if (is_null($options)) {
301+
self::$logger->error('ERROR: could not read settings for command '.$commandId);
302+
} else {
303+
$cmdOptions = $options;
304+
$cmdOptions['isRootTaskList'] = 1; // use this option even if only one issue
305+
}
306+
}
307+
}
308+
}
309+
//self::$logger->error("cmdOptions $commandId = ".var_export($cmdOptions, true));
310+
return $cmdOptions;
311+
}
312+
260313
/**
261314
*
262315
*/
@@ -265,16 +318,21 @@ public function execute() {
265318
// check sesionUser must be Manager !
266319
$sessionUser = UserCache::getInstance()->getUser($this->sessionUserId);
267320
$accessDenied = $sessionUser->isTeamManager($this->teamId) ? '0' : '1';
321+
$team = TeamCache::getInstance()->getTeam($this->teamId);
268322

269323
// --- get command list
270-
$team = TeamCache::getInstance()->getTeam($this->teamId);
271-
$cmdList= $team->getCommands();
272324
$teamCommands = array();
273-
foreach($cmdList as $cmdId => $cmd) {
274-
$teamCommands[$cmdId] = $cmd->getName();
325+
if (IndicatorPluginInterface::DOMAIN_COMMAND === $this->domain) {
326+
$cmd = CommandCache::getInstance()->getCommand($this->commandId);
327+
$teamCommands[$this->commandId] = $cmd->getName();
328+
} else {
329+
$teamCommands[0] = ' '; // default: none selected
330+
$cmdList= $team->getCommands();
331+
foreach($cmdList as $cmdId => $cmd) {
332+
$teamCommands[$cmdId] = $cmd->getName();
333+
}
275334
}
276335

277-
278336
// --- get all tasks (regularProjects + sidetasksProjects)
279337
$hideStatusAndAbove = 0;
280338
$isHideResolved = false;
@@ -294,9 +352,12 @@ public function execute() {
294352
'teamCommands' => $teamCommands,
295353
'taskList' => $taskList,
296354
'accessDenied' => $accessDenied,
297-
);
298-
return $this->execData;
355+
);
299356

357+
// preset Cmd default values
358+
$cmdOpts = $this->getCommandOptions($this->commandId);
359+
$this->execData = array_merge($this->execData, $cmdOpts);
360+
return $this->execData;
300361
}
301362

302363
/**
@@ -309,18 +370,20 @@ public function getSmartyVariables($isAjaxCall = false) {
309370
$prefix='ImportRelationshipTreeToCommand_';
310371

311372
$taskListSmarty = SmartyTools::getSmartyArray($this->execData['taskList'], $this->issueId);
373+
$cmdListSmarty = SmartyTools::getSmartyArray($this->execData['teamCommands'], $this->commandId);
312374

313-
314-
$smartyVariables = array(
315-
$prefix.'teamCommands' => $this->execData['teamCommands'],
316-
$prefix.'taskList' => $taskListSmarty,
317-
$prefix.'accessDenied' => $this->execData['accessDenied'],
318-
);
375+
$smartyVariables = array();
376+
foreach($this->execData as $key => $data) {
377+
$smartyVariables[$prefix.$key] = $data;
378+
}
379+
$smartyVariables[$prefix.'taskList'] = $taskListSmarty; // override
380+
$smartyVariables[$prefix.'teamCommands'] = $cmdListSmarty; // override
319381

320382
if (false == $isAjaxCall) {
321383
$smartyVariables[$prefix.'ajaxFile'] = self::getSmartySubFilename();
322384
$smartyVariables[$prefix.'ajaxPhpURL'] = self::getAjaxPhpURL();
323385
}
386+
//self::$logger->error("smartyVariables = ".var_export($smartyVariables, true));
324387
return $smartyVariables;
325388
}
326389

0 commit comments

Comments
 (0)