/** * Removes assignees from and/or adds assignees to a step. Call after updating entry values. * Make sure you call get_assignees() before you update the entry or the previous assignees may not get removed. * * @param Gravity_Flow_Assignee[] $previous_assignees The previous assign */ public function maybe_adjust_assignment($previous_assignees) { gravity_flow()->log_debug(__METHOD__ . '(): Starting'); $new_assignees = $this->get_assignees(); $new_assignees_keys = array(); foreach ($new_assignees as $new_assignee) { $new_assignees_keys[] = $new_assignee->get_key(); } $previous_assignees_keys = array(); foreach ($previous_assignees as $previous_assignee) { $previous_assignees_keys[] = $previous_assignee->get_key(); } $assignee_keys_to_add = array_diff($new_assignees_keys, $previous_assignees_keys); $assignee_keys_to_remove = array_diff($previous_assignees_keys, $new_assignees_keys); foreach ($assignee_keys_to_add as $assignee_key_to_add) { $assignee_to_add = new Gravity_Flow_Assignee($assignee_key_to_add, $this); $assignee_to_add->update_status('pending'); } foreach ($assignee_keys_to_remove as $assignee_key_to_remove) { $assignee_to_remove = new Gravity_Flow_Assignee($assignee_key_to_remove, $this); $assignee_to_remove->remove(); } }
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; }