Ejemplo n.º 1
0
 /**
  * Store a newly created instrument in storage.
  *
  * @return Response
  */
 public function store()
 {
     //
     $rules = array('name' => 'required', 'ip' => 'sometimes|ip');
     $validator = Validator::make(Input::all(), $rules);
     // Validate form input
     if ($validator->fails()) {
         return redirect()->to('instrument.create')->withErrors($validator);
     } else {
         // Save the instrument
         $newInstrument = new Instrument();
         $newInstrument->name = Input::get('name');
         $newInstrument->description = Input::get('description');
         $newInstrument->ip = Input::get('ip');
         $newInstrument->hostname = Input::get('hostname');
         $newInstrument->save();
         return redirect()->to('instrument.index')->with('message', trans('messages.success-creating-instrument'));
     }
 }
Ejemplo n.º 2
0
 /**
  * Save instrument
  *
  * @param String machineCode, String ip, optional String hostname
  * @return String success/failure message
  */
 public static function saveInstrument($code, $ip, $hostname = "")
 {
     $plugin = Instrument::getInstalledPlugins(true);
     $className = "";
     // Get the class name of the user selected plugin
     foreach ($plugin as $key => $plug) {
         // If the instrument_code matches that of the select box, WE HAVE A MATCH
         if ($key == $code) {
             $className = $plug['class'];
             break;
         }
     }
     if (class_exists($className)) {
         $instrument = new $className($ip);
         $deviceInfo = $instrument->getEquipmentInfo();
         $newInstrument = new Instrument();
         $newInstrument->name = $deviceInfo['name'];
         $newInstrument->description = $deviceInfo['description'];
         $newInstrument->driver_name = $className;
         $newInstrument->ip = $ip;
         $newInstrument->hostname = Input::get('hostname');
         try {
             $newInstrument->save();
             $newInstrument->setTestTypes($deviceInfo['testTypes']);
             return trans('messages.success-creating-instrument');
         } catch (QueryException $e) {
             Log::error($e);
         }
     }
     return trans('messages.failure-creating-instrument');
 }