/** * Действие для создания игрока */ public function action_create() { if (\Input::method() == 'POST') { $val = \Model_Staff::validate('create'); if ($val->run()) { // Валидация для фото $config = array('path' => DOCROOT . 'assets/img/staff', 'randomize' => true, 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png')); \Upload::process($config); if (\Upload::is_valid() or \Upload::get_errors()[0]['errors'][0]['error'] == 4) { $player = \Model_Staff::forge(array('staff_name' => \Input::post('staff_name'), 'birthdate' => strtotime(\Input::post('birthdate')), 'data' => \Input::post('data'))); if (!\Upload::get_errors()) { // Сохраняем файл на диск \Upload::save(); // Меняем размер изображения на 350px * 466px $files = \Upload::get_files(); $path = $files[0]['saved_to'] . $files[0]['saved_as']; \Image::load($path)->resize(350, 466, true)->save($path); $player->image_uri = $files[0]['saved_as']; } // Пишем инфу в БД if ($player and $player->save()) { \Session::set_flash('success', 'Персонал создан.'); \Response::redirect_back('admin/staff'); } else { \Session::set_flash('error', 'Could not save Staff.'); } } } else { \Session::set_flash('error', $val->error()); } // Если есть ошибки при сохранении файла foreach (\Upload::get_errors() as $file) { if (isset($file['errors'][0]) and $file['errors'][0]['error'] != 4) { \Session::set_flash('error', $file['errors'][0]['message']); } } } $this->template->content = \View::forge('staff/create'); }
public function action_create() { if (Input::method() == 'POST') { $val = Model_Staff::validate('create'); if ($val->run()) { $staff = Model_Staff::forge(array('first_name' => Input::post('first_name'), 'last_name' => Input::post('last_name'), 'intranet_id' => Input::post('intranet_id'), 'dialler_id' => Input::post('dialler_id'), 'debtsolv_id' => Input::post('debtsolv_id'), 'network_id' => Input::post('network_id'), 'center_id' => Input::post('center_id'), 'department_id' => Input::post('department_id'), 'active' => Input::post('active'))); if ($staff and $staff->save()) { Session::set_flash('success', 'Added staff #' . $staff->id . '.'); Response::redirect('staff'); } else { Session::set_flash('error', 'Could not save staff.'); } } else { Session::set_flash('error', $val->error()); } } $departments = Model_Staff_Department::find('all'); $centers = Model_Call_Center::find('all'); $this->template->set_global('departments', $departments, false); $this->template->set_global('centers', $centers, false); $this->template->title = "Staffs"; $this->template->content = View::forge('staff/create'); }