public function addAction($id) { /** @var Evaluation $evaluation */ $evaluation = Evaluation::find($id); if (!$evaluation) { app()->abort(422, "Parent evaluation not found"); } $model = new Assertion(); $input = Input::all(); $validator = $model->validateInput($input); if ($validator->fails()) { app()->abort(422, $validator->errors()->first()); } $model->fill(["date" => new Carbon(), "mode" => Input::get("mode"), "test_id" => Input::get("test.@id"), "test_type" => Input::get("test.@type"), "result_type" => Input::get("result.@type"), "result_outcome" => Input::get("result.outcome"), "subject_id" => LDModel::getIdFromLdId(Input::get("subject")), "asserted_by" => LDModel::getIdFromLdId(Input::get("assertedBy.@id"))]); $model->evaluation()->associate($evaluation); $model->save(); return $this->response($model); }
/** * Get Evaluation from session * * @param string $sessionKey * @param Member $user * @param Array $data * @return string sessionKey */ private static function getEvaluation($sessionKey = null, Member $user = null, $data = null) { $session = session(); $evaluation = null; if ($data && $sessionKey) { $webpage = Webpage::firstOrCreate(['url' => $data['HTTP_REFERER']]); if ($webpage->is_enabled) { $evaluation = $webpage->evaluations()->create(['member_id' => $user->id, 'ip' => $data['REMOTE_ADDR'], 'user_agent' => $data['HTTP_USER_AGENT']]); $session->put('tool.session.' . $sessionKey, $evaluation->id); } } else { if ($sessionKey) { $id = $session->get('tool.session.' . $sessionKey); $evaluation = Evaluation::find($id); } } return $evaluation; }