@@ -41,6 +41,11 @@ class PluginFormcreatorFormAnswer extends CommonDBTM
41
41
public $ usenotepad = true ;
42
42
public $ usenotepadrights = true ;
43
43
44
+ /**
45
+ * Generated targets after creation of a form answer
46
+ *
47
+ * @var array
48
+ */
44
49
public $ targetList = [];
45
50
46
51
const SOPTION_ANSWER = 900000 ;
@@ -1064,7 +1069,7 @@ public function post_addItem() {
1064
1069
}
1065
1070
}
1066
1071
$ this ->createIssue ();
1067
- $ minimalStatus = $ formAnswer ->getMinimalStatus ();
1072
+ $ minimalStatus = $ formAnswer ->getAggregatedStatus ();
1068
1073
if ($ minimalStatus !== null ) {
1069
1074
$ this ->updateStatus ($ minimalStatus );
1070
1075
}
@@ -1114,7 +1119,7 @@ public function post_updateItem($history = 1) {
1114
1119
}
1115
1120
}
1116
1121
$ this ->updateIssue ();
1117
- $ minimalStatus = $ formAnswer ->getMinimalStatus ();
1122
+ $ minimalStatus = $ formAnswer ->getAggregatedStatus ();
1118
1123
if ($ minimalStatus !== null ) {
1119
1124
$ this ->updateStatus ($ minimalStatus );
1120
1125
}
@@ -1801,6 +1806,7 @@ public function getCurrentApprovers(): ?array {
1801
1806
1802
1807
/**
1803
1808
* get all generated targets by the form answer
1809
+ * populates the generated targets associated to the instance
1804
1810
*
1805
1811
* @return array An array of target itemtypes to track
1806
1812
*/
@@ -1818,7 +1824,8 @@ public function getGeneratedTargets($itemtypes = []): array {
1818
1824
$ itemtypes = array_intersect (PluginFormcreatorForm::getTargetTypes (), $ itemtypes );
1819
1825
}
1820
1826
/** @var PluginFormcreatorTargetInterface $targetType */
1821
- foreach ($ itemtypes as $ targetType ) {
1827
+ $ this ->targetList = [];
1828
+ foreach (PluginFormcreatorForm::getTargetTypes () as $ targetType ) {
1822
1829
$ targetItem = new $ targetType ();
1823
1830
$ generatedType = $ targetItem ->getTargetItemtypeName ();
1824
1831
$ relationType = $ targetItem ->getItem_Item ();
@@ -1841,12 +1848,16 @@ public function getGeneratedTargets($itemtypes = []): array {
1841
1848
"$ relationTable.items_id " => $ this ->getID (),
1842
1849
],
1843
1850
]);
1844
- foreach ($ iterator as $ row ) {
1851
+ foreach ($ iterator as $ row ) {
1845
1852
/** @var $item CommonDBTM */
1846
1853
$ item = new $ generatedType ();
1847
1854
$ item ->getFromResultSet ($ row );
1848
- $ targets [] = $ item ;
1849
1855
$ this ->targetList [] = clone $ item ;
1856
+ // skip not wanted itemtypes
1857
+ if (!in_array ($ targetType , $ itemtypes )) {
1858
+ continue ;
1859
+ }
1860
+ $ targets [] = $ item ;
1850
1861
}
1851
1862
}
1852
1863
@@ -1858,9 +1869,13 @@ public function getGeneratedTargets($itemtypes = []): array {
1858
1869
*
1859
1870
* @return null|int
1860
1871
*/
1861
- public function getMinimalStatus (): ?int {
1872
+ public function getAggregatedStatus (): ?int {
1862
1873
$ generatedTargets = $ this ->getGeneratedTargets ([PluginFormcreatorTargetTicket::getType ()]);
1863
1874
1875
+ $ isWaiting = false ;
1876
+ $ isAssigned = false ;
1877
+ $ isProcessing = false ;
1878
+
1864
1879
// Find the minimal status of the first generated tickets in the array (deleted items excluded)
1865
1880
$ generatedTarget = array_shift ($ generatedTargets );
1866
1881
while ($ generatedTarget !== null && $ generatedTarget ->fields ['is_deleted ' ]) {
@@ -1871,8 +1886,19 @@ public function getMinimalStatus(): ?int {
1871
1886
return null ;
1872
1887
}
1873
1888
1874
- // Find the minimal status of all (not deleted) generated targets
1875
- $ minimalStatus = PluginFormcreatorCommon::getTicketStatusForIssue ($ generatedTarget );
1889
+ // Find status of the first ticket in the array
1890
+ $ aggregatedStatus = PluginFormcreatorCommon::getTicketStatusForIssue ($ generatedTarget );
1891
+ if ($ aggregatedStatus == CommonITILObject::ASSIGNED ) {
1892
+ $ isAssigned = true ;
1893
+ }
1894
+ if ($ aggregatedStatus == CommonITILObject::PLANNED ) {
1895
+ $ isProcessing = true ;
1896
+ }
1897
+ if ($ aggregatedStatus == CommonITILObject::WAITING ) {
1898
+ $ isWaiting = true ;
1899
+ }
1900
+
1901
+ // Traverse all other tickets and set the minimal status
1876
1902
foreach ($ generatedTargets as $ generatedTarget ) {
1877
1903
/** @var Ticket $generatedTarget */
1878
1904
if ($ generatedTarget ::getType () != Ticket::getType ()) {
@@ -1885,10 +1911,33 @@ public function getMinimalStatus(): ?int {
1885
1911
if ($ ticketStatus >= PluginFormcreatorFormAnswer::STATUS_WAITING ) {
1886
1912
continue ;
1887
1913
}
1888
- $ minimalStatus = min ($ minimalStatus , $ ticketStatus );
1914
+
1915
+ if ($ ticketStatus == CommonITILObject::ASSIGNED ) {
1916
+ $ isAssigned = true ;
1917
+ }
1918
+ if ($ ticketStatus == CommonITILObject::PLANNED ) {
1919
+ $ isProcessing = true ;
1920
+ }
1921
+ if ($ ticketStatus == CommonITILObject::WAITING ) {
1922
+ $ isWaiting = true ;
1923
+ }
1924
+ $ aggregatedStatus = min ($ aggregatedStatus , $ ticketStatus );
1925
+ }
1926
+
1927
+ // Assigned status takes precedence
1928
+ if ($ isAssigned ) {
1929
+ $ aggregatedStatus = CommonITILObject::ASSIGNED ;
1930
+ }
1931
+ // Planned status takes precedence
1932
+ if ($ isProcessing ) {
1933
+ $ aggregatedStatus = CommonITILObject::PLANNED ;
1934
+ }
1935
+ // Waiting status takes precedence to inform the requester his feedback is required
1936
+ if ($ isWaiting ) {
1937
+ $ aggregatedStatus = CommonITILObject::WAITING ;
1889
1938
}
1890
1939
1891
- return $ minimalStatus ;
1940
+ return $ aggregatedStatus ;
1892
1941
}
1893
1942
1894
1943
/**
0 commit comments