public function postAdd() { $fields = ["name" => Input::get("name")]; $rules = ["name" => "required"]; $customMessages = ["name.required" => "Поле \"Заголовок\" обязательно для заполнения"]; $validator = Validator::make($fields, $rules, $customMessages); if ($validator->fails()) { $error = ""; foreach (array_keys($fields) as $k) { $message = $validator->messages()->first($k); if ($message) { $error .= "<div>" . $message . "</div>"; } } return Redirect::to($_SERVER["HTTP_REFERER"])->with("error", $error); } $item = new Workshift(); $item->name = Input::get("name"); $item->from_hour = Input::get("from_hour"); $item->from_min = Input::get("from_min"); $item->to_hour = Input::get("to_hour"); $item->to_min = Input::get("to_min"); $item->comment = Input::get("comment"); $item->save(); return Redirect::to("/structure/workshifts")->with("message", "Вариант смен опубликован"); }
/** * Test method for delete(). */ public function testDelete() { // Test for id not available $workshift = new Workshift(); $workshift->setWorkshiftId(15); try { $workshift->delete(); $this->fail("Non existing ID was not checked!"); } catch (WorkshiftException $e) { $this->assertEquals(WorkshiftException::INVALID_ROW_COUNT, $e->getCode()); } // Test for valid id $workshift = new Workshift(); $workshift->setName("Delete Shift"); $workshift->setHoursPerDay(7); $workshift->save(); // Check the saving $id = $workshift->getWorkshiftId(); $updatedRow = $this->_getWorkshift($id); $this->assertNotNull($updatedRow); // check whether the ID exists $workshift->delete(); $id = $workshift->getWorkshiftId(); $updatedRow = $this->_getWorkshift($id); $this->assertNull($updatedRow); // Empty id $workshift = new Workshift(); try { $workshift->delete(); $this->fail("Empty ID was not checked!"); } catch (WorkshiftException $e) { $this->assertEquals(WorkshiftException::INVALID_ID, $e->getCode()); } // Invalid id $workshift = new Workshift(); $workshift->setWorkshiftId("'fgW"); try { $workshift->delete(); $this->fail("Invalid ID was not checked!"); } catch (WorkshiftException $e) { $this->assertEquals(WorkshiftException::INVALID_ID, $e->getCode()); } }