예제 #1
0
 /**
  * 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);
 }
예제 #2
0
 /**
  * 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'));
 }