@@ -30,6 +30,7 @@ class ImportRelationshipTreeToCommand extends IndicatorPluginAbstract {
30
30
const OPTION_IS_ROOT_TASK_LIST = 'isRootTaskList ' ;
31
31
const OPTION_IS_INCLUDE_PARENT_ISSUE = 'isIncludeParentIssue ' ;
32
32
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)
33
34
34
35
private static $ logger ;
35
36
private static $ domains ;
@@ -41,7 +42,7 @@ class ImportRelationshipTreeToCommand extends IndicatorPluginAbstract {
41
42
private $ teamId ;
42
43
private $ issueId ;
43
44
private $ bugidList ;
44
- private $ commandId ;
45
+ private $ commandId = 0 ;
45
46
private $ command ;
46
47
private $ isRootTaskList ;
47
48
private $ isIncludeParentIssue ;
@@ -50,6 +51,7 @@ class ImportRelationshipTreeToCommand extends IndicatorPluginAbstract {
50
51
// internal
51
52
private $ sessionUserId ;
52
53
protected $ execData ;
54
+ private $ domain ;
53
55
54
56
55
57
/**
@@ -61,6 +63,7 @@ public static function staticInit() {
61
63
62
64
self ::$ domains = array (
63
65
self ::DOMAIN_IMPORT_EXPORT ,
66
+ self ::DOMAIN_COMMAND ,
64
67
);
65
68
self ::$ categories = array (
66
69
self ::CATEGORY_IMPORT
@@ -123,6 +126,27 @@ public function initialize(PluginDataProviderInterface $pluginDataProv) {
123
126
} else {
124
127
throw new Exception ("Missing parameter: " . PluginDataProviderInterface::PARAM_TEAM_ID );
125
128
}
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
+
126
150
$ this ->isRootTaskList = false ;
127
151
$ this ->isIncludeParentIssue = false ;
128
152
$ this ->isIncludeParentInItsOwnWbsFolder = true ;
@@ -257,6 +281,35 @@ private function addChild($issueId, $wbsRootId, $wbsParentId) {
257
281
return $ strActionLogs ;
258
282
}
259
283
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
+
260
313
/**
261
314
*
262
315
*/
@@ -265,16 +318,21 @@ public function execute() {
265
318
// check sesionUser must be Manager !
266
319
$ sessionUser = UserCache::getInstance ()->getUser ($ this ->sessionUserId );
267
320
$ accessDenied = $ sessionUser ->isTeamManager ($ this ->teamId ) ? '0 ' : '1 ' ;
321
+ $ team = TeamCache::getInstance ()->getTeam ($ this ->teamId );
268
322
269
323
// --- get command list
270
- $ team = TeamCache::getInstance ()->getTeam ($ this ->teamId );
271
- $ cmdList = $ team ->getCommands ();
272
324
$ 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
+ }
275
334
}
276
335
277
-
278
336
// --- get all tasks (regularProjects + sidetasksProjects)
279
337
$ hideStatusAndAbove = 0 ;
280
338
$ isHideResolved = false ;
@@ -294,9 +352,12 @@ public function execute() {
294
352
'teamCommands ' => $ teamCommands ,
295
353
'taskList ' => $ taskList ,
296
354
'accessDenied ' => $ accessDenied ,
297
- );
298
- return $ this ->execData ;
355
+ );
299
356
357
+ // preset Cmd default values
358
+ $ cmdOpts = $ this ->getCommandOptions ($ this ->commandId );
359
+ $ this ->execData = array_merge ($ this ->execData , $ cmdOpts );
360
+ return $ this ->execData ;
300
361
}
301
362
302
363
/**
@@ -309,18 +370,20 @@ public function getSmartyVariables($isAjaxCall = false) {
309
370
$ prefix ='ImportRelationshipTreeToCommand_ ' ;
310
371
311
372
$ taskListSmarty = SmartyTools::getSmartyArray ($ this ->execData ['taskList ' ], $ this ->issueId );
373
+ $ cmdListSmarty = SmartyTools::getSmartyArray ($ this ->execData ['teamCommands ' ], $ this ->commandId );
312
374
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
319
381
320
382
if (false == $ isAjaxCall ) {
321
383
$ smartyVariables [$ prefix .'ajaxFile ' ] = self ::getSmartySubFilename ();
322
384
$ smartyVariables [$ prefix .'ajaxPhpURL ' ] = self ::getAjaxPhpURL ();
323
385
}
386
+ //self::$logger->error("smartyVariables = ".var_export($smartyVariables, true));
324
387
return $ smartyVariables ;
325
388
}
326
389
0 commit comments