Example #1
0
 /**
  * Return Configurable ID given the name
  * @param $name the name of the module
  */
 public static function idByName($name = NULL)
 {
     if ($name) {
         if ($name) {
             try {
                 $conf = Configurable::where('name', $name)->orderBy('name', 'asc')->firstOrFail();
                 return $conf->id;
             } catch (ModelNotFoundException $e) {
                 Log::error("The Configurable ` {$name} ` does not exist:  " . $e->getMessage());
                 //TODO: send email?
                 return null;
             }
         }
     } else {
         return null;
     }
 }
Example #2
0
 /**
  * @return \Illuminate\Routing\Route|null|string
  */
 public function ingnoreId()
 {
     $id = $this->route('configurable');
     $name = $this->input('name');
     return Configurable::where(compact('id', 'name'))->exists() ? $id : '';
 }
 /**
  * Remove the specified resource from storage (soft delete).
  *
  * @param  int  $id
  * @return Response
  */
 public function delete($id)
 {
     //Soft delete the Configurable
     $configurable = Configurable::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'));
 }
Example #4
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);
 }
Example #5
0
 /**
  *
  *   Function to generate config file for instrumentation
  *
  */
 public function configFile()
 {
     $id = Input::get('analyzer_id');
     $analyzer = Analyser::find($id);
     $cId = Configurable::idByName($analyzer->name);
     $setting = Configurable::find($cId);
     $fields = $setting->fields;
     // Part 1
     $file = 'BLISInterfaceClient/part1.txt';
     $current = file_get_contents($file);
     $config_p1 = str_replace("--FS--", $analyzer->feedsource(), $current);
     //Part2
     if ($analyzer->feed_source == Analyser::RS232) {
         $file = 'BLISInterfaceClient/rs232.txt';
     } else {
         if ($analyzer->feed_source == Analyser::TEXT) {
             $file = 'BLISInterfaceClient/flatfile.txt';
         } else {
             if ($analyzer->feed_source == Analyser::MSACCESS) {
                 $file = 'BLISInterfaceClient/msaccess.txt';
             } else {
                 if ($analyzer->feed_source == Analyser::HTTP) {
                     $file = 'BLISInterfaceClient/http.txt';
                 } else {
                     if ($analyzer->feed_source == Analyser::TCPIP) {
                         $file = 'BLISInterfaceClient/tcpip.txt';
                     }
                 }
             }
         }
     }
     $current = file_get_contents($file);
     $config_p2 = "";
     foreach ($fields as $field) {
         $config_p2 = str_replace("--" . $field->field_name . "--", $field->field_name . " = " . $field->conf($setting->id)->setting->value, $current);
         $current = $config_p2;
     }
     echo $config_p2;
     //Part 3
     $file = 'BLISInterfaceClient/part3.txt';
     $current = file_get_contents($file);
     $config_p3 = str_replace("--BLIS_URL--", 'http://' . $_SERVER['HTTP_HOST'], $current);
     //Part 4
     $file = 'BLISInterfaceClient/part4.txt';
     $current = file_get_contents($file);
     $config_p4 = str_replace("--EQUIP_NAME--", $analyzer->name, $current);
     //Concatenated file
     $config_file_content = $config_p1 . "\n" . $config_p2 . "\n" . $config_p3 . "\n" . $config_p4;
     $file2 = 'BLISInterfaceClient/BLISInterfaceClient.ini';
     file_put_contents($file2, $config_file_content);
 }