public static function update($id) { $params = $_POST; $employees = Employee::all(); $attributes = array('id' => $id, 'name' => $params['name'], 'price' => $params['price'], 'description' => $params['description']); $service = new Service($attributes); $errors = $service->errors(); // $list = $_POST['checkbox']; foreach ($employees as $emp) { if (isset($_POST[$emp->id])) { OfferedServicesController::create($emp->id, $id); // $attr = array( // 'employeeid' => $emp->id, // 'serviceid' => $id // ); // $offer = new OfferedServices($attr); // $offer->save(); } else { OfferedServicesController::destroy($emp->id, $id); // $offer = new OfferedServices(array('employeeid' => $emp->id, 'serviceid' => $id)); // $offer->destroy($emp->id, $id); } } // // foreach ($list as $employee) { // $attr = array( // 'employeeid' => $employee, // 'serviceid' => $id // ); // // $offer = new OfferedServices($attr); // $offer->save(); // } $employeeList = OfferedServicesController::getEmployees($id, $employees); if (count($errors) > 0) { View::make('service/edit.html', array('errors' => $errors, 'attributes' => $attributes, 'employees' => $employees, 'employeeList' => $employeeList)); } else { $service->update(); Redirect::to('/palvelut/' . $service->id, array('message' => "Palveluun tehdyt muutokset tallennettu!")); } }
public function update($id) { $params = $_POST; $services = Service::all(); $attributes = array('id' => $id, 'name' => $params['name'], 'special' => $params['special'], 'introduction' => $params['introduction']); $employee = new Employee($attributes); $errors = $employee->errors(); foreach ($services as $serv) { if (isset($_POST[$serv->id])) { OfferedServicesController::create($id, $serv->id); } else { OfferedServicesController::destroy($id, $serv->id); } } $serviceList = OfferedServicesController::getServices($id, $services); if (count($errors) > 0) { View::make('employee/edit.html', array('errors' => $errors, 'attributes' => $attributes, 'services' => $services, 'serviceList' => $serviceList)); } else { $employee->update(); Redirect::to('/tyontekijat/' . $employee->id, array('message' => "Työntekijään tehdyt muutokset tallennettu!")); } }