示例#1
0
 public static function store_device($device, $inputs)
 {
     $device_name = $device['name'];
     $category_id = $inputs['category_id'];
     $update_category = Category::find($category_id);
     $update_category->touch();
     $new_device = new Device();
     $new_device->name = $device_name;
     $new_device->category_id = $category_id;
     $new_device->availability = 'AVAILABLE';
     $new_device->status_id = 1;
     if ($new_device->save()) {
         foreach ($inputs as $key => $value) {
             if (strpos($key, 'field') !== false) {
                 $field = explode('-', $key);
                 $field_id = $field[1];
                 $information = new Information();
                 $information->device_id = $new_device->id;
                 $information->field_id = $field_id;
                 $information->value = $value;
                 $information->save();
             }
         }
     }
     return redirect()->back()->with('success_msg', 'Device :: ' . $new_device->name . ' was successfully saved.');
 }
示例#2
0
 public static function importInformation($request)
 {
     $new_information = new Information();
     $new_information->device_id = $request->get('device_id');
     $new_information->field_id = $request->get('field_id');
     $new_information->value = $request->get('value');
     $new_information->save();
 }
示例#3
0
 public function receiveData(Request $request)
 {
     $path = config('path');
     $device = $request->input('device');
     $type = $request->input('type');
     $value = $request->input('value');
     $date = $request->input('date');
     $device_id = Device::select('id')->where('name', '=', $device)->get();
     $type_id = Type::select('id')->where('type', '=', $type)->get();
     $mapping = Mapping::where('device_id', '=', $device_id[0]->id)->where('type_id', '=', $type_id[0]->id)->get();
     $value = $this->convert($mapping[0]->formula, $value);
     $information = new Information();
     $information->mapping_id = $mapping[0]->id;
     $information->value = $value;
     $information->timestamp = $date;
     $information->save();
     $result = shell_exec('python ' . $path . 'publish.py /regis/data/' . config('local') . ' ' . escapeshellarg(json_encode($information)));
     return "true";
 }
示例#4
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $informations = Information::All();
     $count = count($informations);
     if ($count != 0) {
         $last_id = $informations[$count - 1]->id;
         $ip = config('ip');
         $url = $ip . '/data/store';
         $client = new Client();
         $local = config('local');
         $response = $client->request('POST', $url, ['json' => ['data' => $informations, 'parameter' => 'data', 'local' => $local]]);
         // $file = '/home/vagrant/Code/iot-platform/test';
         // $current = $response->getBody()->getContents();
         // file_put_contents($file, $current);
         if ($response->getBody()->getContents() == 'true') {
             Information::where('id', '<=', $last_id)->delete();
         }
         return $this->info('Data from Local A were sent successfully!');
     }
     return $this->info('Nothing to update');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  *
  * @return Response
  */
 public function destroy($id)
 {
     Information::destroy($id);
     Session::flash('flash_message', 'Information deleted!');
     return redirect('admin/information');
 }
示例#6
0
 public function recordActivity($event)
 {
     $model = strtolower(class_basename($this));
     if ($event == "created") {
         $activity = new Activity();
         $activity->subject_id = $this->id;
         $activity->subject_type = get_class($this);
         $activity->name = $this->getActivityName($this, $event);
         $activity->user_id = Auth::guest() ? 0 : Auth::user()->id;
         if ($model == "category") {
             $activity->old_value = $this->name;
         } elseif ($model == "information") {
             $activity->old_value = $this->value;
         } elseif ($model == "field") {
             $activity->old_value = $this->category_label;
         } elseif ($model == "devicelog") {
             $activity->old_value = $this->action;
         } elseif ($model == "owner") {
             $activity->old_value = $this->fullName();
         } else {
             $activity->old_value = $this->name;
         }
         $activity->save();
     } elseif ($event == "updates") {
         if ($model == "category") {
             $activity = new Activity();
             $activity->subject_id = $this->id;
             $activity->subject_type = get_class($this);
             $activity->name = $this->getActivityName($this, $event);
             $activity->old_value = $this->name;
             $activity->new_value = Input::get('name');
             $activity->user_id = Auth::guest() ? 0 : Auth::user()->id;
             $activity->save();
             $this->name = Input::get('name');
             $this->save();
         } elseif ($model == "device") {
             $activity = new Activity();
             $activity->subject_id = $this->id;
             $activity->subject_type = get_class($this);
             $activity->name = $this->getActivityName($this, $event);
             $activity->old_value = $this->name;
             $activity->new_value = Input::get('phone_number');
             $activity->user_id = Auth::guest() ? 0 : Auth::user()->id;
             $activity->save();
             $this->phone_number = Input::get('name');
             $this->save();
         } elseif ($model == "information") {
             foreach (Input::all() as $key => $value) {
                 if (strpos($key, 'info') !== false) {
                     $key = explode('-', $key);
                     $info_id = $key[1];
                     $activity = new Activity();
                     $information = Information::find($info_id);
                     $activity->subject_id = $information->id;
                     $activity->subject_type = get_class($information);
                     $activity->name = $information->getActivityName($information, $event);
                     $activity->old_value = $information->value;
                     $activity->user_id = Auth::guest() ? 0 : Auth::user()->id;
                     $activity->save();
                     $information->value = $value;
                     $information->save();
                     $act = Activity::find($activity->id);
                     $act->new_value = $information->value;
                     $act->save();
                 }
             }
         }
     } elseif ($event == "deleted") {
         $activity = new Activity();
         $activity->subject_id = $this->id;
         $activity->subject_type = get_class($this);
         $activity->name = $this->getActivityName($this, $event);
         $activity->user_id = Auth::guest() ? 0 : Auth::user()->id;
         if ($model == "field") {
             $activity->old_value = $this->category_label;
         } elseif ($model == "information") {
             $activity->old_value = $this->value;
         } else {
             $activity->old_value = $this->name;
         }
         $activity->save();
     }
 }
示例#7
0
 public function storeInformation(Request $request)
 {
     $input = $request->all();
     Information::create($input);
     return redirect('/admin/successSend');
 }
示例#8
0
 public static function getInformationCount()
 {
     return count(Information::all());
 }
示例#9
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy(Request $request)
 {
     $user = Information::find($request->input('id'));
     $user->delete();
     return "User record successfully deleted #" . $request->input('id');
 }
示例#10
0
 public function importInformation(Request $request)
 {
     $import_information = Information::importInformation($request);
     return $import_information;
 }