/** * Reorders actions within a definition * * @param WorkflowDefinition|WorkflowAction $objects * The objects to be reordered * @param array $newOrder * An array of IDs of the actions in the order they should be. */ public function reorder($objects, $newOrder) { $sortVals = array_values($objects->map('ID', 'Sort')->toArray()); sort($sortVals); // save the new ID values - but only use existing sort values to prevent // conflicts with items not in the table foreach ($newOrder as $key => $id) { if (!$id) { continue; } $object = $objects->find('ID', $id); $object->Sort = $sortVals[$key]; $object->write(); } }