public function action_sort($type = false) { if (!$type) { return false; } $items = \Input::post('sort'); if (is_array($items)) { foreach ($items as $item) { list($item, $old_item) = explode('_', $item); if (is_numeric($item)) { $sort[] = $item; } if (is_numeric($old_item)) { $old_sort[] = $old_item; } } if (is_array($sort)) { // Get starting point for sort $start = min($old_sort); $start = $start > 0 ? --$start : $start; $model = Model_Casestudy::factory(ucfirst($type)); foreach ($sort as $key => $id) { $item = $model::find_one_by_id($id); $item->set(array('cover' => $key == 0 ? 1 : 0, 'sort' => ++$start)); $item->save(); } \Messages::success('Items successfully reordered.'); echo \Messages::display('left', false); } } }