/** * Store a newly created resource in storage. * * @param \App\Http\Requests\OptionRequest $request * @param \App\Criteria $criteria * @return \Illuminate\Http\Response */ public function store(Requests\OptionRequest $request, Criteria $criteria) { DB::transaction(function () use($criteria, $request) { $option = $criteria->options()->create(['sort' => $request->get('sort')]); $langs = []; foreach (LaravelLocalization::getSupportedLocales() as $short => $locale) { $langs[] = ['lang_id' => dbTrans($short), 'title' => $request->get('title_' . $short)]; } $option->langs()->createMany($langs); }); return redirect(action('Admin\\CriteriaOptionController@index', [$criteria->id]))->with('success', 'saved'); }
public function cloneCriteras($sourceAsgId, $destinationAsgId) { $sourceAsg = $this->withinGpAsgsController->getAsg($sourceAsgId); $sourceCriterias = $sourceAsg->criterias; foreach ($sourceCriterias as $sourceCriteria) { $criteria = new Criteria(); $criteria->asg_id = $destinationAsgId; $criteria->name = $sourceCriteria->name; $criteria->criteria_gp_id = $sourceCriteria->criteria_gp_id; $criteria->save(); } return true; }
/** * @param int paper * save reviewer evaluation * @return \Illuminate\Http\Response */ public function postEvaluate($paper) { $paper = Paper::findOrFail($paper); if ($paper->department_id != auth()->user()->department_id || !systemAccess(2)) { if (!$this->systemAdmin) { return redirect()->action('Admin\\PaperController@index')->with('error', 'access-denied'); } } $criteriaPaper = $rules = $params = $errors = []; $criteria = Criteria::where('department_id', $paper->department_id)->with(['langs' => function ($query) { $query->lang(); }])->get(); foreach ($criteria as $value) { $errors[$value->id] = $value->langs->first()->title; if (request()->has($value->id)) { $params[$value->id] = request($value->id); $criteriaPaper[$value->id] = ['value' => request($value->id)]; } if ($value->required) { $rules[$value->id] = 'required'; } if ($value->type_id == 1) { $max = 'max:1500'; if (isset($rules[$value->id])) { $rules[$value->id] .= '|' . $max; } else { $rules[$value->id] = $max; } } } $validator = Validator::make($params, $rules); $validator->setAttributeNames($errors); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput(); } DB::transaction(function () use($criteriaPaper, $paper) { $paper->update(['status_id' => 4, 'reviewed_at' => Carbon::now()]); $paper->criteria()->sync($criteriaPaper); }); if (request()->get('email')) { event(new PaperWasFinished($paper)); } return redirect()->action('Admin\\PaperController@index')->with('success', 'paper-evaluated'); }
/** * Remove the specified resource from storage. * * @param \App\Criteria $criteria * @return \Illuminate\Http\Response */ public function destroy(Criteria $criteria) { $criteria->delete(); return redirect(action('Admin\\CriteriaController@index'))->with('success', 'deleted'); }