public function setFields($fields) { $this->fields()->delete(); foreach ($fields as $field) { $fieldModel = new Field($field); if (isset($field['preset'])) { $fieldModel->preset()->associate(new Preset($field['preset'])); } $this->fields()->associate($fieldModel); } return $this; }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $fields = Field::orderBy('field_name')->get(); //Get the Configurable $configurable = Configurable::find($id); //Open the Edit View and pass to it the $configurable return view('config.configurable.edit', compact('configurable', 'fields')); }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); // $this->call(UserTableSeeder::class); $field = Field::create(); for ($i = 0; $i < Config::get('settings.players'); $i++) { $player = Player::create(); $field->addPlayer($player); } Model::reguard(); }
public function index() { $fields = Field::all(); $fileTitles = File::distinct()->groupBy('parsed_title')->select('parsed_title')->get(); $fileArray = []; foreach ($fileTitles as $title) { $file = File::where('parsed_title', '=', $title->parsed_title)->select('parsed_date', 'full_title')->orderBy('parsed_date', 'desc'); $fileData = $file->get(); foreach ($file->get() as $multiFile) { $fileArray[$title->parsed_title][] = $multiFile; } } return view("home.index")->with('fileArray', $fileArray); }
private function saveHeaders($file, $fileID) { //create the path $fileName = base_path() . "/public/files/" . $file->getClientOriginalName(); //create the empty arrays $columnTitles = []; $taxonomyArray = []; $fieldArray = []; //load the file $rows = Excel::load($fileName, function ($reader) { })->get(); //set the values of the columns as the header foreach ($rows as $title => $value) { //set the row data foreach ($value as $key => $column) { $columnTitles[$key][] = $column; } } $files = File::find($fileID); foreach ($columnTitles as $key => $value) { $field_tax = Field_Taxonomy::where('title', '=', $key); $fieldTaxID = 0; $count = 1; //if the title doesn't exist as a record in the field_tax table if ($field_tax->count() === 0) { //grab the id of the newly inserted taxonomy record $fieldTaxID = Field_Taxonomy::insertGetId(['title' => $key]); foreach ($value as $data) { Field::insert(['value' => $data, 'field_taxonomy_id' => $fieldTaxID, 'row_in_file' => $count]); $count++; } File_Field_Taxonomy::insert(['file_id' => $fileID, 'field_taxonomy_id' => $fieldTaxID]); } else { $fileArr = explode(".", $file->getClientOriginalName()); $fileTitleArr = explode("_", $fileArr[0]); $fieldTax = Field_Taxonomy::take(1)->select('field_taxonomy_table.id')->join('file_field_taxonomy_table', 'file_field_taxonomy_table.field_taxonomy_id', '=', 'field_taxonomy_table.id')->join('files', 'files.id', '=', 'file_field_taxonomy_table.file_id')->where('title', '=', $key)->where('parsed_title', '=', $fileTitleArr[0])->get(); if (count($fieldTax) > 0) { $fieldTaxID = $fieldTax[0]->id; } else { $fieldTaxID = Field_Taxonomy::insertGetId(['title' => $key]); } foreach ($value as $data) { Field::insert(['value' => $data, 'field_taxonomy_id' => $fieldTaxID, 'row_in_file' => $count]); $count++; } File_Field_Taxonomy::insert(['file_id' => $fileID, 'field_taxonomy_id' => $fieldTaxID]); } } }
/** * Return field ID given the name * @param $name the name of the field */ public static function idByName($name = NULL) { if ($name) { try { $field = Field::where('field_name', $name)->orderBy('field_name', 'asc')->firstOrFail(); return $field->id; } catch (ModelNotFoundException $e) { Log::error("The field ` {$name} ` does not exist: " . $e->getMessage()); //TODO: send email? return null; } } else { return null; } }
public function getFields() { return $this->hasMany(Field::className(), ['category' => 'id'])->where(['not', ['status' => Field::STATUS_DELETED]])->orderBy('id'); }
/** * Remove the specified resource from storage (soft delete). * * @param int $id * @return Response */ public function delete($id) { //Soft delete the Field $field = Field::find($id); /*$testCategoryInUse = TestType::where('test_category_id', '=', $id)->first(); if (empty($testCategoryInUse)) { // The test category is not in use $testcategory->delete(); } else { // The test category is in use $url = Session::get('SOURCE_URL'); return Redirect::to($url) ->with('message', trans('terms.failure-test-category-in-use')); }*/ // redirect $url = session('SOURCE_URL'); return redirect()->to($url)->with('message', trans('terms.record-successfully-deleted')); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(AnalyserRequest $request, $id) { $analyser = Analyser::find($id); $analyser->name = $request->name; $analyser->version = $request->version; $analyser->test_category_id = $request->test_category_id; $analyser->comm_type = $request->comm_type; $analyser->feed_source = $request->feed_source; $analyser->config_file = $request->config_file; $analyser->description = $request->description; $analyser->user_id = 1; $analyser->save(); //dd(Configurable::idByName($analyser->name)); /* Proceed to update the corresponding equipment */ if (count(Configurable::where('name', $analyser->name)->get()) > 0) { $configurable = Configurable::where('name', $analyser->name)->first(); } else { $configurable = new Configurable(); } $configurable->name = $analyser->name; $configurable->user_id = 1; $configurable->save(); /* Delete existing configs */ DB::table('configurable_fields')->where('configurable_id', '=', $configurable->id)->delete(); /* Save configurable-fields for the configurable RS232,TCP/IP, MSACCESS,HTTP,TEXT */ $fields = []; if ($analyser->feed_source == Analyser::RS232) { $fields = Field::RS232; } else { if ($analyser->feed_source == Analyser::TCPIP) { $fields = Field::TCPIP; } else { if ($analyser->feed_source == Analyser::MSACCESS) { $fields = Field::MSACCESS; } else { if ($analyser->feed_source == Analyser::TEXT) { $fields = Field::TEXT; } } } } foreach ($fields as $field) { $fId = Field::idByName($field); $conf = ConField::where('configurable_id', $configurable->id)->where('field_id', $fId)->first(); if ($conf) { $conField = ConField::find($conf->id); } else { $conField = new ConField(); } $conField->configurable_id = $configurable->id; $conField->field_id = $fId; $conField->user_id = 1; $conField->save(); } $url = session('SOURCE_URL'); return redirect()->to($url)->with('message', trans('terms.record-successfully-saved'))->with('active_analyser', $analyser->id); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update($id) { if (Input::get('equi')) { $anId = Input::get('equi'); $id = Configurable::idByName(Analyser::find($anId)->name); } $conf = Configurable::find((int) $id); foreach (Input::all() as $key => $value) { if (stripos($key, 'token') !== FALSE || stripos($key, 'method') !== FALSE || stripos($key, 'equi') !== FALSE) { continue; } else { if (stripos($key, 'field') !== FALSE) { if (strlen($value) > 0) { $fieldId = $this->strip($key); $conId = ConField::where('configurable_id', $conf->id)->where('field_id', (int) $fieldId)->first(); $counter = count(LabConfig::where('key', $conId->id)->get()); if ($counter == 0) { $setting = new LabConfig(); } else { $setting = LabConfig::where('key', $conId->id)->first(); } $setting->key = $conId->id; $setting->value = $value; if (Field::find($fieldId)->field_type == Field::FILEBROWSER) { $setting->value = $this->imageModifier(Input::file('field_' . $fieldId)); } $setting->user_id = 1; $counter == 0 ? $setting->save() : $setting->update(); } } } } $url = session('SOURCE_URL'); return redirect()->to($url)->with('message', trans('terms.record-successfully-updated')); }
/** * @return \Illuminate\Routing\Route|null|string */ public function ingnoreId() { $id = $this->route('field'); $name = $this->input('name'); return Field::where(compact('id', 'name'))->exists() ? $id : ''; }