/** * Store a newly created WorkFlow in database * */ public function store(WorkFlowRequest $request) { $input = $request->all(); $workflow = new Work_flow($input); // If the new WorkFlow is to be the default one if ($workflow->default == 1) { // Set all others existing as not being default in database $workflows = Work_flow::all(); foreach ($workflows as $workflw) { $workflw->default = 0; $workflw->update(); } } // save new WorkFlow $workflow->save(); return redirect('workflow/create'); }
/** * Show the form for creating a new resource. * * @return Response */ public function create() { $this->middleware('super'); $batch_ids = Session::get('run_batch_ids'); $batches = Batch::whereIn('id', $batch_ids)->get(); $countProjectSamples = array(); // initialise array to count number samples with runs remaining in each project group foreach ($batches as $batch) { $countProjectSamples[$batch->project_group_id] = 0; } // count number samples with runs remaining in each selected batch foreach ($batches as $batch) { $count = 0; foreach ($batch->samples as $sample) { if ($sample->runs_remaining > 0) { $count++; } } $countProjectSamples[$batch->project_group_id] += $count; } // most common project is one with highest count of samples with runs remaining // this will be the automatically selected project to set for the run $mostCommonProject = array_keys($countProjectSamples, max($countProjectSamples)); // create list of dates so run can be scheduled up to 7 days in the future $dates = array('0' => Carbon::now()->format('d-M-Y'), '1' => Carbon::now()->addDays(1)->format('d-M-Y'), '2' => Carbon::now()->addDays(2)->format('d-M-Y'), '3' => Carbon::now()->addDays(3)->format('d-M-Y'), '4' => Carbon::now()->addDays(4)->format('d-M-Y'), '5' => Carbon::now()->addDays(5)->format('d-M-Y'), '6' => Carbon::now()->addDays(6)->format('d-M-Y'), '7' => Carbon::now()->addDays(7)->format('d-M-Y')); // for each database list find which is the default to be set in list $default_chemistry = DB::table('chemistry')->where('default', 1)->first(); $default_adaptor = DB::table('adaptor')->where('default', 1)->first(); $default_iem_file_version = DB::table('iem_file_version')->where('default', 1)->first(); $default_application = DB::table('application')->where('default', 1)->first(); $default_assay = DB::table('assay')->where('default', 1)->first(); $default_work_flow = DB::table('work_flow')->where('default', 1)->first(); $default_run_status = DB::table('run_status')->where('default', 1)->first(); // pass the selected batches and list to view to get the run header fiels to save return view('sampleRuns.createRunDetails', ['batch_ids' => $batch_ids, 'batches' => $batches, 'adaptor' => Adaptor::lists('value', 'id'), 'iem_file_version' => Iem_file_version::lists('file_version', 'id'), 'application' => Application::lists('application', 'id'), 'chemistry' => Chemistry::lists('chemistry', 'id'), 'run_status' => Run_status::lists('status', 'id'), 'instrument' => Instrument::lists('name', 'id'), 'work_flow' => Work_flow::lists('value', 'id'), 'assay' => Assay::lists('name', 'id'), 'run_date' => $dates, 'sampleRun' => SampleRun::lists('run_id', 'sample_id'), 'projectGroup' => ProjectGroup::lists('name', 'id'), 'default_chemistry_id' => $default_chemistry->id, 'default_adaptor_id' => $default_adaptor->id, 'default_iem_file_version_id' => $default_iem_file_version->id, 'default_application_id' => $default_application->id, 'default_assay_id' => $default_assay->id, 'default_work_flow_id' => $default_work_flow->id, 'default_run_status_id' => $default_run_status->id, 'default_project_id' => $mostCommonProject[0]]); }