public function refresh_assignees() { $results = array('removed' => array(), 'added' => array()); $current_step_id = $this->get_current_feed_id(); $form_id = absint(rgget('id')); $current_step = $this->get_step($current_step_id); $entry_count = $current_step->entry_count(); if ($entry_count == 0) { // Nothing to do return $results; } $form = $this->get_current_form(); // Avoid paging through entries from GFAPI::get_entries() by using custom query. $assignee_status_by_entry = $this->get_asssignee_status_by_entry($form['id']); foreach ($assignee_status_by_entry as $entry_id => $assignee_status) { $entry = GFAPI::get_entry($entry_id); $step_for_entry = $this->get_step($current_step_id, $entry); if ($entry['workflow_step'] != $step_for_entry->get_id()) { continue; } $updated = false; $current_assignees = $step_for_entry->get_assignees(); foreach ($current_assignees as $assignee) { /* @var Gravity_Flow_Assignee $assignee */ $assignee_key = $assignee->get_key(); if (!isset($assignee_status[$assignee_key])) { // New assignee - set & send $step = $this->get_step($current_step_id, $entry); $assignee->update_status('pending'); //$step->maybe_send_assignee_notification( $assignee ); $step->end_if_complete(); $results['added'][] = $assignee; $updated = true; } } foreach ($assignee_status as $old_assignee_key => $old_status) { foreach ($current_assignees as $assignee) { $assignee_key = $assignee->get_key(); if ($assignee_key == $old_assignee_key) { continue 2; } } // No longer an assignee - remove $old_assignee = new Gravity_Flow_Assignee($old_assignee_key, $step_for_entry); $old_assignee->remove(); $old_assignee->log_event('removed'); $results['removed'][] = $old_assignee; $updated = true; } if ($updated) { $this->process_workflow($form, $entry_id); } } return $results; }