/** * Store a newly created Project Group in database. * */ public function store(ProjectGroupRequest $request) { $input = $request->all(); $project_group = new ProjectGroup($input); $project_group->save(); return redirect('project_groups/create'); }
public function edit(Sample $sample) { $iSet = IndexSet::lists('name', 'id'); $iAll = IndexSet::all(); $pg = ProjectGroup::lists('name', 'id'); // Set the page where edit came from session(['edit_sample_url' => Request::server('HTTP_REFERER')]); return view('samples.edit', ['iSet' => $iSet, 'iAll' => $iAll, 'pg' => $pg, 'sample' => $sample]); }
public function edit(Batch $batch) { /* Should user be creator of batch to edit? Probably either 'creator || super' */ $pg = ProjectGroup::lists('name', 'id'); $charge = $batch->charge_code; $my_group = $batch->project_group_id; return view('batches.edit', ['batch' => $batch, 'pg' => $pg, 'charge' => $charge, 'my_group' => $my_group]); }
/** * 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]]); }
/** * Builds a new group for a project. * * @param $pid * @param Request $request * @return ProjectGroup */ private function buildGroup($pid, Request $request) { $group = new ProjectGroup(); $group->name = $request['name']; $group->pid = $pid; $group->create = 0; $group->edit = 0; $group->delete = 0; if (!is_null($request['create'])) { $group->create = 1; } if (!is_null($request['edit'])) { $group->edit = 1; } if (!is_null($request['delete'])) { $group->delete = 1; } $group->save(); return $group; }
/** * Creates the project's admin Group. * * @param $project * @param $request * @return Group */ private function makeAdminGroup($project, $request) { $groupName = $project->name; $groupName .= ' Admin Group'; $adminGroup = new ProjectGroup(); $adminGroup->name = $groupName; $adminGroup->pid = $project->pid; $adminGroup->save(); if (!is_null($request['admins'])) { $adminGroup->users()->attach($request['admins']); } $adminGroup->create = 1; $adminGroup->edit = 1; $adminGroup->delete = 1; $adminGroup->save(); return $adminGroup; }
public function restoreData(Request $request) { $this->json_file = null; $this->decoded_json = null; $users_exempt_from_lockout = new Collection(); $users_exempt_from_lockout->put(1, 1); //Add another one of these with (userid,userid) to exempt extra users $this->lockUsers($users_exempt_from_lockout); if ($request->session()->has("restore_file_path")) { $filepath = $request->session()->get("restore_file_path"); $request->session()->forget("restore_file_path"); } else { return $this->ajaxResponse(false, "You did not select a valid restore point or upload a valid backup file"); } try { $this->json_file = Storage::get($filepath); } catch (\Exception $e) { $this->ajaxResponse(false, "The backup file couldn't be opened. Make sure it still exists and the permissions are correct."); } try { $this->decoded_json = json_decode($this->json_file); $this->decoded_json->kora3; } catch (\Exception $e) { $this->ajaxResponse(false, "The backup file contains invalid JSON data, it may be corrupt or damaged. Check the file or try another one.\n The restore did not start, so data already in the database was not deleted."); } $backup_data = $this->decoded_json; //Delete all existing data try { foreach (User::all() as $User) { if ($User->id == 1) { //Do not delete the default admin user continue; } else { $User->delete(); } } foreach (Project::all() as $Project) { $Project->delete(); } foreach (Form::all() as $Form) { $Form->delete(); } foreach (Field::all() as $Field) { $Field->delete(); } foreach (Record::all() as $Record) { $Record->delete(); } foreach (Metadata::all() as $Metadata) { $Metadata->delete(); } foreach (Token::all() as $Token) { $Token->delete(); } foreach (Revision::all() as $Revision) { $Revision->delete(); } foreach (DateField::all() as $DateField) { $DateField->delete(); } foreach (FormGroup::all() as $FormGroup) { $FormGroup->delete(); } foreach (GeneratedListField::all() as $GeneratedListField) { $GeneratedListField->delete(); } foreach (ListField::all() as $ListField) { $ListField->delete(); } foreach (MultiSelectListField::all() as $MultiSelectListField) { $MultiSelectListField->delete(); } foreach (NumberField::all() as $NumberField) { $NumberField->delete(); } foreach (ProjectGroup::all() as $ProjectGroup) { $ProjectGroup->delete(); } foreach (RichTextField::all() as $RichTextField) { $RichTextField->delete(); } foreach (ScheduleField::all() as $ScheduleField) { $ScheduleField->delete(); } foreach (TextField::all() as $TextField) { $TextField->delete(); } } catch (\Exception $e) { $this->ajaxResponse(false, "There was a problem when attempting to remove existing information from the\n database, the database user may not have permission to do this or the database may be in use."); } try { //This try-catch is for non-QueryExceptions, like if a table is missing entirely from the JSON data // User foreach ($backup_data->users as $user) { try { $new_user = User::create(array("username" => $user->username, "name" => $user->name, "email" => $user->email, "password" => $user->password, "organization" => $user->organization, "language" => $user->language, "regtoken" => $user->regtoken)); $new_user->id = $user->id; $new_user->admin = $user->admin; $new_user->active = $user->active; $new_user->remember_token = $user->remember_token; $new_user->created_at = $user->created_at; $new_user->updated_at = $user->updated_at; $new_user->locked_out = true; $new_user->save(); } catch (\Exception $e) { $this->ajax_error_list->push($e->getMessage()); } } // Project foreach ($backup_data->projects as $project) { //$new_project = Project::create(array("name" => $project->name, "slug" => $project->slug, "description" => $project->description, "adminGID" => $project->adminGID, "active" => $project->active)); try { $new_project = Project::create(array()); $new_project->name = $project->name; $new_project->slug = $project->slug; $new_project->description = $project->description; $new_project->adminGID = $project->adminGID; $new_project->active = $project->active; $new_project->pid = $project->pid; $new_project->created_at = $project->created_at; $new_project->updated_at = $project->updated_at; $new_project->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // Form foreach ($backup_data->forms as $form) { try { $new_form = Form::create(array("pid" => $form->pid)); $new_form->fid = $form->fid; $new_form->name = $form->name; $new_form->slug = $form->slug; $new_form->description = $form->description; $new_form->adminGID = $form->adminGID; $new_form->layout = $form->layout; $new_form->public_metadata = $form->public_metadata; $new_form->layout = $form->layout; $new_form->adminGID = $form->adminGID; $new_form->created_at = $form->created_at; $new_form->updated_at = $form->updated_at; $new_form->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // Field foreach ($backup_data->fields as $field) { try { $new_field = Field::create(array("pid" => $field->pid, "fid" => $field->fid, "order" => $field->order, "type" => $field->type, "name" => $field->name, "slug" => $field->slug, "desc" => $field->desc, "required" => $field->required, "default" => $field->default, "options" => $field->options)); $new_field->flid = $field->flid; $new_field->default = $field->default; $new_field->options = $field->options; $new_field->created_at = $field->created_at; $new_field->updated_at = $field->updated_at; $new_field->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // FormGroup foreach ($backup_data->formgroups as $formgroup) { try { $new_formgroup = new FormGroup(); $new_formgroup->name = $formgroup->group_data->name; $new_formgroup->fid = $formgroup->group_data->fid; $new_formgroup->create = $formgroup->group_data->create; $new_formgroup->edit = $formgroup->group_data->edit; $new_formgroup->ingest = $formgroup->group_data->ingest; $new_formgroup->delete = $formgroup->group_data->delete; $new_formgroup->modify = $formgroup->group_data->modify; $new_formgroup->destroy = $formgroup->group_data->destroy; $new_formgroup->id = $formgroup->group_data->id; $new_formgroup->created_at = $formgroup->group_data->created_at; $new_formgroup->updated_at = $formgroup->group_data->updated_at; $new_formgroup->save(); foreach ($formgroup->user_data as $user_id) { $new_formgroup->users()->attach($user_id); } } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // ProjectGroup foreach ($backup_data->projectgroups as $projectgroup) { try { $new_projectgroup = new ProjectGroup(); $new_projectgroup->id = $projectgroup->group_data->id; $new_projectgroup->name = $projectgroup->group_data->name; $new_projectgroup->pid = $projectgroup->group_data->pid; $new_projectgroup->create = $projectgroup->group_data->create; $new_projectgroup->edit = $projectgroup->group_data->edit; $new_projectgroup->delete = $projectgroup->group_data->delete; $new_projectgroup->created_at = $projectgroup->group_data->created_at; $new_projectgroup->updated_at = $projectgroup->group_data->updated_at; $new_projectgroup->save(); foreach ($projectgroup->user_data as $user_id) { $new_projectgroup->users()->attach($user_id); } } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // Record foreach ($backup_data->records as $record) { try { $new_record = new Record(array("pid" => $record->pid, "fid" => $record->fid, "owner" => $record->owner, "kid" => $record->kid)); $new_record->rid = $record->rid; $new_record->created_at = $record->created_at; $new_record->updated_at = $record->updated_at; $new_record->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // TextField foreach ($backup_data->textfields as $textfield) { try { $new_textfield = new TextField(array("rid" => $textfield->rid, "flid" => $textfield->flid, "text" => $textfield->text)); $new_textfield->id = $textfield->id; $new_textfield->created_at = $textfield->created_at; $new_textfield->updated_at = $textfield->updated_at; $new_textfield->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // RichTextField foreach ($backup_data->richtextfields as $richtextfield) { try { $new_richtextfield = new RichTextField(array("rid" => $richtextfield->rid, "flid" => $richtextfield->flid, "rawtext" => $richtextfield->rawtext)); $new_richtextfield->id = $richtextfield->id; $new_richtextfield->created_at = $richtextfield->created_at; $new_richtextfield->updated_at = $richtextfield->updated_at; $new_richtextfield->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // NumberField foreach ($backup_data->numberfields as $numberfield) { try { $new_numberfield = new NumberField(array("rid" => $numberfield->rid, "flid" => $numberfield->flid, "number" => $numberfield->number)); $new_numberfield->id = $numberfield->id; $new_numberfield->created_at = $numberfield->created_at; $new_numberfield->updated_at = $numberfield->updated_at; $new_numberfield->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // ListField foreach ($backup_data->listfields as $listfield) { try { $new_listfield = new ListField(array("rid" => $listfield->rid, "flid" => $listfield->flid, "option" => $listfield->option)); $new_listfield->id = $listfield->id; $new_listfield->created_at = $listfield->created_at; $new_listfield->updated_at = $listfield->updated_at; $new_listfield->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // GeneratedListField foreach ($backup_data->generatedlistfields as $generatedlistfield) { try { $new_generatedlistfield = new GeneratedListField(array("rid" => $generatedlistfield->rid, "flid" => $generatedlistfield->flid, "options" => $generatedlistfield->options)); $new_generatedlistfield->id = $generatedlistfield->id; $new_generatedlistfield->created_at = $generatedlistfield->created_at; $new_generatedlistfield->updated_at = $generatedlistfield->updated_at; $new_generatedlistfield->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // MultiSelectListField foreach ($backup_data->multiselectlistfields as $multiselectlistfield) { try { $new_multiselectlistfield = new MultiSelectListField(array("rid" => $multiselectlistfield->rid, "flid" => $multiselectlistfield->flid, "options" => $multiselectlistfield->options)); $new_multiselectlistfield->id = $multiselectlistfield->id; $new_multiselectlistfield->created_at = $multiselectlistfield->created_at; $new_multiselectlistfield->updated_at = $multiselectlistfield->updated_at; $new_multiselectlistfield->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // DateField foreach ($backup_data->datefields as $datefield) { try { $new_datefield = new DateField(); $new_datefield->id = $datefield->id; $new_datefield->rid = $datefield->rid; $new_datefield->flid = $datefield->flid; $new_datefield->circa = $datefield->circa; $new_datefield->month = $datefield->month; $new_datefield->day = $datefield->day; $new_datefield->year = $datefield->year; $new_datefield->era = $datefield->era; $new_datefield->created_at = $datefield->created_at; $new_datefield->updated_at = $datefield->updated_at; $new_datefield->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // ScheduleField foreach ($backup_data->schedulefields as $schedulefield) { try { $new_schedulefield = new ScheduleField(array("rid" => $schedulefield->rid, "flid" => $schedulefield->flid, "events" => $schedulefield->events)); $new_schedulefield->id = $schedulefield->id; $new_schedulefield->created_at = $schedulefield->created_at; $new_schedulefield->updated_at = $schedulefield->updated_at; $new_schedulefield->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // GeolocatorField foreach ($backup_data->geolocatorfields as $geolocatorfield) { try { $new_geolocatorfield = new GeolocatorField(array("rid" => $geolocatorfield->rid, "flid" => $geolocatorfield->flid, "locations" => $geolocatorfield->locations)); $new_geolocatorfield->id = $geolocatorfield->id; $new_geolocatorfield->created_at = $geolocatorfield->created_at; $new_geolocatorfield->updated_at = $new_geolocatorfield->updated_at; $new_geolocatorfield->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // Token foreach ($backup_data->tokens as $token) { try { $new_token = new Token(array('token' => $token->token, 'type' => $token->type)); $new_token->id = $token->id; $new_token->created_at = $token->created_at; $new_token->updated_at = $token->updated_at; $new_token->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // Metadata foreach ($backup_data->metadatas as $metadata) { try { $new_metadata = new Metadata(array()); $new_metadata->flid = $metadata->flid; $new_metadata->pid = $metadata->pid; $new_metadata->fid = $metadata->fid; $new_metadata->name = $metadata->name; $new_metadata->created_at = $metadata->created_at; $new_metadata->updated_at = $metadata->updated_at; $new_metadata->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } // Revision foreach ($backup_data->revisions as $revision) { try { $new_revision = new Revision(array('id' => $revision->id, 'fid' => $revision->fid, 'rid' => $revision->rid, 'userId' => $revision->userId, 'type' => $revision->type, 'data' => $revision->data, 'oldData' => $revision->oldData, 'rollback' => $revision->rollback)); $new_revision->created_at = $revision->created_at; $new_revision->updated_at = $revision->updated_at; $new_revision->save(); } catch (QueryException $e) { $this->ajax_error_list->push($e->getMessage()); } } } catch (\Exception $e) { $this->ajax_error_list->push($e->getMessage()); $this->ajaxResponse(false, "An unknown error prevented the restore from completing.\n You can try restoring from a different backup file or restore point.\n Users will stay locked out until you run a successful restore or manually unlock them above.\n For this error, it's not recommended that you unlock users unless you have resolved the problem"); } if (count($this->ajax_error_list) != 0) { $this->ajaxResponse(false, "Not all of your data was restored, check the errors below for details.\n The errors are in order that they occurred, if you can resolve the first error, it will often correct\n one or more of the errors below it.\n Users will stay locked out until you run a successful restore or manually unlock them above."); } else { $this->unlockUsers(); $this->ajaxResponse(true, "The restore completed successfully."); } }