@@ -991,6 +991,60 @@ public function getAssignmentRule()
991991 return $ assignment ;
992992 }
993993
994+ /**
995+ * Get user IDs from process variables for task assignment.
996+ *
997+ * Extracts user IDs and group IDs from form data based on the activity's
998+ * assignedUsers and assignedGroups properties. Retrieves all users from
999+ * specified groups (including subgroups recursively) and combines them
1000+ * with directly assigned users.
1001+ *
1002+ * Used when assignment rule is 'process_variable'.
1003+ *
1004+ * @param array $form_data Form data containing process variable values.
1005+ * Keys must match activity's assignedUsers and
1006+ * assignedGroups properties. Values must be arrays.
1007+ *
1008+ * @return array Unique numeric user IDs (direct users + users from groups).
1009+ */
1010+ public function getUsersFromProcessVariable (array $ form_data )
1011+ {
1012+ $ activity = $ this ->getBpmnDefinition ()->getBpmnElementInstance ();
1013+ $ assignedUsers = $ activity ->getProperty ('assignedUsers ' , null );
1014+ $ assignedGroups = $ activity ->getProperty ('assignedGroups ' , null );
1015+
1016+ $ usersIds = [];
1017+ $ groupsIds = [];
1018+
1019+ // Validate and get user IDs from form_data
1020+ if ($ assignedUsers && isset ($ form_data [$ assignedUsers ]) && is_array ($ form_data [$ assignedUsers ])) {
1021+ $ usersIds = $ form_data [$ assignedUsers ];
1022+ }
1023+
1024+ // Validate and get group IDs from form_data
1025+ if ($ assignedGroups && isset ($ form_data [$ assignedGroups ]) && is_array ($ form_data [$ assignedGroups ])) {
1026+ $ groupsIds = $ form_data [$ assignedGroups ];
1027+ }
1028+
1029+ // Get users from groups using the Process model method
1030+ $ usersFromGroups = [];
1031+ if (!empty ($ groupsIds ) && $ this ->process ) {
1032+ // Use the getConsolidatedUsers method from the Process model
1033+ // This method gets users from groups including subgroups recursively
1034+ $ this ->process ->getConsolidatedUsers ($ groupsIds , $ usersFromGroups );
1035+ }
1036+
1037+ // Combine direct users with users from groups
1038+ $ allUserIds = array_unique (array_merge ($ usersIds , $ usersFromGroups ));
1039+
1040+ // Convert to numeric array and filter valid values
1041+ $ allUserIds = array_values (array_filter ($ allUserIds , function ($ id ) {
1042+ return !empty ($ id ) && is_numeric ($ id ) && $ id > 0 ;
1043+ }));
1044+
1045+ return $ allUserIds ;
1046+ }
1047+
9941048 /**
9951049 * Get the assignees for the token.
9961050 *
0 commit comments