FuelPHP Bin
<?php class Controller_Admin_Resources extends Controller_Admin{ public function action_index() { $data['items'] = Model_Resource::find('all'); $this->template->title = "Rohstoffe: Übersicht"; $this->template->content = View::forge('admin/resources/index', $data); } public function action_deleted() { $data['items'] = Model_Resource::find_deleted('all'); $this->template->title = "Rohstoffe: Übersicht (gelöschte Einträge)"; $this->template->content = View::forge('admin/resources/deleted', $data); } public function action_view($id = null) { $data['item'] = Model_Resource::find($id); $this->template->title = "Rohstoffe: Details"; $this->template->content = View::forge('admin/resources/view', $data); } public function action_create() { if (Input::method() == 'POST') { $val = Model_Resource::validate('create'); if ($val->run()) { $item = Model_Resource::forge(array( 'title' => Input::post('title'), 'text' => Input::post('text'), 'basic' => Input::post('basic'), 'type' => Input::post('type', 1), //if needed later for different resource types, actually not in edit action 'position' => Input::post('position', 0), )); $item->image = Model_Image::find(Input::post('image')); if ($item and $item->save()) { // Save same value as ID for position $item->position = $item->id; $item->save(); Session::set_flash('success', e('Anlage erfolgreich')); Response::redirect('admin/resources'); } else { Session::set_flash('error', e('Anlage NICHT erfolgreich')); } } else { Session::set_flash('error', $val->error()); } } $data['images'] = Model_Image::find('all', array('where' => array('category' => 'resources'))); //show only pictures of category resources $this->template->title = "Rohstoffe: Anlage"; $this->template->content = View::forge('admin/resources/create', $data); } public function action_edit($id = null) { $item = Model_Resource::find($id); $images = Model_Image::find('all', array('where' => array('category' => 'resources'))); //show only pictures of category resources $image = array($item->image['id'] => $item->image); $val = Model_Resource::validate('edit'); if ($val->run()) { $item->title = Input::post('title'); $item->text = Input::post('text'); $item->basic = Input::post('basic'); $item->position = Input::post('position'); $item->image = Model_Image::find(Input::post('image')); if ($item->save()) { Session::set_flash('success', e('Bearbeitung erfolgreich')); Response::redirect('admin/resources'); } else { Session::set_flash('error', e('Bearbeitung NICHT erfolgreich')); } } else { if (Input::method() == 'POST') { $item->title = $val->validated('title'); $item->text = $val->validated('text'); $item->basic = $val->validated('basic'); $item->type = $val->validated('type'); $item->position = $val->validated('position'); Session::set_flash('error', $val->error()); } $this->template->set_global('item', $item, false); } $data['images'] = $images; $data['rel_image'] = Functions::objectsArrayToKeysTrueFalse($images, $image); $this->template->title = "Rohstoffe: Bearbeitung"; $this->template->content = View::forge('admin/resources/edit', $data); } public function action_deleteimage($id = null) { if ($item = Model_Resource::find($id)) { $item->image = null; $item->save(); Session::set_flash('success', e('Löschen der Bildzuweisung erfolgreich')); } else { Session::set_flash('error', e('Löschen der Bildzuweisung NICHT erfolgreich')); } Response::redirect('admin/resources'); } public function action_delete($id = null) { if ($item = Model_Resource::find($id)) { $item->delete(); Session::set_flash('success', e('Löschen erfolgreich')); } else { Session::set_flash('error', e('Löschen NICHT erfolgreich')); } Response::redirect('admin/resources'); } public function action_restore($id = null) { if ($item = Model_Resource::find_deleted($id)) { $item->restore(); Session::set_flash('success', e('Wiederherstellung erfolgreich')); } else { Session::set_flash('error', e('Wiederherstellung NICHT erfolgreich')); } Response::redirect('admin/resources'); } public function action_purge($id = null) { if ($item = Model_Resource::find($id)) { $item->purge(); Session::set_flash('success', e('Entgültiges Löschen erfolgreich')); } else { Session::set_flash('error', e('Entgültiges Löschen NICHT erfolgreich')); } Response::redirect('admin/resources'); } }